* [PATCH RESEND v2] mm/percpu-internal.h: optimise pcpu_chunk struct to save memory
@ 2026-05-11 7:03 Hongling Zeng
2026-05-12 22:03 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Hongling Zeng @ 2026-05-11 7:03 UTC (permalink / raw)
To: dennis, tj, cl, akpm; +Cc: linux-mm, kernel, zhongling0719, zenghongling
From: zenghongling <zenghongling@kylinos.cn>
Using pahole, we can see that there are some padding holes
in the current pcpu_chunk structure,Adjusting the layout of pcpu_chunk
can reduce these holes,decreasing its size from 192 bytes to 128 bytes
and eliminating a wasted cache line.
With allmodconfig (CONFIG_PERCPU_STATS + NEED_PCPUOBJ_EXT)
Before:
/* size: 256, cachelines: 4, members: 19 */
After:
/* size: 192, cachelines: 3, members: 19 */
with NEED_PCPUOBJ_EXT
Before:
struct pcpu_chunk {
struct list_head list; /* 0 16 */
int free_bytes; /* 16 4 */
struct pcpu_block_md chunk_md; /* 20 32 */
/* XXX 4 bytes hole, try to pack */
long unsigned int * bound_map; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
void * base_addr __attribute__((__aligned__(64))); /* 64 8 */
long unsigned int * alloc_map; /* 72 8 */
struct pcpu_block_md * md_blocks; /* 80 8 */
void * data; /* 88 8 */
bool immutable; /* 96 1 */
bool isolated; /* 97 1 */
/* XXX 2 bytes hole, try to pack */
int start_offset; /* 100 4 */
int end_offset; /* 104 4 */
/* XXX 4 bytes hole, try to pack */
struct obj_cgroup * * obj_cgroups; /* 112 8 */
int nr_pages; /* 120 4 */
int nr_populated; /* 124 4 */
/* --- cacheline 2 boundary (128 bytes) --- */
int nr_empty_pop_pages; /* 128 4 */
/* XXX 4 bytes hole, try to pack */
long unsigned int populated[]; /* 136 0 */
/* size: 192, cachelines: 3, members: 17 */
/* sum members: 122, holes: 4, sum holes: 14 */
/* padding: 56 */
/* forced alignments: 1 */
} __attribute__((__aligned__(64)));
After:
struct pcpu_chunk {
struct list_head list; /* 0 16 */
int free_bytes; /* 16 4 */
struct pcpu_block_md chunk_md; /* 20 32 */
/* XXX 4 bytes hole, try to pack */
long unsigned int * bound_map; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
void * base_addr __attribute__((__aligned__(64))); /* 64 8 */
long unsigned int * alloc_map; /* 72 8 */
struct pcpu_block_md * md_blocks; /* 80 8 */
void * data; /* 88 8 */
bool immutable; /* 96 1 */
bool isolated; /* 97 1 */
/* XXX 2 bytes hole, try to pack */
int start_offset; /* 100 4 */
int end_offset; /* 104 4 */
int nr_pages; /* 108 4 */
int nr_populated; /* 112 4 */
int nr_empty_pop_pages; /* 116 4 */
struct obj_cgroup * * obj_cgroups; /* 120 8 */
/* --- cacheline 2 boundary (128 bytes) --- */
long unsigned int populated[]; /* 128 0 */
/* size: 128, cachelines: 2, members: 17 */
/* sum members: 122, holes: 2, sum holes: 6 */
/* forced alignments: 1 */
} __attribute__((__aligned__(64)));
Suggested-by: Dennis Zhou <dennis@kernel.org>
Signed-off-by: zenghongling <zenghongling@kylinos.cn>
---
Changes in v2:
- Add pahole output for allmodconfig (CONFIG_PERCPU_STATS + NEED_PCPUOBJ_EXT)
- Fix subject to use "pcpu_chuck struct"
- Reorder nr_pages before nr_empty_pop_pages
- Add suggest by
Changes in v1:
- Fix the error commit message.
- Move nr_pages over nr_empty_pop_pages.
---
---
mm/percpu-internal.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/percpu-internal.h b/mm/percpu-internal.h
index 4b3d6ec43703..8cbe039bf847 100644
--- a/mm/percpu-internal.h
+++ b/mm/percpu-internal.h
@@ -77,13 +77,13 @@ struct pcpu_chunk {
int end_offset; /* additional area required to
have the region end page
aligned */
+ int nr_pages; /* # of pages served by this chunk */
+ int nr_populated; /* # of populated pages */
+ int nr_empty_pop_pages; /* # of empty populated pages */
#ifdef NEED_PCPUOBJ_EXT
struct pcpuobj_ext *obj_exts; /* vector of object cgroups */
#endif
- int nr_pages; /* # of pages served by this chunk */
- int nr_populated; /* # of populated pages */
- int nr_empty_pop_pages; /* # of empty populated pages */
unsigned long populated[]; /* populated bitmap */
};
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND v2] mm/percpu-internal.h: optimise pcpu_chunk struct to save memory
2026-05-11 7:03 [PATCH RESEND v2] mm/percpu-internal.h: optimise pcpu_chunk struct to save memory Hongling Zeng
@ 2026-05-12 22:03 ` Andrew Morton
2026-05-13 8:23 ` Dennis Zhou
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2026-05-12 22:03 UTC (permalink / raw)
To: Hongling Zeng; +Cc: dennis, tj, cl, linux-mm, kernel, zhongling0719
On Mon, 11 May 2026 15:03:09 +0800 Hongling Zeng <zenghongling@kylinos.cn> wrote:
> Using pahole, we can see that there are some padding holes
> in the current pcpu_chunk structure,Adjusting the layout of pcpu_chunk
> can reduce these holes,decreasing its size from 192 bytes to 128 bytes
> and eliminating a wasted cache line.
>
> With allmodconfig (CONFIG_PERCPU_STATS + NEED_PCPUOBJ_EXT)
> Before:
> /* size: 256, cachelines: 4, members: 19 */
>
> After:
> /* size: 192, cachelines: 3, members: 19 */
Thanks, I'll add this to mm.git for testing, but I'm not planning on
taking it further until Dennis has taken a look.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND v2] mm/percpu-internal.h: optimise pcpu_chunk struct to save memory
2026-05-12 22:03 ` Andrew Morton
@ 2026-05-13 8:23 ` Dennis Zhou
0 siblings, 0 replies; 3+ messages in thread
From: Dennis Zhou @ 2026-05-13 8:23 UTC (permalink / raw)
To: Andrew Morton
Cc: Hongling Zeng, dennis, tj, cl, linux-mm, kernel, zhongling0719
Hi Andrew,
On Tue, May 12, 2026 at 03:03:40PM -0700, Andrew Morton wrote:
> On Mon, 11 May 2026 15:03:09 +0800 Hongling Zeng <zenghongling@kylinos.cn> wrote:
>
> > Using pahole, we can see that there are some padding holes
> > in the current pcpu_chunk structure,Adjusting the layout of pcpu_chunk
> > can reduce these holes,decreasing its size from 192 bytes to 128 bytes
> > and eliminating a wasted cache line.
> >
> > With allmodconfig (CONFIG_PERCPU_STATS + NEED_PCPUOBJ_EXT)
> > Before:
> > /* size: 256, cachelines: 4, members: 19 */
> >
> > After:
> > /* size: 192, cachelines: 3, members: 19 */
>
> Thanks, I'll add this to mm.git for testing, but I'm not planning on
> taking it further until Dennis has taken a look.
>
Sorry, I thought we took care of this one prior before. This is per
chunk metadata, so it won't save much. That being said it doesn't hurt.
Acked-by: Dennis Zhou <dennis@kernel.org>
I'm thinking about the other percpu series now.
Thanks,
Dennis
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-13 8:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11 7:03 [PATCH RESEND v2] mm/percpu-internal.h: optimise pcpu_chunk struct to save memory Hongling Zeng
2026-05-12 22:03 ` Andrew Morton
2026-05-13 8:23 ` Dennis Zhou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox