Re: [PATCH] kernfs: reorder 'struct kernfs_node' to save some memory

From: Greg Kroah-Hartman
Date: Sun Nov 26 2023 - 10:17:31 EST


On Sun, Nov 26, 2023 at 03:49:37PM +0100, Christophe JAILLET wrote:
> 'struct kernfs_node' uses a dedicated cache, so shrinking its size is
> always a good idea.
>
> On my system, each entry is 128 bytes and their are 32 entries per pages.
> After the re-ordering, the struct is 120 bytes and 34 entries are stored
> in each page.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
> ---
> The numbers below are with a allmodconfig configuration. The delta is
> related to CONFIG_DEBUG_LOCK_ALLOC and struct lockdep_map dep_map.
>
> When I checked on my system, it would have saved 372kb of RAM:
> sudo less /proc/slabinfo | grep kernf
> kernfs_node_cache 49397 49504 128 32 1 : tunables 0 0 0 : slabdata 1547 1547 0
>
> I have left flags close to the union, I *think* that they are related.
> I don't if having 'mode' here is logical or not.

I'm all for fixing up holes, but have you checked this before and after
with lockdep disabled? That's usually the biggest chunk, and can cause
alignment issues, perhaps moving that to the end would make more sense?
With that, I think everything can fit in 2 cachelines except for the
lockdep structure?

thanks,

greg k-h