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.7 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 61843C433E0 for ; Tue, 2 Mar 2021 09:24:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AFA9464EFC for ; Tue, 2 Mar 2021 09:24:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AFA9464EFC 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 0AD5B8D00F1; Tue, 2 Mar 2021 04:24:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 060148D0063; Tue, 2 Mar 2021 04:24:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E8FA68D00F1; Tue, 2 Mar 2021 04:24:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0107.hostedemail.com [216.40.44.107]) by kanga.kvack.org (Postfix) with ESMTP id D1D7D8D0063 for ; Tue, 2 Mar 2021 04:24:22 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9B3DD8122 for ; Tue, 2 Mar 2021 09:24:22 +0000 (UTC) X-FDA: 77874398364.03.A7A58D6 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf01.hostedemail.com (Postfix) with ESMTP id 48E442000397 for ; Tue, 2 Mar 2021 09:24:21 +0000 (UTC) Received: by mail-pl1-f169.google.com with SMTP id e9so11676823plh.3 for ; Tue, 02 Mar 2021 01:24:20 -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=zaaHr1FdPfn0LfAliQ+IVMh6j7CV9vE3i1cYH9AA51s=; b=1DKygOG8TqNSv78Da7/e2WKSu8WpZGVF1E9BqtDer81jwFyIJSY+s2obSBjq67ht+O +XpcPvQB8M+CdbjJEE40t1lfaA34KTYoI3dSllo6XX0WwasqE2SGbBZiebUsfDzk6pwT QoXRd/DgtdW3gNpK9gINpv0ItpNIr4bE6+v+ZgRr4uvsOjZ/yllkB48vMtr5hcjr6hxX HSRBwMX/s4jIXlVRUPLhBXKBxKj6NgJSSSm5e10oUwR2POOHbu3+BT6BIlAMlPEYBHbh S7PsshZ+W15WpqEsB/e6pqC2pXIdtIBoyI9CxYgNqapOgNU1jKSesuY1I9VIj1bsoRk7 KQRA== 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=zaaHr1FdPfn0LfAliQ+IVMh6j7CV9vE3i1cYH9AA51s=; b=If1tqulMFjIjZMteOC0ZPMKxi4SYsmYbkW60zciGmki39ZniVyCYy16D8nVmPFGJ+t 5p7w9T90vaqrG2Mkv5Z/l5D5g/mN0V3oRQQAn4YhITf7+IWUBlDfX845m54T7F4FR2pW tGEmiKTzmCd5m282kai+P3YZEYrrxbZ82nePpKb3YUZX0pc3k5Lp7sUGo4KoI7/Q5F/N ksfZYS7rnXPGB1I8/t18OBEeNXBpxo1ZEBjDIp22Oyvu9ybbC3GLjWSnMizDVHJeupa+ F6x8DDMn8Ex4uHi2tGRvG9lSzKLyb2h4b0DUoR+UZxXWdqbAdtDnD0MuFWdiWdkt2fXO atUw== X-Gm-Message-State: AOAM533YBD1dHPfjRzaiuUCLxWViwYiQAT9VEN1H2Fp7hD6rs6tbQgHt uGmFcGq9ybe9TKe8AzU/7RmRWVHzHmudK5ucrKZsyA== X-Google-Smtp-Source: ABdhPJyJedaY846+qySN+sLQwRjoChumrNaJQgiaLavT8dqrelfnh0ydhHPI9JFjS+Tf9QI6CyZZ3FeaHAm3Lz7dyy4= X-Received: by 2002:a17:902:e54e:b029:e3:9f84:db8e with SMTP id n14-20020a170902e54eb02900e39f84db8emr2686501plf.24.1614677059972; Tue, 02 Mar 2021 01:24:19 -0800 (PST) MIME-Version: 1.0 References: <20210302073733.8928-1-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Tue, 2 Mar 2021 17:23:42 +0800 Message-ID: Subject: Re: [External] Re: [PATCH] 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: amkahgaqxoxddmx1xdo3un8wkwqj7fbd X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 48E442000397 Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf01; 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: 1614677061-728788 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 Tue, Mar 2, 2021 at 4:44 PM Michal Hocko wrote: > > On Tue 02-03-21 15:37:33, Muchun Song wrote: > > 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. > > What is the actual problem you are trying to address by this patch? > 991e7673859e has deliberately dropped the per page accounting. Can you > explain why that was incorrect? There surely is some imprecision > involved but does it matter and is it even observable? When I read the code of account_kernel_stack(), I see a comment that says "All stack pages are in the same node". I am confused about this. IIUC, there is no guarantee about this. Right? Yeah, imprecision may not be a problem. But if this is what we did deliberately, I think that it is better to add a comment there. Thanks. > > > Fixes: 991e7673859e ("mm: memcontrol: account kernel stack per node") > > Signed-off-by: Muchun Song > > --- > > 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 > > -- > Michal Hocko > SUSE Labs