[PATCH] zram: drop slot trylock and miss_free

Sergey Senozhatsky posted 1 patch 11 hours ago
drivers/block/zram/zram_drv.c | 34 +++-------------------------------
drivers/block/zram/zram_drv.h |  1 -
2 files changed, 3 insertions(+), 32 deletions(-)
[PATCH] zram: drop slot trylock and miss_free
Posted by Sergey Senozhatsky 11 hours ago
Commit e914d8f00391 ("mm: fix unexpected zeroed page
mapping with zram swap") removed swap_slot_free_notify()
calls from end_io callbacks.  This means that there is
no more slot_free_notify() from IRQ context and hence
slot-free cannot deadlock on slot lock any more.  Drop
slot trylock.

Suggested-by: Richard Chang <richardycc@google.com>
Suggested-by: David Stevens <stevensd@google.com>
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 drivers/block/zram/zram_drv.c | 34 +++-------------------------------
 drivers/block/zram/zram_drv.h |  1 -
 2 files changed, 3 insertions(+), 32 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 61d3e2c74901..c2894023c0cd 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -74,23 +74,7 @@ static void slot_lock_init(struct zram *zram, u32 index)
  * 2) lock() function can sleep waiting for the lock
  *
  * 3) Lock owner can sleep
- *
- * 4) Use TRY lock variant when in atomic context
- *    - must check return value and handle locking failers
  */
-static __must_check bool slot_trylock(struct zram *zram, u32 index)
-{
-	unsigned long *lock = &zram->table[index].__lock;
-
-	if (!test_and_set_bit_lock(ZRAM_ENTRY_LOCK, lock)) {
-		mutex_acquire(slot_dep_map(zram, index), 0, 1, _RET_IP_);
-		lock_acquired(slot_dep_map(zram, index), _RET_IP_);
-		return true;
-	}
-
-	return false;
-}
-
 static void slot_lock(struct zram *zram, u32 index)
 {
 	unsigned long *lock = &zram->table[index].__lock;
@@ -1943,15 +1927,9 @@ static ssize_t debug_stat_show(struct device *dev,
 {
 	int version = 1;
 	struct zram *zram = dev_to_zram(dev);
-	ssize_t ret;
 
 	guard(rwsem_read)(&zram->dev_lock);
-	ret = sysfs_emit(buf,
-			"version: %d\n0 %8llu\n",
-			version,
-			(u64)atomic64_read(&zram->stats.miss_free));
-
-	return ret;
+	return sysfs_emit(buf, "version: %d\n0 0\n", version);
 }
 
 static void zram_meta_free(struct zram *zram, u64 disksize)
@@ -2814,16 +2792,10 @@ static void zram_submit_bio(struct bio *bio)
 static void zram_slot_free_notify(struct block_device *bdev,
 				unsigned long index)
 {
-	struct zram *zram;
-
-	zram = bdev->bd_disk->private_data;
+	struct zram *zram = bdev->bd_disk->private_data;
 
 	atomic64_inc(&zram->stats.notify_free);
-	if (!slot_trylock(zram, index)) {
-		atomic64_inc(&zram->stats.miss_free);
-		return;
-	}
-
+	slot_lock(zram, index);
 	slot_free(zram, index);
 	slot_unlock(zram, index);
 }
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 515a72d9c06f..d90d9b6c9575 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -87,7 +87,6 @@ struct zram_stats {
 	atomic64_t huge_pages_since;	/* no. of huge pages since zram set up */
 	atomic64_t pages_stored;	/* no. of pages currently stored */
 	atomic_long_t max_used_pages;	/* no. of maximum pages stored */
-	atomic64_t miss_free;		/* no. of missed free */
 #ifdef	CONFIG_ZRAM_WRITEBACK
 	atomic64_t bd_count;		/* no. of pages in backing device */
 	atomic64_t bd_reads;		/* no. of reads from backing device */
-- 
2.53.0.239.g8d8fc8a987-goog
Re: [PATCH] zram: drop slot trylock and miss_free
Posted by Matthew Wilcox 31 minutes ago
On Tue, Feb 10, 2026 at 12:50:37PM +0900, Sergey Senozhatsky wrote:
> @@ -1943,15 +1927,9 @@ static ssize_t debug_stat_show(struct device *dev,
>  {
>  	int version = 1;
>  	struct zram *zram = dev_to_zram(dev);
> -	ssize_t ret;
>  
>  	guard(rwsem_read)(&zram->dev_lock);
> -	ret = sysfs_emit(buf,
> -			"version: %d\n0 %8llu\n",
> -			version,
> -			(u64)atomic64_read(&zram->stats.miss_free));
> -
> -	return ret;
> +	return sysfs_emit(buf, "version: %d\n0 0\n", version);
>  }

You don't need the dev_lock any more to just report the version.
And should the version be changed now that you've changed the format to
not include miss_free?
Re: [PATCH] zram: drop slot trylock and miss_free
Posted by Sergey Senozhatsky 10 hours ago
On (26/02/10 12:50), Sergey Senozhatsky wrote:
> Commit e914d8f00391 ("mm: fix unexpected zeroed page
> mapping with zram swap") removed swap_slot_free_notify()
> calls from end_io callbacks.  This means that there is
> no more slot_free_notify() from IRQ context and hence
> slot-free cannot deadlock on slot lock any more.  Drop
> slot trylock.

Oh, please ignore this patch.  I realized it doesn't make sense,
we can drop miss_free, but trylock has to stay.