From patchwork Wed Jul 24 19:02:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 13741273 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 84950C3DA63 for ; Wed, 24 Jul 2024 19:02:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 177AA6B0088; Wed, 24 Jul 2024 15:02:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D9E76B0089; Wed, 24 Jul 2024 15:02:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE35D6B008A; Wed, 24 Jul 2024 15:02:26 -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 C6B7E6B0088 for ; Wed, 24 Jul 2024 15:02:26 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7D39EA4487 for ; Wed, 24 Jul 2024 19:02:26 +0000 (UTC) X-FDA: 82375567092.16.69621BB Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf30.hostedemail.com (Postfix) with ESMTP id 187478000E for ; Wed, 24 Jul 2024 19:02:23 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=El0g2WUQ; spf=pass (imf30.hostedemail.com: domain of 3vk-hZggKCB8FDIN9TCJBJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--kinseyho.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3vk-hZggKCB8FDIN9TCJBJJBG9.7JHGDIPS-HHFQ57F.JMB@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=1721847720; 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=AmGz1OUSAYzLu3Mkr9WfTC/ktWFGonkMAhMj+nbyydo=; b=kXAEA5KkgJxpZ39RiIJbY3BzSY+Rc68Y6tm80+Ga49zQUsUFQGXiQLc8vk+rS5j2KNQrx0 YUr4o0JJl7PGei8ydmkk9WoyjLPUHG1IkCvqfxgoR4TzL8t40UQJvKFi0sOsdHrih7wgLJ GFuYQjkGvY/yf+9WfuTWXttomwkX2Io= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=El0g2WUQ; spf=pass (imf30.hostedemail.com: domain of 3vk-hZggKCB8FDIN9TCJBJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--kinseyho.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3vk-hZggKCB8FDIN9TCJBJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--kinseyho.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721847720; a=rsa-sha256; cv=none; b=XdcMgL41iLyz7ua0xJY/aYMZGTWunn3Cr+dq593T42sPS2YJw5pIv42XADffUcHN2BolbZ lP/CJMaJYowABccloMQWA17KCtNKnweNMv32adLpHcKYijKfO0UTwjN5Ifi8Gu6IDfQjkX pxx/cr0BhNZVHHMjTTd0BJxjz2pRON4= Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7a994e332a8so102090a12.3 for ; Wed, 24 Jul 2024 12:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721847743; x=1722452543; 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=AmGz1OUSAYzLu3Mkr9WfTC/ktWFGonkMAhMj+nbyydo=; b=El0g2WUQJWUcPlZ/36alMQmUqxM0ckAcXzZbAIZ+se3ILxkSkGEi4Vf+pYYIlpVkKo H4XOrx37WAGRHBmBN+OycWCQkD/QtN9BtlonjhYfeNBTv01fakCBiLul0doicVqR0QH+ Y04QIr8PgUC4YIpfijVKL/stQJYeLwg7JcC+1LPkGjrrlQkj6+CEyWzIfxYWz0KR9spf oKsafRquzus5pAu+UcGVWcr5QXsg0q5sta5wyQiG8rtkjZS0nVKPm1uP3AXu28zyndOh ZZ9RlSOqdb9aaGmqkcZDcKG/nUHFUIaIZkwByd6I3LBTb2e51NgWkZkAh2mpQKbj7WjP u5zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721847743; x=1722452543; 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=AmGz1OUSAYzLu3Mkr9WfTC/ktWFGonkMAhMj+nbyydo=; b=kAHp5iszNjxi5hxNUPTcorfDVCCH+5be7SQfsQ7fxTBJj+14rq2vtvAIgHpSkMoaWW AuH3cYQkRfxs7rDYLmd+Fe8gWkck1DxheEzTLRoxquUL0f8MTaxJSIdV2IiGUTkN/wce siRBBT5NptGNlNZgqBUrKxqC4bDC9fD47qkgSXUhoKs+e1HiiqfLxezZzFhdGXpH/2p9 4JcdE0JpV/sShLiThGhVYPhQNQy5vSnaj+S/p/eFFveSkiWuvUxrJE9ISyi89CtlIgY/ 0CTrBaBvj22KKCl+h8uEGlWJ8J0VdBHN5SHvwxlS9ELTY1Sbvq3L79TTlxnIXf2JS2gb Fz/w== X-Gm-Message-State: AOJu0YzgIXrTJvSIxz0h5q40CdX/GYpA2tO6KuEGmY/ezKnd/LWxMR1U Xuh8Bv0FFdFLzPfHNjSuemFbSitXM86eoMEzuuwE32K1uB52/DD8aDVLacPexc6v0McwvC35wWa s2un2e0Vhng== X-Google-Smtp-Source: AGHT+IGLvyDW6X3i6jqfX6m7Tz2BzQtjRTiuAHBzI1w6qDTToawljkbGNllzBAuC3KsBrh2qsLZDEguaiP99GA== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:46b]) (user=kinseyho job=sendgmr) by 2002:a17:903:1105:b0:1fb:27bd:82e2 with SMTP id d9443c01a7336-1fed38ccc31mr9895ad.8.1721847742363; Wed, 24 Jul 2024 12:02:22 -0700 (PDT) Date: Wed, 24 Jul 2024 19:02:12 +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-3-kinseyho@google.com> Subject: [PATCH mm-unstable v1 2/4] mm: increment gen # before restarting traversal From: Kinsey Ho To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed , Roman Gushchin , Kinsey Ho X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 187478000E X-Stat-Signature: bi3pc1oqkqoumr17eanc6fyrur3spd6u X-HE-Tag: 1721847743-529909 X-HE-Meta: U2FsdGVkX1/CbzMuO7XxYIPoc6k6SBTULN5uQU44la1ISw2O2wuZbTp0qbqY341T+fD0XDtivjMFzBUZgFAScqIhCoSPsTbvSrnZZo65c4P50LGFaKjA3bLDlMC0ewWDQMXvE9coLQLbU/u4MXCMOsa3rAyFyXmeO3gpimYcS5IxqKMx8cpxzB3Cy2gEpCRlZexyZJF/YtwqX/BBH4ZaEFUBu+O9wzRa1vTnPWiMWuUFUpGlvRsNdZvJ6g5EwQxoJhAchCiU8kndG8o57suQBs2pN1D2GVJnfv4lemV+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ph1n0uBCIqw/TTG4S7BzAEnUVviYqb3XqmMZHBkaB0YQA+5iunooVlGhLQPhlM+PW1AcPhxxPVibivnTp8a7DEdY6oCnSa+fRYkAvRobxI0FqMCkE0WG4X4hP0wZ0ZIg/X6Q+Q727FGJk5XIP24Xg== 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: The generation number in struct mem_cgroup_reclaim_iter should be incremented on every round-trip. Currently, it is possible for a concurrent reclaimer to jump in at the end of the hierarchy, causing a traversal restart (resetting the iteration position) without incrementing the generation number. Move the traversal restart such that the generation number is incremented before the restart. Signed-off-by: Kinsey Ho Acked-by: Johannes Weiner --- mm/memcontrol.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 062bfeee799c..f672bc47c6b5 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1003,7 +1003,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, root = root_mem_cgroup; rcu_read_lock(); - +restart: if (reclaim) { struct mem_cgroup_per_node *mz; @@ -1030,14 +1030,6 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, for (;;) { css = css_next_descendant_pre(css, &root->css); if (!css) { - /* - * Reclaimers share the hierarchy walk, and a - * new one might jump in right at the end of - * the hierarchy - make sure they see at least - * one group and restart from the beginning. - */ - if (!prev) - continue; break; } @@ -1060,8 +1052,18 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, */ (void)cmpxchg(&iter->position, pos, memcg); - if (!memcg) + if (!memcg) { iter->generation++; + + /* + * Reclaimers share the hierarchy walk, and a + * new one might jump in right at the end of + * the hierarchy - make sure they see at least + * one group and restart from the beginning. + */ + if (!prev) + goto restart; + } } out_unlock: