Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp4104142rdg; Wed, 18 Oct 2023 15:27:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGeLDcgzc7v+LwqikjAZe26JRxqwNGq8XySV0FcU0QloV9vz+E2FYLgFI24M1/gnzG4+fll X-Received: by 2002:a17:90a:5e:b0:27d:7f1b:1bec with SMTP id 30-20020a17090a005e00b0027d7f1b1becmr429935pjb.35.1697668048642; Wed, 18 Oct 2023 15:27:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697668048; cv=none; d=google.com; s=arc-20160816; b=FJTyyqQAuyXqlg+p8nsshT10ePRymPSdaGcFxTFFzuEL90arqTACGt9ktYhsAZz6f1 oHi2mZThfFeckFJ0D/qjVQFsjbwLD0WpsweBgX5JcobG6lOqxp524LQzbKpw7Y3lvtPZ Rn74tvdnrOztMr81kastno8oMkqK2sTKs/FwwGet77gzySQV1XFRZWOo4Mtecv5T8MZ2 xQ3vr/jiq6KI1jX/Km3xXo0P90KAC9+7Kht/ppkQicRtA1cx+dYyoAKx7+lpBrsHJTbe qrEj3ee3nqkfpWe3SY43ikssqQZqZON8AmUC811rdbUUlM2tXOrOHbLIb38e4nl133z1 rK4A== 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=YKT0DhFzK/7HUpXkHzrCihZCJECXU9c5i5HWV8bW/EM=; fh=DkjA2sPo1IHhj3dSLT/8nkkbEQExnFRA5si61kyVZaQ=; b=TEIaxA31kvl9hLT7+kXUrcXrxqMV1ocKGGA00o7UkK+RwjymI2ysz9ylBXlViK4klL DP1M4wEprGRLvsGfFwcGJK+rTieBl4VinhpfDgWebFIyf+aMlTJdiUxzcC8SQv6ID4tb AgS7kTBYEO984S2/BK8csss4R5WS2AvxiE32D/YHSe2SFQ5Izykg1FIs9mFryfDyp8Vx 35CF2nAY0mK2qliTN/+9PNTKKEaSSSg28PL5g0kG1cNACkq8u7c6Vgo+KhVNatIiOBE0 9iR+datV80O1vxuNGFwZU21hfBTsU6vPDl1zwaXl+JkkgPPKZDRJQfBGN9KjODiYUXt9 g79Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=NN9SmvU2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id fs8-20020a17090af28800b002774e4d6e7dsi714709pjb.147.2023.10.18.15.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 15:27:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=NN9SmvU2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DB4DE820DA34; Wed, 18 Oct 2023 15:27:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231704AbjJRW1X (ORCPT + 99 others); Wed, 18 Oct 2023 18:27:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231892AbjJRW1V (ORCPT ); Wed, 18 Oct 2023 18:27:21 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 959EB119 for ; Wed, 18 Oct 2023 15:27:17 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-9b6559cbd74so1262650766b.1 for ; Wed, 18 Oct 2023 15:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697668035; x=1698272835; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=YKT0DhFzK/7HUpXkHzrCihZCJECXU9c5i5HWV8bW/EM=; b=NN9SmvU2TJg1k06b6OhM/X5iwrPshR8TgLX6IJE3eX0j3o+09mvNILuymNT79an4W8 P9ydNx9uyvbwNLcxsxn3g6y0PIuEu3eBntnwumN/LCjLn2l9TkMM1NmYKmhFjrgV+sBV Fff59sWtx76MOYelgYUQ3k1pJQaHhMtRSsTGfbO+hBURUS/spU54kcswDZfBX3ARL27L bSo+TfB7IyONgQihkJjJoTyM8wA4iUkgo5MQH5PlMwB6zrBkZnAjujrfx554nQSvmeln DMUrGHv3uxd2v7VCtqc4t0QH1bOn39Jeu4pkdFH8JwdwNDyBd4N06WalJ2OeY7zafjwM QZPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697668035; x=1698272835; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YKT0DhFzK/7HUpXkHzrCihZCJECXU9c5i5HWV8bW/EM=; b=p+vil6xkwPIqacSrPX7P6/W+MjmUtl86sH84WXgkLuCg6XryHhD1vv11up+d/1TYgc ZFnJqpRzfPvJILviUcmvUgbOS04bM9NpfbirNW67XziIAFzkXYHplfNn7RHvflPC3TNM dLI+IP4tU2pUVZ6K8cnFvRSzOIsUN9tRHF0nR19ZgoaiZl2UF4aMn7T5J/QYPWMkvDdn gcjsr7cZ+C0gsCo/JQ2vqtEGn30ukJxD/IcD1P2eEPr/uMVN//b+LAyRrhTD5ThVqmuh o4VLoH3+MYYEQF3OiUBOabx0w2PGrwiJLs70rC5EzZwBGNRFAMGHmF0qn9C96RdkWboC uExw== X-Gm-Message-State: AOJu0Yyknt1QPfh4HkDH60FA1JvGMw2G3wiziutXzNaTe5P3NCpjXGTS XaIHsMXiuC1XMXuU+46gAKB4R86rzo0XrJcXeZkMrg== X-Received: by 2002:a17:907:3f13:b0:9ae:69b8:322b with SMTP id hq19-20020a1709073f1300b009ae69b8322bmr426010ejc.60.1697668034993; Wed, 18 Oct 2023 15:27:14 -0700 (PDT) MIME-Version: 1.0 References: <20231017232152.2605440-1-nphamcs@gmail.com> <20231017232152.2605440-2-nphamcs@gmail.com> In-Reply-To: <20231017232152.2605440-2-nphamcs@gmail.com> From: Yosry Ahmed Date: Wed, 18 Oct 2023 15:26:36 -0700 Message-ID: Subject: Re: [PATCH v3 1/5] mm: list_lru: allow external numa node and cgroup tracking To: Nhat Pham Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, cerasuolodomenico@gmail.com, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, shuah@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 18 Oct 2023 15:27:27 -0700 (PDT) On Tue, Oct 17, 2023 at 4:21=E2=80=AFPM Nhat Pham wrote= : > > The interface of list_lru is based on the assumption that objects are > allocated on the correct node/memcg, with this change it is introduced th= e > possibility to explicitly specify numa node and memcgroup when adding and > removing objects. This is so that users of list_lru can track node/memcg > of the items outside of the list_lru, like in zswap, where the allocation= s > can be made by kswapd for data that's charged to a different cgroup. > > Signed-off-by: Nhat Pham I prefer what Johannes suggested, making list_lru_add() and friends take in the memcg and nid, and add list_lru_add_obj() (or similar) and friends that assume the object is on the right node and memcg. This is clearer and more explicit imo. I am not very familiar with list_lrus though, so I'll leave this to folks who actually are. > --- > include/linux/list_lru.h | 38 +++++++++++++++++++++++++++++++++++ > mm/list_lru.c | 43 +++++++++++++++++++++++++++++++++++----- > 2 files changed, 76 insertions(+), 5 deletions(-) > > diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h > index b35968ee9fb5..0f5f39cacbbb 100644 > --- a/include/linux/list_lru.h > +++ b/include/linux/list_lru.h > @@ -89,6 +89,24 @@ void memcg_reparent_list_lrus(struct mem_cgroup *memcg= , struct mem_cgroup *paren > */ > bool list_lru_add(struct list_lru *lru, struct list_head *item); > > +/** > + * __list_lru_add: add an element to a specific sublist. > + * @list_lru: the lru pointer > + * @item: the item to be added. > + * @memcg: the cgroup of the sublist to add the item to. > + * @nid: the node id of the sublist to add the item to. > + * > + * This function is similar to list_lru_add(), but it allows the caller = to > + * specify the sublist to which the item should be added. This can be us= eful > + * when the list_head node is not necessarily in the same cgroup and NUM= A node > + * as the data it represents, such as zswap, where the list_head node co= uld be > + * from kswapd and the data from a different cgroup altogether. > + * > + * Return value: true if the list was updated, false otherwise > + */ > +bool __list_lru_add(struct list_lru *lru, struct list_head *item, int ni= d, > + struct mem_cgroup *memcg); > + > /** > * list_lru_del: delete an element to the lru list > * @list_lru: the lru pointer > @@ -102,6 +120,18 @@ bool list_lru_add(struct list_lru *lru, struct list_= head *item); > */ > bool list_lru_del(struct list_lru *lru, struct list_head *item); > > +/** > + * __list_lru_del: delete an element from a specific sublist. > + * @list_lru: the lru pointer > + * @item: the item to be deleted. > + * @memcg: the cgroup of the sublist to delete the item from. > + * @nid: the node id of the sublist to delete the item from. > + * > + * Return value: true if the list was updated, false otherwise. > + */ > +bool __list_lru_del(struct list_lru *lru, struct list_head *item, int ni= d, > + struct mem_cgroup *memcg); > + > /** > * list_lru_count_one: return the number of objects currently held by @l= ru > * @lru: the lru pointer. > @@ -136,6 +166,14 @@ static inline unsigned long list_lru_count(struct li= st_lru *lru) > void list_lru_isolate(struct list_lru_one *list, struct list_head *item)= ; > void list_lru_isolate_move(struct list_lru_one *list, struct list_head *= item, > struct list_head *head); > +/* > + * list_lru_putback: undo list_lru_isolate. > + * > + * Since we might have dropped the LRU lock in between, recompute list_l= ru_one > + * from the node's id and memcg. > + */ > +void list_lru_putback(struct list_lru *lru, struct list_head *item, int = nid, > + struct mem_cgroup *memcg); > > typedef enum lru_status (*list_lru_walk_cb)(struct list_head *item, > struct list_lru_one *list, spinlock_t *lock, void *cb_arg= ); > diff --git a/mm/list_lru.c b/mm/list_lru.c > index a05e5bef3b40..63b75163c6ad 100644 > --- a/mm/list_lru.c > +++ b/mm/list_lru.c > @@ -119,13 +119,22 @@ list_lru_from_kmem(struct list_lru *lru, int nid, v= oid *ptr, > bool list_lru_add(struct list_lru *lru, struct list_head *item) > { > int nid =3D page_to_nid(virt_to_page(item)); > + struct mem_cgroup *memcg =3D list_lru_memcg_aware(lru) ? > + mem_cgroup_from_slab_obj(item) : NULL; > + > + return __list_lru_add(lru, item, nid, memcg); > +} > +EXPORT_SYMBOL_GPL(list_lru_add); > + > +bool __list_lru_add(struct list_lru *lru, struct list_head *item, int ni= d, > + struct mem_cgroup *memcg) > +{ > struct list_lru_node *nlru =3D &lru->node[nid]; > - struct mem_cgroup *memcg; > struct list_lru_one *l; > > spin_lock(&nlru->lock); > if (list_empty(item)) { > - l =3D list_lru_from_kmem(lru, nid, item, &memcg); > + l =3D list_lru_from_memcg_idx(lru, nid, memcg_kmem_id(mem= cg)); > list_add_tail(item, &l->list); > /* Set shrinker bit if the first element was added */ > if (!l->nr_items++) > @@ -138,17 +147,27 @@ bool list_lru_add(struct list_lru *lru, struct list= _head *item) > spin_unlock(&nlru->lock); > return false; > } > -EXPORT_SYMBOL_GPL(list_lru_add); > +EXPORT_SYMBOL_GPL(__list_lru_add); > > bool list_lru_del(struct list_lru *lru, struct list_head *item) > { > int nid =3D page_to_nid(virt_to_page(item)); > + struct mem_cgroup *memcg =3D list_lru_memcg_aware(lru) ? > + mem_cgroup_from_slab_obj(item) : NULL; > + > + return __list_lru_del(lru, item, nid, memcg); > +} > +EXPORT_SYMBOL_GPL(list_lru_del); > + > +bool __list_lru_del(struct list_lru *lru, struct list_head *item, int ni= d, > + struct mem_cgroup *memcg) > +{ > struct list_lru_node *nlru =3D &lru->node[nid]; > struct list_lru_one *l; > > spin_lock(&nlru->lock); > if (!list_empty(item)) { > - l =3D list_lru_from_kmem(lru, nid, item, NULL); > + l =3D list_lru_from_memcg_idx(lru, nid, memcg_kmem_id(mem= cg)); > list_del_init(item); > l->nr_items--; > nlru->nr_items--; > @@ -158,7 +177,7 @@ bool list_lru_del(struct list_lru *lru, struct list_h= ead *item) > spin_unlock(&nlru->lock); > return false; > } > -EXPORT_SYMBOL_GPL(list_lru_del); > +EXPORT_SYMBOL_GPL(__list_lru_del); > > void list_lru_isolate(struct list_lru_one *list, struct list_head *item) > { > @@ -175,6 +194,20 @@ void list_lru_isolate_move(struct list_lru_one *list= , struct list_head *item, > } > EXPORT_SYMBOL_GPL(list_lru_isolate_move); > > +void list_lru_putback(struct list_lru *lru, struct list_head *item, int = nid, > + struct mem_cgroup *memcg) > +{ > + struct list_lru_one *list =3D > + list_lru_from_memcg_idx(lru, nid, memcg_kmem_id(memcg)); > + > + if (list_empty(item)) { > + list_add_tail(item, &list->list); > + if (!list->nr_items++) > + set_shrinker_bit(memcg, nid, lru_shrinker_id(lru)= ); > + } > +} > +EXPORT_SYMBOL_GPL(list_lru_putback); > + > unsigned long list_lru_count_one(struct list_lru *lru, > int nid, struct mem_cgroup *memcg) > { > -- > 2.34.1