Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

memcg: use mod_node_page_state to update stats

Patch series "memcg: cleanup the memcg stats interfaces".

The memcg stats are safe against irq (and nmi) context and thus does not
require disabling irqs. However for some stats which are also maintained
at node level, it is using irq unsafe interface and thus requiring the
users to still disables irqs or use interfaces which explicitly disables
irqs. Let's move memcg code to use irq safe node level stats function
which is already optimized for architectures with HAVE_CMPXCHG_LOCAL (all
major ones), so there will not be any performance penalty for its usage.


This patch (of 4):

The memcg stats are safe against irq (and nmi) context and thus does not
require disabling irqs. However some code paths for memcg stats also
update the node level stats and use irq unsafe interface and thus require
the users to disable irqs. However node level stats, on architectures
with HAVE_CMPXCHG_LOCAL (all major ones), has interface which does not
require irq disabling. Let's move memcg stats code to start using that
interface for node level stats.

Link: https://lkml.kernel.org/r/20251110232008.1352063-1-shakeel.butt@linux.dev
Link: https://lkml.kernel.org/r/20251110232008.1352063-2-shakeel.butt@linux.dev
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Shakeel Butt and committed by
Andrew Morton
7e44d00a 3e700b71

+6 -6
+1 -1
include/linux/memcontrol.h
··· 1408 1408 { 1409 1409 struct page *page = virt_to_head_page(p); 1410 1410 1411 - __mod_node_page_state(page_pgdat(page), idx, val); 1411 + mod_node_page_state(page_pgdat(page), idx, val); 1412 1412 } 1413 1413 1414 1414 static inline void mod_lruvec_kmem_state(void *p, enum node_stat_item idx,
+2 -2
include/linux/vmstat.h
··· 557 557 static inline void __mod_lruvec_state(struct lruvec *lruvec, 558 558 enum node_stat_item idx, int val) 559 559 { 560 - __mod_node_page_state(lruvec_pgdat(lruvec), idx, val); 560 + mod_node_page_state(lruvec_pgdat(lruvec), idx, val); 561 561 } 562 562 563 563 static inline void mod_lruvec_state(struct lruvec *lruvec, ··· 569 569 static inline void __lruvec_stat_mod_folio(struct folio *folio, 570 570 enum node_stat_item idx, int val) 571 571 { 572 - __mod_node_page_state(folio_pgdat(folio), idx, val); 572 + mod_node_page_state(folio_pgdat(folio), idx, val); 573 573 } 574 574 575 575 static inline void lruvec_stat_mod_folio(struct folio *folio,
+3 -3
mm/memcontrol.c
··· 770 770 int val) 771 771 { 772 772 /* Update node */ 773 - __mod_node_page_state(lruvec_pgdat(lruvec), idx, val); 773 + mod_node_page_state(lruvec_pgdat(lruvec), idx, val); 774 774 775 775 /* Update memcg and lruvec */ 776 776 if (!mem_cgroup_disabled()) ··· 789 789 /* Untracked pages have no memcg, no lruvec. Update only the node */ 790 790 if (!memcg) { 791 791 rcu_read_unlock(); 792 - __mod_node_page_state(pgdat, idx, val); 792 + mod_node_page_state(pgdat, idx, val); 793 793 return; 794 794 } 795 795 ··· 815 815 * vmstats to keep it correct for the root memcg. 816 816 */ 817 817 if (!memcg) { 818 - __mod_node_page_state(pgdat, idx, val); 818 + mod_node_page_state(pgdat, idx, val); 819 819 } else { 820 820 lruvec = mem_cgroup_lruvec(memcg, pgdat); 821 821 __mod_lruvec_state(lruvec, idx, val);