From patchwork Fri Jan 17 01:46:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13942786 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 4D47AC02188 for ; Fri, 17 Jan 2025 01:57:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E64686B008A; Thu, 16 Jan 2025 20:57:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C1BA06B0095; Thu, 16 Jan 2025 20:57:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B0B86B0089; Thu, 16 Jan 2025 20:57:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2453B6B008A for ; Thu, 16 Jan 2025 20:57:44 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D29A91C8475 for ; Fri, 17 Jan 2025 01:57:43 +0000 (UTC) X-FDA: 83015282406.21.2B3C708 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf01.hostedemail.com (Postfix) with ESMTP id 8937F4000A for ; Fri, 17 Jan 2025 01:57:39 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf01.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=chenridong@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737079062; a=rsa-sha256; cv=none; b=CYLz6zlcDd+HySg+cg3jQ+Fhea8P0Sss0qiTBpC/nEnH7WVKSuFdArCebJececWCNQR/IJ kR+w6cWKk4F7Jfh7M4b+5HW8jPU3ft/ev8tuX2YO3t3KXkf0J0LAw5k4VjmTJ1QOCr+w3D zefUyr6aGf6HSoYuvoJWZPiGxaZf0Ko= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf01.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=1737079062; 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=v3xUg3PKofabJz2WARxXH5CRN72BJHtSpp1Yxf6bUPnTnsXe+ZL05BT7cUL/OgrsaP1vzz pc+lAnjNraVdKuuXxVjHjKhRGW73htomBZlfzTWPvU5k8x98/hl2fW1UM2Dr3Ya/arVnLq dCWj1QAq22gq/VL/+kPHphKDOalmYBM= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4YZ2t02LFtz4f3kvl for ; Fri, 17 Jan 2025 09:57:12 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 0A0DA1A0D8F for ; Fri, 17 Jan 2025 09:57:34 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP2 (Coremail) with SMTP id Syh0CgCnsWT7uIln8NWrBA--.20802S4; Fri, 17 Jan 2025 09:57:33 +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 v3 next 2/5] memcg: call the free function when allocation of pn fails Date: Fri, 17 Jan 2025 01:46:42 +0000 Message-Id: <20250117014645.1673127-3-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117014645.1673127-1-chenridong@huaweicloud.com> References: <20250117014645.1673127-1-chenridong@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgCnsWT7uIln8NWrBA--.20802S4 X-Coremail-Antispam: 1UD129KBjvJXoW7WFWUuFykKFWktw1xCr13CFg_yoW8trWrpa nxKa45Z3y5Jr4UWa1fKa4jva4rZa18Xw4UWryxXw1IkF1aqwnYqr12yw1F9r98CFyfXrnr trn8Aw1xK39FkrUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPFb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI 0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG 67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MI IYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E 14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUob18 DUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 8937F4000A X-Stat-Signature: 5am8coenmkje6mppfuup6efpa69ptnrm X-HE-Tag: 1737079059-188633 X-HE-Meta: U2FsdGVkX1+J4JEfB6TvOJEk7YkNukY0d7ZCeqRx74xcbfIlOWoD2mOA7xKcxRIGDY5MoW5r04nRvxA99yYr7/+m0v3phYBqWXZN1g4p6d9dC31rucCYKjmF+t/QC5BDjXKkIrRSjahH2qCTVmusoIf3TrJwSVLoS1S+GrlOaAsTO+FlaAEFfarfE1Ycerd6WIlrbFSctAZj1xry2vdDSyz69Ys2NibTWb/E2NzCllw1xOXR80YqO9Y6VFpXEQm/Be+lcjJQvouVpNN+PG6sFS6eQyWLDAjkdvKKbTrb57DP0jdIJ2g+QDM0UTugN0Vn4DvOaNkbkrnfThykhY6q3UDuRJzC4zLVhgEii+MS4xIAO5WCxXyOPhcAXEoOKerYL2TyOolakhgYzX3EUSn4YskwtXBnB+idsEBnz8DqXCwtisFWs0AjgxsDfz5vxBRU7gsIDneCG5C/mpxAx56DLEeoHKD76j96plsA+jmOd/P6t8lGObdUyMzY9OwLuD4IelIqvHI1n5UwaMbHiIY220jD6eR+EWlTAU+BVCVsmEvdNjAbty/vSo5pMp3D74yyBahEw9EQOeIKFyyqzz1vuWvc/hMYzaOYSCHx+eRk7wWHOwbUKHVGJU9d2lf4nZA88g/UXbn9slQbIhConKDx/w8lDtXQPNC8ke50JuGyYVVoND6uUhz1mcB+lMQrciZLPgvh+8bWdMvUWkrtp83C64I+W04ndZiYjhZprLWGNH+c+/ONFh+xE5M8wth/V5E1NxeEI+LkVnJg4juN2mx5bn5WtRg1XZSYkIcOOYyMXfVFZbWVUb1ka2hnGZA3JlRdmPiQC+DrJN2B06TuufBQzJIjlSBwpe6TfhtU94bCs0PpU059ea99AXx1go6tNFjMq/YNue4nqjFG80KyzUuYoKM09BD+bU4cu3sIEuZ4hL9geHtgoLOZHgXaA6mP1Up9X9IRWVIfICreb938Sah 7BetzKkx S7J/OznuN6g2x1jMD7Dt+VRypiCQq4lh3EnMjr4rIIvubU1fgxbgma9b+a4S3+iZVS7bqi7b9lRIpWpnR234hECJvVgaTX0gf5bDYHoI2DQ1lpYjDhz4bGULCg1VnKYE1b+SfnjESA/BSt4rUxkKmNUCnx0oygeaoAKrSWzH/flyOcwwJFnGjB34IyJyekNY7w95IJpBh0PSONd37j0Azuv5aeyTZLr2yIEdj 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 Acked-by: Johannes Weiner --- 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);