Skip to content

Commit 68d20eb

Browse files
Sebastian Andrzej Siewioraxboe
authored andcommitted
zram: Shrink zram_table_entry::flags.
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 <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Reviewed-by: Jens Axboe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 6086aeb commit 68d20eb

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2404,9 +2404,10 @@ static void destroy_devices(void)
24042404

24052405
static int __init zram_init(void)
24062406
{
2407+
struct zram_table_entry zram_te;
24072408
int ret;
24082409

2409-
BUILD_BUG_ON(__NR_ZRAM_PAGEFLAGS > BITS_PER_LONG);
2410+
BUILD_BUG_ON(__NR_ZRAM_PAGEFLAGS > sizeof(zram_te.flags) * 8);
24102411

24112412
ret = cpuhp_setup_state_multi(CPUHP_ZCOMP_PREPARE, "block/zram:prepare",
24122413
zcomp_cpu_up_prepare, zcomp_cpu_dead);

drivers/block/zram/zram_drv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct zram_table_entry {
6666
unsigned long handle;
6767
unsigned long element;
6868
};
69-
unsigned long flags;
69+
unsigned int flags;
7070
spinlock_t lock;
7171
#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
7272
ktime_t ac_time;

0 commit comments

Comments
 (0)