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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49998C43217 for ; Fri, 4 Nov 2022 23:05:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7AA466B0078; Fri, 4 Nov 2022 19:05:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 732AF6B007B; Fri, 4 Nov 2022 19:05:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FA918E0001; Fri, 4 Nov 2022 19:05:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4CEA76B0078 for ; Fri, 4 Nov 2022 19:05:57 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0F1F6AC240 for ; Fri, 4 Nov 2022 23:05:57 +0000 (UTC) X-FDA: 80097294354.25.451CF8B Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf16.hostedemail.com (Postfix) with ESMTP id 558DE180007 for ; Fri, 4 Nov 2022 23:05:56 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B8493B82FF0; Fri, 4 Nov 2022 23:05:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45F69C433D7; Fri, 4 Nov 2022 23:05:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1667603153; bh=Rw/MCWcvLjCJ/UWizKXePGmZvqTCn6fbSwOgN113JjU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MjklJDPHV10dl3G3Mc3kX/3WBeuIFfo+ldITzNm0LKr27MJrZLTXB0dA6tQLoVdLu YiqFyit8Xt8MmuzxlgmCoREIG472Rm/9MGgnBHaR6aG+JQNAEUI3P8M0/ulLEZ1o5i jnM3C0OVq++n5h8Jk3dy5fh8BWTma5R0EiSRMUTw= Date: Fri, 4 Nov 2022 16:05:52 -0700 From: Andrew Morton To: Shakeel Butt Cc: Marek Szyprowski , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: convert mm's rss stats into percpu_counter Message-Id: <20221104160552.c249397512c5c7f8b293869f@linux-foundation.org> In-Reply-To: <20221103171407.ydubp43x7tzahriq@google.com> References: <20221024052841.3291983-1-shakeelb@google.com> <20221103171407.ydubp43x7tzahriq@google.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=MjklJDPH; spf=pass (imf16.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667603156; a=rsa-sha256; cv=none; b=VZI9rjor2zxKNaAyjckMT+dh6+N1Gt06J6y7/WN3hiBpf6FD5yKliMEe8+l2lvr2iG7/UJ yrUMadY+fPqAEQ/7Vgc4sBHNi/b4X8krfWhOXklQ6/ltdOV8n+O3RgqjjLx+yuOinwEfea ct+ls6a+VxyHot0hAcwWCIbzDJXSZxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667603156; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=t0NXrJz6RBGQatmAab53FWu8Q4qKORqaCEexs4v4Rog=; b=fRR0X13Y57ojbPGfCeQJIrzmVDsLZg2twxzUuu453H3skU/ZBHGZX0stCDf1D/tgmSJraF 6ic6EvnIkGJ9pzJvgCl3PidoSxLi6YJzgbSe04XZILzdepEE9m3SFPs5etAn2ZIUE+MKGl iMzGs5HAuaqKRdO/qCwG6CBWvGDKKOk= X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=MjklJDPH; spf=pass (imf16.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 558DE180007 X-Stat-Signature: 7fjxrjotydqybuhtw6dbaqhrrqng74zj X-HE-Tag: 1667603156-893998 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 Thu, 3 Nov 2022 17:14:07 +0000 Shakeel Butt wrote: > > ... > > Thanks for the report. It seems like there is a race between > for_each_online_cpu() in __percpu_counter_sum() and > percpu_counter_cpu_dead()/cpu-offlining. Normally this race is fine for > percpu_counter users but for check_mm() is not happy with this race. Can > you please try the following patch: percpu-counters supposedly avoid such races via the hotplup notifier. So can you please fully describe the race and let's see if it can be fixed at the percpu_counter level? > > From: Shakeel Butt > Date: Thu, 3 Nov 2022 06:05:13 +0000 > Subject: [PATCH] mm: percpu_counter: use race free percpu_counter sum > interface > > percpu_counter_sum can race with cpu offlining. Add a new interface > which does not race with it and use that for check_mm(). I'll grab this version for now, as others might be seeing this issue. > --- > include/linux/percpu_counter.h | 11 +++++++++++ > kernel/fork.c | 2 +- > lib/percpu_counter.c | 24 ++++++++++++++++++------ > 3 files changed, 30 insertions(+), 7 deletions(-) > > diff --git a/include/linux/percpu_counter.h b/include/linux/percpu_counter.h > index bde6c4c1f405..3070c1043acf 100644 > --- a/include/linux/percpu_counter.h > +++ b/include/linux/percpu_counter.h > @@ -45,6 +45,7 @@ void percpu_counter_set(struct percpu_counter *fbc, s64 amount); > void percpu_counter_add_batch(struct percpu_counter *fbc, s64 amount, > s32 batch); > s64 __percpu_counter_sum(struct percpu_counter *fbc); > +s64 __percpu_counter_sum_all(struct percpu_counter *fbc); > int __percpu_counter_compare(struct percpu_counter *fbc, s64 rhs, s32 batch); > void percpu_counter_sync(struct percpu_counter *fbc); > > @@ -85,6 +86,11 @@ static inline s64 percpu_counter_sum(struct percpu_counter *fbc) > return __percpu_counter_sum(fbc); > } > > +static inline s64 percpu_counter_sum_all(struct percpu_counter *fbc) > +{ > + return __percpu_counter_sum_all(fbc); > +} We haven't been good about documenting these interfaces. Can we please start now? ;) > > ... > > + > +/* > + * Add up all the per-cpu counts, return the result. This is a more accurate > + * but much slower version of percpu_counter_read_positive() > + */ > +s64 __percpu_counter_sum(struct percpu_counter *fbc) > +{ > + return __percpu_counter_sum_mask(fbc, cpu_online_mask); > +} > EXPORT_SYMBOL(__percpu_counter_sum); > > +s64 __percpu_counter_sum_all(struct percpu_counter *fbc) > +{ > + return __percpu_counter_sum_mask(fbc, cpu_possible_mask); > +} > +EXPORT_SYMBOL(__percpu_counter_sum_all); Probably here is a good place to document it. Is there any point in having the percpu_counter_sum_all()->__percpu_counter_sum_all() inlined wrapper? Why not name this percpu_counter_sum_all() directly? > int __percpu_counter_init(struct percpu_counter *fbc, s64 amount, gfp_t gfp, > struct lock_class_key *key) > { > -- > 2.38.1.431.g37b22c650d-goog