From patchwork Tue Jan 14 12:25:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13938733 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 8B9F7C02183 for ; Tue, 14 Jan 2025 12:36:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 292C56B0085; Tue, 14 Jan 2025 07:36:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 242956B0088; Tue, 14 Jan 2025 07:36:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10A226B0089; Tue, 14 Jan 2025 07:36:19 -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 E1D8A6B0085 for ; Tue, 14 Jan 2025 07:36:18 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8BC26C0AE3 for ; Tue, 14 Jan 2025 12:36:08 +0000 (UTC) X-FDA: 83006004858.23.D42EAF3 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf27.hostedemail.com (Postfix) with ESMTP id 2F0A940016 for ; Tue, 14 Jan 2025 12:36:03 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=chenridong@huaweicloud.com; dmarc=none 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UPKc7ft2JpOg+OAKWpamlj/AW0n8d8vPesZcgRRiI6s=; b=ea+DwgrXT3vX76KxWtfvmAwpd+6IAmCBbJk/Y131LpRuH1LUvztEkQ0mubnV7qRQff+1N2 mqYO1u8J3CAnuCOaIOfU9J4/pGYHYUC99Nln6a+pFe5oP3wyw0hwJvK0FRtjDA0pDq3hYr 8WUkNW7e9vIBUWY6DSP30IUmP9nKNlk= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=chenridong@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736858166; a=rsa-sha256; cv=none; b=Qk70OxNc1aGdeuuXH42Joh9NkI64VVcmQxg+3fwachZ4GshUdYkLfLZp/8k1C/VpTHPM3a /jtIWHiNXsym8s3krtvaBSZN0sM4kl8YyQNdqnCfLKqJ8rWthVt6xXZk0O4jMlRg3pyd8d h/xju1ZqWNx+FVggNgXRc+K+kuw/r2g= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4YXTB26pTgz4f3jdP for ; Tue, 14 Jan 2025 20:35:38 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.252]) by mail.maildlp.com (Postfix) with ESMTP id 4D8971A1285 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--.1325S3; 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 1/4] memcg: use OFP_PEAK_UNSET instead of -1 Date: Tue, 14 Jan 2025 12:25:16 +0000 Message-Id: <20250114122519.1404275-2-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--.1325S3 X-Coremail-Antispam: 1UD129KBjvdXoWrZFWrJF43Cw1xWF1xWr4Uurg_yoWfGFX_uF WkKr1DZr15J3ySk3Z0yrySvrnayF1UX347Kw45tw13AFyqqasYvF1vqr4vvw1kXr47try3 Cwsaqayqgw12gjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbDAYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r18M2 8IrcIa0xkI8VCY1x0267AKxVW8JVW5JwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK 021l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx 0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWU JVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCY1x0262kKe7AKxV WUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jnpnQU UUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2F0A940016 X-Rspam-User: X-Stat-Signature: 9f77cne3tpf9cocs5dtsmkrhxc5epyuu X-HE-Tag: 1736858163-941162 X-HE-Meta: U2FsdGVkX1/bvPvzAPpjHH+pSN9heXnHTSgbFO3NxppSKY+mFJjzwyCKXWBLUlLthg51WbL5/SfVLtIvVYWwMJkEB06oQSfbatVgAYa6SKbQOUNnl6O2BN8IZo8qQJoasSRIfkmArCHNcKvH2jiPYufqLZvwLrnV67xk8OK9IDtiI0QuwVdr/O6ulIklpC1mNmTYpR5+DJiBkIov/3/yRyaF9GB0gBa3Uqb5bm6ols1EFx5EaRhbnpDqut4U9cmyUfj+iaaCGo/fLyScPYHnHhRNsVkbPP217C8gkcJCiVUGNqHOEwWLCJ3ZCHsorQQAl6JHqgOzFOScRNdhbYFMFIkKjTT8pYaCg34CLnGAcMI1OKF9Msf0PlVNUaY4S3Gp6xhyAreTJPmr1tOeDULGzp9R61zWmQWU12FhKjL4SMsXlwHmHXbDBujcWc7FK0wJgAkTZPJDwq4GqOdJ9gT+CG559yj8zZr5/6ph9gN99GgW7jSyS2PymWTMZO3ltItaltTH/JXBsHFV7+ddGO4/kO3P/VRDbbgzXj2JKEKmTplzUOF9zLIqJA3b0rmjxArEXUywAARuFxLOuq6s+FGucf31Um8tqOFulWGGWyTgzrv9VrvQzYK3T8V2xE8NDgqKyb1vkzvvYuvA1IiRbiR43xT3NsFEEx42axfVw03U5FLRFFYoWSVkOYD5DO4iViKimMj3sxddNGCfoqjYIJbx5tKK1at2v9KpOxpsQK5ZVAM4zDiYgPT3mXSO5Z+R98sjwd3aMjl5wS0i8/DeMdj4CGIAArfeiztwoywJz/xdXysuUNAz2ionjzUmhQfdXr2vFfSEbn4Gr3LT23El8DYvjnnqPdF5UeCVx6iqDqAYndmgJYbykyqe8YWKCDs4eL0OdFuOFNA5ynSunE7ZhnjAybT3HS61IohypMCeIGvEIwy6hrAtnihXIhAbKtzoG3XKkKJg4Xt6uqeyKsrD+uU 88rBdRiq fODbXHXusQSboPW4cz2baRFu1HNFRTw6E65Z585fyAawHyvuewA5ABxFxicyuLoV/kaKVtd+mLT2/XWeCf+db9nde/n2CKvoetr4Xrv+zKJGnL60z1B6HsR3FlOoh3pTA3iE8xpwna4LM3XLGUlyH5JTjR/br5ynFDd+el5jmEmgu5GuotNpydKsZUDR5xwYlSjVxPrFy2SNJkT/Qam65ARzCVXi/+RacaZtmW6yplFIiRNkigJna1cW2Xs8m/h7MXAhARzQzVxtxodoLCFCCBT9AMLHa8Yw4wrp38JARwPYmJLY= 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 'OFP_PEAK_UNSET' has been defined, use it instead of '-1'. Signed-off-by: Chen Ridong Reviewed-by: Michal Koutný Acked-by: David Finkel Acked-by: Shakeel Butt Reviewed-by: Roman Gushchin --- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 46f8b372d212..05a32c860554 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4004,7 +4004,7 @@ static ssize_t peak_write(struct kernfs_open_file *of, char *buf, size_t nbytes, WRITE_ONCE(peer_ctx->value, usage); /* initial write, register watcher */ - if (ofp->value == -1) + if (ofp->value == OFP_PEAK_UNSET) list_add(&ofp->list, watchers); WRITE_ONCE(ofp->value, usage); 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_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI 0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG 67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MI IYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E 14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUFSdy UUUUU X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ X-Stat-Signature: khuc3fyfde5a5rosbmgwqrxrwwue83bm X-Rspamd-Queue-Id: 5AC372000F X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1736858163-920551 X-HE-Meta: U2FsdGVkX19XoDAQVlkqrGQ67KqnnFGS8uE2QfrVtxdLa0RxaALXQ4L3xrjX4mipCU5wZfUWKzfhlTabjmcEUnIzDZD/NXKM+mlMhrPMjrQ3/Jy1bQoIPst6Tn7LsoJ4Mq7MxkveFYWS78tfMAc5ZG+PVMCYbvDRBVyEBJ19AyvrZdL3Qaahs/yo6wTNPMuHrgA6GtDNVUM+cZVNiMBI/Qnzs4+q0egz/YukVfLIwFafvlpSL8/NF5x7HwhnVuc0022/zqAr1FF3MnEJMYWbIZIUbpQJVvs/1utHKAWEDNce7RQQs8TqgoFvwYcR/lCZKkr/wPv/aRH0soVFa7an9MehLT9zUSyR4m79d4mAA+IAATNiTMBJQOGEcT3Q3xwwz5y37ZFpHB5kYstGcR1T7goFpdDW+lKwKo1LyBpJQKospGnsvqCNp0lvbOgFFj0v1HML+1GuO4g2utA7f9WXAS6dimx2HOUG79oh2PHDkpk0XeFYLDZ+cUkxxTmhx9G8jaNrEkhECxRbYNzy8tDv/+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); 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 --- 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; From patchwork Tue Jan 14 12:25:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13938735 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 ED271E77188 for ; Tue, 14 Jan 2025 12:36:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C31A6B0088; Tue, 14 Jan 2025 07:36:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7726D6B0089; 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 5ED466B008C; Tue, 14 Jan 2025 07:36:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 425AE6B0088 for ; Tue, 14 Jan 2025 07:36:57 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 64172AF323 for ; Tue, 14 Jan 2025 12:36:08 +0000 (UTC) X-FDA: 83006004816.05.62A7628 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf24.hostedemail.com (Postfix) with ESMTP id B46FF180016 for ; Tue, 14 Jan 2025 12:36:04 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.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=7ydYpndpRJmJFmZQj+DQyRJThoROW0LRsQ/1tw8rMWQ=; b=Mve14cPZsFtQWmyzoaqm3k9w+PSSVO9Ht5z8XWiSp41Q5T44CKY+OdOAexl/Gz1+MsawJp cs/8SZ5xNPKOf8bV7s4Jn6xRrKn9o9W1CaWExRQ8cusqKD1BYTtYVrDtH1vOyyOPniV91i Zd2NBgf2HIbLMoGZHPKiLmHltswape8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736858166; a=rsa-sha256; cv=none; b=DP+aEmUscUivr6R77X2+ktS6yGFAu/4iGELd0m72pO/gx5Ef6fHvMvudZuKAAzjB5OAq3T +97w5yi2e6iu3SOiPjjnPJwzTS+s06JhYmKtIKubiTH+6/4kaFLFRJOqIzgiDbwwdyrkv1 vXmGmOKyXgN92iiuOhx7p4HqpHo0EQQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.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.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4YXTB314mLz4f3kG6 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 82B401A0F38 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--.1325S6; 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 4/4] memcg: factor out stat(event)/stat_local(event_local) reading functions Date: Tue, 14 Jan 2025 12:25:19 +0000 Message-Id: <20250114122519.1404275-5-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--.1325S6 X-Coremail-Antispam: 1UD129KBjvJXoWxKw4kZFyrKw4rJr18tryxXwb_yoW7XFWUpF sxtayY9rW3Jw4F9r1ftFWjv34rA3WxX3yUJryxJ3ySvasxtw1Yg3ZxKF9rZrW5Cr95ZF13 Jayqyr1DJ3y2qa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPqb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2 AFwI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAq x4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r 43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF 7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI 0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x 07UZTmfUUUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ X-Stat-Signature: ab31hy85xg8474awi7zywmsfm5ahcx33 X-Rspamd-Queue-Id: B46FF180016 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1736858164-900666 X-HE-Meta: U2FsdGVkX1/cj8BWGIci+ANO8hB2Fhhu4qPMu0lyVtXcgLdrX3D4fOokZ0G4Mk18K3T+vAQ/n88wgR4ms2WinnDTk1aBm4fmmKR6nRPUHCGHvU6OmBo1Ta1FqAvNKz9NdRs6OxZ4pF0WEiu6Bxs63va2d4Ri+GCUioMoZ+QNKJtWgwu9MaFqBSi1Iga8LrcjubKP0VHNxVcNO34YRxHj6/iitCuBSWbsrF45ELF9piqxpOm4VHvkMkZqEvrft+6OIYZRQXvbPY5mV41fFy4OD46zNrCY9Y2hLkD7sTB9hTZdoFwyf6ZTr/CsRP470WLFHNGjJxM+yn6OzrzgrlpTJe+o0+41hqTB0090fNuQHKT/6AHAjIM7/1PmtkaHAiSE6ta3fGyOyAgnoY/fJL4KVBStikHJvt0ChYU35PAWnaWXPSR+8TH34xZzPGSQUmSkmFgWbjeJN2jljKGKh4p1ZkbmnpHyopA9Mv2Z0b37jDolpl9/VsggwowZsj0Sx7z/262RQRHGCcm7dgt80/UnONoectz7cFAZUbex0H6+A1BSt7U4czGxddek7ry2QE381/8LyqotilsNary/QjUA3IlPWq2XMI1cX3zChUyS+zzF+81YMPphUdxIfZyRG4geLzENwh5cj3tMRz6pojPWA/gmwVgs+nYr7wFZ2VDalk6dweuEa7Lt46rQy3Sf25BtjXeKViPfU+caaKp+fcKr0ROusnUvReHxYErp6HTzGip/yMmGM8PtunDdQ/ddkffNER9kHYtoG+mMPeu6oP6zV7gycqTLAxrPin6+20yUwg5b6i4cJ5oAzWH6XWdqawBr26+LLNWMf5cs7aWaFLGgGFr/6R4Jk5IPeOH4XSU+N/ezoMEDe0D6IETRCql67omPNwEkfcC9aKQS+1al59KTeEmVsrEvvalpsDIvt6fO7KLI9JIFb3qVqnOqAu1Rh1lbp7VOl0IN01eu83og+Qx Xa1k10B5 pB1b8cShaq76tF4NrVaaY2E6EByTnaH5NXGF3Yh0Kwjuy3azroX3huYr428YDAwIGOLG+B83YRmP6VcbF8m0Er6jzfweeAmafe3JIoKh5CMxBOMdTTveazQYx0VkSLYOClNnrXJ26MTrrT9/+FrdfNhPB9AQWsHjh+//K8q7jNPPSYfCBL8tlxkB1vA== 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 only difference between 'lruvec_page_state' and 'lruvec_page_state_local' is that they read 'state' and 'state_local', respectively. Factor out an inner functions to make the code more concise. Do the same for reading 'memcg_page_stat' and 'memcg_events'. Signed-off-by: Chen Ridong --- mm/memcontrol.c | 72 +++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b10e0a8f3375..14541610cad0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -375,7 +375,8 @@ struct lruvec_stats { long state_pending[NR_MEMCG_NODE_STAT_ITEMS]; }; -unsigned long lruvec_page_state(struct lruvec *lruvec, enum node_stat_item idx) +static unsigned long __lruvec_page_state(struct lruvec *lruvec, + enum node_stat_item idx, bool local) { struct mem_cgroup_per_node *pn; long x; @@ -389,7 +390,8 @@ unsigned long lruvec_page_state(struct lruvec *lruvec, enum node_stat_item idx) return 0; pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); - x = READ_ONCE(pn->lruvec_stats->state[i]); + x = local ? READ_ONCE(pn->lruvec_stats->state_local[i]) : + READ_ONCE(pn->lruvec_stats->state[i]); #ifdef CONFIG_SMP if (x < 0) x = 0; @@ -397,27 +399,16 @@ unsigned long lruvec_page_state(struct lruvec *lruvec, enum node_stat_item idx) return x; } + +unsigned long lruvec_page_state(struct lruvec *lruvec, enum node_stat_item idx) +{ + return __lruvec_page_state(lruvec, idx, false); +} + unsigned long lruvec_page_state_local(struct lruvec *lruvec, enum node_stat_item idx) { - struct mem_cgroup_per_node *pn; - long x; - int i; - - if (mem_cgroup_disabled()) - return node_page_state(lruvec_pgdat(lruvec), idx); - - i = memcg_stats_index(idx); - if (WARN_ONCE(BAD_STAT_IDX(i), "%s: missing stat item %d\n", __func__, idx)) - return 0; - - pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); - x = READ_ONCE(pn->lruvec_stats->state_local[i]); -#ifdef CONFIG_SMP - if (x < 0) - x = 0; -#endif - return x; + return __lruvec_page_state(lruvec, idx, true); } /* Subset of vm_event_item to report for memcg event stats */ @@ -651,7 +642,7 @@ static void flush_memcg_stats_dwork(struct work_struct *w) queue_delayed_work(system_unbound_wq, &stats_flush_dwork, FLUSH_TIME); } -unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx) +static unsigned long __memcg_page_state(struct mem_cgroup *memcg, int idx, bool local) { long x; int i = memcg_stats_index(idx); @@ -659,7 +650,9 @@ unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx) if (WARN_ONCE(BAD_STAT_IDX(i), "%s: missing stat item %d\n", __func__, idx)) return 0; - x = READ_ONCE(memcg->vmstats->state[i]); + x = local ? READ_ONCE(memcg->vmstats->state_local[i]) : + READ_ONCE(memcg->vmstats->state[i]); + #ifdef CONFIG_SMP if (x < 0) x = 0; @@ -667,6 +660,11 @@ unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx) return x; } +unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx) +{ + return __memcg_page_state(memcg, idx, false); +} + static int memcg_page_state_unit(int item); /* @@ -709,18 +707,7 @@ void __mod_memcg_state(struct mem_cgroup *memcg, enum memcg_stat_item idx, /* idx can be of type enum memcg_stat_item or node_stat_item. */ unsigned long memcg_page_state_local(struct mem_cgroup *memcg, int idx) { - long x; - int i = memcg_stats_index(idx); - - if (WARN_ONCE(BAD_STAT_IDX(i), "%s: missing stat item %d\n", __func__, idx)) - return 0; - - x = READ_ONCE(memcg->vmstats->state_local[i]); -#ifdef CONFIG_SMP - if (x < 0) - x = 0; -#endif - return x; + return __memcg_page_state(memcg, idx, true); } static void __mod_memcg_lruvec_state(struct lruvec *lruvec, @@ -859,24 +846,25 @@ void __count_memcg_events(struct mem_cgroup *memcg, enum vm_event_item idx, memcg_stats_unlock(); } -unsigned long memcg_events(struct mem_cgroup *memcg, int event) +static unsigned long __memcg_events(struct mem_cgroup *memcg, int event, bool local) { int i = memcg_events_index(event); if (WARN_ONCE(BAD_STAT_IDX(i), "%s: missing stat item %d\n", __func__, event)) return 0; - return READ_ONCE(memcg->vmstats->events[i]); + return local ? READ_ONCE(memcg->vmstats->events_local[i]) : + READ_ONCE(memcg->vmstats->events[i]); } -unsigned long memcg_events_local(struct mem_cgroup *memcg, int event) +unsigned long memcg_events(struct mem_cgroup *memcg, int event) { - int i = memcg_events_index(event); - - if (WARN_ONCE(BAD_STAT_IDX(i), "%s: missing stat item %d\n", __func__, event)) - return 0; + return __memcg_events(memcg, event, false); +} - return READ_ONCE(memcg->vmstats->events_local[i]); +unsigned long memcg_events_local(struct mem_cgroup *memcg, int event) +{ + return __memcg_events(memcg, event, true); } struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)