Re: [PATCH v2] zram: fix idle age_sec underflow in idle_store()
From: Hao Jia
Date: Mon Aug 31 2026 - 04:54:12 EST
On 2026/8/31 12:15, Sergey Senozhatsky wrote:
On (26/08/28 10:24), Andrew Morton wrote:
On Fri, 28 Aug 2026 16:31:49 +0800 Hao Jia <jiahao.kernel@xxxxxxxxx> wrote:[..]
Thanks. Sashiko asked a couple of questions about this change:
https://sashiko.dev/#/patchset/20260828083149.45760-1-jiahao.kernel@xxxxxxxxx
Does this early return prevent marking valid boot-time pages as idle?
When a page is accessed during the first second of system boot, its ac_time
would be 0.
There is no possibility for zram to hold pages during first second of
system boot, regardless of whether zram was configured as a swap device
or as a block device (mount-ed with real filesystem).
Can the early return above bypass this zram device initialization check?
We already do that, e.g. when kstrtouint(buf, 0, &age_sec) fails. Apart
from that, that's not how one checks if device was initialized. We may
want to consolidate those checks, just for symmetry.
Agreed on both points -- the early return is not a new "bypass", and
the write() return value was never a way to probe init state.
How about moving the init_done() check to the top, so all the early
returns sit behind the same device-state check?
static ssize_t idle_store(...)
{
struct zram *zram = dev_to_zram(dev);
time64_t cutoff = 0;
guard(rwsem_read)(&zram->dev_lock);
if (!init_done(zram))
return -EINVAL;
if (!sysfs_streq(buf, "all")) {
...
}
mark_idle(zram, cutoff);
return len;
}
The read lock then also covers the parsing, but that is non-sleeping
and its cost is negligible.
Thanks,
Hao