From patchwork Thu Sep 5 00:30:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 13791564 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 A4CC8CD4F4A for ; Thu, 5 Sep 2024 00:31:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B20D6B00EF; Wed, 4 Sep 2024 20:31:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 161D86B0100; Wed, 4 Sep 2024 20:31:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF7376B01F3; Wed, 4 Sep 2024 20:31:49 -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 CD9776B01F1 for ; Wed, 4 Sep 2024 20:31:49 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6EDA51A0FD6 for ; Thu, 5 Sep 2024 00:31:49 +0000 (UTC) X-FDA: 82528806738.24.F43A449 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf16.hostedemail.com (Postfix) with ESMTP id BB06718000B for ; Thu, 5 Sep 2024 00:31:47 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1farXctb; spf=pass (imf16.hostedemail.com: domain of 38vvYZggKCIszx27tDw3v33v0t.r310x29C-11zAprz.36v@flex--kinseyho.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=38vvYZggKCIszx27tDw3v33v0t.r310x29C-11zAprz.36v@flex--kinseyho.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725496259; a=rsa-sha256; cv=none; b=YkeshnIf9azl9y6VhSnph7xSj4MoxA1b1wbdaeOO8hJORqWsGtqZs7qCu7tejQzzqE4HHM f78fM1X2ZHWwDUpP6mvtMFzrAV5G24I8MDzlWYt6eIRTp862D74hC2jbBaKf9wQ8BWi18h Z2062bBiNqiF0RpoC7bvCKV3aMGExCw= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1farXctb; spf=pass (imf16.hostedemail.com: domain of 38vvYZggKCIszx27tDw3v33v0t.r310x29C-11zAprz.36v@flex--kinseyho.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=38vvYZggKCIszx27tDw3v33v0t.r310x29C-11zAprz.36v@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=1725496259; 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: references:dkim-signature; bh=dCiOKpOFqlD6C2iCSSs7Lyoq3x0IlMR0Jw1jQQmJ13E=; b=317epkvojLj5um7PmVToAva9/JXRLFX+YWlM/07GdJ8SmgzLe79fCLp0s6pimHwGc0kmY9 ymFrDeeKETIjqQqS02aa2FbER9/sRITIrH1t8Sc9PjrklydmKlQ+BDgfqpTZouqWlqMY8D 409ZpppukARVFFstMYBSJRzPTHFlh0U= Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2d889fc26e7so158270a91.3 for ; Wed, 04 Sep 2024 17:31:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725496306; x=1726101106; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=dCiOKpOFqlD6C2iCSSs7Lyoq3x0IlMR0Jw1jQQmJ13E=; b=1farXctbehQhiovl6vmh2hTO7mVIZDInpIErkGut2F21fv16qbrbgq8u/L56PZexWO sQApHoo/36If+XH71+NEFv31XLbGoiuF3T7gj0Dt+6tWFk4S4n2NprtQeFRmdbwjB1eb MEKD18YTEZnpZ78PQstaGNl93lqmEm4Sa/brDsIrMCqW83ISF2fjrtGO+TJ5ziIWid+d 0coLfGnHtlmTU7NvbC6ycjHTAuEqGq9PaB35PnX6M6cwHBACirHefXJ9oZGhsrDhMC5T 7waZtrghBX4U+rQ0BLKVcfl5xS9uq859KD9hFJl/Bt+hZrgnmTz+EKv3oXQ18ZObSryj 9wOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725496306; x=1726101106; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dCiOKpOFqlD6C2iCSSs7Lyoq3x0IlMR0Jw1jQQmJ13E=; b=LD3LTQQLEkuaiTW1jASSP6nqzz8GDfZqbnXf5lc/aLY04TxhlqpdnCbCAX7oGquIfd jPqicBiLt7SwebTJFsLgSMBo6YPQZi2NCyTKrOGH17KFCm9F3WvdbRsJOtLw7m4ceb9O 2n0mEIMQh1Phf2rdBPBoxIuPpj0A1458l1NRpESf8lT0kMm08dBVADnF46og8xRU2x1t d9NFhFxAVcuM6zW1EwYOb9LuOY4y0tU4WYckWwB6zjCX46T0+yD6y6eHbFWDWx0Y/h3e vqEQO8tzdAdo/xTcEOy51Gmmy3spejSXnuyNazF5LaXDgtIFFK4rqh1ctetCrG0ki+Zu HkUg== X-Gm-Message-State: AOJu0Yyh3Sw/2HeBPZ8203HMSefbGS6KPGbnDPL0E+/9/xE+0PtHD4qI nmk+2pga8gsgUY3Zco2ffW8whixXzs4OdS4TkSg0riLTzdu9VxD/xnCa6DTb1jm6AmtmibGrjop dEgI9j264PA== X-Google-Smtp-Source: AGHT+IHGHiTuciDfvv/IhVf91ROgyhWylO6eINXSVTS1ZmC1WL6d+mazuFmoRnQz+5tklBVZyYGtt0yYpGER1A== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:46b]) (user=kinseyho job=sendgmr) by 2002:a17:902:e84b:b0:205:5550:f34f with SMTP id d9443c01a7336-2055550ff57mr10546555ad.6.1725496306005; Wed, 04 Sep 2024 17:31:46 -0700 (PDT) Date: Thu, 5 Sep 2024 00:30:49 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240905003058.1859929-1-kinseyho@google.com> Subject: [PATCH mm-unstable v4 0/5] Improve 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-Stat-Signature: ufdtm4wgpmqe3ze4mjrp9ubowqtrbter X-Rspamd-Queue-Id: BB06718000B X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1725496307-793710 X-HE-Meta: U2FsdGVkX18u2PZdfkPkzza6XoKtsgEoiX3iOooDw43Ry8bNd5zjGpSZJdcMR1mNRYJKkVa40zWTp3slSjGOsAKpdOEUWpZ0T5N0QQAzM0A76Bu+P/8F6teIsFocFPekAnlc8P5sf3l+q8xkeF4EEpYBVMhOckgB6mw7N+myLYkfx6eLyQs67jDLlVxsav9FUO2I+tH+0XKmGKZnUCJlRhEw1rZ+XKFj0xmMjEQXkLlkQj6V/mF/emw6498XeOtDD0qKDJnDEcfCJ9fZTti++IEwHYQg6VdHidO/Bp19KDBvHW6XADdn2hHrDFeUHZ3/5txKBt8LrcKOjcWY/s6RnXuz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QVM6wU9JHCK2UyxjbSZTB6r6xdnENM5Xj7ZjiMxxPb8ZK1o6tNHIZfYQinbIWTqzn3qQolxQtKk+4JGHdICOYjWkAFYGgnfyC0R+AkuqkQ5lL7kJwdDqPXE8MHWUegeZkYIRFIpCG2mDem2OX0MKWjGWh4bBw5i6Betryo7YgXYb5+wZ81TZDQB2B+LtlYmT+jgIrAr+WB0aSDGQCwk5koI4maGBtJdUXg//1nIrbAouMatqN1TsgVwxGJPdgGwEVBzSHEfBJXrOA== 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: Incremental cgroup iteration is being used again [1]. This patchset improves the reliability of mem_cgroup_iter(). It also improves simplicity and code readability. [1] https://lore.kernel.org/20240514202641.2821494-1-hannes@cmpxchg.org/ --- v4: Fixed memcg restart bug reported by hughd in v3, patch 4/5 v3: https://lore.kernel.org/20240827230753.2073580-1-kinseyho@google.com/ Removed __rcu tag from patch 2/5 which removes the need for rcu_dereference(). This helps readability. v2: https://lore.kernel.org/20240813204716.842811-1-kinseyho@google.com/ Add patch to clarify css sibling linkage is RCU protected. The kernel build bot RCU sparse error from v1 has been ignored. v1: https://lore.kernel.org/20240724190214.1108049-1-kinseyho@google.com/ Kinsey Ho (5): cgroup: clarify css sibling linkage is protected by cgroup_mutex or RCU mm: don't hold css->refcnt during traversal mm: increment gen # before restarting traversal mm: restart if multiple traversals raced mm: clean up mem_cgroup_iter() include/linux/cgroup-defs.h | 6 ++- include/linux/memcontrol.h | 4 +- kernel/cgroup/cgroup.c | 16 +++---- mm/memcontrol.c | 84 ++++++++++++++++--------------------- 4 files changed, 51 insertions(+), 59 deletions(-)