From patchwork Fri Dec 6 01:35:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13896222 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 490A0E77171 for ; Fri, 6 Dec 2024 01:45:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3ED16B015A; Thu, 5 Dec 2024 20:45:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0DB66B0153; Thu, 5 Dec 2024 20:45:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94A4D6B014F; Thu, 5 Dec 2024 20:45:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1DFF96B0151 for ; Thu, 5 Dec 2024 20:45:12 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B63F5AE760 for ; Fri, 6 Dec 2024 01:45:11 +0000 (UTC) X-FDA: 82862840760.12.7294A20 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf23.hostedemail.com (Postfix) with ESMTP id 5A840140017 for ; Fri, 6 Dec 2024 01:44:55 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.51 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=1733449502; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2R4RCS5NdNkyJyduBdGri5Wc2CfjA1o0GCIeo5ZN/4A=; b=MPhyJDWT/E+OCfSxxRrS0Q3NN3fvlOfRZ60Hh1cyzREvG8gEIIUW8a/9zpLXWd1BBj1a+H 3uCWg7cm+ypqcl8yfBYhpZctB/cVHkwwwBPA1xeYFTsiYg1BGHwnZrEeUgt095za37xhbp 5KUANNtNXoz/dv4sjpy4ViK9LGDW0q4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733449502; a=rsa-sha256; cv=none; b=dOTtX2M1qmEcz2ZbReJ7q9rC5TRcURry8S3rpaZa6Y9F6oeTHPaUrKuvu0ZaGBnCbO98pt aOuQTxpoQCMwERBTAeQpeOiuozi+O4owHzmOAVp15EAvZg9qHIb9wu/ecfvl+kvvRf34+J R8HNlTlvhLHhgA7ygLGyydCkzSV1Wko= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=chenridong@huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Y4Db44znjz4f3jqj for ; Fri, 6 Dec 2024 09:44:48 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id A9A6C1A08DC for ; Fri, 6 Dec 2024 09:45:02 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP4 (Coremail) with SMTP id gCh0CgD30oYKV1JnkkskDw--.31315S4; Fri, 06 Dec 2024 09:45:02 +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 Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, chenridong@huawei.com, wangweiyang2@huawei.com Subject: [next -v1 2/5] memcg: call the free function when allocation of pn fails Date: Fri, 6 Dec 2024 01:35:09 +0000 Message-Id: <20241206013512.2883617-3-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241206013512.2883617-1-chenridong@huaweicloud.com> References: <20241206013512.2883617-1-chenridong@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgD30oYKV1JnkkskDw--.31315S4 X-Coremail-Antispam: 1UD129KBjvJXoW7WFWUuFykKFWktw1xCr13CFg_yoW8uF13pa nxta45Z3y5Jr4UWa1fKa4jva4rAa18Xw4UW34xtr1SkFnIqwnYqr12vw1S9ry5CFyfXrnr tr98Aw1xK39FkrUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmlb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI 0_Jw0_GFyl42xK82IYc2Ij64vIr41l4c8EcI0Ec7CjxVAaw2AFwI0_Jw0_GFyl4I8I3I0E 4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGV WUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_ Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rV WUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4U JbIYCTnIWIevJa73UjIFyTuYvjxUob18DUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ X-Stat-Signature: j8qif6sb4woocowe6drze91dphsfwjtp X-Rspamd-Queue-Id: 5A840140017 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1733449495-39076 X-HE-Meta: U2FsdGVkX18WQz5RzPVLKppx5FTR5EQxgH4BW4wqkO910C/nhVJK+0BCvjYXRLG8IrK5aTZ5FX26EgNPijnsRwW8Qvzuk2O028K/F2CDX4ZLK7tRRv0pZhgcirsmTG0K5Gn/Ghf26q7uJ/L4t30CbF8+mf0wjfcOMv92UOGkPGe+KCz9nyMcItPZvVNr6+nOqiK68L3gY61cgsrlajbYAAcczC5mPNguSt7Y+r5J4Gia+1YW4wF5enNxHunZlkKQrnGxT96fNNF9D71mu2ru+vjYFoPmh5dNLqwtPw0jwinJYhrMqpSipJR4pIFYLOIoU/1QoV1sBMLl7HPknjdMobfc1mCvHwdY7/k7Jfv81USF6bgiyI1W7si5RESIkitrWgD7mKSE/AAYTVxUjXlh9egQdTtKUJ8S/mPF7EEHKq5pv1keFi0EcgrQUjftrwjg+MPciktEP+jRnTxCEG+Taw8oEdxeOTIlFcSLCkHIFB/19lgQdCXNSyDo/CWhU4mPg0g1p0fUuwdgsKYpXeTr4BjBRST6wTgV6nP+flsnrZNkiyBXzoOG4MuZEzwEihC3a1Jbc+NguE1lD/2R+MXVvm9ceGQKt7gZPLPHV9dwRFVs4/aDYv26Mhf/oZ17suPROwMxD8lbAv+GBH+1rdZF9FBLO2507yoRJs7hlwnCc8hpPYB2woAic3xVzsKbum3Kp3unznYrs5MmfQQ+ey9ZGL9li9/Uu9FcRmCAfubkPf5g2K24EHHm5ZhMqvGMpcTnTRlwvnA5JSqMsRxKHLw7/GAR5o/3qHTlvdcYcEHhzQEmCtAPXwUarOwK89IhKRIREvG9uB7sGghJxYebpgotSvI72pIANGxEfY3Pc/HrByCgfCwFZQJVb4HgCf39JLERML1z75woocoG7RU6bXx87RaH/hVnIV+khUvW8BMi5DKZSYZRySQDDIvpswRZimw3IdrgntBlryuQhWUwro5 QUJPwe8P i8xjNjmaG08mXFaWDHF6t86ximqLuVXscRUX2TUE07rniISXgl6ptffCixZp65WmrlFKGfxNjMVWi2JaZU1Jdxx8sEU3EmvThl/UGfGPW/f92Zg/gMzLeIOy9nltUiy/B+Cfs 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 --- mm/memcontrol.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index fc18633aba5d..da6e4e9bd0fa 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3434,6 +3434,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; @@ -3458,23 +3468,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; @@ -3482,7 +3479,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);