From patchwork Thu Sep 5 00:30:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 13791569 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 110AFCD4F4E for ; Thu, 5 Sep 2024 00:32:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8439F6B020F; Wed, 4 Sep 2024 20:32:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A6A26B0248; Wed, 4 Sep 2024 20:32:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F76D6B0213; Wed, 4 Sep 2024 20:32:00 -0400 (EDT) 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 3D0E26B020D for ; Wed, 4 Sep 2024 20:32:00 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E75CEC06EE for ; Thu, 5 Sep 2024 00:31:59 +0000 (UTC) X-FDA: 82528807158.19.AEC9BC3 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf10.hostedemail.com (Postfix) with ESMTP id 2568CC0007 for ; Thu, 5 Sep 2024 00:31:57 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KElEiLIy; spf=pass (imf10.hostedemail.com: domain of 3_PvYZggKCJU97CH3N6D5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--kinseyho.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3_PvYZggKCJU97CH3N6D5DD5A3.1DBA7CJM-BB9Kz19.DG5@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=1725496221; 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:dkim-signature; bh=UFlJk+bdMFXrL5bkGb5l4QnCCI5p7k/K3Pj8oKz1txU=; b=zVyft0Qw+3Z8dyXQh3cAOLgAzdRJqxujhq53BX9BpLSagSpeJBLQsnlBgeoHIaYpWLchQO n/7swMRFVNAjxsHFo9us+tkABf2XumvdgF05C/3VPaK/Cmf0hTCiamBnV4GDw+M6Ls6/tW rZNHy+CxPL231kbMapDkUaEO/29q7xk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725496221; a=rsa-sha256; cv=none; b=W1i8wMfdDF84ch1niEH9AO9lKXWpFuMdvPHv0SA3p2AdlcDGE410disQjTK/gGUWWk8yEg aOlVN++5ZeCCBxEKdmg0QhyAr/MRutBCiXWzO7QK76pXHLfYBToSi5M+2ZMMy37HbYMA5C pbDLxNztCOi7JAXw8IPed/rjCSBk5j0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KElEiLIy; spf=pass (imf10.hostedemail.com: domain of 3_PvYZggKCJU97CH3N6D5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--kinseyho.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3_PvYZggKCJU97CH3N6D5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--kinseyho.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7cf546bbcffso289072a12.1 for ; Wed, 04 Sep 2024 17:31:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725496317; x=1726101117; darn=kvack.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=UFlJk+bdMFXrL5bkGb5l4QnCCI5p7k/K3Pj8oKz1txU=; b=KElEiLIy2Aec2eJ7zbFfjGaLdwRMT07BKso9vfDDpXsQCvcWD5NbqtAW1q70bC+/uA TA/kwWojLzGyajB8VqyvfeLSQjdBG+MKHCBCBhTH8554YMCv6wFTwGHx3302HNh/6zAv SVIt9SnOZpzhkTaShMU+yL5yDcFQhHbKtR4K/o+8d/FbgXa+XLCycXkmfRZ2DzYmqCOW XP8eLAYQkad/2e9YubJSckwqh0yWRaNo5qPg6OcW5rYSGyhtfLKlpCPQct+ZTrX/QMFD 4V/J0rh4Z8xl6jWNpIWIGY94eIwfnxzdAb6JpmnK7XUGQWSV5p+O0jL4mM0QzWmflSrF YJBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725496317; x=1726101117; h=content-transfer-encoding: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=UFlJk+bdMFXrL5bkGb5l4QnCCI5p7k/K3Pj8oKz1txU=; b=St2wBUnJqUpjLMYMpOpTF4zpGYW3Y5nodxLV8OLJAmJxKBTnK9x6cAtPk5Df0okMwd CRfWj9ZCGU7mf6XCn3oVQW5BTitGkuRYWRenLeb+YXEJcacUOwpzmzpBDIPAv+tbWflF mKrXqDQR9qBiunyZ7o1T4wde/TlsLViKURO/cHQ8tRavlJgzl1RvaJ0fsj+TsE6BI7Q5 dlIx/PYufVWX6H8zIN6ATLUiO9vytFD82gdHnQX5nLruzAyHIGRexPwN59P9+b5Qjr46 br9qD06y9j7vIxyk0xosNNZUWLeyfceEM/zmOiBa6ob/n84RsWcbmsTilyMkC13NfTgT 3Mpg== X-Gm-Message-State: AOJu0YyGEldm2pjO9mi/pjPb6m4I0lCyE3Qp0eFvBVpXxzqJn2mClaRF Z+2JP9gd6IE4RYF+T3lx3PuGEFkZ376WwWsMu5CdSrnrQv9Cpv+hmfQolUfm2Ti3ru/dQcgGzsa OBkP4h2uiQQ== X-Google-Smtp-Source: AGHT+IFCmyZz1oeuwdzh9ujb+lyKCdb7Lv33IMyUDlAfA9IgJETASTtABlliPQg/ISAiLVSGlddqDM0VzXnGuQ== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:46b]) (user=kinseyho job=sendgmr) by 2002:a05:6a02:2385:b0:6c4:5b35:c986 with SMTP id 41be03b00d2f7-7d50176fca8mr4225a12.8.1725496316657; Wed, 04 Sep 2024 17:31:56 -0700 (PDT) Date: Thu, 5 Sep 2024 00:30:54 +0000 In-Reply-To: <20240905003058.1859929-1-kinseyho@google.com> Mime-Version: 1.0 References: <20240905003058.1859929-1-kinseyho@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240905003058.1859929-6-kinseyho@google.com> Subject: [PATCH mm-unstable v4 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, "T . J . Mercier" , Hugh Dickins , Kinsey Ho X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2568CC0007 X-Stat-Signature: qd5664sjknfaouzf9khfuc9zspo7fksh X-HE-Tag: 1725496317-462057 X-HE-Meta: U2FsdGVkX1//IRTDHhOTGopswsRGZOqGZHwlnRqV2dLV0rMdxWPJNJNCaEpcsJ19UZoqKX4Y1h1x8YIqcWCYoOyPqE2O7yzWBmOcLQ5Ca8Oc9Il9q3Z7Nr0KvrSqDyL6bg22EiNwJV/BAf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PpnDWk/G+cl4tzzRKxkNKwOFYAbjGO/fR4VXqDCAJqCiVHDm3PoSiMxKRUdH0D2nALZ8JCfeguc4GdOyI83sOvSPzOiwVea5IgsqyTARAbCRe38tmuE7z9YJ1L/EJNdMnC7pBgpfVIQwX54bu580rAeVJXl0H2X38sRwvdgVgH1DFQTR3+44MsVtWnHDCH7a4XVG+E+xlhzzszfY3bhQY19HcDnHsMQmn/8HxqWYpZjsOlmLErhVroATOezA53iZlhJfCdPvYggTvH1VZc3PJKxIiRnWCkviAviJmBxarm2xoIfPtXvdQws5p3cGFkzJHisoJRDHO9k2b6+c3/uUEp5bpX5odWUQmtKWN+XlLyhY6G566s3zx2tbSMQm7mAB98y96anTRJ+eYLxpiey5LZHxDUftJ7E6j1HR1lt61oHWk8NE509enLq3vkyA8tvaWD0wAL+PxfT1h/rz/SD95WIx4phZJXzBHBxeVmtB3gD2Nt55zzs3ZmUHob874K3TyB2a0J5rOOwPoY1XazybyN3foBTZNssOatyCM= 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 Cc: Johannes Weiner Cc: Michal Hocko Cc: Michal Koutný Cc: Muchun Song Cc: Roman Gushchin Cc: Shakeel Butt Cc: Tejun Heo Cc: Yosry Ahmed Cc: Zefan Li Cc: Hugh Dickins --- mm/memcontrol.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ce5d066393c9..31db8467f19d 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -989,8 +989,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; - struct mem_cgroup *pos = NULL; + struct mem_cgroup *pos; + struct mem_cgroup *next; if (mem_cgroup_disabled()) return NULL; @@ -1000,14 +1000,13 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, rcu_read_lock(); restart: - memcg = NULL; + next = NULL; 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); /* @@ -1020,29 +1019,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) { /* @@ -1050,13 +1042,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); /* @@ -1075,7 +1067,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, if (prev && prev != root) css_put(&prev->css); - return memcg; + return next; } /**