Skip to content

Commit 4df9106

Browse files
ftang1torvalds
authored andcommitted
mm: memcg: relayout structure mem_cgroup to avoid cache interference
0day reported one -22.7% regression for will-it-scale page_fault2 case [1] on a 4 sockets 144 CPU platform, and bisected to it to be caused by Waiman's optimization (commit bd0b230) of saving one 'struct page_counter' space for 'struct mem_cgroup'. Initially we thought it was due to the cache alignment change introduced by the patch, but further debug shows that it is due to some hot data members ('vmstats_local', 'vmstats_percpu', 'vmstats') sit in 2 adjacent cacheline (2N and 2N+1 cacheline), and when adjacent cache line prefetch is enabled, it triggers an "extended level" of cache false sharing for 2 adjacent cache lines. So exchange the 2 member blocks, while keeping mostly the original cache alignment, which can restore and even enhance the performance, and save 64 bytes of space for 'struct mem_cgroup' (from 2880 to 2816, with 0day's default RHEL-8.3 kernel config) [1]. https://lore.kernel.org/lkml/20201102091543.GM31092@shao2-debian/ Fixes: bd0b230 ("mm/memcg: unify swap and memsw page counters") Reported-by: kernel test robot <[email protected]> Signed-off-by: Feng Tang <[email protected]> Acked-by: Waiman Long <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent fa02fcd commit 4df9106

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

include/linux/memcontrol.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,6 @@ struct mem_cgroup {
282282

283283
MEMCG_PADDING(_pad1_);
284284

285-
/*
286-
* set > 0 if pages under this cgroup are moving to other cgroup.
287-
*/
288-
atomic_t moving_account;
289-
struct task_struct *move_lock_task;
290-
291-
/* Legacy local VM stats and events */
292-
struct memcg_vmstats_percpu __percpu *vmstats_local;
293-
294-
/* Subtree VM stats and events (batched updates) */
295-
struct memcg_vmstats_percpu __percpu *vmstats_percpu;
296-
297-
MEMCG_PADDING(_pad2_);
298-
299285
atomic_long_t vmstats[MEMCG_NR_STAT];
300286
atomic_long_t vmevents[NR_VM_EVENT_ITEMS];
301287

@@ -317,6 +303,20 @@ struct mem_cgroup {
317303
struct list_head objcg_list; /* list of inherited objcgs */
318304
#endif
319305

306+
MEMCG_PADDING(_pad2_);
307+
308+
/*
309+
* set > 0 if pages under this cgroup are moving to other cgroup.
310+
*/
311+
atomic_t moving_account;
312+
struct task_struct *move_lock_task;
313+
314+
/* Legacy local VM stats and events */
315+
struct memcg_vmstats_percpu __percpu *vmstats_local;
316+
317+
/* Subtree VM stats and events (batched updates) */
318+
struct memcg_vmstats_percpu __percpu *vmstats_percpu;
319+
320320
#ifdef CONFIG_CGROUP_WRITEBACK
321321
struct list_head cgwb_list;
322322
struct wb_domain cgwb_domain;

0 commit comments

Comments
 (0)