From mboxrd@z Thu Jan 1 00:00:00 1970 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 C80ADC4167B for ; Tue, 5 Dec 2023 02:29:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66B316B008A; Mon, 4 Dec 2023 21:29:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 61AD86B008C; Mon, 4 Dec 2023 21:29:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 509D26B0092; Mon, 4 Dec 2023 21:29:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 404E46B008A for ; Mon, 4 Dec 2023 21:29:28 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 17483404D9 for ; Tue, 5 Dec 2023 02:29:28 +0000 (UTC) X-FDA: 81531183216.18.42616CE Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) by imf21.hostedemail.com (Postfix) with ESMTP id 0F7CA1C0004 for ; Tue, 5 Dec 2023 02:29:24 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=rBnFTf7X; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf21.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.178 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701743365; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ymMLu9FZ8CtZOyGQwaalZh7+0iVyegROhtwrn5KGHB4=; b=ClCuHxS43KPUXU8zhqFOqWafZvFjB9G/QHjBwShOKSNzevcxRQgeG06MYad/7rU8qP3tCY F6Yv7HeZVl6YXmGWUAqXZHbShnKMU6To6kr9iAKqgMwjcLmXb9rMtoTVwaDTRtL/VMseEs Yyx62ILQC0ugV/qVOK4LCUm3xZRYQXc= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=rBnFTf7X; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf21.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.178 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701743365; a=rsa-sha256; cv=none; b=195tBbvZWnYFcuYN/FaiKwNKqZhJwR6V1Am4a832Pf4o6fd1hrWKAoQt45RaixwmyqOOvH +jHg7WIcQ+Xs/LhsrPF/8hhTyPv0U7OqIADQ1DMbY7ro9V09bvI56zcLvUKJaVVoVpbrOM CQu+P1ORz5n68zx6Ulo9zCNaEzw68SM= Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1701743362; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ymMLu9FZ8CtZOyGQwaalZh7+0iVyegROhtwrn5KGHB4=; b=rBnFTf7X21Q4cNhSaM8MqzICMe44z516qx66zq5Z6w5CwqtmCX3plbgQuWQ1hCNrqI0WUk 3WKu7/haEG+O2MStW7f6iHUOZppGPjNOI+ul/Og7Lahu3inHi79MCDKxEiB+fyHev+DmDm GpH3C1ZZNsCzXdv7S4quXwwA1vd3TKU= Date: Tue, 5 Dec 2023 10:28:50 +0800 MIME-Version: 1.0 Subject: Re: [PATCH v8 1/6] list_lru: allows explicit memcg and NUMA node selection Content-Language: en-US To: Nhat Pham Cc: Johannes Weiner , Matthew Wilcox , akpm@linux-foundation.org, cerasuolodomenico@gmail.com, yosryahmed@google.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, chrisl@kernel.org, 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 References: <20231130194023.4102148-1-nphamcs@gmail.com> <20231130194023.4102148-2-nphamcs@gmail.com> <20231130203522.GC543908@cmpxchg.org> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0F7CA1C0004 X-Stat-Signature: z8snu9787dg4ja6m5imw3h4m8st7yi4i X-HE-Tag: 1701743364-215717 X-HE-Meta: U2FsdGVkX18Qjsb3ZT+2+OPRZRtc1CC7ItjRcNLBs5UqPYCUfX/bMRZ73ZY4z0OZ2QFp+ZCn/PFO9eT5FTamkI5G75ixi+O47sgfS8KLrEOMzaxM81LGP3ki4EEkdYLKE+TPl5epD705RkcGXoyefzj2hTfc1DxxlFPGWYf8eRNANCDF76mvy+a6r7mwl+jrkNZaILdmvn4Gq7QTxLGtkVF05Ezxp1aFH8hWxI6iIurWHsuegjGk0TDEwhG6ClHRhAwb3CB02I/pW+X1xTYIjUrTK4u/YGpJJG3ttylzah/hZFVLb/TU186GCHcwtp+S+OrPq8mbkWH6GQ66OQOl+O7zTx9WGgE+PMgvbYCByas4PVDrIwA9xwp4Z4JDFaBKuQqkzt1gjsTuv1nMajwnxlg6HSR0Zjs2TWKNSSI2VtKkIjX5/7LFXQnyc2BPLFXPD4piAfCuGSeOU1LJyecKPqFp7yi0dMAfKXZcQueiLLknWWkQnd6Mf9wmpH1Vmw3axMJraYJanxfeyxETZx5c9XsyvmeYA3TZJhHZd7LWNhSAdyPrl1t6VfAzFd8OYnBDtdoDw+y6dbRtFC6nmaug9xHd+kwb6O7L4JbEyBoIL/9I/f/QDmnltpNLuH6jxsG3DFCq6Lt1YET1THORtpiPk/Gxf8esf9nj1sToNzqSXD2woYLzcCInGNMcw5sOVZObhZm7fBm7NtzjWvM7X02zGyH2wQ53i6nIyk8luanRInLoO6q+4OP/pymTZpaikvPdCnFP0H+Fz1LFJcfuit/t6UDc50ibPzxVhFztAaHcKoejrPEtzM/KrJQuoV0N0IE4ZL+8nPHN78kZoIK6/1ctu2SllWnpUu2rrKwDoNTridzCYPaRfhfBvl6hoXOPQCfaGphJojSRmp4ABpDXk3n4FhZzlWeL3Kp1EzOTS+rmmIoIV2CHFhLR5S9aFdrOp/Zq92o7v/p7CORfZpOWwK6 VVItHg36 EIe6Cz2ase4tl3cSi4yM2wKTUVbUf0lT7g0L7hxjksjOBOtH6+FyTEa4AM+Yt7ItxpFmVgDhIH+vP0mUfkIbDoVv/gExZhyVrI4jVnAFARtw28sybwm2K6AX3c0AulxqepxfwVOw+lzUX2GTUXIdu5+qVGxdwrD8RrD5RJFbYvijQmux3pZLpshNea+wJXVjTIMrlqwPtCR4PPCyzwbmp1qY9tyYfBVrIda7TS/LbOiqq24I8dZOjDJEdZA== 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: On 2023/12/5 01:48, Nhat Pham wrote: > On Mon, Dec 4, 2023 at 12:30 AM Chengming Zhou wrote: >> >> On 2023/12/1 04:35, Johannes Weiner wrote: >>> On Thu, Nov 30, 2023 at 12:07:41PM -0800, Nhat Pham wrote: >>>> On Thu, Nov 30, 2023 at 11:57 AM Matthew Wilcox wrote: >>>>> >>>>> On Thu, Nov 30, 2023 at 11:40:18AM -0800, Nhat Pham wrote: >>>>>> This patch changes list_lru interface so that the caller must explicitly >>>>>> specify numa node and memcg when adding and removing objects. The old >>>>>> list_lru_add() and list_lru_del() are renamed to list_lru_add_obj() and >>>>>> list_lru_del_obj(), respectively. >>>>> >>>>> Wouldn't it be better to add list_lru_add_memcg() and >>>>> list_lru_del_memcg() and have: >>>>> >>>>> +bool list_lru_del(struct list_lru *lru, struct list_head *item) >>>>> +{ >>>>> + int nid = page_to_nid(virt_to_page(item)); >>>>> + struct mem_cgroup *memcg = list_lru_memcg_aware(lru) ? >>>>> + mem_cgroup_from_slab_obj(item) : NULL; >>>>> + >>>>> + return list_lru_del_memcg(lru, item, nid, memcg); >>>>> +} >>>>> >>>>> Seems like _most_ callers will want the original versions and only >>>>> a few will want the explicit memcg/nid versions. No? >>>>> >>>> >>>> I actually did something along that line in earlier iterations of this >>>> patch series (albeit with poorer naming - __list_lru_add() instead of >>>> list_lru_add_memcg()). The consensus after some back and forth was >>>> that the original list_lru_add() was not a very good design (the >>>> better one was this new version that allows for explicit numa/memcg >>>> selection). So I agreed to fix it everywhere as a prep patch. >>>> >>>> I don't have strong opinions here to be completely honest, but I do >>>> think this new API makes more sense (at the cost of quite a bit of >>>> elbow grease to fix every callsites and extra reviewing). >>> >>> Maybe I can shed some light since I was pushing for doing it this way. >>> >>> The quiet assumption that 'struct list_head *item' is (embedded in) a >>> slab object that is also charged to a cgroup is a bit much, given that >>> nothing in the name or documentation of the function points to that. >>> >>> It bit us in the THP shrinker where that list head is embedded in a >>> tailpage (virt_to_page(page) is fun to debug). And it caused some >>> confusion in this case as well, where the zswap entry is a slab object >>> but not charged (the entry descriptor is not attractive for cgroup >>> accounting, only the backing memory it points to.) >> >> Hi, >> >> I have a question, maybe I missed something since I haven't read all >> the earlier versions. >> >> IIUC, the problem here is that "zswap_entry" has different memcg and node >> than the "page", so I wonder if we can just charge "zswap_entry" to the >> same memcg of the "page". >> >> Like we can do these when allocating the "zswap_entry": >> >> old_memcg = set_active_memcg(memcg) >> kmem_cache_alloc_lru(zswap_entry_cache, lru, gfp) >> set_active_memcg(old_memcg) >> >> The good points are: >> >> 1. "zswap_entry" is charged to the memcg of "page", which is more sensible? >> >> 2. We can reuse the kmem_cache_alloc_lru() interface, which makes code simpler >> since we don't need to manage list_lru_memcg by ourselves. >> >> 3. Maybe the new list_lru_add() and list_lru_del() are not needed anymore? >> Since the "zswap_entry" is of the same memcg and node with the "page". >> But don't know if THP shrinker still need it. >> >> Thanks! > > That idea was considered in earlier iterations/discussions of the > patch series as well. Charging things is not free - there is an > overhead associated with it, which is why we are usually selective > about whether to charge something. We were not super keen to do this > for zswap_entry just to plumb around the list_lru's restriction. Might > as well pay the price of extending the list_lru interface now. > > If in the future, not charging the zswap entry causes a separate > isolation issue, we could revisit this decision and charge it. > Otherwise, IMHO we should just stick with this for now. > Ok, I get it. Thanks much for your clear explanation!