Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1527505pxb; Thu, 4 Mar 2021 13:48:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFMbfczOxBvyhq9wOwO6H8tJXtQpp2WPidCBBoS1yVfd2PBv9O5sZ3qUrUwbb0PJrMZbxo X-Received: by 2002:a17:906:c24b:: with SMTP id bl11mr6622639ejb.80.1614894528826; Thu, 04 Mar 2021 13:48:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614894528; cv=none; d=google.com; s=arc-20160816; b=mO9vKjNi5vSqASQ8uUXqGVRMH9DwWOkDe8hiUNk+THRS3ZgRcXa4qsnL3BIpSQ+ORF L2zWtRuT8Mm2715qFAUgUYoijdd+SPVcCo2HM1yUgiXyG5ON0wzO/H5YH39h3R//ryhf 0rq9J9265uUwVkzlAOfCAFe1GF64OArvXJw9kkvCu2w4KKFU56mRO/2rQxHDGfZQqEPJ QvgXs6fUVl+4/in6YFnPAUpUZXD12N2hm5rg5vt1iU7fV+4hJjCSTb0GxHipi8J746iA wnwYoHX/VtBcs+mjjFCkVanmk+4UZxU3mSJ2YYjdIjR5DnPguGXnoQEYBNkuxI+rEXlx Lx8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=0sFDgqNuAGBwdZtFGlQ6KMAz588jj5D84lNaxniNvRs=; b=N+aoxYWWcqW1NOWYwDyIKoBiETMn40HrbSbenBKVoDmrupD1F7/8zNNgPKmQJSyTP9 Irnl2E9kAPwX/Wx1dKKjmMzmXYkYgfwofLByDzSKa1Sq+XaekqNm8VBxZW6F3TySw3Xh 8k4LskUlZD81A+3BVSausJ2ndDZx/3orUNtvKJOUiOL88W1ho+VXc7ys9dVvXVNhGzSa JkQ0jzPo4vQ48AeBN3+gSpyYK3XbF0hLMEs37JL1HWYqaOt3803D3KEff43Vtd+YY9Il M2Y0mCQetO7bpP1B+NqQUZ45zO3gOASJF/IX9ALz9DcO7UHDmUZMdPHyaux9oqP0txIo NzsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=hg77FMOH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r16si237000ejc.439.2021.03.04.13.48.25; Thu, 04 Mar 2021 13:48:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=hg77FMOH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1447606AbhCCPEb (ORCPT + 99 others); Wed, 3 Mar 2021 10:04:31 -0500 Received: from mx2.suse.de ([195.135.220.15]:51954 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1843086AbhCCKZ7 (ORCPT ); Wed, 3 Mar 2021 05:25:59 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1614767113; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0sFDgqNuAGBwdZtFGlQ6KMAz588jj5D84lNaxniNvRs=; b=hg77FMOHpvTO3oWdodqeuN17jinSq0WZyJsnSiMukBFGgmEK7hHBZqWuv0rjv6UJj0r3X5 RPBO9w8QzYZxYezbpPOICA/n2UKAGOkEbqaqiwC1p/ffIyeEIGGHmBjhqjC3YcGsBDkmjB XGi6yay6liJiYsq/B6ejf0CVxdjxTkw= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 08813AD87; Wed, 3 Mar 2021 10:25:13 +0000 (UTC) Date: Wed, 3 Mar 2021 11:25:12 +0100 From: Michal Hocko To: Muchun Song Cc: guro@fb.com, hannes@cmpxchg.org, akpm@linux-foundation.org, shakeelb@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2] mm: memcontrol: fix kernel stack account Message-ID: References: <20210303093956.72318-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210303093956.72318-1-songmuchun@bytedance.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > 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. > Signed-off-by: Muchun Song > Reviewed-by: Shakeel Butt Anyway Acked-by: Michal Hocko 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? > + > + 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