Re: [PATCH 1/3] zram: use u32 for entry ac_time tracking

From: Chris Mason

Date: Wed Jan 14 2026 - 07:45:47 EST


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

> We can reduce sizeof(zram_table_entry) on 64-bit systems
> by converting flags and ac_time to u32. Entry flags fit
> into u32, and for ac_time u32 gives us over a century of
> entry lifespan (approx 136 years) which is plenty (zram
> uses system boot time (seconds)).
>
> In struct zram_table_entry we use bytes aliasing, because
> bit-wait API (for slot lock) requires a whole unsigned
> long word.

Hi everyone,

I ran mm-new through the AI patch review prompts, and this one was flagged:

> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c

[ ... ]

> @@ -222,7 +221,7 @@ 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].ac_time = ktime_get_boottime();
> + zram->table[index].attr.ac_time = (u32)ktime_get_boottime_seconds();
> #endif
> }

This stores seconds in ac_time.

[ ... ]

> @@ -1588,7 +1588,7 @@ static ssize_t read_block_state(struct file *file, char __user *buf,
> if (!zram_allocated(zram, index))
> goto next;
>
> - ts = ktime_to_timespec64(zram->table[index].ac_time);
> + ts = ktime_to_timespec64(zram->table[index].attr.ac_time);
> copied = snprintf(kbuf + written, count,
> "%12zd %12lld.%06lu %c%c%c%c%c%c\n",
> index, (s64)ts.tv_sec,
> ts.tv_nsec / NSEC_PER_USEC,

ktime_to_timespec64() is defined as ns_to_timespec64(), which expects
nanoseconds. Since ac_time now stores seconds, will this produce
incorrect output?

For example, if ac_time is 3600 (representing 1 hour of uptime),
ns_to_timespec64(3600) would compute ts.tv_sec = 3600 / 1000000000 = 0
and ts.tv_nsec = 3600, resulting in "0.000003" instead of "3600.000000".