From patchwork Tue Jan 14 12:25:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13938736 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 C593FC02184 for ; Tue, 14 Jan 2025 12:36:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3D246B0089; Tue, 14 Jan 2025 07:36:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 99BCA6B0092; Tue, 14 Jan 2025 07:36:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6897F6B008A; Tue, 14 Jan 2025 07:36:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4942F6B0089 for ; Tue, 14 Jan 2025 07:36:57 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 622DB160990 for ; Tue, 14 Jan 2025 12:36:09 +0000 (UTC) X-FDA: 83006004858.27.E406984 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf03.hostedemail.com (Postfix) with ESMTP id 5AC372000F for ; Tue, 14 Jan 2025 12:36:03 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=chenridong@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736858167; 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; bh=2psctKiVePjiZ4h0wf9BJ41NNOvoxDC8B6IHotnpCWU=; b=6+GRpUUBnT4iv24iTFFnISLP0MRkMVEHoHoNWa1CDbfMnoUpXw+1l54MAl62tYEyweLNc1 miLsFHrUsae1wi7dOaFxfDPXZ5w5hHHwlStNf5jcDPeKYpNpuWVHTTGC/YpK5e+pBwNh5a i0BKx8Va+Izcdi55PN9bCCHjSPE3w/0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736858167; a=rsa-sha256; cv=none; b=5NHbsr46IY/FYbSD+kI7zVmBE6EJVwsRzMZ+ShVmiKOyo7BhxHXt509bYXY+PAj55ogWlD wEa52Jdd//DSsIgBBkIzbVRE7QhbCImZyymdNzBhTMn1KtIdVVCO02EFEfqt7hkFSU19fR 6YaLCdLbeWsFHXookOPWKcdzcmDWmno= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=chenridong@huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4YXTB30N1Gz4f3jrp for ; Tue, 14 Jan 2025 20:35:39 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.252]) by mail.maildlp.com (Postfix) with ESMTP id 61E061A1295 for ; Tue, 14 Jan 2025 20:35:59 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP3 (Coremail) with SMTP id _Ch0CgB3F8IhWoZnN4KvAw--.1325S4; Tue, 14 Jan 2025 20:35:59 +0800 (CST) From: Chen Ridong To: akpm@linux-foundation.org, mhocko@kernel.org, hannes@cmpxchg.org, yosryahmed@google.com, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, davidf@vimeo.com, vbabka@suse.cz, mkoutny@suse.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, chenridong@huawei.com, wangweiyang2@huawei.com Subject: [PATCH -v2 next 2/4] memcg: call the free function when allocation of pn fails Date: Tue, 14 Jan 2025 12:25:17 +0000 Message-Id: <20250114122519.1404275-3-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250114122519.1404275-1-chenridong@huaweicloud.com> References: <20250114122519.1404275-1-chenridong@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgB3F8IhWoZnN4KvAw--.1325S4 X-Coremail-Antispam: 1UD129KBjvJXoW7WFWUuFykKFWktw1xCr13CFg_yoW8trWrpa nxKa45Z3y5Jr4UWa1fKa4jva4rZa18Xw4UWryxXw1IkF1aqwnYqr12yw1F9r98CFyfXrnr trn8Aw1xK39FkrUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPFb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7Cj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EkhECxRbYNzy8tDv/+tmP13T5AWmIBr6n2EPmtwOPqGX6eqDgtPcn1dj7BV4oCj0BQdbytzdgPmaIOlNe5QJloCtF2g4uWjkBiBiYex6W3bSdN581o4ES9RlZx62T7viRoStY0EfGofpDGeGJNn/pu2bqpl9tRLUPzSvjSVWWHEsCd5oemH37BFX52NUk0LhZkbEtvz1Q/EDxaG9uGgcJytpNgLgj7km+xIQqTO76MvzL3NVf1RFRVdJlnHwAx/5XzmSP//MkEV3U4ZFLlxfyqCAZTwzj7Oiw/5Oa2QV4h7cUNEx1T5uzE50tAidp3NuERqyDq5qaYSOOcER7VA5b1sUmxX+H8f1SryyvJDcWbllEGANQVI+InNv0RzgJveQD7ZOCu6/X+XwG8K2J8eW9vhx/Xtm9V2V5IQRfUMyDdVzaoN+YXhQm9noDg82G8u2puAZdAe/xu2D5Mm 5obCP1gt NsF0y7RkpbaE3cWuC5tx98bxNJb+4mkwqzzsXWT8DtNGVdnOMrdMzbsSidK4gjJ2nLb5yqSf8bVnIHlC9zTMf1/vImZklQ4BcQPOF4ZlgHfYI4KVIXoDB5LxOQHH3qdEhcfqx6ohzQOdYUjq2U96gU9VhDnkPBN/UWu9ba5Uskw0dGu0yZ0dbKUCnE6XLviopvAqwc4yRBgMA3Gg4313j+EJKGjLt060xg6OI 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: List-Subscribe: List-Unsubscribe: From: Chen Ridong The 'free_mem_cgroup_per_node_info' function is used to free the 'mem_cgroup_per_node' struct. Using 'pn' as the input for the free_mem_cgroup_per_node_info function will be much clearer. Call 'free_mem_cgroup_per_node_info' when 'alloc_mem_cgroup_per_node_info' fails, to free 'pn' as a whole, which makes the code more cohesive. Signed-off-by: Chen Ridong Reviewed-by: Michal Koutný Acked-by: Shakeel Butt Reviewed-by: Roman Gushchin --- mm/memcontrol.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 05a32c860554..98f84a9fa228 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3424,6 +3424,16 @@ struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino) } #endif +static void free_mem_cgroup_per_node_info(struct mem_cgroup_per_node *pn) +{ + if (!pn) + return; + + free_percpu(pn->lruvec_stats_percpu); + kfree(pn->lruvec_stats); + kfree(pn); +} + static bool alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) { struct mem_cgroup_per_node *pn; @@ -3448,23 +3458,10 @@ static bool alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) memcg->nodeinfo[node] = pn; return true; fail: - kfree(pn->lruvec_stats); - kfree(pn); + free_mem_cgroup_per_node_info(pn); return false; } -static void free_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) -{ - struct mem_cgroup_per_node *pn = memcg->nodeinfo[node]; - - if (!pn) - return; - - free_percpu(pn->lruvec_stats_percpu); - kfree(pn->lruvec_stats); - kfree(pn); -} - static void __mem_cgroup_free(struct mem_cgroup *memcg) { int node; @@ -3472,7 +3469,7 @@ static void __mem_cgroup_free(struct mem_cgroup *memcg) obj_cgroup_put(memcg->orig_objcg); for_each_node(node) - free_mem_cgroup_per_node_info(memcg, node); + free_mem_cgroup_per_node_info(memcg->nodeinfo[node]); memcg1_free_events(memcg); kfree(memcg->vmstats); free_percpu(memcg->vmstats_percpu);