From patchwork Wed Mar 3 09:39:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12113183 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B63AC433E0 for ; Wed, 3 Mar 2021 09:41:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7C92764EE9 for ; Wed, 3 Mar 2021 09:41:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C92764EE9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EB1E58D013E; Wed, 3 Mar 2021 04:41:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E891C8D0135; Wed, 3 Mar 2021 04:41:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D51AD8D013E; Wed, 3 Mar 2021 04:41:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0174.hostedemail.com [216.40.44.174]) by kanga.kvack.org (Postfix) with ESMTP id BA0B08D0135 for ; Wed, 3 Mar 2021 04:41:31 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6EEE4181CBDD4 for ; Wed, 3 Mar 2021 09:41:31 +0000 (UTC) X-FDA: 77878070382.14.57420F4 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf28.hostedemail.com (Postfix) with ESMTP id 7C6F92000385 for ; Wed, 3 Mar 2021 09:41:28 +0000 (UTC) Received: by mail-pf1-f177.google.com with SMTP id 192so8866953pfv.0 for ; Wed, 03 Mar 2021 01:41:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HuoFzrfHBgRpGB1S/Pm90uFoEaWpFEXI5cv//wG4H2s=; b=Xr6ER+bksZxkJbMXLoySGxJaEmmcYGK3nmHQapWxz3W7BTIa8Y+vTnfB6r/G+HFBqt DEJtMk6baSN0IO1VhtSHxnr9HFL+mXL30chhMwpW2HSGa1meGo3N44SyxDSzST4IbA8h qVTWdIctGswX7OumTWDziApBZqlzcCzNP6Skst0zK+ex8KotHXi7KTUc/lAm6uGod8vL EEGYX3KI+2ovo+s3zh+bsp+8VJTGE6A2GvX0/Wh9jsGo2EcQd2SX4g1QMwd8GVdWXXq/ pXL214erEC2KeZQVnfHESUCmOzYRkcvBJZxfDgaXemkAdCv6iC2DjQ8LniDyopVb4ZIY B94Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HuoFzrfHBgRpGB1S/Pm90uFoEaWpFEXI5cv//wG4H2s=; b=cgiVJLAn10Ti/Qb+yqSNInn7yqUdlSMTCz8G6z6tKHRorTtehtFKXSrt+sUErCwnE1 bFYs8dlL0z58prRym6Az/EgIMGj8ZfJg9s/jrLIU1jE4WRejCilzahNoWb4Te1l6VT6D +WSrwiCj66K3BXCiGtg8XbrRgBefyG9OdfT9osheX0aVZmNbOgq9PJUhRXFMarZimJNk eVks1uol9fr+k1Ls0UpP5P1MM+QRm9XYqVW9Kqq7Lt3csw6Udebw747+ZJikyKl9XNK4 pwpmeGRYOpWtDLG0DHGDIM40Gjm/+Fu2XV2mOpMSpoPvSJXZHS3ABUdo20V9H4g+YzM7 w8bw== X-Gm-Message-State: AOAM532oZM6Auix1rwwwGNxNFESYoQZLjzvnFXzWwAAVZ61ZULdORq+c 7O+cJUJ1Ww/She7Y44wY9OzL/g== X-Google-Smtp-Source: ABdhPJxf4CEDONXrnyzwQQbOoexCzNLf9VH258dboqUGrOOFaod19GbchLPaEuPlDKJSwM5iWYBC1g== X-Received: by 2002:a63:5b57:: with SMTP id l23mr4313299pgm.445.1614764487006; Wed, 03 Mar 2021 01:41:27 -0800 (PST) Received: from localhost.localdomain ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id u66sm26346459pfc.72.2021.03.03.01.41.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Mar 2021 01:41:26 -0800 (PST) From: Muchun Song To: guro@fb.com, hannes@cmpxchg.org, mhocko@kernel.org, akpm@linux-foundation.org, shakeelb@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song Subject: [PATCH v2] mm: memcontrol: fix kernel stack account Date: Wed, 3 Mar 2021 17:39:56 +0800 Message-Id: <20210303093956.72318-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 7C6F92000385 X-Stat-Signature: ddib353h39kqp4zgbaqs9ek6jfiry1o3 Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=mail-pf1-f177.google.com; client-ip=209.85.210.177 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614764488-626973 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: For simplification 991e7673859e ("mm: memcontrol: account kernel stack per node") has changed the per zone vmalloc backed stack pages accounting to per node. By doing that we have lost a certain precision because those pages might live in different NUMA nodes. In the end NR_KERNEL_STACK_KB exported to the userspace might be over estimated on some nodes while underestimated on others. This doesn't impose any real problem to correctnes of the kernel behavior as the counter is not used for any internal processing but it can cause some confusion to the userspace. Address the problem by accounting each vmalloc backing page to its own node. Fixes: 991e7673859e ("mm: memcontrol: account kernel stack per node") Signed-off-by: Muchun Song Reviewed-by: Shakeel Butt Acked-by: Michal Hocko Acked-by: Johannes Weiner --- Changelog in v2: - Rework commit log suggested by Michal. Thanks to Michal and Shakeel for review. 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)