Re: [PATCH v2] zram: fix idle age_sec underflow in idle_store()

From: Sergey Senozhatsky

Date: Mon Aug 31 2026 - 06:04:37 EST


On (26/08/31 16:37), Hao Jia wrote:
> 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?

Yeah, I don't know... Moving it under device lock doesn't buy us
anything. We don't need device lock to validate integer rangers,
etc. There are validations that we need to do under device lock
because those require a consistent device state. But things like
"is system uptime less than supplied sysfs data" don't logically
require a device lock.