From patchwork Tue Aug 27 23:07:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 13780212 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 9D9FFC54742 for ; Tue, 27 Aug 2024 23:11:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1209E6B0096; Tue, 27 Aug 2024 19:11:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CD036B0098; Tue, 27 Aug 2024 19:11:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9AB76B0099; Tue, 27 Aug 2024 19:11:49 -0400 (EDT) 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 B76E26B0096 for ; Tue, 27 Aug 2024 19:11:49 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7C1D41C6319 for ; Tue, 27 Aug 2024 23:11:49 +0000 (UTC) X-FDA: 82499574738.03.B7C931A Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf07.hostedemail.com (Postfix) with ESMTP id AC1BB40013 for ; Tue, 27 Aug 2024 23:11:47 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=XKMcNwjd; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3Ml3OZggKCGMLJOTFZIPHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--kinseyho.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3Ml3OZggKCGMLJOTFZIPHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--kinseyho.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724800236; a=rsa-sha256; cv=none; b=KcV8kVX9hpB6rU0LvTOjLS2CjVZmXC44cFhJSl+0z8aa9gY3LitLc4mxxt7ZY/+2eMC+9B Lqi6LqhLJ6UmVYJc5Aqy/T3duqkK7PoKTJDYrKzayVWh0RnIHwZ6bNg1615kxefu8GM2Ww t8qWPeIVucaNKeknALLAFj/jPCUls8Y= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=XKMcNwjd; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3Ml3OZggKCGMLJOTFZIPHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--kinseyho.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3Ml3OZggKCGMLJOTFZIPHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--kinseyho.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724800236; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=F9O1xAoZAOV8c4zW9/De55yG0OzoFjxVL+7Ggug8PCo=; b=eeydZ/jGUd+ZPMN7+GLWdcuyk5ubX+2U3BUVbUJgqjStEzyg5qXqQAFNusSCwE5wD66vIY yGWxKZPu7FJuF8aUWWKf7QTdDD62ai0484PmWUnCypxIPdFqRmP9bwm3G6mzNpRlKT/hPT ZkJXot+r4M+2UbvcCpI5/OtdTL6jV4w= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6b47ff8a5c4so107269827b3.2 for ; Tue, 27 Aug 2024 16:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724800307; x=1725405107; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=F9O1xAoZAOV8c4zW9/De55yG0OzoFjxVL+7Ggug8PCo=; b=XKMcNwjdZt3OKCG1RPfOjYYr4KvOKEmZ9q9fWhswL44nnHG2FNPAVlQiBvQp25Ao5P oqbOR3G2uMjynp2Qn5O53eMRQmPwYO62MZEBXuyK7cgekyxGlZew+RnUNDFb/DVRfEGy uobdGKbGdIVoF2F02VVOAIpZtsPuWvpOElq1DTn1pwPHEn3aUhamsVxM+WIO6A7qfT7w ICqZokWYkIg0UdG9Hk0kfiemvHeUmJFRb58NnTgtKbGBZGysv+taODCCG4c3evPerMRu bWB7quAcp2HH8VxMoDizybW0ONLfSa6JPnRNH7c1l8uKeF1Bo0nIPl/t7XomPfhWAhxF u81A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800307; x=1725405107; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=F9O1xAoZAOV8c4zW9/De55yG0OzoFjxVL+7Ggug8PCo=; b=Bfy9cGU1xs8QSX/+lkrhTykvytZb33vVySsVSDSVKED4pKEm1ESz9UbPIjtmj8O1Yc 3ZrWsw2/zDCBQT1G1NMZv6JztwEthS9Qtxe7KKbu2kvgj8d12rqfzbOB/0ImKozHEkng 7IGvvmk1dBBbOgUkasf5fHfSJxHRrIJiW0qgs0fSHOupLq7yFx8ZdnIKe4ApYe4V+FEy qFjkSYifn1AafYixOM5vt+AMqTywnuT2ZlKBhPsGRyygWl1mCbVmPQmhNIdnDDiVdCYR WPM8G2eKoYOS0zk4VxOJ94/G+VpeERuCCVch4huF/SBTdukv91lh6KMBuVTTGIJwXkMM fmEA== X-Gm-Message-State: AOJu0Yye5BbS5n1u8amGKzCd92I6qSHjuoKG831yF6/wUsUd9RYrDECv g8sRHITSALxn3EJcvBxr+njBugVgTn/NjWvE7nZ+1ZWvkteB4pre+aZZL6vIerosx439YWewHb2 +0IryW15Ncg== X-Google-Smtp-Source: AGHT+IGhyXg3/eIiJrPzV8LA1GsjfwoUYtS3Vb5uXpGkz/KSc2MBd8B85rwqll+iK9yx1Z8d0EFBFb/FbykjYg== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:46b]) (user=kinseyho job=sendgmr) by 2002:a25:2905:0:b0:e0b:f69b:da30 with SMTP id 3f1490d57ef6-e1a4580f12amr2713276.9.1724800306773; Tue, 27 Aug 2024 16:11:46 -0700 (PDT) Date: Tue, 27 Aug 2024 23:07:42 +0000 In-Reply-To: <20240827230753.2073580-1-kinseyho@google.com> Mime-Version: 1.0 References: <20240827230753.2073580-1-kinseyho@google.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog Message-ID: <20240827230753.2073580-6-kinseyho@google.com> Subject: [PATCH mm-unstable v3 5/5] mm: clean up mem_cgroup_iter() From: Kinsey Ho To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Yosry Ahmed , Roman Gushchin , Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Tejun Heo , Zefan Li , mkoutny@suse.com, Kinsey Ho X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: AC1BB40013 X-Stat-Signature: wf4dir7etdz7odkdxzarf66u6yj7rd8g X-Rspam-User: X-HE-Tag: 1724800307-634678 X-HE-Meta: U2FsdGVkX1/Eh/nOVehB8ifJ1/WxbKk9kf2QESjubHizY3gVgvD8En8QD1/7W/QoScOSJv4JPlHHOeNMN91T52whj+HSg4lDZzvNToaTH4JMaCtbaedCG2avWV0kkeuh9Cob6CF6hWvTOmJoTVcxNkTd3sPLcxW0zr7V7VKoq7s3NjyFuCqd2Q7o0OERUfQxSEET6aT4rPYL9mroVjw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bKHV08Z2cwjpPwBOj95vUk3SEEsE+BekkbSN5yunbswQWnek0BvNzDmSnj095CVE5Zs2ywyEIZe/8AJx3TCb3wyGeaQ/ePAntzH2PZdtBCRKhZld6G5gtIlsd+xkMU04GwxdPjgwxAUgc3+Obqqkx4vW1s3TV7HXCobQZnIvm/ztbH2zX4yZ72LI4kEdUwVZHkVVI4MUAIslVedqf5RSSLZpGU+plgss6nwkxzac65mb8vN9RlgPFvPacJA0jX5vJuuubji2upFtw+9x2BrU 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: A clean up to make variable names more clear and to improve code readability. No functional change. Signed-off-by: Kinsey Ho Reviewed-by: T.J. Mercier --- mm/memcontrol.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 33bd379c738b..2bdad7c29ac0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -987,8 +987,8 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, { struct mem_cgroup_reclaim_iter *iter; struct cgroup_subsys_state *css; - struct mem_cgroup *memcg = NULL; - struct mem_cgroup *pos = NULL; + struct mem_cgroup *pos; + struct mem_cgroup *next = NULL; if (mem_cgroup_disabled()) return NULL; @@ -1000,10 +1000,9 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, restart: if (reclaim) { int gen; - struct mem_cgroup_per_node *mz; + int nid = reclaim->pgdat->node_id; - mz = root->nodeinfo[reclaim->pgdat->node_id]; - iter = &mz->iter; + iter = &root->nodeinfo[nid]->iter; gen = atomic_read(&iter->generation); /* @@ -1016,29 +1015,22 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, goto out_unlock; pos = READ_ONCE(iter->position); - } else if (prev) { + } else pos = prev; - } css = pos ? &pos->css : NULL; - for (;;) { - css = css_next_descendant_pre(css, &root->css); - if (!css) { - break; - } - + while ((css = css_next_descendant_pre(css, &root->css))) { /* * Verify the css and acquire a reference. The root * is provided by the caller, so we know it's alive * and kicking, and don't take an extra reference. */ - if (css == &root->css || css_tryget(css)) { + if (css == &root->css || css_tryget(css)) break; - } } - memcg = mem_cgroup_from_css(css); + next = mem_cgroup_from_css(css); if (reclaim) { /* @@ -1046,13 +1038,13 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, * thread, so check that the value hasn't changed since we read * it to avoid reclaiming from the same cgroup twice. */ - if (cmpxchg(&iter->position, pos, memcg) != pos) { + if (cmpxchg(&iter->position, pos, next) != pos) { if (css && css != &root->css) css_put(css); goto restart; } - if (!memcg) { + if (!next) { atomic_inc(&iter->generation); /* @@ -1071,7 +1063,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, if (prev && prev != root) css_put(&prev->css); - return memcg; + return next; } /**