From patchwork Sat Feb 26 20:41:44 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: 12761453 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 BFC2FC433EF for ; Sat, 26 Feb 2022 20:42:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAECF8D0008; Sat, 26 Feb 2022 15:41:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E384E8D0007; Sat, 26 Feb 2022 15:41:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C65998D0008; Sat, 26 Feb 2022 15:41:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0230.hostedemail.com [216.40.44.230]) by kanga.kvack.org (Postfix) with ESMTP id A05BA8D0005 for ; Sat, 26 Feb 2022 15:41:54 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5AEA097315 for ; Sat, 26 Feb 2022 20:41:54 +0000 (UTC) X-FDA: 79186102548.25.05C8575 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf10.hostedemail.com (Postfix) with ESMTP id CE08DC0007 for ; Sat, 26 Feb 2022 20:41:53 +0000 (UTC) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1645908112; 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=VuB/1jlIhEyPDsXw/VrUOxUQMh/b8hRGxZ9Q00QMyEw=; b=Ft6l+vfY/mtjKmilohDaR2FygjHI2QE8zu8W3iTBIBD8onmMtmfYo1oeZ8oEnQ/p2xDuPu ALZbRB6CepCK5z0ICaHCoqUQ07bv3yGEKNvnp4tiClDYlySh7fSfuV+dhGfFewOkMFOoWV 1ADT4IB+uN99kBJP3GJz9OcBVMfz0G8gksA7ihnaHs7n+pXZPuzAvCKN2g8F9lj+yByvxh sx8cBN8dWgurKJyknZZMN27qKIeR6h+xJiRG6tvZvHrcntnvTSDg1ulpejxFkKP59UYGs7 PCn+0EGrzV9TUYn1BmCmV7LIYciewy75tr2gacolu2k4NiMUjaEphkpS/Cq/Mw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1645908112; 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=VuB/1jlIhEyPDsXw/VrUOxUQMh/b8hRGxZ9Q00QMyEw=; b=vwOE5noON8Etg+MQn1ibZzISWjg5NtyzZxugs4RVno03ttWjNyc0HuiLypBCngSlgscdhl ZPuggoD0HSrn9LCA== 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 , Michal Hocko Subject: [PATCH v5 6/6] mm/memcg: Disable migration instead of preemption in drain_all_stock(). Date: Sat, 26 Feb 2022 21:41:44 +0100 Message-Id: <20220226204144.1008339-7-bigeasy@linutronix.de> In-Reply-To: <20220226204144.1008339-1-bigeasy@linutronix.de> References: <20220226204144.1008339-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: CE08DC0007 X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=Ft6l+vfY; dkim=pass header.d=linutronix.de header.s=2020e header.b=vwOE5noO; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf10.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de X-Stat-Signature: 7xo914utntzsz9ixxwkg5i93cdqtc141 X-HE-Tag: 1645908113-324554 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 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. 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 --- mm/memcontrol.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6439b0089d392..89664d8094bc0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2300,7 +2300,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; @@ -2323,7 +2324,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); }