From patchwork Tue Aug 13 20:47:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 13762484 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 31740C52D7D for ; Tue, 13 Aug 2024 20:48:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 397CB6B0098; Tue, 13 Aug 2024 16:48:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 31FEB6B0099; Tue, 13 Aug 2024 16:48:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14EBE6B009A; Tue, 13 Aug 2024 16:48:05 -0400 (EDT) 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 E1B996B0098 for ; Tue, 13 Aug 2024 16:48:04 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 91A9D140AAF for ; Tue, 13 Aug 2024 20:48:04 +0000 (UTC) X-FDA: 82448409288.08.53D052B Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf17.hostedemail.com (Postfix) with ESMTP id BFBF74000D for ; Tue, 13 Aug 2024 20:48:02 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="FttFr/2r"; spf=pass (imf17.hostedemail.com: domain of 3gca7ZggKCDogejoaudkckkcha.Ykihejqt-iigrWYg.knc@flex--kinseyho.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3gca7ZggKCDogejoaudkckkcha.Ykihejqt-iigrWYg.knc@flex--kinseyho.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723582011; 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=IUGrqgCsQ93s1mn5jRCuzR3kYh6lZBiPS4o7+rn6SUc=; b=oRUxutSKILTi1Tx8yWEcTgXtWLbqPc9HROSl0XrKE21FmZIqk4WNxeTZYYxcTCBKkzQUaU ujqGsjR1uoEjN8YsadaPY/fCqVPLjPtirnj2Bg7HgWkopQS1HWp1nXkYUkh84qAJE90mu7 SI0HM4dNGuOpqESmXCTaPaPRKGcSIhk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723582011; a=rsa-sha256; cv=none; b=jVv10PTJwXDbFjT1VWHg50pDuNUFGgg2wQYjZNrTa+t31pJ4ZfIKWabSEzDSKXn8MhLMJz pUFY+Ul1bQDS4d5otkXHtfeZ+N76E6WRA+BdC21ovlnVtcY7WQoyHIr1Qvn3IFaNu1aYC4 uXh1GQCpkbc/MHn/gyCzJZT1dsvMUlY= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="FttFr/2r"; spf=pass (imf17.hostedemail.com: domain of 3gca7ZggKCDogejoaudkckkcha.Ykihejqt-iigrWYg.knc@flex--kinseyho.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3gca7ZggKCDogejoaudkckkcha.Ykihejqt-iigrWYg.knc@flex--kinseyho.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-664aa55c690so135083437b3.2 for ; Tue, 13 Aug 2024 13:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723582082; x=1724186882; 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=IUGrqgCsQ93s1mn5jRCuzR3kYh6lZBiPS4o7+rn6SUc=; b=FttFr/2rlFddbtg4qj1Arhp5lyL7U1kEa+RDWLLK43NcazJfoK7Z9XTx7BouJtjAVj NJgfZaZkZUoHDiXA/bLivcoXYn0sdmVWTGcTAc0wxSTrcBKcAuQITob5q2twCo0PoXfw vqPmR2aFZXpJabGOJWcmSDaKtZbyU6tBmaAwhHhXDlx1Rr+peNRLP2UfT3emlWC9TVl1 Tqw6871RTgDUgFoD3fGSB/OC2/XOZAzm6wED1RZriwOHB4IHlsogUE7C0UEDBnpYD2Sm G7xKYlKWT/AuyNNiXtvMW6vx0cP3WK2nl0vi28h+/i+A7cYn8nB1KXyjvW+X77bn9uSP 7hFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723582082; x=1724186882; 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=IUGrqgCsQ93s1mn5jRCuzR3kYh6lZBiPS4o7+rn6SUc=; b=QBC/GmZmeSpPWKlsGFRMNe2q2Aw6UsdgF5bsO71y5jmxryiZ9rg5MtbcvmsZ997/HX Hl71ve8gYYBcWI8zoSqQZGFcQvzJw0xG3/NBsngIOB6trLuse61GjqSKiA3/NaGfgig5 x8wgQmuGOeFxp0AN1gIrdvK4XPrI/dJKbYtE/+ZMLjzl4ZIcSazlGiiz1V4uswhL4v5d KIdlri60GG/mxkt3QbJDPiHvB6Y1i5EpaToATEmYdcWa3UDeLmZWgRidaTr+xoy9bSDL S2KczL8Wb8mYxDy/DFA3jTviTVjqW/BMFBuw7OkdU0/3ASkjpLVydYneNt35s2CGjMLs JVlA== X-Gm-Message-State: AOJu0YyYcSfaesc8gVufnF6XwRfxgIGrlQj8N6bpGPhI+zshEiFZPGIB NJfcQ49PXzR1CfMKa3jKsJzJUcLxxbZSagwie5BBSzkoovlhVqlIRxhtQmlZw4Q/+4qCmqgoFMI gOvEkVW6odg== X-Google-Smtp-Source: AGHT+IFKq4mle76EHVxRvn3g1KvqjdbIlRdYAcckM9mm8INZMPhwqmIEIFFgUqblYHs8iR9k3Dh891L/+5f5YA== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:46b]) (user=kinseyho job=sendgmr) by 2002:a05:6902:18d:b0:e03:589b:cbe1 with SMTP id 3f1490d57ef6-e1155b67c75mr35668276.7.1723582081844; Tue, 13 Aug 2024 13:48:01 -0700 (PDT) Date: Tue, 13 Aug 2024 20:47:15 +0000 In-Reply-To: <20240813204716.842811-1-kinseyho@google.com> Mime-Version: 1.0 References: <20240813204716.842811-1-kinseyho@google.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog Message-ID: <20240813204716.842811-6-kinseyho@google.com> Subject: [PATCH mm-unstable v2 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-Stat-Signature: 3bgwq4smzf8fkwybn6im7abuh3qf87dd X-Rspamd-Queue-Id: BFBF74000D X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723582082-59884 X-HE-Meta: U2FsdGVkX1+AsnlOGf7zj9mf2OvdLdPmhOKQJgUcgcxdfHIZaxjdVrKLMg/4WV8jDdVHU6YJX7WpD9NTeENH10Lktrc8YmL4l1uUIC+7ndvo6yAISIzI19+ddq04WnGtnD+vfRwd6uBNfC1vwV1PvI5eP/6jeCjXf99ewGC8ahbjph7U+eGwmaKtg9ungAam7pXGBwbsTlfNyvyO6hTpbYKaZaYoD6pdc6+RX+aI4DK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iYPvZzp/KuS+bYkVnrh0e02UdBko7Hw+yV5p6AsRIUxyACXPPcjuIKQ47w3UZaH/2/aplH0MDlki9WNkIkW0z9v9cxfvmw1jxFK/Gly32faVx/o08m5ZlYENzcm5xxQLAVdk/QKS1VZ7c92wOK8a+DgtdpJhh2b+8fl+H2vMNtspodlMEK0VXtTtIT8efBAAHFIJwrYa7Yrw9iQTjRrRtR/vWlgcWShXCzk3h+fTPnUejh34CKbJgNYur2t925NO5pMdUfol59vcDVDSPYckH9+OiDRhA= 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 --- mm/memcontrol.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 84de46ece9a9..87a0dc9d779a 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1026,8 +1026,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; @@ -1039,10 +1039,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); /* @@ -1055,29 +1054,22 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, goto out_unlock; pos = rcu_dereference(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) { /* @@ -1085,13 +1077,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); /* @@ -1110,7 +1102,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, if (prev && prev != root) css_put(&prev->css); - return memcg; + return next; } /**