From patchwork Mon Feb 21 18:25:38 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: 12754040 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 64D7CC433FE for ; Mon, 21 Feb 2022 18:26:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D7FE8D0001; Mon, 21 Feb 2022 13:26:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E18348D0007; Mon, 21 Feb 2022 13:26:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FB2E8D0008; Mon, 21 Feb 2022 13:26:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 51ECC8D0005 for ; Mon, 21 Feb 2022 13:26:10 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 13A3D80E95 for ; Mon, 21 Feb 2022 18:26:10 +0000 (UTC) X-FDA: 79167616500.04.177FDE3 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf08.hostedemail.com (Postfix) with ESMTP id 7BFE5160003 for ; Mon, 21 Feb 2022 18:26:09 +0000 (UTC) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1645467968; 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=OJ639ubhamTA68aEXLSN3tHwY7pmpkeJGHp8wxnKX68=; b=XOkdGXMKeJnVWBWAuiqAMV1bWbZ7A+kWb8SftOOMuJH+SghpVCaPwm2XbKILCshUro3fT0 nOezgNc7AKlhofj4T/225qEqYpzuCNpqqKRHgiQ7oxNNawjvd1GRAWN0g8yFBOqePzyBhV 2qOh0a0DlK2vjHbnQkxUnpHW2je2z3dMmo5QxX/OMecmpwbaEFKJwO5gm646a3WHEMZddl 3nrKo46t8btVMv6SEZCkcWWpThD6VzQn3VK5KgkNKCfV8O/wP+sc0zBKwy+Br7Ns5QsK8o 46UfoN+CSEZIzV7JAvQyp5ZxBrAdXMptK7MXqzFrt3Csjlw4S4VCaJ7iSP3qsw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1645467968; 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=OJ639ubhamTA68aEXLSN3tHwY7pmpkeJGHp8wxnKX68=; b=vrQ+5+s0gaSVbC0vsB9nerTL9R9oeYuYyapd7gsouhVKB3wEKSuRU/sF7QekBKc2ihPiHy zrEqR4OkFoWi4oBw== 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 , Shakeel Butt , Roman Gushchin , Michal Hocko Subject: [PATCH v4 4/6] mm/memcg: Opencode the inner part of obj_cgroup_uncharge_pages() in drain_obj_stock() Date: Mon, 21 Feb 2022 19:25:38 +0100 Message-Id: <20220221182540.380526-5-bigeasy@linutronix.de> In-Reply-To: <20220221182540.380526-1-bigeasy@linutronix.de> References: <20220221182540.380526-1-bigeasy@linutronix.de> MIME-Version: 1.0 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=XOkdGXMK; dkim=pass header.d=linutronix.de header.s=2020e header.b=vrQ+5+s0; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf08.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7BFE5160003 X-Stat-Signature: kdseseywpaf6m6gcpgoq7o5qken6g8kt X-HE-Tag: 1645467969-831597 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: From: Johannes Weiner Provide the inner part of refill_stock() as __refill_stock() without disabling interrupts. This eases the integration of local_lock_t where recursive locking must be avoided. Open code obj_cgroup_uncharge_pages() in drain_obj_stock() and use __refill_stock(). The caller of drain_obj_stock() already disables interrupts. [bigeasy: Patch body around Johannes' diff ] Signed-off-by: Johannes Weiner Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Shakeel Butt Reviewed-by: Roman Gushchin Acked-by: Michal Hocko --- mm/memcontrol.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 28174c099aa1f..cd3950256519d 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2244,12 +2244,9 @@ static void drain_local_stock(struct work_struct *dummy) * Cache charges(val) to local per_cpu area. * This will be consumed by consume_stock() function, later. */ -static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages) +static void __refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages) { struct memcg_stock_pcp *stock; - unsigned long flags; - - local_irq_save(flags); stock = this_cpu_ptr(&memcg_stock); if (stock->cached != memcg) { /* reset if necessary */ @@ -2261,7 +2258,14 @@ static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages) if (stock->nr_pages > MEMCG_CHARGE_BATCH) drain_stock(stock); +} +static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages) +{ + unsigned long flags; + + local_irq_save(flags); + __refill_stock(memcg, nr_pages); local_irq_restore(flags); } @@ -3178,8 +3182,16 @@ static void drain_obj_stock(struct memcg_stock_pcp *stock) unsigned int nr_pages = stock->nr_bytes >> PAGE_SHIFT; unsigned int nr_bytes = stock->nr_bytes & (PAGE_SIZE - 1); - if (nr_pages) - obj_cgroup_uncharge_pages(old, nr_pages); + if (nr_pages) { + struct mem_cgroup *memcg; + + memcg = get_mem_cgroup_from_objcg(old); + + memcg_account_kmem(memcg, -nr_pages); + __refill_stock(memcg, nr_pages); + + css_put(&memcg->css); + } /* * The leftover is flushed to the centralized per-memcg value.