]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
zram: Shrink zram_table_entry::flags.
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Fri, 6 Sep 2024 14:14:45 +0000 (16:14 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 6 Sep 2024 14:51:08 +0000 (08:51 -0600)
The zram_table_entry::flags member is of type long and uses 8 bytes on a
64bit architecture. With a PAGE_SIZE of 256KiB we have PAGE_SHIFT of 18
which in turn leads to __NR_ZRAM_PAGEFLAGS = 27. This still fits in an
ordinary integer.
By reducing the size of `flags' to four bytes, the size of the struct
goes back to 16 bytes. The padding between the lock and ac_time (if
enabled) is also gone.

Make zram_table_entry::flags an unsigned int and update the build test
to reflect the change.

Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Link: https://lore.kernel.org/r/20240906141520.730009-4-bigeasy@linutronix.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/zram/zram_drv.c
drivers/block/zram/zram_drv.h

index 60946a9a7bc4306bbd98129468245986aa9be5ac..84cd62efac0f640d21c364e55b2dc14eebadee6a 100644 (file)
@@ -2404,9 +2404,10 @@ static void destroy_devices(void)
 
 static int __init zram_init(void)
 {
+       struct zram_table_entry zram_te;
        int ret;
 
-       BUILD_BUG_ON(__NR_ZRAM_PAGEFLAGS > BITS_PER_LONG);
+       BUILD_BUG_ON(__NR_ZRAM_PAGEFLAGS > sizeof(zram_te.flags) * 8);
 
        ret = cpuhp_setup_state_multi(CPUHP_ZCOMP_PREPARE, "block/zram:prepare",
                                      zcomp_cpu_up_prepare, zcomp_cpu_dead);
index 262fa960a0783eb4f2d7e8adbab9bced0b933416..531cefc6666823fad187b97f5ec57ebdd6313cae 100644 (file)
@@ -66,7 +66,7 @@ struct zram_table_entry {
                unsigned long handle;
                unsigned long element;
        };
-       unsigned long flags;
+       unsigned int flags;
        spinlock_t lock;
 #ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
        ktime_t ac_time;