Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5622828pxb; Thu, 20 Jan 2022 00:51:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJykw6k7CWd0VILngFKsk/FnzYfQLo2CICDVNYGBbTDJ/pdx84J/Whdl5tYsOKLdKUHt/7tm X-Received: by 2002:a63:9f12:: with SMTP id g18mr30526690pge.534.1642668662990; Thu, 20 Jan 2022 00:51:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642668662; cv=none; d=google.com; s=arc-20160816; b=Y4XUu5YWBncUlBPV9yVbyU8BLTsLrK6yM25zMIE4WcHdLtlGpc7O7E/nzpqOruixt9 NpHakUM1TiCikwyGJ8vzFeOvu/QEiAm/gfgL9bWGKKqlIQkADHebDvAYN4/ZDirn+XcT DbicJ1TbHbbSsxgFy00bXL55TsGaXIVlOlWZOH/u7YIhmcieuAibQShxW78iJ6m9Yaa7 Oi7ekRmJs1tQSbzXGuLlc8d2nnomXpWwQEOsrbo1NDBy3jsKUs/NKl7hsvmJJSukrFGk Yzm3lVN7EGcyzMMZQrocsAUJC6DI7lv8SZGN8puh0e6yQxkFpNob+3VRelgcFiGaqmhX nliA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=OC5quY8+bzQ7YwLxGQW1P7Vgcog//q1EsjQWuTsPZiA=; b=NMZrGHr//mCRYI8xZuqJgUZImPNdVQIjeShDKth7CgI1uzRKSltxhjlrYKKlTbfT/O 7eVF13c7QB8AU3KkPwPD5sJi8ubeKXPn+zwmJ8p5CIvtsfHTukKtgnrXgPccqYhlOsYA RMhjZrp81ezdCU0zZ5fgTWQkFzPHH8oiRB6Yh8Zgepdu2buIFUromrkrfgYd+4w9s/zd CguFpf9ZlYdhn4W+LxGu58R6SY/PHSlbhDux1hUalNgu45YdxFrPmnMODMfI4v3ek7BE sVi00caC0zkqm3tVTJ1N2osf7A2YD35yiPMsootUJkGu4xpXud3FRIK52EHKQoD5TIqc BYQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=c3af9NXf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nk16si2273898pjb.55.2022.01.20.00.50.51; Thu, 20 Jan 2022 00:51:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=c3af9NXf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241276AbiARMHa (ORCPT + 99 others); Tue, 18 Jan 2022 07:07:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241260AbiARMH3 (ORCPT ); Tue, 18 Jan 2022 07:07:29 -0500 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5838C06161C for ; Tue, 18 Jan 2022 04:07:28 -0800 (PST) Received: by mail-yb1-xb2b.google.com with SMTP id v186so55068142ybg.1 for ; Tue, 18 Jan 2022 04:07:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=OC5quY8+bzQ7YwLxGQW1P7Vgcog//q1EsjQWuTsPZiA=; b=c3af9NXfUtTV/ISsfNREopmBIAf8fT4PPP17qdILfbQoqvb1yfMa+D0XLlYT6JoNjU ePaLArNrWW5zLYdpo1aCAVvBM7NZdg3qoad2pIpBpn+dKX2qpHWbIzeTo/ZWGlUzG9m6 hdWzHLZgMHYc+km3yxBo/4gsymQJh83zgMLiF405qZowaqIxM7BnTJJFnGp2/q35ZIA6 maVqxHfZSqMXQDeOLAlQCpQMgLny1kM6wpQgjMqc1MgA20REMRU1Kyb60DSCWB1/YGt0 nmM29RNua0k7xFUkauKHhL0GFjcs9AX976BwT6xrQiJmMLPjBfkMK40ffRMoWetReJqm /lFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=OC5quY8+bzQ7YwLxGQW1P7Vgcog//q1EsjQWuTsPZiA=; b=iXo70MOhdE5p2LxFivhRW1dMmcfSYZkZfesXtVPBhA33ydrDTaYevv63J9ezYfGc/p mgEMayXKuWO12RPzc5LiApq6zQMX4vqsQ83k1b/P5YjR/hcJMzaKVEukNPoWRbby8dz9 sofVJHroIC7kmuQ0XK229PnvWx3NIKCP71MB6MsPPGG3b0YWuNq8nH3W/Yhf02hKYp5G O0IaWMjUJSSIk/DUXyNqJrNY8sh2qFP0ASHZOm49/fyd+8qwIbcCkKhGOtUCfRl/m4/g WQzV2v/rjz0PArcRCXBtNfDjf7fGSFy4/M100QPcwLFps9G3jRtAAugKHIOFNrbDGJb/ jLJw== X-Gm-Message-State: AOAM530+YLlNeKcHqcnC3JYYBP+9eAEfwjolwVM73QHYpYGHvTa9tfSR wpjylKYipjLXQSSvHZYhmg+ZbpSQ1TcEH3YVp8ZECA== X-Received: by 2002:a25:8806:: with SMTP id c6mr31085871ybl.199.1642507648082; Tue, 18 Jan 2022 04:07:28 -0800 (PST) MIME-Version: 1.0 References: <20211220085649.8196-1-songmuchun@bytedance.com> <20211220085649.8196-11-songmuchun@bytedance.com> <20220106110051.GA470@blackbody.suse.cz> <20220113133213.GA28468@blackbody.suse.cz> In-Reply-To: <20220113133213.GA28468@blackbody.suse.cz> From: Muchun Song Date: Tue, 18 Jan 2022 20:05:44 +0800 Message-ID: Subject: Re: [PATCH v5 10/16] mm: list_lru: allocate list_lru_one only when needed To: =?UTF-8?Q?Michal_Koutn=C3=BD?= Cc: Matthew Wilcox , Andrew Morton , Johannes Weiner , Michal Hocko , Vladimir Davydov , Shakeel Butt , Roman Gushchin , Yang Shi , Alex Shi , Wei Yang , Dave Chinner , trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, jaegeuk@kernel.org, chao@kernel.org, Kari Argillander , linux-fsdevel , LKML , Linux Memory Management List , linux-nfs@vger.kernel.org, Qi Zheng , Xiongchun duan , Fam Zheng , Muchun Song Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 13, 2022 at 9:32 PM Michal Koutn=C3=BD wrote= : > > On Wed, Jan 12, 2022 at 09:22:36PM +0800, Muchun Song wrote: > > root(-1) -> A(0) -> B(1) -> C(2) > > > > CPU0: CPU1: > > memcg_list_lru_alloc(C) > > memcg_drain_all_list_lrus(C) > > memcg_drain_all_list_lrus(B) > > // Now C and B are offline. The > > // kmemcg_id becomes the follow= ing if > > // we do not the kmemcg_id of i= ts > > // descendants in > > // memcg_drain_all_list_lrus(). > > // > > // root(-1) -> A(0) -> B(0) -> = C(1) > > > > for (i =3D 0; memcg; memcg =3D parent_mem_cgroup(memcg), i++) { > > // allocate struct list_lru_per_memcg for memcg C > > table[i].mlru =3D memcg_init_list_lru_one(gfp); > > } > > > > spin_lock_irqsave(&lru->lock, flags); > > while (i--) { > > // here index =3D 1 > > int index =3D table[i].memcg->kmemcg_id; > > > > struct list_lru_per_memcg *mlru =3D table[i].mlru; > > if (index < 0 || rcu_dereference_protected(mlrus->mlru[index], tr= ue)) > > kfree(mlru); > > else > > // mlrus->mlru[index] will be assigned a new value regardless > > // memcg C is already offline. > > rcu_assign_pointer(mlrus->mlru[index], mlru); > > } > > spin_unlock_irqrestore(&lru->lock, flags); > > > > > So changing ->kmemcg_id of all its descendants can prevent > > memcg_list_lru_alloc() from allocating list lrus for the offlined > > cgroup after memcg_list_lru_free() calling. > > Thanks for the illustrative example. I can see how this can be a problem > in a general call of memcg_list_lru_alloc(C). > > However, the code, as I understand it, resolves the memcg to which lru > allocation should be associated via get_mem_cgroup_from_objcg() and > memcg_reparent_list_lrus(C) comes after memcg_reparent_objcgs(C, B), > i.e. the allocation would target B (or even A if after > memcg_reparent_objcgs(B, A))? > > It seems to me like "wasting" the existing objcg reparenting mechanism. > Or what do you think could be a problem relying on it? > I have thought about this. It's a little different to rely on objcg reparenting since the user can get memcg from objcg and then does not realize the memcg has reparented. Although it can check memcg->objcg to know whether the memcg is reparented, it should also prevent this memcg from being reparented throughout memcg_list_lru_alloc(). Maybe holding css_set_lock can do that. I do not think this is a good choice. Do you have any thoughts about this? Thanks.