From patchwork Fri Jan 24 07:35:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13949032 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 01D8FC0218B for ; Fri, 24 Jan 2025 07:46:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B49728002E; Fri, 24 Jan 2025 02:46:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A90A280039; Fri, 24 Jan 2025 02:46:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 488A728002E; Fri, 24 Jan 2025 02:46:17 -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 04967280039 for ; Fri, 24 Jan 2025 02:46:16 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 85C2E160EC9 for ; Fri, 24 Jan 2025 07:46:16 +0000 (UTC) X-FDA: 83041562352.16.47E155F Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf28.hostedemail.com (Postfix) with ESMTP id 2196BC0007 for ; Fri, 24 Jan 2025 07:46:13 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=none; spf=none (imf28.hostedemail.com: domain of chenridong@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=chenridong@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737704774; 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=C8bF7wjCk+mtY3eBs/iy7sO2fjY2uHRA9TT6+EiiZUI=; b=S9Kx8BZeJhAJJwRpmy0RLb+Z0/hJv74ovvajTMbY9UChGuQ7FGKsp0PNutc/E8/Ovkj83z 4QG4kqZg0InsMrh97ooMM5NyJbnnsPL8+8Ruv8ZzEmRjEZQKT0Xiv0T5p534hqGJf94Hzq jDrArJ3UU6GnM2UZO4svxI4A6B8ejx8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=none; spf=none (imf28.hostedemail.com: domain of chenridong@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=chenridong@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737704774; a=rsa-sha256; cv=none; b=lljFUDwpLPoNfdLDCLQp1uux6xW5dMgWY6p4PIfo8WB3kcGhti6ki7TbTIooRjZjjof7Ub EFxw5VeIMVxFJhDy3KL+BdqyX34xVYTorwAyPiBwaSDIh+lTtUDADuOyvuCLHpUfqTH8mS EeUaGcQZroPdhzenBNlen6JsJbbnMXM= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4YfVH54gQPz4f3jsy for ; Fri, 24 Jan 2025 15:45:53 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 293F81A1020 for ; Fri, 24 Jan 2025 15:46:09 +0800 (CST) Received: from hulk-vt.huawei.com (unknown [10.67.174.121]) by APP1 (Coremail) with SMTP id cCh0CgBHqnozRZNn89xFBw--.58969S5; Fri, 24 Jan 2025 15:46:09 +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 -v4 next 3/4] memcg: factor out the replace_stock_objcg function Date: Fri, 24 Jan 2025 07:35:13 +0000 Message-Id: <20250124073514.2375622-4-chenridong@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250124073514.2375622-1-chenridong@huaweicloud.com> References: <20250124073514.2375622-1-chenridong@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgBHqnozRZNn89xFBw--.58969S5 X-Coremail-Antispam: 1UD129KBjvJXoW7trykJFWUuF1fWryrKF4UJwb_yoW5JF1fpa 9rKas8Jr48AFW2gan8Ga17Zr1fXF4vvFnFkr4Iqw1xCFnIgFn0q342yFyjya4kJr93tF4x Jr4qyFsFkayUJ37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP2b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA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kdO+YwZkZYENeujLiKUN35DH6GnmBb3qGH7JdFDz4ygMxWa5NSNPvLlC+ikTwWXT7jesoW/BkMLfFR6X1aSpV4rI7DxLQ/6l8cbcc30r/I3jh7Iy/QzZ4UTzljHg6ZrAXvDa+aMJvvUG/iW1C0E67WS1OGC8HG/+ZQkYQArxlWftxrRfO75qM3+0MQUD/d3eta1ijLz2Ju99tTO4lOqt9ej61v5tAnkDncYd/obDk2dvLPjG/DY/qYlAxh8Qmj4z+4kEd+7p2MAinL+BYblQNAjcGXwWyJoDCBE0wExbr0CFXieeOk+GOI1gXG1eeGIXw7e86yai49i8vg3cw/oxTRdUbxFZ7B0BoFZpMbymyXvbeJuR1vFAocD3sSdLSjKi+pTIl8ikeIUpyE4sNJTUbjyhbqzi3m4a1O0d/C4KTvu/gmdzBPop79qdZh8+YlEBHCpCiWiv rClTTl4H sFeJyhR8L/dE5sne9u9yE+IS+2zI0u1ZVn6IDfNtYETwwCuNhjc7+bwXjJ29GOlw1X0+HNJOI32JdluJxsi8aeFrtLZ+y7/ftLjmvwoxAyaQNydGBWF8XfwncXLa3cAfnEZ7C6NVDVAowEagK/QmgAvxGdtbqut1Lk5YOKDnvSeCzakMn4Hfph7CO65VTpm+rb5qQqKz1FvdRuwFAWmgv0wPcRaPFFwWY8qBT7bXpIpJT5g/KafVbU9qdN4XOf/SZD/+p 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 Factor out the 'replace_stock_objcg' function to make the code more cohesive. Signed-off-by: Chen Ridong Reviewed-by: Roman Gushchin Acked-by: Shakeel Butt Acked-by: Johannes Weiner --- mm/memcontrol.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 98f84a9fa228..b10e0a8f3375 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2691,6 +2691,20 @@ void __memcg_kmem_uncharge_page(struct page *page, int order) obj_cgroup_put(objcg); } +/* Replace the stock objcg with objcg, return the old objcg */ +static struct obj_cgroup *replace_stock_objcg(struct memcg_stock_pcp *stock, + struct obj_cgroup *objcg) +{ + struct obj_cgroup *old = NULL; + + old = drain_obj_stock(stock); + obj_cgroup_get(objcg); + stock->nr_bytes = atomic_read(&objcg->nr_charged_bytes) + ? atomic_xchg(&objcg->nr_charged_bytes, 0) : 0; + WRITE_ONCE(stock->cached_objcg, objcg); + return old; +} + static void mod_objcg_state(struct obj_cgroup *objcg, struct pglist_data *pgdat, enum node_stat_item idx, int nr) { @@ -2708,11 +2722,7 @@ static void mod_objcg_state(struct obj_cgroup *objcg, struct pglist_data *pgdat, * changes. */ if (READ_ONCE(stock->cached_objcg) != objcg) { - old = drain_obj_stock(stock); - obj_cgroup_get(objcg); - stock->nr_bytes = atomic_read(&objcg->nr_charged_bytes) - ? atomic_xchg(&objcg->nr_charged_bytes, 0) : 0; - WRITE_ONCE(stock->cached_objcg, objcg); + old = replace_stock_objcg(stock, objcg); stock->cached_pgdat = pgdat; } else if (stock->cached_pgdat != pgdat) { /* Flush the existing cached vmstat data */ @@ -2866,11 +2876,7 @@ static void refill_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes, stock = this_cpu_ptr(&memcg_stock); if (READ_ONCE(stock->cached_objcg) != objcg) { /* reset if necessary */ - old = drain_obj_stock(stock); - obj_cgroup_get(objcg); - WRITE_ONCE(stock->cached_objcg, objcg); - stock->nr_bytes = atomic_read(&objcg->nr_charged_bytes) - ? atomic_xchg(&objcg->nr_charged_bytes, 0) : 0; + old = replace_stock_objcg(stock, objcg); allow_uncharge = true; /* Allow uncharge when objcg changes */ } stock->nr_bytes += nr_bytes;