From: Brian Geffon <bgeffon@google.com>
To: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Minchan Kim <minchan@kernel.org>,
Yuwen Chen <ywen.chen@foxmail.com>,
Richard Chang <richardycc@google.com>,
Fengyu Lian <licayy@outlook.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-block@vger.kernel.org
Subject: Re: [RFC PATCHv5 4/6] zram: drop wb_limit_lock
Date: Thu, 20 Nov 2025 11:03:45 -0500 [thread overview]
Message-ID: <CADyq12zxgAAHWn61wECEo=StOm2DAEFU_qUL83tv0aT5S9mb0w@mail.gmail.com> (raw)
In-Reply-To: <20251120152126.3126298-5-senozhatsky@chromium.org>
On Thu, Nov 20, 2025 at 10:22 AM Sergey Senozhatsky
<senozhatsky@chromium.org> wrote:
>
> We don't need wb_limit_lock. Writeback limit setters take an
> exclusive write zram init_lock, while wb_limit modifications
> happen only from a single task and under zram read init_lock.
> No concurrent wb_limit modifications are possible (we permit
> only one post-processing task at a time). Add lockdep
> assertions to wb_limit mutators.
>
> While at it, fixup coding styles.
>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Brian Geffon <bgeffon@google.com>
> ---
> drivers/block/zram/zram_drv.c | 22 +++++-----------------
> drivers/block/zram/zram_drv.h | 1 -
> 2 files changed, 5 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 71f37b960812..671ef2ec9b11 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -530,9 +530,7 @@ static ssize_t writeback_limit_enable_store(struct device *dev,
> return ret;
>
> down_write(&zram->init_lock);
> - spin_lock(&zram->wb_limit_lock);
> zram->wb_limit_enable = val;
> - spin_unlock(&zram->wb_limit_lock);
> up_write(&zram->init_lock);
> ret = len;
>
> @@ -547,9 +545,7 @@ static ssize_t writeback_limit_enable_show(struct device *dev,
> struct zram *zram = dev_to_zram(dev);
>
> down_read(&zram->init_lock);
> - spin_lock(&zram->wb_limit_lock);
> val = zram->wb_limit_enable;
> - spin_unlock(&zram->wb_limit_lock);
> up_read(&zram->init_lock);
>
> return sysfs_emit(buf, "%d\n", val);
> @@ -567,9 +563,7 @@ static ssize_t writeback_limit_store(struct device *dev,
> return ret;
>
> down_write(&zram->init_lock);
> - spin_lock(&zram->wb_limit_lock);
> zram->bd_wb_limit = val;
> - spin_unlock(&zram->wb_limit_lock);
> up_write(&zram->init_lock);
> ret = len;
>
> @@ -577,15 +571,13 @@ static ssize_t writeback_limit_store(struct device *dev,
> }
>
> static ssize_t writeback_limit_show(struct device *dev,
> - struct device_attribute *attr, char *buf)
> + struct device_attribute *attr, char *buf)
> {
> u64 val;
> struct zram *zram = dev_to_zram(dev);
>
> down_read(&zram->init_lock);
> - spin_lock(&zram->wb_limit_lock);
> val = zram->bd_wb_limit;
> - spin_unlock(&zram->wb_limit_lock);
> up_read(&zram->init_lock);
>
> return sysfs_emit(buf, "%llu\n", val);
> @@ -869,18 +861,18 @@ static struct zram_wb_ctl *init_wb_ctl(struct zram *zram)
>
> static void zram_account_writeback_rollback(struct zram *zram)
> {
> - spin_lock(&zram->wb_limit_lock);
> + lockdep_assert_held_read(&zram->init_lock);
> +
> if (zram->wb_limit_enable)
> zram->bd_wb_limit += 1UL << (PAGE_SHIFT - 12);
> - spin_unlock(&zram->wb_limit_lock);
> }
>
> static void zram_account_writeback_submit(struct zram *zram)
> {
> - spin_lock(&zram->wb_limit_lock);
> + lockdep_assert_held_read(&zram->init_lock);
> +
> if (zram->wb_limit_enable && zram->bd_wb_limit > 0)
> zram->bd_wb_limit -= 1UL << (PAGE_SHIFT - 12);
> - spin_unlock(&zram->wb_limit_lock);
> }
>
> static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)
> @@ -1004,13 +996,10 @@ static int zram_writeback_slots(struct zram *zram,
> u32 index = 0;
>
> while ((pps = select_pp_slot(ctl))) {
> - spin_lock(&zram->wb_limit_lock);
> if (zram->wb_limit_enable && !zram->bd_wb_limit) {
> - spin_unlock(&zram->wb_limit_lock);
> ret = -EIO;
> break;
> }
> - spin_unlock(&zram->wb_limit_lock);
>
> while (!req) {
> req = zram_select_idle_req(wb_ctl);
> @@ -2961,7 +2950,6 @@ static int zram_add(void)
> init_rwsem(&zram->init_lock);
> #ifdef CONFIG_ZRAM_WRITEBACK
> zram->wb_batch_size = 32;
> - spin_lock_init(&zram->wb_limit_lock);
> #endif
>
> /* gendisk structure */
> diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
> index 1a647f42c1a4..c6d94501376c 100644
> --- a/drivers/block/zram/zram_drv.h
> +++ b/drivers/block/zram/zram_drv.h
> @@ -127,7 +127,6 @@ struct zram {
> bool claim; /* Protected by disk->open_mutex */
> #ifdef CONFIG_ZRAM_WRITEBACK
> struct file *backing_dev;
> - spinlock_t wb_limit_lock;
> bool wb_limit_enable;
> u32 wb_batch_size;
> u64 bd_wb_limit;
> --
> 2.52.0.rc1.455.g30608eb744-goog
>
next prev parent reply other threads:[~2025-11-20 16:04 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-20 15:21 [RFC PATCHv5 0/6] zram: introduce writeback bio batching Sergey Senozhatsky
2025-11-20 15:21 ` [RFC PATCHv5 1/6] " Sergey Senozhatsky
2025-11-21 7:05 ` Yuwen Chen
2025-11-21 7:18 ` Sergey Senozhatsky
2025-11-21 7:40 ` Hannes Reinecke
2025-11-21 7:47 ` Sergey Senozhatsky
2025-11-20 15:21 ` [RFC PATCHv5 2/6] zram: add writeback batch size device attr Sergey Senozhatsky
2025-11-20 15:57 ` Brian Geffon
2025-11-21 1:56 ` Sergey Senozhatsky
2025-11-21 2:48 ` Sergey Senozhatsky
2025-11-20 15:21 ` [RFC PATCHv5 3/6] zram: take write lock in wb limit store handlers Sergey Senozhatsky
2025-11-20 16:03 ` Brian Geffon
2025-11-20 15:21 ` [RFC PATCHv5 4/6] zram: drop wb_limit_lock Sergey Senozhatsky
2025-11-20 16:03 ` Brian Geffon [this message]
2025-11-20 15:21 ` [RFC PATCHv5 5/6] zram: rework bdev block allocation Sergey Senozhatsky
2025-11-20 16:35 ` Brian Geffon
2025-11-20 15:21 ` [RFC PATCHv5 6/6] zram: read slot block idx under slot lock Sergey Senozhatsky
2025-11-20 18:13 ` Brian Geffon
2025-11-24 14:49 ` Brian Geffon
2025-11-21 7:14 ` [RFC PATCHv5 0/6] zram: introduce writeback bio batching Yuwen Chen
2025-11-21 7:32 ` Sergey Senozhatsky
2025-11-21 7:44 ` Yuwen Chen
2025-11-21 7:58 ` Sergey Senozhatsky
2025-11-21 8:23 ` Yuwen Chen
2025-11-21 9:12 ` Sergey Senozhatsky
2025-11-21 12:21 ` Gao Xiang
2025-11-21 12:43 ` Gao Xiang
2025-11-22 10:07 ` Sergey Senozhatsky
2025-11-22 12:24 ` Gao Xiang
2025-11-22 13:43 ` Sergey Senozhatsky
2025-11-22 14:09 ` Gao Xiang
2025-11-23 0:08 ` Sergey Senozhatsky
2025-11-23 1:23 ` Gao Xiang
2025-11-23 3:07 ` Sergey Senozhatsky
2025-11-23 0:22 ` Sergey Senozhatsky
2025-11-23 1:39 ` Gao Xiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADyq12zxgAAHWn61wECEo=StOm2DAEFU_qUL83tv0aT5S9mb0w@mail.gmail.com' \
--to=bgeffon@google.com \
--cc=akpm@linux-foundation.org \
--cc=licayy@outlook.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=richardycc@google.com \
--cc=senozhatsky@chromium.org \
--cc=ywen.chen@foxmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox