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: 1.0 X-CM-TRANSID: gCh0CgD30oYKV1JnkkskDw--.31315S5 X-Coremail-Antispam: 1UD129KBjvJXoWxJryftr4ruw4ftw4xGFWrGrg_yoW8Jw1Upw srCa4Fya4rZry3XwnrtFn8uayfAa18tay8A343Xw13Jr13K340934DKrW8WFW7Xa4kCF43 XFWDJr4ft3yDZr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmGb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI 0_Jw0_GFyl42xK82IYc2Ij64vIr41l4c8EcI0Ec7CjxVAaw2AFwI0_Jw0_GFyl4I8I3I0E 4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGV WUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_ Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj4 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; } /**