From patchwork Mon Jun 24 17:53:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13709939 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 62B54C2BD09 for ; Mon, 24 Jun 2024 17:53:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0EEB6B039E; Mon, 24 Jun 2024 13:53:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E96E16B039F; Mon, 24 Jun 2024 13:53:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D136E6B03A0; Mon, 24 Jun 2024 13:53:42 -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 AEFD66B039E for ; Mon, 24 Jun 2024 13:53:42 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 58C5B141121 for ; Mon, 24 Jun 2024 17:53:42 +0000 (UTC) X-FDA: 82266529884.03.F45DFB0 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf23.hostedemail.com (Postfix) with ESMTP id 7AC2214000E for ; Mon, 24 Jun 2024 17:53:40 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SIWL2t8W; spf=pass (imf23.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719251602; 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=wR7nCSc7wycOJ85fc2vh7+9RCx1gdhpfbe952wKPpHE=; b=PfzhZrwn3Inj9T1ciJspr17oOlQcmBy7kRTIH5+kynxho7pdNGLQUefIyMDlFti9mtClRU sKXOQMXmmVNWowiR9RymiZjCyim71HKKO8RYzGMC0XCCy3B+Uj2Fn+NunXcEULFVvkbgOa BtwCmUOjXy0xPBpWahC+5cyf97Y5Qrc= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SIWL2t8W; spf=pass (imf23.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719251602; a=rsa-sha256; cv=none; b=1UzJ1RUV4JxTNqaeUW9oiYCKKif2Wqx1aJqO/hKIinxe9eS0vimg72sQQNL2fFYi/EKSA8 T58k5gimH1IGk8eM6NfgTUTdbfNnqCdf4TaXRqJqZVWZbADNNk9o8JTIx+kQi9l7q9pWoM yjR6AKtvPuk+P4hfsur+rx77XHoGHPY= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-70666ab6434so1771793b3a.1 for ; Mon, 24 Jun 2024 10:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719251619; x=1719856419; 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=wR7nCSc7wycOJ85fc2vh7+9RCx1gdhpfbe952wKPpHE=; b=SIWL2t8WjwBB4Vznyzmn6PaouWc6Ie88JFiP576JjMQBFNjlVV+oGDQ9djHvOZSxG2 ItW4bOklHgmY7rU7i+OM4Dhxr3FKJWaUlYWF1x558QFEOPDqvj/B6tONwrWSWeomgyX9 ydrbL+6bhL6bJL+8OQ7vCM8D2TiOl180AYr4h5qRklRqIuTiM1tQEa5SC9wZpE5B2JwJ +L6BnKFMqhiVAtEmWyU4D3zgJPgbYzmxj0a7FxR9FhAT9yu4xEjFbIt/Z5VbrZ2kA1et nyx34I5iHfMo7UvlgCETzlpiRQRIIuypF2x65oBZKds5cUukZYTwpw33H34T9wmcWQfx RkLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719251619; x=1719856419; 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=wR7nCSc7wycOJ85fc2vh7+9RCx1gdhpfbe952wKPpHE=; b=uy7o1nDQJbb0wf6Ch58Biax3nMvSyMtk1OWzxJd9si3MfZd4fWds4SMSlyfy+CvA17 /iN06J1rEGGH+UcvaTQf/YeEDXtt7CqOqrzDir++5m6xnk0iMvLqiUziZbRXFLZ/mqY6 6C+ULoRJ+PhkS7jRV8dPzVzktEyH9t/oEg317ZnEIZ4e4C8tzXjiftcqSLcTdE7hS4l2 onIJbslOYpcNWmfo+5Jtux1GoElILOGK8opnp1XMmCASeZg3/9e57qANbvRa55Ehp42G u6bHNk20u9FCUqcz7//uIpxr1m7dGX0iA3cac113QwavEFZ36VhENeaQ2ZhnnmdlZIIm wPgQ== X-Gm-Message-State: AOJu0YyOMRi10lnJ9XugPNRr89OefahFzAeVar18DQOUmgP9KUXvU0Nf Oo52aV9dJGfuLLAFdFp63XOSwMGrXfs5w8biDiEkcwf7w2iNO86nktxxXkQJcbE= X-Google-Smtp-Source: AGHT+IHLHZoQzy7hopsa8iKiLEPkc3wyIys/gHGkIAkSEHRVzjCjaC0AObbeFEAQGbN6VramW1Ve3w== X-Received: by 2002:a05:6a00:b21:b0:704:32dc:c4e4 with SMTP id d2e1a72fcca58-70670e7a958mr4910003b3a.1.1719251618830; Mon, 24 Jun 2024 10:53:38 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70662ee117asm5008049b3a.211.2024.06.24.10.53.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 10:53:38 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Waiman Long , Shakeel Butt , Nhat Pham , Michal Hocko , Chengming Zhou , Qi Zheng , Muchun Song , Chris Li , Yosry Ahmed , "Huang, Ying" , Kairui Song Subject: [PATCH 4/7] mm/list_lru: code clean up for reparenting Date: Tue, 25 Jun 2024 01:53:10 +0800 Message-ID: <20240624175313.47329-5-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240624175313.47329-1-ryncsn@gmail.com> References: <20240624175313.47329-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7AC2214000E X-Stat-Signature: ha9qk8gkjynpa4eeuajw5k6eu5aucrzt X-Rspam-User: X-HE-Tag: 1719251620-803326 X-HE-Meta: U2FsdGVkX19VKbkRQPqCodtyROed9y2UwIz7yYu9OHLgldD78TzkSEPO2cChMiBAaa885c4aQx2TuJzWdrW73We2TI/tQqccE8Koi5tTqaU00FjIOz8s/mOZJCwiggWS6+lqAS5v2+fH0TfK4HXZEXrcUENU0nFT2sVpCrF1jZw4Z7LRfCvG+Ip5x3yH2LCuEOcF1QcX/OIEoKQ18HbMJhA4qBj50oCi3hI6UoeNgBsrEDXdTQmdduSP2/hVZ9jRIDpAabAZpdQhDAuOOEjydFiG2qUT4QhcMzwhFx1gCBYN/mBAkX/oqR6BnJZ1HnE9Ge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k3DgXaAesVgOH7K7AtC/jvik0mjT0SegJVy3lXc0ZSH2VE2ud8zMc8OV8E53NSJ510fjdeJ8BGPrEfqI3HW0TmCMLIruSeaVIz/Sg37jIGez53KB3+C4vmSfXuRFnBVzprRRuxg0tA8MaDQb9vaJMAU4U9SLkagmXJoL4aLvXCfRDM3/0= 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 --- 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 9d9ec8661354..4c619857e916 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -405,35 +405,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) { @@ -444,9 +425,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 lru lock 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 71fe2a95b8bd..fc35c1d3f109 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4187,13 +4187,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); } #else