Re: [PATCH] mm/percpu-internal.h: optimise pcpu_chunk_struct to save memory

Dennis Zhou
2026-03-27T07:32:10Z

Hello,

On Thu, Mar 26, 2026 at 10:16:41PM -0700, Andrew Morton wrote:
> On Thu, 5 Mar 2026 15:30:43 +0800 zenghongling <zenghongling@kylinos.cn> wrote:
>
> > Subject: [PATCH] mm/percpu-internal.h: optimise pcpu_chunk_struct to save memory
>
> There is no pcpu_chunk_struct, I'll change this to "struct pcpu_chunk".
>
> > Date: Thu, 5 Mar 2026 15:30:43 +0800
> > Sender: owner-linux-mm@kvack.org
> > X-Mailer: git-send-email 2.25.1
> >
> > The pcpu_chunk_struct has a hole of 4 bytes and pushes the struct to three
> > cachelines. Relocating the three booleans upwards allows for the struct
> > to only use two cachelines.
>

Wait, this patch moves `int nr_empty_pop_pages` not 3 booleans?

> before:
>
> (gdb) p sizeof(struct pcpu_chunk)
> $2 = 256
>
> after:
>
> (gdb) p sizeof(struct pcpu_chunk)
> $1 = 192
>
> That's remarkable. It was an allmodconfig build which tends to add
> bloat, but the only source-level alteration was this patch.
>

There is also still PERCPU_STATS at the beginning of the chunk depending
on config, defaults no.

struct pcpu_chunk {
#ifdef CONFIG_PERCPU_STATS
int nr_alloc; /* # of allocations */
size_t max_alloc_size; /* largest allocation size */
#endif

In my experience this is an order 10s - 100 # of chunks. So this would
save give or take like 4k.

>
> Another consideration here is that moving members around can have a
> performance impact - it can cause more (or less) cacheline
> invalidations. I worry that because someone has carefully commented
> all the member offsets, this might have been a consideration.
>

I'd probably move nr_pages over nr_empty_pop_pages as if you're touching
the populated[] array, you're more likely to touch nr_empty_pop_pages.

> Also I think your patch may have made those comments incorrect?
>
>
> Dennis, Tejun, Christoph: I think we want this space saving. Can
> you please advise?
>

I don't think it hurts. I'd move nr_pages over nr_empty_pop_pages.

Thanks,
Dennis