From patchwork Wed Jul 24 19:02:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 13741275 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 0DD83C3DA61 for ; Wed, 24 Jul 2024 19:02:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1039E6B0092; Wed, 24 Jul 2024 15:02:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B3116B0095; Wed, 24 Jul 2024 15:02:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E93A46B0093; Wed, 24 Jul 2024 15:02:30 -0400 (EDT) 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 C3EE86B008C for ; Wed, 24 Jul 2024 15:02:30 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8ADB1160B35 for ; Wed, 24 Jul 2024 19:02:30 +0000 (UTC) X-FDA: 82375567260.16.C079FEE Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf26.hostedemail.com (Postfix) with ESMTP id 9D50114002C for ; Wed, 24 Jul 2024 19:02:27 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=j5PmW+K8; spf=pass (imf26.hostedemail.com: domain of 3wk-hZggKCCMJHMRDXGNFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--kinseyho.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3wk-hZggKCCMJHMRDXGNFNNFKD.BNLKHMTW-LLJU9BJ.NQF@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=1721847699; 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=Ys2craRirgSkjM83RG964eoUiETMfTD1cND24tGgc4M=; b=lhQbuU4BaY8betAJRJuBMWA7ahv7Fa1UvWzmEYVAPEvE+dn9P5f5Qn+AcQIRDLXl7Sj5KU +kEiNPKTz+vP2MGbOKPPlRQucGMuy7nsgMBUN6Mfd2ZE/SEdFSV/Z2M34XDTa19bgGakzW sOrYriEW3swFdaXguC68UT6zn+LhiUI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721847699; a=rsa-sha256; cv=none; b=lQqco1LKtj6cdoKOjCmnfKQkurFpXvrJaqh0UMuU7Z+C0WxDgAL1e+RCM2U2rSM0jeT7J1 cUrKA7JF7e4OZFUqcsKW8zJT5rKQPUre1f//G21DiRktMikaQLTybSEYRO/CHRS1znH8Yl tzuvArioUBuTrKmAgQSo4e7S0B7ot4A= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=j5PmW+K8; spf=pass (imf26.hostedemail.com: domain of 3wk-hZggKCCMJHMRDXGNFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--kinseyho.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3wk-hZggKCCMJHMRDXGNFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--kinseyho.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2cb656e4d97so168423a91.2 for ; Wed, 24 Jul 2024 12:02:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721847746; x=1722452546; 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=Ys2craRirgSkjM83RG964eoUiETMfTD1cND24tGgc4M=; b=j5PmW+K8cw7alSLrvllyu7IsJuzhsaJ9SF/mViDIcouDxMLMfisvJ/BeyRx4BEQ9P+ 2WIlXGqgglYrwZlWcGl92Jz0gP3ThAWeJA16HRBj3q6xYb1+ueAY6hN66t7F5N1PVASf k0IWes604TCbicIgC1NPKoAZog/bTtQm0X/zPJtAhP9nzynK7vNlw9BLI/kiynxJhyt6 KzZJKmWBAsvfAF3BKmrKxoM78LEcpSLDyjNaNh1n6KHC+WUxHccAXJuK3v/bpP07c8J6 4xzqv+cPMbqYPhoDs2JyUhMIJb61GuViWoumNBdTmIpg6bNaIvZpVX4zjor3XK2d0pM6 3beQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721847746; x=1722452546; 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=Ys2craRirgSkjM83RG964eoUiETMfTD1cND24tGgc4M=; b=Npm+5QoERUth/OrOWMxRguD911nB+VzZrIenqd64iahd1KJz2qT7z6Y4ttqgkONtLL uaeZWjsAgwa+raikeAbR2BrblWhsY6Qpq1EFVf+yET8IMfKAgAxHtNe7lf9FETfDEBUC SbGDnWNNsJVHA3B9gHsEW83tjR12n6YpI+1MZonomcpjf0TQvKFXl+VgRh2e2/OIYFv5 a8v7lzyGpbUXGNUdXZWu4ifoYh6JDVq/r/MSnryRFT8ws/puCLBw8dsuduckdnMBfn+K NvIDAUdJhIdsRUc7IAzXG3bgH+E2YJbbqhMceX5cSLc6Y7W5Do3ne36fIm09u1qqwUZG cHag== X-Gm-Message-State: AOJu0Yzf6GSa6AOMNRMDRoZNuphNTXIPmWSJSvYlsDPhZLS+Gn+SJEPt doj+7RbD8fNZO4OtF2iSff5HLSMipxZhXhDQZYzLFRrRp0rOq6+tE1ItRQAJBWJVs0XGQtp4TS5 jk9XD3V2YDg== X-Google-Smtp-Source: AGHT+IGYuWhGCshfz/1OfOrlFgcnBDPUyftLtmcQ4FX3/fi/oAJTe3cbfgo0sG0FCKIUMQtWQ+YJ7xLut+dAxw== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:46b]) (user=kinseyho job=sendgmr) by 2002:a17:90a:17ec:b0:2c9:9c25:7584 with SMTP id 98e67ed59e1d1-2cf23e1b73bmr1597a91.5.1721847746082; Wed, 24 Jul 2024 12:02:26 -0700 (PDT) Date: Wed, 24 Jul 2024 19:02:14 +0000 In-Reply-To: <20240724190214.1108049-1-kinseyho@google.com> Mime-Version: 1.0 References: <20240724190214.1108049-1-kinseyho@google.com> X-Mailer: git-send-email 2.45.2.1089.g2a221341d9-goog Message-ID: <20240724190214.1108049-5-kinseyho@google.com> Subject: [PATCH mm-unstable v1 4/4] mm: clean up mem_cgroup_iter() From: Kinsey Ho To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed , Roman Gushchin , Kinsey Ho X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9D50114002C X-Stat-Signature: tmwidgsqd8houg9tgh9zbpwizt69didy X-HE-Tag: 1721847747-846920 X-HE-Meta: U2FsdGVkX1/4AmtCryG4Q9R5nYHrPIZwfu3evkDixhKwcw29NjIvHBil27RTrGaG4flVEbK9r6Wgjl7FLRnQnLh/J+t2g8pQV+CbkmXnekhChHKpNT1JrEpMNQALBqNnkhkUB5CyW1MdfSzA0it88qxujimYBKffmJmP3QqkifwqB5eqzPM1c0LiA49JnErTnLDmAdXn5jpsokx1MoJnEQBFTR2MoJ910MnN/m9uKszEFyCcksIA20t+BAr8nYXeA/lpxbccdIwhsoTsY0bu4n7US3UQ+JFrRgGrz29bfEVQzU0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Dgv0naqG+nwsp8DVF7jsj9ZEKpIahMatH79FzPL6jCvgerCDbRkIEMoHnq+lYhh5aCAVbNccnamlvkSKmokEvYLm/M6CnbfE2slSPpQWi3gfuUy/xX0Xa5xzfk5tailAo5SEPC4cxqSbk8qQ33bk6yPiGHYCJe2WUtGCRH2jTpoM/1Q8pPPOdA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, 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 | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 4314a2b8848d..7e3e95c62122 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -992,9 +992,9 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, struct mem_cgroup_reclaim_cookie *reclaim) { struct mem_cgroup_reclaim_iter *iter; - struct cgroup_subsys_state *css = NULL; - struct mem_cgroup *memcg = NULL; - struct mem_cgroup *pos = NULL; + struct cgroup_subsys_state *css; + struct mem_cgroup *pos; + struct mem_cgroup *next = NULL; if (mem_cgroup_disabled()) return NULL; @@ -1006,10 +1006,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); /* @@ -1022,43 +1021,36 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, goto out_unlock; pos = rcu_dereference(iter->position); - } else if (prev) { + } else pos = prev; - } - if (pos) - css = &pos->css; - - for (;;) { - css = css_next_descendant_pre(css, &root->css); - if (!css) { - break; - } + css = pos ? &pos->css : NULL; + 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)) { - memcg = mem_cgroup_from_css(css); + if (css == &root->css || css_tryget(css)) break; - } } + next = mem_cgroup_from_css(css); + if (reclaim) { /* * The position could have already been updated by a competing * 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); /* @@ -1077,7 +1069,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, if (prev && prev != root) css_put(&prev->css); - return memcg; + return next; } /**