From patchwork Mon Feb 21 18:25:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 12754042 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 5EB67C433F5 for ; Mon, 21 Feb 2022 18:26:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA5A98D0008; Mon, 21 Feb 2022 13:26:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D2D908D0009; Mon, 21 Feb 2022 13:26:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B82DC8D0008; Mon, 21 Feb 2022 13:26:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id 87A9C8D0007 for ; Mon, 21 Feb 2022 13:26:11 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 540A09F87F for ; Mon, 21 Feb 2022 18:26:11 +0000 (UTC) X-FDA: 79167616542.16.B295620 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf02.hostedemail.com (Postfix) with ESMTP id CC32180014 for ; Mon, 21 Feb 2022 18:26:10 +0000 (UTC) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1645467969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gvKLAjshqPjuJx5ztcwEtexZwZtdDzb7fAKUE2HVkQU=; b=PEzb3aIxfpjcvav45uwZ/XAP5tsylptBaf3coAMien+gIDOi0YgXo5W4taoeELpQnpJoQG dQwtURHyc3f2B992/qnd7aSncUnevwjtF2DQyTpU5LXD6Wl7xRHEIpycSFxb/io7sZlB/H QCw1DctrICIXLOOj1FFz3rrHknrGZWyKHfwKfHhgAp2NjrekZJScmRrh0nQErd6rv4L10c Wl9YiTaqNcTbElCaUKxzb5UhpUeAfmGnwVG294T8xFTjlnlBhA8iltld2TleYSsFFAdMNl sUs/8ovN0BpRyW3awA/TUkX/pHzD11/0ubUQ9rJqtsGL/DxIx29YFtNrQ7s4Wg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1645467969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gvKLAjshqPjuJx5ztcwEtexZwZtdDzb7fAKUE2HVkQU=; b=HNtHCBGBc/LlVUnDbybDcjrsjJz/mWiGnlx9SA6zjIRlEJG006jryfCkj40bgGuuuO8Zqp gJRFgF773pmfxiCQ== To: cgroups@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Johannes Weiner , Michal Hocko , =?utf-8?q?Michal_Koutn=C3=BD?= , Peter Zijlstra , Thomas Gleixner , Vladimir Davydov , Waiman Long , Sebastian Andrzej Siewior Subject: [PATCH v4 6/6] mm/memcg: Disable migration instead of preemption in drain_all_stock(). Date: Mon, 21 Feb 2022 19:25:40 +0100 Message-Id: <20220221182540.380526-7-bigeasy@linutronix.de> In-Reply-To: <20220221182540.380526-1-bigeasy@linutronix.de> References: <20220221182540.380526-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: CC32180014 X-Stat-Signature: iobomomx896awwao7ffcufo7my1jjfcm Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=PEzb3aIx; dkim=pass header.d=linutronix.de header.s=2020e header.b=HNtHCBGB; spf=pass (imf02.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de X-Rspam-User: X-HE-Tag: 1645467970-474033 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: 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. Use migrate_disable() instead of get_cpu() around the for_each_online_cpu() loop. Signed-off-by: Sebastian Andrzej Siewior Acked-by: Michal Hocko --- 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); }