From patchwork Fri Feb 25 00:34:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12759478 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 0F2CBC433F5 for ; Fri, 25 Feb 2022 00:34:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25E9F8D0005; Thu, 24 Feb 2022 19:34:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E89A8D0001; Thu, 24 Feb 2022 19:34:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB8A58D0005; Thu, 24 Feb 2022 19:34:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id DB8EE8D0001 for ; Thu, 24 Feb 2022 19:34:44 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id AB438804F6 for ; Fri, 25 Feb 2022 00:34:44 +0000 (UTC) X-FDA: 79179431688.10.A2E9411 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by imf06.hostedemail.com (Postfix) with ESMTP id 2E5C7180006 for ; Fri, 25 Feb 2022 00:34:43 +0000 (UTC) Received: by mail-ed1-f43.google.com with SMTP id h15so5210002edv.7 for ; Thu, 24 Feb 2022 16:34:43 -0800 (PST) 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=ilQGiGw+cHHnWYdpNd2TsqiqLrmn72vknxopCrZER/Q=; b=EXhP+YADKLWYCXD23XUiXLkpefnymxGvQ/D3MVz2Nk0z3XGGwRNe8I8uITmCtQwIFm 4VBod9Tn78bwab2BZ6kHXnt2BwHZ8uUEHy7OzOAKBSZJ6fc1QETVMyQqbXCcNsyyNHmj 97dZX0Epb88JPt0lOOpWx5jvJ4XY959jv7wVBuSoVSgpqg8I0ylEXoDrTok1pLCiMh5F tXdlQvD1HPzeefQzeA955geaPEZK76a0puWvb624G1Uk60kRkYJM9LXDRiEGmrQ7jnYq 0HtNtCuP/AO4ipwxFWETbeAfyVM1DbdZnpvq2VBPheijzUBcevHVMOJzgQp4VUcYlosT Qe9w== 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=ilQGiGw+cHHnWYdpNd2TsqiqLrmn72vknxopCrZER/Q=; b=CP7rtZ4BF77MOloYI3OzGMYWSS0eptUznTQt8jyXyOIpoE988UKzfry8qVGyA9a8d5 jrU8ph6mNLcKvC5k7hE5f8CQlA6HpAZTDE4QzyG34uJtRcHPo9DcOuFp1aGSo6RBokml CGyO879NcIx34rKb0/nfosvsuYhMC3RSa4+NkvA715jm3D12Tt8GFIIxIIJXOUOuQ0Y3 sMEKKqllhJbMGcBtFQPi08q9x0ur9eu4P6YtVQ9xVomLCVCbhwTE6u4uvVzZY/gWm1Ti TJlFVv8i3oR4eJ0vCgi5VVHdizxrCoQJWAYaHB4BviVsiJZ5Lcy3vSbmA3VIgZHTsZzV PAyA== X-Gm-Message-State: AOAM5332ZDTah5sparcXRVzX70Joi7r16e3RVrbK9c1Wc7OY3Ol+QqkR Pxtlrr9sdwYTk7QJ5tj8m94= X-Google-Smtp-Source: ABdhPJyuoa5ezgs1FJUFIN4JTKE1OZe4PXfPQZ6hNFf3F6TNXGWk9P7dqdy+drSU3xm8bap1JfloTQ== X-Received: by 2002:aa7:cc82:0:b0:410:d2b0:1a07 with SMTP id p2-20020aa7cc82000000b00410d2b01a07mr4691617edt.359.1645749282998; Thu, 24 Feb 2022 16:34:42 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id dc4-20020a170906c7c400b006a9bca854c2sm337086ejb.37.2022.02.24.16.34.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Feb 2022 16:34:42 -0800 (PST) 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 3/3] mm/memcg: move generation assignment and comparison together Date: Fri, 25 Feb 2022 00:34:37 +0000 Message-Id: <20220225003437.12620-4-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220225003437.12620-1-richard.weiyang@gmail.com> References: <20220225003437.12620-1-richard.weiyang@gmail.com> X-Rspamd-Queue-Id: 2E5C7180006 X-Stat-Signature: 1dkdw65o5yidy6xsdj6zpfcdfqipxx9d X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=EXhP+YAD; spf=pass (imf06.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.43 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam05 X-HE-Tag: 1645749283-895156 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. Signed-off-by: Wei Yang Acked-by: Johannes Weiner --- mm/memcontrol.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 03399146168f..17da93c2f94e 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -996,7 +996,14 @@ 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 first invocation, assign iter->generation to + * reclaim->generation. + * On subsequent invocations, make sure no one else jump in. + */ + if (!prev) + reclaim->generation = iter->generation; + else if (reclaim->generation != iter->generation) goto out_unlock; while (1) { @@ -1056,8 +1063,6 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, if (!memcg) iter->generation++; - else if (!prev) - reclaim->generation = iter->generation; } out_unlock: