From patchwork Wed Sep 25 17:10:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13812338 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 5223DCCF9E8 for ; Wed, 25 Sep 2024 17:10:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF8D86B00B8; Wed, 25 Sep 2024 13:10:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C81936B00B9; Wed, 25 Sep 2024 13:10:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD2EC6B00BA; Wed, 25 Sep 2024 13:10:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8B0C86B00B8 for ; Wed, 25 Sep 2024 13:10:41 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 526FE160524 for ; Wed, 25 Sep 2024 17:10:41 +0000 (UTC) X-FDA: 82603899882.23.98ED026 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf04.hostedemail.com (Postfix) with ESMTP id 6FFF440003 for ; Wed, 25 Sep 2024 17:10:39 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="KoO2wbS/"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727284141; a=rsa-sha256; cv=none; b=XxsWSlLXB1f+252T6XbxnmOhoG4Z/9cYE3BtakkfLaK45ndSS2ID7waw/UXpAs/2Efts0d fbi8dSCFSxgAutQpFYx8QVDlqsd5yb17SnTkGKi47172hJxQWY+OKmRKEwrpz87wRxlVj3 yUdUq/vgGK3TjWojhP3yXsoOd9WH1XA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="KoO2wbS/"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727284141; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=V5rpPame40tPuYqilRt6PKKEmhwrT8TBQfaU/Nj3qXg=; b=oVzxAPco2NwnSZ6akQwRjxzNhJBeCZLq/2CKPq/iVZ9HtDbBNqM27k0RnACfXhP1+onMIh lVWNDH09f1qrpwwY1gZ8RdP4FbdiSzh1YICma9vMlA0BQukiaAuNd+fehU41jaivmxWkz7 rKTyplzUldOda0f6U9xUcgPSPjw79uQ= Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-7198de684a7so101604b3a.2 for ; Wed, 25 Sep 2024 10:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727284238; x=1727889038; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=V5rpPame40tPuYqilRt6PKKEmhwrT8TBQfaU/Nj3qXg=; b=KoO2wbS/pXRiD9wt96FnbIekklv6FrSdsnetmBev/acbWrcmIp8Yo6iUeGvpP7vBaC eE4BeLhabUI+12gRTYD11vAbtZttNFrDd08PVC68Hjuh8mGC2WtlDbSR8dQP9SFrfwFn 3lIxhfi0y1zKd9OZ063FFwnZyouIt/eAoVt/35uNsLxOCqfjvGy0quzTRgMF8x+U6oTF D/JW/adv+WOAbNqG7EnaF7WYRvjVKLATYfO2fBjbOUGp86TlanbytQ/3dVWSwgNX/NDC kUIrK4yXRGOw0NnyCac4+m3DoNnDI1L9x21MV1W4KXJIMmjjBRfRMsOrQgmLRRSJPJZC MqxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727284238; x=1727889038; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=V5rpPame40tPuYqilRt6PKKEmhwrT8TBQfaU/Nj3qXg=; b=Oov5+yxvDGl7pbgmpmDeA0cw+Un12Mv8jRXrLL7oMcYLjbK9yui7NWECuNyqUlHPKd YnGKjzxtdbceujVG7ACYWiw+/YQhFceshsPPFoL2QNtIbwqI/GeHBLgxWc+cbijt3xeg 2SjVCbHoW31SRrTWoZe8P40L/cWv3oxRWtfEfT0dK/Rjp77yz7LDI8EUNKB6vJfkbSuR Vai7KbldAOvM0WVgDqV9MT9OYcnxzonpoj3l7qSLLFxRovSC3kFZ3akXjj6EDCZdXRuL YWcqYTZRpC0Qxn1aK7yqigKJSniK68wihBJAbsX2vtgeHdEmGA5THYv6SOWx8VSahIEk CNFQ== X-Gm-Message-State: AOJu0YzVKgPgI5qPBGr3MB76FsK/0K3TQmDIWfA1biRejt2DwN8bbSIp Q5QDyJCar8OTSPflM3WNV/Z9qKrFKoYr5N+Of5PRpcKqCXVy1PfK8HmJjyDe X-Google-Smtp-Source: AGHT+IGf2FiqU8wh6uDCOV7YyLhTSsPhlKdicE3S39+oA0aW8f9anu6q8aRA1unBV1HOXQVQQld2ig== X-Received: by 2002:aa7:93ac:0:b0:718:e188:fdf1 with SMTP id d2e1a72fcca58-71b0ac5157bmr3694049b3a.20.1727284236763; Wed, 25 Sep 2024 10:10:36 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b032eb4f7sm2437900b3a.181.2024.09.25.10.10.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 25 Sep 2024 10:10:36 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Waiman Long , Shakeel Butt , Michal Hocko , Chengming Zhou , Qi Zheng , Muchun Song , Kairui Song Subject: [PATCH v2 3/6] mm/list_lru: code clean up for reparenting Date: Thu, 26 Sep 2024 01:10:17 +0800 Message-ID: <20240925171020.32142-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240925171020.32142-1-ryncsn@gmail.com> References: <20240925171020.32142-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6FFF440003 X-Stat-Signature: xuscrxm6ngxkt8brrfseh69wkacc6w6p X-Rspam-User: X-HE-Tag: 1727284239-431363 X-HE-Meta: U2FsdGVkX19rPqLa9e4Z2ty7vqfvsQYsbhH6x+hnGH2pA5tFkXT4RgFEqsQ2okyjI/glux/bbh12fnglhanBZ6iQPhj6zubFQnavBuKhfwzUMWm5tHnLy/E4YlMB+djXXnuR/MPot/VYOb4zp/O3bU2WS6oEqwJk+yA2EGignPUS/+10QnYZ1AJB2z8jn9NPTct6574OVtgSRp3XssE/DRuQ1fcbc+jCQ8ku4Mn35coK6g8RYPZFZpMEPmVHR9mm12/vFM0xbhBz4PVj8f1NSKQSGBMOJ4TVHdLqUJAG43SE6mMwljY02S97LZuWpQ9uwuzJGoFz5Lh0xXPr+4WrpkT22+ASGF/6mVIlW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J5SA+jiyqcMQlNgNOoIDySeuFl2h69KENmzABd+4dRLtI9U93VtP44EVev1Kw/nOJ8aWjPVQOBUAKMJD7+9mm2Vr+QTjDCzMNZagq8MbFP4S5fP+0/accYgIxS/auXMUb 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: From: Kairui Song No feature change, just change of code structure and fix comment. The list lrus are not empty until memcg_reparent_list_lru_node() calls are all done, so the comments in memcg_offline_kmem were slightly inaccurate. Signed-off-by: Kairui Song Reviewed-by: Muchun Song Acked-by: Shakeel Butt --- mm/list_lru.c | 39 +++++++++++++++++---------------------- mm/memcontrol.c | 7 ------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/mm/list_lru.c b/mm/list_lru.c index a798e7624f69..b54f092d4d65 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -421,35 +421,16 @@ static void memcg_reparent_list_lru_node(struct list_lru *lru, int nid, spin_unlock_irq(&nlru->lock); } -static void memcg_reparent_list_lru(struct list_lru *lru, - int src_idx, struct mem_cgroup *dst_memcg) -{ - int i; - - for_each_node(i) - memcg_reparent_list_lru_node(lru, i, src_idx, dst_memcg); - - memcg_list_lru_free(lru, src_idx); -} - void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *parent) { struct cgroup_subsys_state *css; struct list_lru *lru; - int src_idx = memcg->kmemcg_id; + int src_idx = memcg->kmemcg_id, i; /* * Change kmemcg_id of this cgroup and all its descendants to the * parent's id, and then move all entries from this cgroup's list_lrus * to ones of the parent. - * - * After we have finished, all list_lrus corresponding to this cgroup - * are guaranteed to remain empty. So we can safely free this cgroup's - * list lrus in memcg_list_lru_free(). - * - * Changing ->kmemcg_id to the parent can prevent memcg_list_lru_alloc() - * from allocating list lrus for this cgroup after memcg_list_lru_free() - * call. */ rcu_read_lock(); css_for_each_descendant_pre(css, &memcg->css) { @@ -460,9 +441,23 @@ void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *paren } rcu_read_unlock(); + /* + * With kmemcg_id set to parent, holding the lock of each list_lru_node + * below can prevent list_lru_{add,del,isolate} from touching the lru, + * safe to reparent. + */ mutex_lock(&list_lrus_mutex); - list_for_each_entry(lru, &memcg_list_lrus, list) - memcg_reparent_list_lru(lru, src_idx, parent); + list_for_each_entry(lru, &memcg_list_lrus, list) { + for_each_node(i) + memcg_reparent_list_lru_node(lru, i, src_idx, parent); + + /* + * Here all list_lrus corresponding to the cgroup are guaranteed + * to remain empty, we can safely free this lru, any further + * memcg_list_lru_alloc() call will simply bail out. + */ + memcg_list_lru_free(lru, src_idx); + } mutex_unlock(&list_lrus_mutex); } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7845c64a2c57..8e90aa026c47 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3099,13 +3099,6 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg) parent = root_mem_cgroup; memcg_reparent_objcgs(memcg, parent); - - /* - * After we have finished memcg_reparent_objcgs(), all list_lrus - * corresponding to this cgroup are guaranteed to remain empty. - * The ordering is imposed by list_lru_node->lock taken by - * memcg_reparent_list_lrus(). - */ memcg_reparent_list_lrus(memcg, parent); }