From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796103451; b=IXVnX7QxGpQjCNUEb/7g92dqYDONmxpDjAGfQ4A7P+YaFf6P+o2wn2/ut2Bir4tut6xQ bAJsf+fEQAJBP0U417VAPJ/AbeQrCy2pD/wRvYGAZKqx06FWxPSjp1r15L2jGG88tVitk je5s/0X/0X0JbNcwwN0+/k3pNx8Am9dLFr95r9cE+PhmsbKB1KN8n8CHUBtxud+SYhWL3 OFxzFGjtD6rCoYGwkU3QF4ZPcjsz9d21jOAYCny1DDjI+Wivi25jFdLz/t6gKTLJbK6HR dDDryy7GnyNVGsnwJgMK97HQGXaUNM+30shZkaUe0pWK77dOERyoBob6ZmrdnplBuXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796103451; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=kOFYeUP2gtBrMW+kleY5/LoTIfkC45ytsLrmulqbOkM=; b=TVCsvBsp0MuzQ5ebbJHApUfzhpNSQ7A5hUR0+rakl3Y/J99bzpE94Hfrn1LKnuR2YVWM Okim7GW2HXRYoscDqBiD7mftYuX7UfUjq5UkZOSg2XeoAw3lpHQlYSuJQmY/yyINXm93t fFZ7gAL5WMChXnP0CocZPXm7jcbHsht6KHeaqTRfI3lCHyKaM8ytHWe/6/4iGv6HKexwf IvK21lp2HTudgIBZ77UwFuOiX0uTjsyK0UUxHkJRs5xheZo3t4ZCyTMneEJszPmvtuFq3 lFEXVuQ0p3SWmVDr0TZ84Bh8Ow9Vs5c1yOwgki4RulqA1XGLueFa0tU+N7vSgKqOm9g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YBPsEl86; arc=none smtp.remote-ip=74.125.82.46 Received: from mail-dl1-f46.google.com (mail-dl1-f46.google.com [74.125.82.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD11A606A6B7 for ; Tue, 1 Dec 2026 05:37:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AD11A606A6B7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YBPsEl86 Received: by mail-dl1-f46.google.com with SMTP id a92af1059eb24-1b5b910c838so1416285c88.1 for ; Mon, 30 Nov 2026 21:37:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796103450; x=1796708250; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kOFYeUP2gtBrMW+kleY5/LoTIfkC45ytsLrmulqbOkM=; b=YBPsEl86XnQu6CKt6TsvDHohdoSEA2nVVkr6/xyzv+FiWUAYLBAG0xfcJ9mWcFEWGX CRwtYxuPlYVO2QCUuSWBh3KGzPMcQvI1fbbONVxIJDJioghxjkwbKJCsyPrMdNe3+Od7 ugztMz0c55MMqfkgYIewsqRIQt5n4PJNS9DCzgpSLcDsO+0NsMLPuLj8wGySmKDBkyRj dn7Na2MBzYj2ejX6vFIoylqGWAL/skd4bLwirml/GqKHYgYMVgmPd3kX1VLGbTTOxHXI n3DLW1Crq+MWanHQ2UZK7TgeKCwFwpdUYiayxIQAjVJ5W/ecTdSrv2VwqtcAj/qxzcCE 3/Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796103450; x=1796708250; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=kOFYeUP2gtBrMW+kleY5/LoTIfkC45ytsLrmulqbOkM=; b=rYdcoqghJuDmg7Esu7JehTXWRRVABLavUD0JB01hofI1GK1FE+q7nWiBTfKly9N2oK zagDmJEDlsGlvK74I4uxxTbYnKWlAVc5gD9BKM3sk5v0IwR1AzrQCFuCqSEvmN7swDIO y8L1VNeA77xpY+Oa4b6YrNr2Neqpdy7qgDM+PLrEFGNUZZOil49/iaTBdMKh5nj7hx9q OCMg6TxUy+lGAhMiCmczeF7hwQOH5Nv+/HedNZsMZnX2N4rwhJcMRfpykBApwbscRjzQ KpEEqUQkNHwzk1jDThZNeg7VFzlvx9Gb7SVEUXUWCXcCJV7wKh4+3r+I54ZuYeosm6k1 JkXQ== X-Forwarded-Encrypted: i=1; AL+hErE5yCkuSaUfgV/sNnubQW3KEYRJOsmSWaqzgrQ02Bt/y2E/RDBkKuN5U/hirjk4mGBkW4WtaMgAMKQZw2E=@vger.kernel.org X-Gm-Message-State: APuU4Z9gE5l1Ea98A45lYLH9USSssKP6NE/S2qWbRVc8CsKWWw6Did91 hPTiR51nuGthSijRgpOjPV+EQhG9UYNqFP5ot+h5vEEGNq+2l9zV/93G X-Gm-Gg: AZFdTZenRTXqSGwBLwz6SxE8PZxczpa06xyy+OQMo69mptS/as+hw/bp2yGR/ZcwuqG jcGechfWtrNJzmZR1OzWmyuy7HOKeYC6Mthob7/DAHBT1z18l3kjZtS23CJgwvWfXNkfglkuMpb z79zBhjUzz8mc+5FFnSL0f7AnkxPPgKonUBSPTeoGrq/N8FTkMpi9mPEYg6NRfT2Ef4zKfVMIE8 9kbCkACjTlRbSEhp8+r11AYNAcuO/r6GZoOz3Yo9GjPnRKzPmI/1KJRT3UEaH66t6eMmRJ6O3KR vRs19oj+glSg6MGMw9ZvwCDQBSbIi0d2ZPf2CHw3D++XbRDQJmcvezlyoYnfZuoDT0RcZ/G4cue C2jGFj7ZLhjgPry939+XicCu8EuZLnc2up79qa7RhFymv9mWkkWQcRd+0ZRYGa7kMI37J+rR0Nx 4xbcjx2HQ5s0kG+x1upd9hq6MQs8h8DBmz4WiS2+PCcCzwbmdhlXG1p85pnE7V6jm+T+A1oHzJe dMKOAwOEES8XdOrPmqTJRi23GFhOSHGoP94WlpguVvcK6LKVtPQAz1r57SD8kZYvOuFDhFxS8s6 c/Z8AlcowT5/AdvSdjzMTUkUvundXCk6WKtCpX5ncg== X-Received: by 2002:a05:7022:f50f:b0:1ac:1022:b60c with SMTP id a92af1059eb24-1b5567b2091mr29725812c88.1.1796103449761; Mon, 30 Nov 2026 21:37:29 -0800 (PST) Received: from penguin.lxd ([12.187.136.98]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5566c3052sm81183292c88.1.2026.11.30.21.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 21:37:29 -0800 (PST) From: "Kanchana P. Sridhar" To: hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com, chengming.zhou@linux.dev, akpm@linux-foundation.org, linux-mm@kvack.org, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org, kanchanapsridhar2026@gmail.com, linux-kernel@vger.kernel.org Cc: rientjes@google.com, willy@infradead.org, senozhatsky@chromium.org Subject: [PATCH v5 5/9] mm: zswap: Store the folio's node id in the zswap_entry. Date: Mon, 30 Nov 2026 21:37:07 -0800 Message-Id: <20261201053711.8090-6-kanchanapsridhar2026@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20261201053711.8090-1-kanchanapsridhar2026@gmail.com> References: <20261201053711.8090-1-kanchanapsridhar2026@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When storing a folio in zswap, save the folio's node id in the zswap entry instead of relying on the zswap_entry being allocated on the same node. This enables optimizations such as batch allocation of zswap entries for large folios using kmem_cache_alloc_bulk() that does not support specifying a node id. Accordingly, replace the SLUB allocation in zswap_entry_cache_alloc() to be node-agnostic. The size of the zswap_entry remains unchanged as 'referenced' is lumped in with the 'length' (as it doesn't need a full unsigned int anyway). A build time assertion checks for the zswap_entry's 'length' bitfield being large enough to represent PAGE_SIZE, which can be 256KB on some architectures. Suggested-by: Nhat Pham Suggested-by: Yosry Ahmed Signed-off-by: Kanchana P Sridhar Signed-off-by: Kanchana P. Sridhar --- mm/zswap.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 9ee20b576eff..cdca497ef8db 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -181,6 +181,7 @@ struct zswap_pool { */ #define ZSWAP_FIRST_POOL_ID 1 #define ZSWAP_MAX_POOL_ID U8_MAX +#define ZSWAP_MAX_COMPR_LENGTH_SHIFT 19U static DEFINE_XARRAY_FLAGS(zswap_pools, XA_FLAGS_ALLOC1 | XA_FLAGS_LOCK_BH); static struct zswap_pool __rcu *zswap_current_pool; @@ -207,15 +208,19 @@ static struct shrinker *zswap_shrinker; * logic if referenced is unset. See comments in the shrinker * section for context. * pool_idx - id of the zswap_pool that the entry's data is in. + * nid - NUMA node id of the original page of this zswap entry. * handle - zsmalloc allocation handle that stores the compressed page data * objcg - the obj_cgroup that the compressed memory is charged to * lru - handle to the pool's lru used to evict pages. */ struct zswap_entry { swp_entry_t swpentry; - unsigned int length; - bool referenced; - u8 pool_idx; + struct { + unsigned int length:ZSWAP_MAX_COMPR_LENGTH_SHIFT; + bool referenced:1U; + u8 pool_idx; + }; + int nid; struct zs_handle handle; struct obj_cgroup *objcg; struct list_head lru; @@ -680,14 +685,8 @@ static int zswap_enabled_param_set(const char *val, * lru functions **********************************/ -static inline int entry_to_nid(struct zswap_entry *entry) -{ - return page_to_nid(virt_to_page(entry)); -} - static void zswap_lru_add(struct zswap_entry *entry) { - int nid = entry_to_nid(entry); struct mem_cgroup *memcg; /* @@ -704,19 +703,18 @@ static void zswap_lru_add(struct zswap_entry *entry) rcu_read_lock(); memcg = obj_cgroup_memcg(entry->objcg); /* will always succeed */ - list_lru_add(&zswap_list_lru, &entry->lru, nid, memcg); + list_lru_add(&zswap_list_lru, &entry->lru, entry->nid, memcg); rcu_read_unlock(); } static void zswap_lru_del(struct zswap_entry *entry) { - int nid = entry_to_nid(entry); struct mem_cgroup *memcg; rcu_read_lock(); memcg = obj_cgroup_memcg(entry->objcg); /* will always succeed */ - list_lru_del(&zswap_list_lru, &entry->lru, nid, memcg); + list_lru_del(&zswap_list_lru, &entry->lru, entry->nid, memcg); rcu_read_unlock(); } @@ -764,10 +762,11 @@ void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg) **********************************/ static struct kmem_cache *zswap_entry_cache; -static struct zswap_entry *zswap_entry_cache_alloc(gfp_t gfp, int nid) +static struct zswap_entry *zswap_entry_cache_alloc(gfp_t gfp) { struct zswap_entry *entry; - entry = kmem_cache_alloc_node(zswap_entry_cache, gfp, nid); + + entry = kmem_cache_alloc(zswap_entry_cache, gfp); if (!entry) return NULL; zs_handle_init(&entry->handle); @@ -1537,9 +1536,10 @@ static bool zswap_store_page(struct folio *folio, long index, { swp_entry_t page_swpentry = folio_swap_entry(folio, index); struct zswap_entry *entry, *old; + int nid = folio_nid(folio); /* allocate entry */ - entry = zswap_entry_cache_alloc(GFP_KERNEL, folio_nid(folio)); + entry = zswap_entry_cache_alloc(GFP_KERNEL); if (!entry) { zswap_reject_kmemcache_fail++; return false; @@ -1554,6 +1554,7 @@ static bool zswap_store_page(struct folio *folio, long index, * to an unrelated live pool. */ entry->pool_idx = pool->idx; + entry->nid = nid; old = xa_store(swap_zswap_tree(page_swpentry), swp_offset(page_swpentry), @@ -1928,6 +1929,8 @@ static int zswap_setup(void) struct zswap_pool *pool; int ret; + BUILD_BUG_ON(ZSWAP_MAX_COMPR_LENGTH_SHIFT <= PAGE_SHIFT); + zswap_entry_cache = KMEM_CACHE(zswap_entry, 0); if (!zswap_entry_cache) { pr_err("entry cache creation failed\n"); -- 2.39.5