linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC] mm: get_mm_counter() get the total memory usage of the process
@ 2024-03-22 15:11 Chen Taotao
  2024-04-10  2:17 ` Tim Chen
  0 siblings, 1 reply; 2+ messages in thread
From: Chen Taotao @ 2024-03-22 15:11 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel

Currently, the get_mm_counter() function returns only the value of
the process memory counter percpu_counter ->count record, ignoring
the memory usage count maintained by each CPU in the
percpu_counter->counters array, which leads to an error in obtaining
the memory usage count of a process, especially when there are many
CPU cores. counts, especially when there are many CPU cores.

It is now possible to have get_mm_counter() get the memory count of a
process by adding the memory counts maintained by each cpu, thus getting
an accurate memory count of the process.

This patch is an unofficial version that simply fixes the above problem,
as I'm not sure if it makes sense to do so.

Signed-off-by: Chen Taotao <chentt10@chinatelecom.cn>
---
 include/linux/mm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index f5a97dec5..5cf6443aa 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2569,7 +2569,7 @@ static inline bool get_user_page_fast_only(unsigned long addr,
  */
 static inline unsigned long get_mm_counter(struct mm_struct *mm, int member)
 {
-	return percpu_counter_read_positive(&mm->rss_stat[member]);
+	return percpu_counter_sum_positive(&mm->rss_stat[member]);
 }
 
 void mm_trace_rss_stat(struct mm_struct *mm, int member);
-- 
2.27.0



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-10  2:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22 15:11 [RFC] mm: get_mm_counter() get the total memory usage of the process Chen Taotao
2024-04-10  2:17 ` Tim Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox