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 DC223C3600C for ; Thu, 3 Apr 2025 15:06:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19A2B280007; Thu, 3 Apr 2025 11:06:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12455280001; Thu, 3 Apr 2025 11:06:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0438280007; Thu, 3 Apr 2025 11:06:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D2360280001 for ; Thu, 3 Apr 2025 11:06:11 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 915251609B8 for ; Thu, 3 Apr 2025 15:06:12 +0000 (UTC) X-FDA: 83293058184.10.17994C5 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) by imf17.hostedemail.com (Postfix) with ESMTP id A8E8540013 for ; Thu, 3 Apr 2025 15:06:10 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nOGMwRXp; spf=pass (imf17.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.45 as permitted sender) smtp.mailfrom=nphamcs@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=1743692770; 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=iK8KEJBVYPl6HLxUuQQ2klCL+ZgkeKSI3+E7obEM/WI=; b=t2y8Ys8JiR+rzQSB9g87hLP/K00HZLLbVYsuo+Td4XjPIl48muWtg/0WDjwoKW+amVY7+Q VucJA+UoQflKbDJDRjOaf3JkGEeGTi+YYA6hSWT0zvj2BJ7YMACNj/x1PVbBTe9sO36/rl VWnWHRU4aQKNuuxw+EKX+i9Ra396kLo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743692770; a=rsa-sha256; cv=none; b=n7QL/lWAV4+JMC3tBmZGHKP7XxQX02NVSS1Ze4AW/hY1Am/+/5jXMX1sVQ8VNdYGkhwxDr 1YfTYV+mxj0knt3pM4/AjAEeSArfif8Ft8pDxVuqc+WGFFB0mtcF0ZApAXmW/bsL5qpg46 e7WGnNjGlw1VmHDw0kIicwVKzb8hFjw= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nOGMwRXp; spf=pass (imf17.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.45 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-6e904f53151so9031386d6.3 for ; Thu, 03 Apr 2025 08:06:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743692770; x=1744297570; darn=kvack.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=iK8KEJBVYPl6HLxUuQQ2klCL+ZgkeKSI3+E7obEM/WI=; b=nOGMwRXphaWPNIG4TJASIW2hhMzxO9JnszFGnPSKRkfq2Q2TAkHjqyv8G3lP66wyKl G89ZYqw0yBQiEjmI1JKH7Yy5eiFPQXfgCOxUwkgg9h5ZLFUdiSE/1NmDPlU0xZYalYDu deQixKmucRuO5qCyXtpiWGLQtRNnto+PXKKdkXV6RwA6GS+HR4ZklZtScUCEKfaLoqXg e9erofJZP9cgG9soCl3jt3fudBeDs5tjWiC9jiVvU3Y5qEjptfm5c85xpcky3NQkK/5A uwEhDL/scBfv4u8XE/X1uIeLESoFx3mLzRZiyrQJr9/02ityvNVon2xeWyvZ5lpCHGAW Wgtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743692770; x=1744297570; 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=iK8KEJBVYPl6HLxUuQQ2klCL+ZgkeKSI3+E7obEM/WI=; b=DtlUwIUjnMSI1di9WfucqcYSf1b/jM/VdwulKZQyKHM6skqNEkbI5w/2gaNubWyxgP vxsfxxc+DUk8TNdF48KsXM6hw76e1QGW/YlLMvWXpZB5HqO7ttCswNPScFuDGXCDC8oD iebdbeAMRLCRjKikkVe4cv9K4V9inCoslfP/9Ki6clgNTHMW1j5hUXdGoCqyD6A1ZuMx zLK6fVR1WyDRzgXLjRd882Q+jz3SHYP6yFuAAkyHu42fv8hHbQbNn5c9IEjimg/Rzxfh SI/NidKn8EJqhSD+7O2PKSbYRM/IVn/CtSsZVgsAKBNlXauuWGlUOewBwOWpo9kxa5LA ix6w== X-Forwarded-Encrypted: i=1; AJvYcCWhPrMeCO7F2Zsi6WwcIxY4WtkvkiL12bEE7FMxWnWZ9VNWojp6ygJVMkNrrmENUhlu9GQTicvUIg==@kvack.org X-Gm-Message-State: AOJu0YynsfbJ6qQRPa0MIBaiHr4qr8bGWAQLnwmZ5UHSx8NN+ALWX42W wc2sdatIie3QCSJawkF6Z51MTTWvNtY/BRcmqb/dxFFgd8L0E6saPKE0siYtCjMiBOmwJ7nkEJz /3wDbOHManLXC3AD8B2nB4g8BR9E= X-Gm-Gg: ASbGncs8gI1q5+N5o1CUb1VX+8bo/64EMge7kK1KPBRKKlLE8Vq+Uy18iZkDdl9ezir Uy5VbF8sfD6dQbiYzw/oNBZvM7RDL0QwB8pgye19w/H67Lox82gcXyvFfZRoFj4etZ/rmlKI4+4 Hqiq9GRSxlgNA4niIdu7xQQtEBR+/iloUTyf+T3GJaTEDseqTPscYXnrHqiQ== X-Google-Smtp-Source: AGHT+IHhT/kv3ErEBGGfcWsnYD74kOhA0A8+Rch51ZBJnkmq+tPsrAIdzQtaOiWaOiHnDiOdafpEDaK/ECwlaCjb0Pg= X-Received: by 2002:ad4:5f07:0:b0:6e8:eabf:fd55 with SMTP id 6a1803df08f44-6eed625b85dmr310628256d6.39.1743692768242; Thu, 03 Apr 2025 08:06:08 -0700 (PDT) MIME-Version: 1.0 References: <20250402204416.3435994-1-nphamcs@gmail.com> In-Reply-To: From: Nhat Pham Date: Thu, 3 Apr 2025 08:05:57 -0700 X-Gm-Features: ATxdqUFYf4wIA9R_L2Co5iER6d9yuAcNU5JyorPqrHSFoabj94WPG9kBtVsSVkU Message-ID: Subject: Re: [PATCH v2] zsmalloc: prefer the the original page's node for compressed data To: Sergey Senozhatsky Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, yosry.ahmed@linux.dev, chengming.zhou@linux.dev, sj@kernel.org, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, gourry@gourry.net, ying.huang@linux.alibaba.com, jonathan.cameron@huawei.com, dan.j.williams@intel.com, linux-cxl@vger.kernel.org, minchan@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: nzy8pqs77qgxymp8yrw4yuuif98i5mhm X-Rspam-User: X-Rspamd-Queue-Id: A8E8540013 X-Rspamd-Server: rspam08 X-HE-Tag: 1743692770-687125 X-HE-Meta: U2FsdGVkX19Ijii4vexQucrKphLFbpkKMtkH7z5KoIBehjlZNr7ydodTHI0UmcQFKWYaRhKNQgvJJO+YLL3VDJmIValtAn5g9RZRF9K/nGmq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ekwdvqWstdUvgFKmzHkrNqfPXWfsLhQ+TROtil7vt7xB9gsS5Xn0m84LlHKlSuXNvjlnUNoKDU1CfMbKmyzdo488i+2m/amEfOF9/8V+abz5VSKcEnOf9oChDkvKhLrxkftGJYhPWbBm6pUSUGWB4UIyPC1IQ== 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 Wed, Apr 2, 2025 at 8:55=E2=80=AFPM Sergey Senozhatsky wrote: > > On (25/04/02 13:44), Nhat Pham wrote: > [..] > > @@ -1981,10 +1981,15 @@ static int recompress_slot(struct zram *zram, u= 32 index, struct page *page, > > * We are holding per-CPU stream mutex and entry lock so better > > * avoid direct reclaim. Allocation error is not fatal since > > * we still have the old object in the mem_pool. > > + * > > + * XXX: technically, the node we really want here is the node tha= t holds > > + * the original compressed data. But that would require us to mod= ify > > + * zsmalloc API to return this information. For now, we will make= do with > > + * the node of the page allocated for recompression. > > */ > > handle_new =3D zs_malloc(zram->mem_pool, comp_len_new, > > GFP_NOIO | __GFP_NOWARN | > > - __GFP_HIGHMEM | __GFP_MOVABLE); > > + __GFP_HIGHMEM | __GFP_MOVABLE, page_to_nid= (page)); > > This works for me. I saw in other threads (and sorry, I'm on a sick > leave now, can't reply fast) that "zram people need to fix it"/etc. > I guess I'm one of those zram people and I don't think I run any > multi-node NUMA systems, so that problem probably has never occurred > to me. We can add a simple API extension to lookup node-id by > zsmalloc handle, if anyone really needs it, but I'm okay with the > status quo (and XXX) for the time being. Yeah tbh this path is not that much different from the status quo (page is also allocated via the task's policy here), and all the other paths are fixed, so this seems to be an overall improvement still :) If someone uses recompress + multi node, we can fix it then. It's not impossible, just more code :) > > [..] > > -unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp) > > +unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp, > > + const int nid) > > { > > I'm not the zspool maintainer, but if I may ask, for new zsmalloc code my > preference is to follow the kernel styles (yes, the old code doesn't foll= ow > any at all, whenever I touch the old code I fix it). > > Do you mind if we do something like below? (at least for zsmalloc) I don't mind at all! Thanks for fixing it, Sergey. I saw that Andrew already added this as a fixlet. Thanks, Andrew! > > With this > Acked-by: Sergey Senozhatsky #zram and zsmallo= c > > > --- > > diff --git a/include/linux/zpool.h b/include/linux/zpool.h > index 697525cb00bd..369ef068fad8 100644 > --- a/include/linux/zpool.h > +++ b/include/linux/zpool.h > @@ -22,7 +22,7 @@ const char *zpool_get_type(struct zpool *pool); > void zpool_destroy_pool(struct zpool *pool); > > int zpool_malloc(struct zpool *pool, size_t size, gfp_t gfp, > - unsigned long *handle, const int nid); > + unsigned long *handle, const int nid); > > void zpool_free(struct zpool *pool, unsigned long handle); > > @@ -64,7 +64,7 @@ struct zpool_driver { > void (*destroy)(void *pool); > > int (*malloc)(void *pool, size_t size, gfp_t gfp, > - unsigned long *handle, const int nid); > + unsigned long *handle, const int nid); > void (*free)(void *pool, unsigned long handle); > > void *(*obj_read_begin)(void *pool, unsigned long handle, > diff --git a/mm/zpool.c b/mm/zpool.c > index b99a7c03e735..0a71d03369f1 100644 > --- a/mm/zpool.c > +++ b/mm/zpool.c > @@ -239,7 +239,7 @@ const char *zpool_get_type(struct zpool *zpool) > * Returns: 0 on success, negative value on error. > */ > int zpool_malloc(struct zpool *zpool, size_t size, gfp_t gfp, > - unsigned long *handle, const int nid) > + unsigned long *handle, const int nid) > { > return zpool->driver->malloc(zpool->pool, size, gfp, handle, nid)= ; > } > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c > index daa16ce4cf07..70406ac94bbd 100644 > --- a/mm/zsmalloc.c > +++ b/mm/zsmalloc.c > @@ -452,7 +452,7 @@ static void zs_zpool_destroy(void *pool) > } > > static int zs_zpool_malloc(void *pool, size_t size, gfp_t gfp, > - unsigned long *handle, const int nid) > + unsigned long *handle, const int nid) > { > *handle =3D zs_malloc(pool, size, gfp, nid); > > @@ -1033,8 +1033,8 @@ static void create_page_chain(struct size_class *cl= ass, struct zspage *zspage, > * Allocate a zspage for the given size class > */ > static struct zspage *alloc_zspage(struct zs_pool *pool, > - struct size_class *class, > - gfp_t gfp, const int nid) > + struct size_class *class, > + gfp_t gfp, const int nid) > { > int i; > struct zpdesc *zpdescs[ZS_MAX_PAGES_PER_ZSPAGE]; > @@ -1333,7 +1333,7 @@ static unsigned long obj_malloc(struct zs_pool *poo= l, > * Allocation requests with size > ZS_MAX_ALLOC_SIZE will fail. > */ > unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp, > - const int nid) > + const int nid) > { > unsigned long handle; > struct size_class *class;