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 DCFF1C433F5 for ; Tue, 22 Feb 2022 09:56:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D4298D0002; Tue, 22 Feb 2022 04:56:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 683AA8D0001; Tue, 22 Feb 2022 04:56:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 572CD8D0002; Tue, 22 Feb 2022 04:56:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 4922E8D0001 for ; Tue, 22 Feb 2022 04:56:44 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1D2CB604A5 for ; Tue, 22 Feb 2022 09:56:44 +0000 (UTC) X-FDA: 79169961528.03.C341966 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf20.hostedemail.com (Postfix) with ESMTP id 7ED351C0006 for ; Tue, 22 Feb 2022 09:56:43 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 3142F1F39A; Tue, 22 Feb 2022 09:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1645523802; 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=VGiep3feZi3i71q2uR3AtjKvdwdXMRiWG5Ve1qZIums=; b=HH/AA24vtus8H7QzqmXfaHlpyMoTTdIz4y7K1qhVbmoA0oHm70LgWbqT7UD5GdFkWF18uu 6PWMKoEWPeLobCcxBRmt/+cxE91ngjt3PJR1FWOxIrecN5iuOvg8hafX5lil//rLNxm2tF DM5K8wHHX7YrlQpH9ouqeYgQBo/Jx/4= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 1B290A3B85; Tue, 22 Feb 2022 09:56:42 +0000 (UTC) Date: Tue, 22 Feb 2022 10:56:41 +0100 From: Michal Hocko To: Sebastian Andrzej Siewior Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Johannes Weiner , Michal =?iso-8859-1?Q?Koutn=FD?= , Peter Zijlstra , Thomas Gleixner , Vladimir Davydov , Waiman Long Subject: Re: [PATCH v4 6/6] mm/memcg: Disable migration instead of preemption in drain_all_stock(). Message-ID: References: <20220221182540.380526-1-bigeasy@linutronix.de> <20220221182540.380526-7-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220221182540.380526-7-bigeasy@linutronix.de> X-Rspamd-Queue-Id: 7ED351C0006 X-Stat-Signature: nz5ktkkt4e67pmqrrjw7ata6k1wzq1mz Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b="HH/AA24v"; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf20.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1645523803-867871 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 Mon 21-02-22 19:25:40, Sebastian Andrzej Siewior wrote: > Before the for-each-CPU loop, preemption is disabled so that so that > drain_local_stock() can be invoked directly instead of scheduling a > worker. Ensuring that drain_local_stock() completed on the local CPU is > not correctness problem. It _could_ be that the charging path will be > forced to reclaim memory because cached charges are still waiting for > their draining. > > Disabling preemption before invoking drain_local_stock() is problematic > on PREEMPT_RT due to the sleeping locks involved. To ensure that no CPU > migrations happens across the for_each_online_cpu() it is enouhg to use > migrate_disable() which disables migration and keeps context preemptible > to a sleeping lock can be acquired. I would just add that a race with cpu hotplug is not a problem because pcp data is not going away. In the worst case we just schedule draining of an empty stock. > > Use migrate_disable() instead of get_cpu() around the > for_each_online_cpu() loop. > > Signed-off-by: Sebastian Andrzej Siewior Acked-by: Michal Hocko Thanks! > --- > mm/memcontrol.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 3d7ccb104374c..9c29b1a0e6bec 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -2293,7 +2293,8 @@ static void drain_all_stock(struct mem_cgroup *root_memcg) > * as well as workers from this path always operate on the local > * per-cpu data. CPU up doesn't touch memcg_stock at all. > */ > - curcpu = get_cpu(); > + migrate_disable(); > + curcpu = smp_processor_id(); > for_each_online_cpu(cpu) { > struct memcg_stock_pcp *stock = &per_cpu(memcg_stock, cpu); > struct mem_cgroup *memcg; > @@ -2316,7 +2317,7 @@ static void drain_all_stock(struct mem_cgroup *root_memcg) > schedule_work_on(cpu, &stock->work); > } > } > - put_cpu(); > + migrate_enable(); > mutex_unlock(&percpu_charge_mutex); > } > > -- > 2.35.1 -- Michal Hocko SUSE Labs