From patchwork Fri Dec 6 01:35:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13896221 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 80768E77170 for ; Fri, 6 Dec 2024 01:45:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B095B6B0150; Thu, 5 Dec 2024 20:45:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FC386B015A; 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 578F36B0154; Thu, 5 Dec 2024 20:45:12 -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 1721A6B014F for ; Thu, 5 Dec 2024 20:45:12 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 921A0C1828 for ; Fri, 6 Dec 2024 01:45:11 +0000 (UTC) X-FDA: 82862840508.27.67E8430 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf15.hostedemail.com (Postfix) with ESMTP id 5E24FA0007 for ; Fri, 6 Dec 2024 01:44:50 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf15.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=1733449493; 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=aarG5x0F6As3NG//sAUTnErB/Ygp1DCXiUfC13G9XS4=; b=M4zV6UQnzRgK14dpID8txaWMhyOPjKoWbSgvpbE4SXR3BgZTp4VVVyGb/hnuRlQZVXuU9a kzGWesB3Pg5sTt768T1FW7sunJNztvm8q+PIBSWo5eVMjTQoZ4TFdQpSKCT8Nz5x5++GbG IxGPADJgcvIQzipCdr2kTc6LfAMZjXk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733449493; a=rsa-sha256; cv=none; b=yJYO5W9r5P+btS6pQdWHNyAKgkLmk1fOy7f+jpVLmmqnRYXZU03AvkwCgGoNhtTxvm0VjQ Ej60nZVHAj9HWvhzmWxdBR4tvxzLrdE15UEEqATXxLeqJI6X1CuQuI/dfDBbIKgW5a1u+4 tlb8eOGlJo5atEN1XGJMzqljXfzHq2k= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf15.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.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Y4Db43HrRz4f3jq9 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 7FD281A06D7 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--.31315S3; 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 1/5] memcg: use OFP_PEAK_UNSET instead of -1 Date: Fri, 6 Dec 2024 01:35:08 +0000 Message-Id: <20241206013512.2883617-2-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--.31315S3 X-Coremail-Antispam: 1UD129KBjvdXoWrZFWrJF48XF4kAF15tw4UXFb_yoWxKrg_uF 97Kr1Dur15J34Sk3WqyrySvFn2yF1Uuw1DKw15tw13AF9Yq3sYvF1kXr4Fvry8ZrW3try3 uwsYqayqgr12kjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb9AYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r18M2 8IrcIa0xkI8VCY1x0267AKxVW8JVW5JwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK 021l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx 0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWU JVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCY1x0262kKe7AKxV WUtVW8ZwCF04k20xvY0x0EwIxGrwCF54CYxVCY1x0262kKe7AKxVWUtVW8ZwCFx2IqxVCF s4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r 1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWU JVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r 1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1U YxBIdaVFxhVjvjDU0xZFpf9x07jjuWdUUUUU= X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ X-Rspamd-Queue-Id: 5E24FA0007 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: zqwg3heo1mqk4krs9q147drtdrdzc8ha X-HE-Tag: 1733449489-377970 X-HE-Meta: U2FsdGVkX1/9WrTPseqdk7ka1dkQ/cpbFU+XUb68r5xxYa9H0JAcNLG1eJ24TtKpzPfH3UbQBvQUT7OgO5PZVQk7pBabMJ/u18ebjeVcwmPHf5oClXmzPlJkI2UuMHUUsVgylTbdiwpNoKh0OrGKLCZ1MLyrtgCuo/zSV6aw5DugDXJofgml4LOpDCnzBwd026bdOPBKEf/hbPBkhetXFmUwxzTVP7uSd53Dv4iF8OpVI10depVhd4b0t7V5H9MMgmzSsQfh+k7Y6wueHn5v/J8q4lPuX4eFKaXcde43NfARuGtbBsT7Rz/+5t4POPoen6oadzZEH2sWEEJ5+YRG/HrreyPtVheHjrjf2Y0xM/nKXu3X0lB4nvT0y/DldujDxDl0qAFMdV8ugTxL3HjddFzcHwBY0QTjKNpwJLhLeodidu0N+KcdcRTayqXtsuXiEe8pAxO1fFLOXJw/EWRrnivdJweO8E9o52Tzl3vJt4zfvSX18hglUv8FLXmuEMYvmwPAEP490hYwBJWMcnzMON9XFHD/ysTvlVze0qAQazdBkoTpKltLfMli2TkRMyXRUgrh4IHa0Bxa8neZhFZ67aSYyEgCiO8rLVVDho1nA0zIgfEoIlSY9Ik7p+KRaNFn980mrgRc4W/oLrgigvt2oeowIR2EVWSV04FiPmVvgx/svEnhNU3HaPQXMwxac79vFUPUm3j8AOlDgvwZWZAuF6O1emTAmuZ+ee1DUQlABxONqykUx1jrmyoW3I8T2P17tusx8CB5kJDXmHnHGy226aXg6LFCl/FLxxmzSZRYZQxRCZH35Drjm2GORSv3/DLn4uaZVVU1jsGMvch6tvHNBT1Oq3EWSbzUPLATadkWb13/yqf5pIcgXmmrB9nGk0mY4xu/9IwYDMIT4KhXw0QQH4a7u5XEFzaprO7PXkohdp7kNBlFMFZms4paDbo30Qwtv0eDRlh3igrJJPozGEs FnHo/JV3 RnzTg54iWfSEd2BZlS4++A9UWYsTyTbRSv4cTvZRd8WIu9Iu7vuiKA4UdTkpeA2NYPKawn0ODX0XtIeezrgMqIMUGFD8lO8wRQiQ4hLBnkFm0J3RJlQ46S4zkta2BXpUryRpUTJqhDSaC80rRA134Nv0RaMmAfiqBwSTgMoVO7EReP2j5t6OhHvmcgw== 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 --- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7b3503d12aaf..fc18633aba5d 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4014,7 +4014,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 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); From patchwork Fri Dec 6 01:35:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13896224 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 9CB1BE77171 for ; Fri, 6 Dec 2024 01:45:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F7266B0151; Thu, 5 Dec 2024 20:45:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E77736B015B; 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 CA5616B0154; Thu, 5 Dec 2024 20:45:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 88CB16B0152 for ; Thu, 5 Dec 2024 20:45:12 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3934242B82 for ; Fri, 6 Dec 2024 01:45:12 +0000 (UTC) X-FDA: 82862841096.29.F113C51 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf18.hostedemail.com (Postfix) with ESMTP id AC2EE1C0010 for ; Fri, 6 Dec 2024 01:45:02 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.51 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=1733449492; 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=+8qktzXMdRjxXhxiAklsmSf7Wr/BH3gMSJje+TS31gU=; b=0Ss4eXZBXhONRAML9H8L+xotOGZ6KsPG2Mqo0HAAsELUb3IdF0D3lSbfrAVkT2r+Gi0pcU QhBGGjRxf3f02SrgNL7etp2z4U6Lzpy/i79JzT9zHcPhY7l1mJT52OEBpnsxA90HFx9PF+ hSwnWNU6HePclFxNLb78cyekgT9YDsY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=chenridong@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733449492; a=rsa-sha256; cv=none; b=2/WTTtjyKOVcLlcoZ7Tqz88PrOLPfUYifgK6DNylcFPxqmcnOuM27sNRcVJ5jy9WT9u1pi aiZR0N7TBsehzFNVJwD9J6LMVZWtqRdfVGz2BJcqetWt9bnEyyq2rg+tbcTMWeisajv67a a3rZt9WuoQEQni2zEQdyHAb9VE1fY/E= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Y4DZy436Qz4f3lDG for ; Fri, 6 Dec 2024 09:44:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 9D7BE1A06DA 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--.31315S5; 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 3/5] memcg: simplify the mem_cgroup_update_lru_size function Date: Fri, 6 Dec 2024 01:35:10 +0000 Message-Id: <20241206013512.2883617-4-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: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EY4v20xvaj4 0_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8 JrUvcSsGvfC2KfnxnUUI43ZEXa7IUbd-BtUUUUU== X-CM-SenderInfo: hfkh02xlgr0w46kxt4xhlfz01xgou0bp/ X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AC2EE1C0010 X-Rspam-User: X-Stat-Signature: tywdtbgyw4etarpephashi73sgkhjxfd X-HE-Tag: 1733449502-848022 X-HE-Meta: U2FsdGVkX1/D50+Uh52sk5H5ncT5bhHQJp7pXYdlhzfwxqTJ9sSK12cA1mlHRy0SCOQThKM5ANsad+5X32PE9gDmNuYVipaNLz9z311OnYKYl6z3x+JIbilec2rg1uAhq1PgzjQzvp3II/NA0BoOkbwiGFhPm2RZPk2ajQBIsFm9EYWe/vvQjKMbYWlhkglyk7qr4BHLCcEU7nn6ASjnD/iOBD7mfTfbvm6KbHrXCnPVLUDxwkGq063qGk/zxYMCd3F9LkBu4b47zy79qiIq/179u7SPokgl/KNNu3e4ev73bEnvI29ev0ioaAkw0cqiAgLZIitxQFbhDCSZpB/ALejqpW1uymXHEQ+6Qxk0YUBtmjkbFNeC8rF3Ru9fMGJdYwFoprSossZH4LeWTuVT3nzVkzwBfl6gordIkLugARPdP+AVjya4RmvNUqEN8F1DR7G0/NakE0zP1bM/05iiMSnkmw1EztQam4wU8/VmrVSqiAjJoJ8+exsQn4oi+RZPlOfYSSsLh2wg7JajkYafrFtqI8RewPENN5fIgeNOUaxVxrepP3SaYc3mqrXYc1m1tzC57wJEqBte4SQwJ+OeeXidMGpzZK9uqBdaAGpHFU86TZauP8vJNHcjW07vE646QZ21F0V2Fkqve1R4XdEtbuOqqPZ0xiLynHuQgLlzW6ZYVHdXzW/cyzTD9Bj/vc7zRCn+mPUxfpFWqxwji41dtz8Y/6FawwOeRPhu0Ib4N9MYpT53wr9Vc00j/3YYhObtStYhUNWqumgMAFgfNzRelGJElvUQiLL7sl1K2hR2yw15BDaV7gfk5FQOTriGghzhQUwWbTyz9v4bI9/IALJdz7UZfBidtRM7Hgwgq1BqE7HeOD9JNw09Ohy8xXW7kbUeVuBHG0R8FbT5PAU+4QWc+wpZU320DphRUVPlnPyfQH56msoTbKNl3mk0Gdzv5WjbhdyOCJZ+AKwR8s/+YSu L3Tt2OSb V+D0YQRCHTX0tjWlaOP8RswTFyBYDVlw7zcdIHLxKmd2PCQIk7GeY7lA/GREj2L7Z6y5GjRWeJ1pZYMyMVWyT1ay/7T9uF6KEDKnvm3st3k8fhPWsFZF1efKHnUo/amj8Usd8mZHTUvMayCS30wXVjH7xA+oblmpyLjjIZNhZemRK4QShGrU6xs1CaA== 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 In the `mem_cgroup_update_lru_size` function, the `lru_size` should be updated by adding `nr_pages` regardless of whether `nr_pages` is greater than 0 or less than 0. To simplify this function, add a check for `nr_pages` == 0. When `nr_pages` is not equal to 0, perform the same actions. Signed-off-by: Chen Ridong --- mm/memcontrol.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index da6e4e9bd0fa..f977e0be1c04 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1280,15 +1280,14 @@ void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru, unsigned long *lru_size; long size; - if (mem_cgroup_disabled()) + if (mem_cgroup_disabled() || !nr_pages) return; mz = container_of(lruvec, struct mem_cgroup_per_node, lruvec); lru_size = &mz->lru_zone_size[zid][lru]; - if (nr_pages < 0) - *lru_size += nr_pages; + *lru_size += nr_pages; size = *lru_size; if (WARN_ONCE(size < 0, "%s(%p, %d, %d): lru_size %ld\n", @@ -1296,9 +1295,6 @@ void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru, VM_BUG_ON(1); *lru_size = 0; } - - if (nr_pages > 0) - *lru_size += nr_pages; } /** From patchwork Fri Dec 6 01:35:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13896220 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 64525E77171 for ; Fri, 6 Dec 2024 01:45:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C1026B014D; Thu, 5 Dec 2024 20:45:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D8FB6B0150; 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 4679C6B014D; Thu, 5 Dec 2024 20:45:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 17FE66B0150 for ; Thu, 5 Dec 2024 20:45:12 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 943B080BBC for ; Fri, 6 Dec 2024 01:45:11 +0000 (UTC) X-FDA: 82862840592.25.8FA16A3 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf16.hostedemail.com (Postfix) with ESMTP id B73EE180010 for ; Fri, 6 Dec 2024 01:44:51 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.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=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=CcvOGVirthUfv80HLNyKloVSeZGr/n2sGkEM368NT9M=; b=5lWJTYQVy/OfxpYn5zd5Nfe7z2vXHsujhCGNfAo9knNcadnB+eMT3eFp+uu4ln2M80tOSC 4ZWb6B52GV9OmNMoqm6OkbMGl9VfvmTHsP5Hba3ff9z5/omuzWHFltVWZZh8K3G2kAHpPs CkVg4x+dtJ5sfv8Afk5r9Rj28qg9i7I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733449502; a=rsa-sha256; cv=none; b=AWCeL5mGOS61fW+TV7u6q4vu6rxVbJBKYRbG3dmkls5g74/tlvfwyLp72H1nqEValzjddR UK8KFc0VPWKCPLZyLgoxUb+oD31PKuzBk+1QYvD+VVAG/rhaPXWP+dCzhvZDY9Mz9M/zLn 2kzK5ldyG4NKJSsl3nIiXkvDuOj9SmE= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of chenridong@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=chenridong@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Y4DZz4X62z4f3kF4 for ; Fri, 6 Dec 2024 09:44:43 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id AE7171A07BD 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--.31315S6; 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 4/5] memcg: factor out the __refill_obj_stock function Date: Fri, 6 Dec 2024 01:35:11 +0000 Message-Id: <20241206013512.2883617-5-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--.31315S6 X-Coremail-Antispam: 1UD129KBjvJXoWxJF43Zry7Xry8tr43ArW5ZFb_yoW5GrWDpr ZrWa4UKw4kZFWxWrs8CF47Zr1rJF1vqFnFyw4Iqw1xCFnagFn0q34jya4jya48JrySqF4x Jr4qy3Z7CayUG37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE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LB2GNUoICXCEd3nJ3rdmvxJbYTArtWTH57RSFXe7syFnSOy+2jDSTaR55o1oXWCMMry8eWOGZ5gRfkS68LnrSeAef7VXw3zX4WZDjq2wq0KyMQwVFDRXausaBjtNsQ/3CqyS/FIRb5q+ZbeH+l0sc6iAN5M1x27ggsQOXqnhHey0gIqqpDz9MKrSlrxVoJFRpT4mBQxJD7O/R3qjkjpTlJ5uzY/HCNYhp+RQKAN4sGhBIfUlOw0BhQAxddIdQOvQESEYrHyFjGXEPQ+b43MajSe375R6hoddWdlII1Ht9j7ekOZVfC6Kapjndea54i8CA8Qj1iSrRxluvsvFVMfqMS29GoWg+t43XKIe/40i4VPZVnnBbQW/iydm5CKcR/PJUvdtGABUidsi2jXeSvr/HXFir9FmVPlK619o3e0QSaHDbcpYEectITIjF2sokxZgh/UQDVPlX7SEfna3UtOJZpil4I2Pqp7GM3cvKGJ9tkbGGbJoS9ff87G0ORs44gCql08FM2VNPLaGw0olol4OjboglMdYECOXgLW1HKf IFkXelzn OYGIp4ZSPV37AS15PxD08GlDZpHrvh/FXvXJrBTJy8B95Q6geIDoPH2zKYZ2k9m3BKbJPidmQLd3gvaEok0dLMlzPGO2rJhqOP5M79Me8KxUJ5dOqYk5gxTOwSl/8V9Qa3e+urrs+iLn16/z1VcV4Rk58vsVdt8ht39M+KEd8Lk213BOEzDVK2KNXDw== 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 '__refill_obj_stock' function to make the code more cohesive. Signed-off-by: Chen Ridong --- mm/memcontrol.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index f977e0be1c04..0c9331d7b606 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2697,6 +2697,21 @@ void __memcg_kmem_uncharge_page(struct page *page, int order) obj_cgroup_put(objcg); } +/* If the cached_objcg was refilled, return true; otherwise, return false */ +static bool __refill_obj_stock(struct memcg_stock_pcp *stock, + struct obj_cgroup *objcg, struct obj_cgroup **old_objcg) +{ + if (READ_ONCE(stock->cached_objcg) != objcg) { + *old_objcg = 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 true; + } + return false; +} + static void mod_objcg_state(struct obj_cgroup *objcg, struct pglist_data *pgdat, enum node_stat_item idx, int nr) { @@ -2713,12 +2728,7 @@ static void mod_objcg_state(struct obj_cgroup *objcg, struct pglist_data *pgdat, * accumulating over a page of vmstat data or when pgdat or idx * 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); + if (__refill_obj_stock(stock, objcg, &old)) { stock->cached_pgdat = pgdat; } else if (stock->cached_pgdat != pgdat) { /* Flush the existing cached vmstat data */ @@ -2871,14 +2881,9 @@ static void refill_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes, local_lock_irqsave(&memcg_stock.stock_lock, flags); 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; + if (__refill_obj_stock(stock, objcg, &old)) allow_uncharge = true; /* Allow uncharge when objcg changes */ - } + stock->nr_bytes += nr_bytes; if (allow_uncharge && (stock->nr_bytes > PAGE_SIZE)) { From patchwork Fri Dec 6 01:35:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Ridong X-Patchwork-Id: 13896223 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 7BE2DE77170 for ; Fri, 6 Dec 2024 01:45:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 235776B0153; Thu, 5 Dec 2024 20:45:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C088D6B0151; 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 A402B6B0154; Thu, 5 Dec 2024 20:45:12 -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 3F8C26B0153 for ; Thu, 5 Dec 2024 20:45:12 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E5D9C1C8942 for ; Fri, 6 Dec 2024 01:45:11 +0000 (UTC) X-FDA: 82862841096.29.8B22334 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf28.hostedemail.com (Postfix) with ESMTP id ECD0BC0007 for ; Fri, 6 Dec 2024 01:44:47 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf28.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=1733449494; a=rsa-sha256; cv=none; b=Jd1VNsmwe7nroXz0/5UeSVE0sIolWiFQokVyYlIiIhXvM/KjDlOlenVeRIy1PKy4Ynvu2M Do4ulOTrhJq0PsUydxbyJyE3YpbuOVZ1ljqzMudiQSISWA7zJVVXnuxq+2+EYbibgsJOqp cCqck5N/eEd2BmWwP05L5xwq6J8pwp0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf28.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=1733449494; 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=v8l6Qu8B7zFhjEfKrPVkTwlnR8NKfT7bcZX2irjZ4QQ=; b=SqpSl4eQgX35Z1RBfwqf/up1E8FSG1AoS4VTi5JI5yl5m7moEx3ggptZi8RkgHP6kJjtD7 BcTRdtuN9e8IxuA5/KUm7DkSiq5cE9Gv1O19/7lL87odv3nP9dju5wgsBaP6QCcuvXwgHr TUr9Av1F0laouT3wzncqzadI4zbJfUI= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Y4Db45WKfz4f3jqy 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 C65D41A0196 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--.31315S7; 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 5/5] memcg: factor out stat(event)/stat_local(event_local) reading functions Date: Fri, 6 Dec 2024 01:35:12 +0000 Message-Id: <20241206013512.2883617-6-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--.31315S7 X-Coremail-Antispam: 1UD129KBjvJXoWxKw4kZFyrKw4rJr18tryxXwb_yoW7XFWUpF sxKayY93y3Jw4F9r1ftFWjv34rA3WxX3yUJryxJ3ySvasxtw1Yg3ZxKF9rZrW5Cr95ZF13 Jayqyr1DJ3y2qa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y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7pPFCUKKd3pLr3/fsvMk2K//wA1sVlxJgp8LNq1tsaCMDfTBeU/XVZExAPwGRlOiTYkX9x0FirRiObn0tMDz1AvovKDbnUzaST9VmMLMSvJfuUPVJ0H6OVtHRaZYkYMNN3i+8ytbkHqXXWoYzf/esIMQBTnMWDVz8FEfyrsjanJExvpAxzAMiqOteH6Ae7Vstll2fXLYUTy/XxiBsalVPXANvqwB1fenTIPqD7C/SWLVEFzP3Xyy2Z3clF70nGy0O4DbWRiymcJ6q5eccpmK2Ee/KWl/rkQdEbUn50v0mtp1qFbG/xh8FAKaNCybfPEpsTC+S6CKi2QukO6u8LtB6hczKryQE6bUOxPf4fPwACUwW/P7iV7VTqcI2w6e2jy+zzvGMU1Jf+KclUI/kkUYNvhnecgtfROtkN2+qwg5wqxvMs3ViVcZ4xHdzD2xmXGXKqMMel+xXIF07VFVs/j5nhxR6rszcyI6gThDFzNZkEQXwxMG53nhLqrm HUWwqCk7 0ukTdmiY4raL+DhlZOE4x0OM2VqnaoIQen2DPuQtgzmc34mQSZ3HqlYoe1MgyDBDKaZaVDh50dflhPNARqfx6JiTUpymGuCf1Tez24m1Bf1RgP2s+absHHuVyC9YhkxKyGBxjkSjaZuB6tu6+HNHCrJRvksTEOD8evOgLEMWc6/NdxSbPppMqWD7a7g== 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 0c9331d7b606..a1b1409a0dce 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)