From patchwork Tue Jan 14 12:25:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13938734 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 58EC8E77188 for ; Tue, 14 Jan 2025 12:36:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E520D280002; Tue, 14 Jan 2025 07:36:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E02DA6B0089; Tue, 14 Jan 2025 07:36:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCA1A280002; Tue, 14 Jan 2025 07:36:40 -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 B1A656B0088 for ; Tue, 14 Jan 2025 07:36:40 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9509714097B for ; Tue, 14 Jan 2025 12:36:08 +0000 (UTC) X-FDA: 83006004816.22.7EAD7E3 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf13.hostedemail.com (Postfix) with ESMTP id 215952000A for ; Tue, 14 Jan 2025 12:36:03 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf13.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=chenridong@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736858166; a=rsa-sha256; cv=none; b=OyzpKs4oQCLyJKwjpiiUJVT5O9XY7B4On+FpwJLjgTAsKnb4TkJeHorb0DBgtyGOXUD4+Q v0E3S5iwIegwpbtTPExEekcyU8QtXe/mqG2BHwlqE99jBKYg8GE4uNiKKM79GmgsBLf0EU 9MAr5lwpjnJ9ZrOGQ9FrCnU8COk9jEU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf13.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=1736858166; 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=OhvrghEKDUlC55WkCuKwVnvPayhXqCXwWrOyJVoao44=; b=Mr/ch4+1vWyC/WZm5HISgjbNs6TmLXofSzYXQrIJXCSBbJEU5BDByds7Z3xANETXOeLyBD FaF1clsm832uJB7p8q+C50pNvqQfS1jRSOESzsP9ZSJW/WEzppXBRnVyDVZ0U7+VwC3Lws Wqpfib/PNktzswrmAPojiSCfVW/Ie6s= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4YXTB30j40z4f3kFT 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 6E6A61A18A2 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--.1325S5; 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 3/4] memcg: factor out the replace_stock_objcg function Date: Tue, 14 Jan 2025 12:25:18 +0000 Message-Id: <20250114122519.1404275-4-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--.1325S5 X-Coremail-Antispam: 1UD129KBjvJXoW7tryDAw47ur15CF4UuF1xZrb_yoW8Kr1kpF srJas8Jw18AFW2gws8Ga17Zr1fJF4vqFnrKrs2qw1xCFnIgF1Yq342yFyjya48Jr93tF4x Jr4qyanrGay7J37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP2b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI 0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG 67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MI IYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E 14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU14x RDUUUUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 215952000A X-Stat-Signature: mg1pwxj69igswosmirofpnjydz4c3nd1 X-Rspam-User: X-HE-Tag: 1736858163-366908 X-HE-Meta: U2FsdGVkX190IIKHxe7FP98CIai/YeAvBN6iRz7LOpvPpC+vAldLlsyOE9nNCJmBXDkNMzNSEGN6MYYgSnbQrAfpGN1OtoPbmU47x87vxXInCp3xwtFEf5BCqsUTd3QC838zs8O9Jq1Hpw0Q3TDzpSHwbGKC1P3b/O7HJMQHJRNusuCY+/i6p0mp3LnJVxHnvBJoc2Ca6j3TYY7e1rHHq2Lpv1LAkmlNTUl0aGhY6zVRHl2Q44N6gmCmcsdhMXhsHBlaeSJDSfT2rNKkCYEING1mEDYlGRkw5sah9P0vhKQdjmtoTBaL0lYVcyguHPYqt6x/GxtRE4pkM73EEYE8BhSwd6rhgeNLpCxrbRhoKHFhDy+Ea6lxFv+FqoASixvrH65XeKHLK8XU5l2986WlX5jVP+SZQFp3ZeYMh68sh6wBy1Uq21pixJw+lP6eCKghiVksDQSxue4ASg9lJd3+UznYd+LH36Ey/mYev7hQV0TfnXSgUXfiTY+G/58QuemuXZ1uFilKtAOin8aHoaGF/jrVchJY9vkVSTekgm3TCJ2p4jMx6QHM0BP/O0z/qK5aQhe1305QBUrqgYVkacHSABEalEPykYScJNBWHq8e4ReWVVJG0rMd8zNi2hFSyiSZOj/Sw+lrLll2u2jt4lb5fvLs8kNEAeg+2HLres9L4KJToTz9mrZywNVVi5ZHiTQsHJf4Q6UnFixeRIpvQLSpqkIo4f4npXWpy31BIqhhoQ7cL6DvLsyHv0rmkk4cxyh1mdU30ez9rD/m56eX2ElvVle/kP9EHYRCOC7sYs4Uf3O1/wvAr5lzqsBnJ3h6W6je0U2jhFGRhKEo+yxACgvMlb5sgX98fB1AGnJR80pKBvoiAUgS7MHOgTBOP1MI2Y9MSEw0a6qyfqxH4dxP/GIBc+hjdhicfTltHOeOwW0MyI+QqfUEDq98TkvPY64fs6TrvfzJMD56hl7PHf0bHDU +TcmF+9A AAnKZHkYASPyPPRscujeSY83SGoMLDCi+I/gcccBNe8aP9q3sxrjGqfzeYqgMSgRMlcmP4XsCWgNdMa4iPT5IZm5qbHTrBosX0XkBKcgNIgWKzTjgMySa0iP0O+ZEbsU6V3nlRqIuLrN6qjPwBtd58vdnNFCR+nsFrQFsn7mOGZ61BCC8u3M7Bh0Jrw== 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 --- 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;