From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 4D20BC433DB for ; Wed, 3 Mar 2021 13:28:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8D55660C3D for ; Wed, 3 Mar 2021 13:28:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D55660C3D 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 0FC4F8D0164; Wed, 3 Mar 2021 08:28:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AD2F8D0157; Wed, 3 Mar 2021 08:28:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E8F918D0164; Wed, 3 Mar 2021 08:28:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0044.hostedemail.com [216.40.44.44]) by kanga.kvack.org (Postfix) with ESMTP id CD4E98D0157 for ; Wed, 3 Mar 2021 08:28:04 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8E0A98249980 for ; Wed, 3 Mar 2021 13:28:04 +0000 (UTC) X-FDA: 77878641288.24.36DCA46 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf03.hostedemail.com (Postfix) with ESMTP id D88B5C0007C2 for ; Wed, 3 Mar 2021 13:28:00 +0000 (UTC) Received: by mail-pl1-f169.google.com with SMTP id s7so6845876plg.5 for ; Wed, 03 Mar 2021 05:28:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GDH7lgjRH5u3RTqXMq5Tl04VvG/bzdMWK3DmgGuHjNg=; b=bazKNP9smhGB0AaA3ZgST/1l2rLawqsYZX+v6I4r9lrS8ig/5GAQoWRLViI7EZf1sY y7PTVw012LS0dGujFogrqhAWzA2YAuxRwfJP4pzs+mnb/mJK/Df3OnvAd3115XKogSdv i4BQ92i9aL6wzN5TtptJuew9+X2mIWnnu2b3KlRnoL6azIjyUlgw1BT6AoClmmfqOWb7 DHUhVdJJn9iwnSj951+gBTJrgMTla6tqo/rmI/NM/gtuETmNJ7TleDB8TTTzdfuUw6yn OaFaUMcPnyuFQgEy9QilQwkmmJnCsqRVi63N4hKP6JxiztStR28iXv8mmA8T28RcqGoN VxQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GDH7lgjRH5u3RTqXMq5Tl04VvG/bzdMWK3DmgGuHjNg=; b=ZItglBeyWa26jJiCMVdKUKwBvgXcZ7MP+5tTxZ0nQuQyfAod072b5VBFXMSG76EIVz Ap9cqpZ7eW1LMyEk8ZxxV219Qb2pTy2G+0H/NBohv1mln/ofu252WOmp1fsv0wDv9dOv drKd4jRSkjGDh+IbqJeTfmoC2clpa9NglVFWiWMhG0NqVGMDB9hV6oKfvOjdnMjvXMcZ ltinhUPc9ijx+Py3j+DUaQmZP4krhBVmslnJN4YnIP8o+PLcp6eTMCw4Oj1IJVYxyASr 18uc6/Ct2tRrT7qTTAJhGVSlkg5XV4gY8QlWmt6N/CAvydVt7CJfzDKPcuohsOihsil7 g2lw== X-Gm-Message-State: AOAM5304PJ0NoApKsyZDh0PFar4TjgWnaXJ+SKwkziTn0l/JJFVaxkKI ruSkWBFVz5pvQSnIthjzm7V9qVnD+3yiXbDIVa2ejeFp19UjiHDf X-Google-Smtp-Source: ABdhPJw0LwArSdnvTDr+Hc6zokLHVmsmS5LG8oVeZyn9/01/gqylWDQXxsUWCHfelRedXOK5pHQY8aBf6SPZcfd4/Uw= X-Received: by 2002:a17:90a:778a:: with SMTP id v10mr9402005pjk.229.1614778081078; Wed, 03 Mar 2021 05:28:01 -0800 (PST) MIME-Version: 1.0 References: <20210303093956.72318-1-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Wed, 3 Mar 2021 21:27:24 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v2] mm: memcontrol: fix kernel stack account To: Michal Hocko Cc: Roman Gushchin , Johannes Weiner , Andrew Morton , Shakeel Butt , LKML , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: xbdjrosbqtp6gahj8p38ad5qodnr8ctk X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D88B5C0007C2 Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf03; identity=mailfrom; envelope-from=""; helo=mail-pl1-f169.google.com; client-ip=209.85.214.169 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614778080-227351 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: On Wed, Mar 3, 2021 at 6:25 PM Michal Hocko wrote: > > On Wed 03-03-21 17:39:56, Muchun Song wrote: > > 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. > > You have skipped over one part of the changelog I have proposed and that > is to provide an actual data. Because this is a problem I found by looking at the code, not a real world problem. I do not have any actual data. :-( > > > Address the problem by accounting each vmalloc backing page to its own > > node. > > > > Fixes: 991e7673859e ("mm: memcontrol: account kernel stack per node") > > Fixes tag might make somebody assume this is worth backporting but I > highly doubt so. OK. I can remove the Fixes tag. > > > Signed-off-by: Muchun Song > > Reviewed-by: Shakeel Butt > > Anyway > Acked-by: Michal Hocko Thanks for your review. > > as the patch is correct with one comment below > > > --- > > 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); > > I do not think we need this BUG_ON. What kind of purpose does it serve? vm->nr_pages should be always equal to THREAD_SIZE / PAGE_SIZE if the system is not corrupted. It makes sense to remove the BUG_ON. I will remove it in the next version. Thanks. > > > + > > + 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 > > -- > Michal Hocko > SUSE Labs