Re: [PATCH 2/3] zram: rename internal slot API

From: Chris Mason

Date: Wed Jan 14 2026 - 07:37:19 EST


On Mon, 15 Dec 2025 14:47:12 +0900 Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx> wrote:

> We have a somewhat confusing internal API naming. E.g.
> the following code:
>
> zram_slot_lock()
> if (zram_allocated())
> zram_set_flag()
> zram_slot_unlock()
>
> may look like it does something on zram device level, but in
> fact it tests and sets slot entry flags, not the device ones.
>
> Rename API to explicitly distinguish functions that operate on
> the slot level from functions that operate on the zram device
> level.
>
> While at it, fixup some coding styles.

Hi everyone,

I ran mm-new through the AI patch review prompts and this one was flagged.
It uses a lot of words here to suggest a copy/paste error, but it does look
right to me:

> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 65f99ff3e2e54..f00f3d22d5e32 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c

[ ... ]

> +static void mark_slot_accessed(struct zram *zram, u32 index)
> +{
> + clear_slot_flag(zram, index, ZRAM_IDLE);
> + clear_slot_flag(zram, index, ZRAM_PP_SLOT);
> +#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
> + zram->table[index].attr.ac_time = ktime_get_boottime();
^^^^^^^^^^^^^^^^^^^^

The previous commit (472f3f208d78e "zram: use u32 for entry ac_time
tracking") changed this from ktime_get_boottime() to
(u32)ktime_get_boottime_seconds() because ac_time was changed from
ktime_t to u32.

This patch appears to revert that change, storing the result of
ktime_get_boottime() (which returns a 64-bit nanosecond value) into
the u32 ac_time field. This truncates to the lower 32 bits, which
wraps every ~4.29 seconds.

The result is that mark_idle() will compare ktime_after(cutoff, ac_time)
using a truncated nanosecond value, causing pages to be incorrectly
marked as IDLE almost immediately after being accessed.

Was this change intentional, or was it accidentally reverted during
the rename refactoring?

> +#endif
> +}

[ ... ]

> -static void zram_accessed(struct zram *zram, u32 index)
> -{
> - zram_clear_flag(zram, index, ZRAM_IDLE);
> - zram_clear_flag(zram, index, ZRAM_PP_SLOT);
> -#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
> - zram->table[index].attr.ac_time = (u32)ktime_get_boottime_seconds();
> -#endif
> -}

This is the original code that was correctly using
ktime_get_boottime_seconds() with the u32 cast. The new
mark_slot_accessed() function above should preserve this behavior.