summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorShakeel Butt <shakeel.butt@linux.dev>2026-09-04 20:05:19 -0700
committerAndrew Morton <akpm@linux-foundation.org>2026-10-08 22:54:40 -0700
commit0ceeb2c7c543a660b1f58a7ba113c9fa2e269661 (patch)
tree8d879333b28c0e4c0360a8f21edce1e9e7d0d695 /include/linux
parent43eae38b7b294e6320a48e3f0a799ec6de3d34f6 (diff)
downloadlinux-0ceeb2c7c543a660b1f58a7ba113c9fa2e269661.tar.gz
linux-0ceeb2c7c543a660b1f58a7ba113c9fa2e269661.zip
memcg: group the write-hot fields of struct mem_cgroup
These fields are written on the charge, reclaim and socket paths: socket_pressure written by reclaim, read on every socket charge memory_events bumped for this memcg and every ancestor, so a busy child dirties the whole chain memory_events_local vmpressure written on every reclaim iteration private_id_ref written on every swap charge and uncharge kmem_stat high_irq_work, high_work They are spread over the struct today and share cache lines with read-mostly fields. Put them in one cache line group. socket_pressure is kept next to memory_events because mem_cgroup_sk_under_memory_pressure() reads one and bumps the other. Add memcg_struct_check() so the build fails if a field lands outside its group. No functional change. Link: https://lore.kernel.org/20260905030522.1887837-4-shakeel.butt@linux.dev Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Muchun Song <muchun.song@linux.dev> Cc: Roman Gushchin <roman.gushchin@linux.dev>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/memcontrol.h58
1 files changed, 34 insertions, 24 deletions
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 32a959f1890a..66431981f4f7 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -185,7 +185,6 @@ struct mem_cgroup {
/* Private memcg ID. Used to ID objects that outlive the cgroup */
int private_id;
- refcount_t private_id_ref;
/* Accounted resources */
struct page_counter memory; /* Both v1 & v2 */
@@ -195,14 +194,45 @@ struct mem_cgroup {
struct page_counter memsw; /* v1 only */
};
+ /* Written on the charge, reclaim and socket paths. */
+ __cacheline_group_begin_aligned(memcg_write_hot);
+ /*
+ * Hint of reclaim pressure for socket memory management. Note
+ * that this indicator should NOT be used in legacy cgroup mode
+ * where socket memory is accounted/charged separately.
+ */
+ u64 socket_pressure;
+#if BITS_PER_LONG < 64
+ seqlock_t socket_pressure_seqlock;
+#endif
+ /*
+ * memory.events is bumped for this memcg and all its ancestors, so a
+ * busy child dirties every ancestor.
+ */
+ atomic_long_t memory_events[MEMCG_NR_MEMORY_EVENTS];
+ atomic_long_t memory_events_local[MEMCG_NR_MEMORY_EVENTS];
+
+ /* vmpressure notifications. Written on every reclaim iteration. */
+ struct vmpressure vmpressure;
+
+ /* Written on every swap charge and uncharge. */
+ refcount_t private_id_ref;
+
+#ifdef CONFIG_MEMCG_NMI_SAFETY_REQUIRES_ATOMIC
+ /* MEMCG_KMEM for nmi context */
+ atomic_t kmem_stat;
+#endif
+
+ /* Range enforcement for interrupt charges */
+ struct work_struct high_work;
+
+ __cacheline_group_end_aligned(memcg_write_hot);
+
/* registered local peak watchers */
struct list_head memory_peaks;
struct list_head swap_peaks;
spinlock_t peaks_lock;
- /* Range enforcement for interrupt charges */
- struct work_struct high_work;
-
#ifdef CONFIG_ZSWAP
unsigned long zswap_max;
@@ -213,9 +243,6 @@ struct mem_cgroup {
bool zswap_writeback;
#endif
- /* vmpressure notifications */
- struct vmpressure vmpressure;
-
/*
* Should the OOM killer kill all belonging tasks, had it kill one?
*/
@@ -231,23 +258,6 @@ struct mem_cgroup {
/* memory.stat */
struct memcg_vmstats *vmstats;
- /* memory.events */
- atomic_long_t memory_events[MEMCG_NR_MEMORY_EVENTS];
- atomic_long_t memory_events_local[MEMCG_NR_MEMORY_EVENTS];
-
-#ifdef CONFIG_MEMCG_NMI_SAFETY_REQUIRES_ATOMIC
- /* MEMCG_KMEM for nmi context */
- atomic_t kmem_stat;
-#endif
- /*
- * Hint of reclaim pressure for socket memroy management. Note
- * that this indicator should NOT be used in legacy cgroup mode
- * where socket memory is accounted/charged separately.
- */
- u64 socket_pressure;
-#if BITS_PER_LONG < 64
- seqlock_t socket_pressure_seqlock;
-#endif
int kmemcg_id;
#ifdef CONFIG_CGROUP_WRITEBACK