Re: [PATCH 1/3] zram: use u32 for entry ac_time tracking
From: Sergey Senozhatsky
Date: Wed Jan 14 2026 - 22:13:52 EST
On (26/01/14 04:45), Chris Mason wrote:
> > @@ -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".
Good catch.
I think it simply should be like this now (I don't think anyone uses
this function tho):
---
drivers/block/zram/zram_drv.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index cc51aa8b6181..912711faa4e4 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1579,11 +1579,9 @@ static ssize_t read_block_state(struct file *file, char __user *buf,
if (!slot_allocated(zram, index))
goto next;
- 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,
+ "%12zd %12u.%06lu %c%c%c%c%c%c\n",
+ index, zram->table[index].attr.ac_time, 0,
test_slot_flag(zram, index, ZRAM_SAME) ? 's' : '.',
test_slot_flag(zram, index, ZRAM_WB) ? 'w' : '.',
test_slot_flag(zram, index, ZRAM_HUGE) ? 'h' : '.',
--
2.52.0.457.g6b5491de43-goog