linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: memcontrol: fix kernel stack account
@ 2021-03-02  7:37 Muchun Song
  2021-03-02  8:44 ` Michal Hocko
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Muchun Song @ 2021-03-02  7:37 UTC (permalink / raw)
  To: guro, hannes, mhocko, akpm, shakeelb; +Cc: linux-kernel, linux-mm, Muchun Song

The alloc_thread_stack_node() cannot guarantee that allocated stack pages
are in the same node when CONFIG_VMAP_STACK. Because we do not specify
__GFP_THISNODE to __vmalloc_node_range(). Fix it by caling
mod_lruvec_page_state() for each page one by one.

Fixes: 991e7673859e ("mm: memcontrol: account kernel stack per node")
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 kernel/fork.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index d66cd1014211..6e2201feb524 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -379,14 +379,19 @@ static void account_kernel_stack(struct task_struct *tsk, int account)
 	void *stack = task_stack_page(tsk);
 	struct vm_struct *vm = task_stack_vm_area(tsk);
 
+	if (vm) {
+		int i;
 
-	/* All stack pages are in the same node. */
-	if (vm)
-		mod_lruvec_page_state(vm->pages[0], NR_KERNEL_STACK_KB,
-				      account * (THREAD_SIZE / 1024));
-	else
+		BUG_ON(vm->nr_pages != THREAD_SIZE / PAGE_SIZE);
+
+		for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
+			mod_lruvec_page_state(vm->pages[i], NR_KERNEL_STACK_KB,
+					      account * (PAGE_SIZE / 1024));
+	} else {
+		/* All stack pages are in the same node. */
 		mod_lruvec_kmem_state(stack, NR_KERNEL_STACK_KB,
 				      account * (THREAD_SIZE / 1024));
+	}
 }
 
 static int memcg_charge_kernel_stack(struct task_struct *tsk)
-- 
2.11.0


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

end of thread, other threads:[~2021-03-02 22:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02  7:37 [PATCH] mm: memcontrol: fix kernel stack account Muchun Song
2021-03-02  8:44 ` Michal Hocko
2021-03-02  9:23   ` [External] " Muchun Song
2021-03-02  9:34     ` Michal Hocko
2021-03-02  9:49       ` Muchun Song
2021-03-02 14:04       ` Shakeel Butt
2021-03-02 14:02 ` Shakeel Butt
2021-03-02 14:18   ` Michal Hocko
2021-03-02 18:50 ` Roman Gushchin
2021-03-02 19:33   ` Michal Hocko
2021-03-02 20:37     ` Roman Gushchin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).