From patchwork Wed Mar 30 23:47:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12796518 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 6DB1CC433FE for ; Wed, 30 Mar 2022 23:47:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B5898D0005; Wed, 30 Mar 2022 19:47:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F333A8D0003; Wed, 30 Mar 2022 19:47:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAC078D0005; Wed, 30 Mar 2022 19:47:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id BE5AF8D0003 for ; Wed, 30 Mar 2022 19:47:45 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 86462182CA8D0 for ; Wed, 30 Mar 2022 23:47:45 +0000 (UTC) X-FDA: 79302692490.18.624E3FC Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by imf11.hostedemail.com (Postfix) with ESMTP id 2BA3440014 for ; Wed, 30 Mar 2022 23:47:44 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id bg10so44618579ejb.4 for ; Wed, 30 Mar 2022 16:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VUJcnVdgNFYpQDTJEWf7H0xzus0K/Xa4FeMP7a1KnEQ=; b=ncvvGkdIFWyKuP25ghEWF3nSN6sW8+Q7qWkT1iDxucHp0v6lYGY/ZDllouL2Y/nAUz EfKl+Yna/ir+zTvabWIpqqPHbltci3rU6r0a/FfdvzTVkf/skKhGJIz18w5ccDRwnvyU PkCYTjGdCQqDJx0pTYz+iL5ZB/pY+zf4Ib1Q5D9f2xj+T1Sb9GR92JTnrsXPdu6ybLJ6 QOKZxMy/CHs6nqkCPMHlp3Gr0FNX3f+TDadXhTC+jZM0QMdlg192xUdoD+jezjIDkBoz zEQ86AmCcX1LTF0ikiCsHDhKBWGD/mK/GxpycZ7iTVU31o0EMsfFH4hiQomO1nQr+xKL CUIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VUJcnVdgNFYpQDTJEWf7H0xzus0K/Xa4FeMP7a1KnEQ=; b=TuIl8N7HpZ6Ed/t9NkyXixQu+GRBS2ILZMn8KCdN1cWluzxVYnBs8Tmbw/AaY2/1ue HtL2q7WocrDUZFg6e0WgV2w3FjHADHNsRSrIVIFBnip3BvM1K9zdlbtC5IbnX49v7rj6 x9WLXme34tfqqU+yelhGNdBRm0bcoTNYk1LzDNWDvbEMZ7v5QkuydGcci7xDRuHnH0xg XQYRpFVKHouBDNY0u2wPcrHuDo9/35fBdseW6HBz8y8PijidV7dbE5nibP+ceRleDCRG XjRPvrY/OjebrwaGcZRKMn+V1dG3Xow/9731dJl2jqw5ahzWv5m3nUy85P9n/9rLjLl1 Ch/w== X-Gm-Message-State: AOAM530fB9o0OWOqbibiyqzAlCvXKhXdLT8PfPe7+pl8th+MXAwUavbW /E/FcRSHEDlf4TtWGSe39oUzOlbkxo8= X-Google-Smtp-Source: ABdhPJw/jBcGuEajUDutfuFfQAkzGZRZEOEI2ekZslgcYDUMcqzDRhHPQu4M3nSpuKl7u4RxhGoE6g== X-Received: by 2002:a17:907:7244:b0:6df:fb38:1d02 with SMTP id ds4-20020a170907724400b006dffb381d02mr2309148ejc.453.1648684064052; Wed, 30 Mar 2022 16:47:44 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id qa30-20020a170907869e00b006df9ff41154sm8734153ejc.141.2022.03.30.16.47.43 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Mar 2022 16:47:43 -0700 (PDT) From: Wei Yang To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, Wei Yang Subject: [Patch v2 3/3] mm/memcg: move generation assignment and comparison together Date: Wed, 30 Mar 2022 23:47:19 +0000 Message-Id: <20220330234719.18340-4-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220330234719.18340-1-richard.weiyang@gmail.com> References: <20220330234719.18340-1-richard.weiyang@gmail.com> X-Rspam-User: X-Stat-Signature: 7qcd6ig46q7occ81nhfgc44mwi57s9dm Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ncvvGkdI; spf=pass (imf11.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.42 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2BA3440014 X-HE-Tag: 1648684064-986839 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: For each round-trip, we assign generation on first invocation and compare it on subsequent invocations. Let's move them together to make it more self-explaining. Also this reduce a check on prev. [hannes@cmpxchg.org: better comment to explain reclaim model] Signed-off-by: Wei Yang Acked-by: Johannes Weiner Reviewed-by: Roman Gushchin --- v2: a better comment from Johannes --- mm/memcontrol.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5d433b79ba47..2cd8bfdec379 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1013,7 +1013,13 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, mz = root->nodeinfo[reclaim->pgdat->node_id]; iter = &mz->iter; - if (prev && reclaim->generation != iter->generation) + /* + * On start, join the current reclaim iteration cycle. + * Exit when a concurrent walker completes it. + */ + if (!prev) + reclaim->generation = iter->generation; + else if (reclaim->generation != iter->generation) goto out_unlock; while (1) { @@ -1075,8 +1081,6 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, if (!memcg) iter->generation++; - else if (!prev) - reclaim->generation = iter->generation; } out_unlock: