From nobody Wed Feb 11 08:12:15 2026 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5659934321C for ; Sun, 8 Feb 2026 21:59:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770587958; cv=none; b=p15yoEXhPubAP6dVFGONsOIw8+gvt/pKNCvRs647POaUDZxYlx51qT3KdJD9XNwgAuNxpodJDq+FoyJQuvLyDSdTRgvXe2EBVWzCyQGTfhOEn83Cb6lNaeqsit5lyrjfmHTPGxLaediFQTyy2w+nX9wOleuR6ScJsQK89ltts/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770587958; c=relaxed/simple; bh=dR6T7pstuCqgQMWtQrm6D0fc/evHR/Uw+D+DUpIeiPM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mE57AJ1YfgjbDkItBMzbV90MRn4+FIruuIakja/FWJRi6i//61b6k1jhrF0eIPq4wbKpEvz+g2W2DR0QoR4jLAIzFXRFg6egGdnczf96dzmjQZ2i6xFgR+gG4//El/Zpqfh6oTuHfLFM3eetnhnR4NUhR+V0z/wXj/pQ/V26vaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lzHchwVW; arc=none smtp.client-ip=209.85.160.50 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.b="lzHchwVW" Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-40946982a78so1137428fac.2 for ; Sun, 08 Feb 2026 13:59:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770587957; x=1771192757; 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; bh=YdV+3Aw+NBxu35sOMXTrxQg3lkskWJESSW2tnr6DOts=; b=lzHchwVWFMR2YvvnlatYNHmu3ebjPVTNwwZPPQphTmGW23av5KikGiUs1o/3rV9WGO vksiQcQLj0hAK6iJcZnzS9z7dNDYqPu2sklav/1GkeYOf7JROb2dw7VM9w6kHW28T+5R rwkTuUHJ19VLOqqk8z75KuiP07FXVdnWuNokU5wFN7tl6eD0h1Ay3NCrrgZSADVOavT3 8JHns1bkH2OvI2s5lZ4/hO2PnNT2qhh4gO4Y0sBszefECiMQrlax4sx10yLo9puoT9Ym k53yV1iJt8EF2zmLHYBi3IoSk2JVxAxVMuDYehiJ0gLgU40FTztW4zVP8RpYcX7vw2FD IDtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770587957; x=1771192757; 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; bh=YdV+3Aw+NBxu35sOMXTrxQg3lkskWJESSW2tnr6DOts=; b=fXIM3SHTxmikzkTmJJ6J5QCIImzYPP1KaTMWLi9yeZWxYgeKBTqoa+JG4gjGtG3Xe3 gRMiE9vHObZcZ1b04o6ugq2piIdvmtfVx/zfWoPTkgkIFOJqQvyxISMIe0L7GPrQU13u eA2jhq3wNLrThybDGAjfeN+4Mt67SUm87KUEhwY6hRu3tesbfV+tBYDnML/e9CMibHSC 86iun0yUA9aPg8nkgBR8mVHhFRYJe6WxoflOSE252LlPPt9WtXw5bLrBYX7olR8XDHkS yn6/wsdi/W/APa+z/E+3eDnP6ydJXAr5pCKg2NsqWQ74XnkSOq4bnaqWbpd/gLDKHTV2 AT/Q== X-Forwarded-Encrypted: i=1; AJvYcCWaZwuxoK1ce+/Q2hQxKvyLfAE/Rj2QUSwfzn2zX0J2GCDVZg58bWdWHvx+rUO/JeYtTh3gtguR/6Y2nT0=@vger.kernel.org X-Gm-Message-State: AOJu0YxSHTRIeDhBa/LpWe0Rot+ESEwJjGq0AKzLuZ0X7Nl5+0Hlhroh s68nWD8eG8igrcay5PE5s6DOa4mVt1l2YaWMpxyLDxOEFMEK01x+fcNxc6v/Zg== X-Gm-Gg: AZuq6aLCGZEN2DQ16NymrHkmqViw+WCS5c/XLhLjAWE1veJz3Jzu2z5Hk7lCK8K8ed+ HDP8CtNWDsC820ryYoXS6bFOPsqvGI+VX8MWE+J3cMkFmVzjqhhChTUc4Qfh7hofTwFU6k0xNp8 gr5p2M6HAymfL8tiOYQnUtD1Pz7+rPgBqqklLAyHYA2cr9l2sGqXAp1bqAzv/MCbTnYGYmi4+EC jT4SHAY4psYVl9ER5Yl96qnCE04mwX7jNN0M917UotsEpbuo9LAW/cQan+J5lCGj9SYafGT0meH oMcY5BMRd5vtSuPqLzEs19XalSM8KVeYbWh/ZuOHn8V7xay0psNFiIVEykYl+6dlJM/VHAIWMA5 QpP9vmxt7Z0kfBiZL8hOiQlzqpQBrCdj4ncwbi2IDP5dAhj4gc89ZI24jfCGacgwFCddG7AGX7x v30asgmDLRqdfKpGgGwl9+k1XhNZyHS9/V7/nh9kp7UtE= X-Received: by 2002:a05:6870:829e:b0:332:8989:4ef8 with SMTP id 586e51a60fabf-40a96ec6c37mr4495223fac.31.1770587957178; Sun, 08 Feb 2026 13:59:17 -0800 (PST) Received: from localhost ([2a03:2880:10ff:3::]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-40a99355b7fsm6268799fac.8.2026.02.08.13.59.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Feb 2026 13:59:16 -0800 (PST) From: Nhat Pham To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, hughd@google.com, yosry.ahmed@linux.dev, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, len.brown@intel.com, chengming.zhou@linux.dev, kasong@tencent.com, chrisl@kernel.org, huang.ying.caritas@gmail.com, ryan.roberts@arm.com, shikemeng@huaweicloud.com, viro@zeniv.linux.org.uk, baohua@kernel.org, bhe@redhat.com, osalvador@suse.de, lorenzo.stoakes@oracle.com, christophe.leroy@csgroup.eu, pavel@kernel.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-pm@vger.kernel.org, peterx@redhat.com, riel@surriel.com, joshua.hahnjy@gmail.com, npache@redhat.com, gourry@gourry.net, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, rafael@kernel.org, jannh@google.com, pfalcato@suse.de, zhengqi.arch@bytedance.com Subject: [PATCH v3 17/20] swapfile: remove zeromap bitmap Date: Sun, 8 Feb 2026 13:58:30 -0800 Message-ID: <20260208215839.87595-18-nphamcs@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260208215839.87595-1-nphamcs@gmail.com> References: <20260208215839.87595-1-nphamcs@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Zero swap entries are now treated as a separate, decoupled backend in the virtual swap layer. The zeromap bitmap of physical swapfile is no longer used - remove it. This does not have any behavioral change, and save 1 bit per swap page in terms of memory overhead. Signed-off-by: Nhat Pham --- include/linux/swap.h | 1 - mm/swapfile.c | 30 +++++------------------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 54df972608047..9cd45eab313f8 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -260,7 +260,6 @@ struct swap_info_struct { signed char type; /* strange name for an index */ unsigned int max; /* extent of the swap_map */ unsigned char *swap_map; /* vmalloc'ed array of usage counts */ - unsigned long *zeromap; /* kvmalloc'ed bitmap to track zero pages */ struct swap_cluster_info *cluster_info; /* cluster info. Only for SSD */ struct list_head free_clusters; /* free clusters list */ struct list_head full_clusters; /* full clusters list */ diff --git a/mm/swapfile.c b/mm/swapfile.c index 1aa29dd220f9a..e1cb01b821ff3 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2317,8 +2317,7 @@ static int setup_swap_extents(struct swap_info_struct= *sis, sector_t *span) =20 static void setup_swap_info(struct swap_info_struct *si, int prio, unsigned char *swap_map, - struct swap_cluster_info *cluster_info, - unsigned long *zeromap) + struct swap_cluster_info *cluster_info) { si->prio =3D prio; /* @@ -2329,7 +2328,6 @@ static void setup_swap_info(struct swap_info_struct *= si, int prio, si->avail_list.prio =3D -si->prio; si->swap_map =3D swap_map; si->cluster_info =3D cluster_info; - si->zeromap =3D zeromap; } =20 static void _enable_swap_info(struct swap_info_struct *si) @@ -2347,12 +2345,11 @@ static void _enable_swap_info(struct swap_info_stru= ct *si) =20 static void enable_swap_info(struct swap_info_struct *si, int prio, unsigned char *swap_map, - struct swap_cluster_info *cluster_info, - unsigned long *zeromap) + struct swap_cluster_info *cluster_info) { spin_lock(&swap_lock); spin_lock(&si->lock); - setup_swap_info(si, prio, swap_map, cluster_info, zeromap); + setup_swap_info(si, prio, swap_map, cluster_info); spin_unlock(&si->lock); spin_unlock(&swap_lock); /* @@ -2370,7 +2367,7 @@ static void reinsert_swap_info(struct swap_info_struc= t *si) { spin_lock(&swap_lock); spin_lock(&si->lock); - setup_swap_info(si, si->prio, si->swap_map, si->cluster_info, si->zeromap= ); + setup_swap_info(si, si->prio, si->swap_map, si->cluster_info); _enable_swap_info(si); spin_unlock(&si->lock); spin_unlock(&swap_lock); @@ -2441,7 +2438,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, special= file) { struct swap_info_struct *p =3D NULL; unsigned char *swap_map; - unsigned long *zeromap; struct swap_cluster_info *cluster_info; struct file *swap_file, *victim; struct address_space *mapping; @@ -2536,8 +2532,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, special= file) p->swap_file =3D NULL; swap_map =3D p->swap_map; p->swap_map =3D NULL; - zeromap =3D p->zeromap; - p->zeromap =3D NULL; maxpages =3D p->max; cluster_info =3D p->cluster_info; p->max =3D 0; @@ -2549,7 +2543,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, special= file) kfree(p->global_cluster); p->global_cluster =3D NULL; vfree(swap_map); - kvfree(zeromap); free_cluster_info(cluster_info, maxpages); =20 inode =3D mapping->host; @@ -3013,7 +3006,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialf= ile, int, swap_flags) sector_t span; unsigned long maxpages; unsigned char *swap_map =3D NULL; - unsigned long *zeromap =3D NULL; struct swap_cluster_info *cluster_info =3D NULL; struct folio *folio =3D NULL; struct inode *inode =3D NULL; @@ -3119,17 +3111,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, special= file, int, swap_flags) if (error) goto bad_swap_unlock_inode; =20 - /* - * Use kvmalloc_array instead of bitmap_zalloc as the allocation order mi= ght - * be above MAX_PAGE_ORDER incase of a large swap file. - */ - zeromap =3D kvmalloc_array(BITS_TO_LONGS(maxpages), sizeof(long), - GFP_KERNEL | __GFP_ZERO); - if (!zeromap) { - error =3D -ENOMEM; - goto bad_swap_unlock_inode; - } - if (si->bdev && bdev_stable_writes(si->bdev)) si->flags |=3D SWP_STABLE_WRITES; =20 @@ -3196,7 +3177,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialf= ile, int, swap_flags) prio =3D DEF_SWAP_PRIO; if (swap_flags & SWAP_FLAG_PREFER) prio =3D swap_flags & SWAP_FLAG_PRIO_MASK; - enable_swap_info(si, prio, swap_map, cluster_info, zeromap); + enable_swap_info(si, prio, swap_map, cluster_info); =20 pr_info("Adding %uk swap on %s. Priority:%d extents:%d across:%lluk %s%s= %s%s\n", K(si->pages), name->name, si->prio, nr_extents, @@ -3224,7 +3205,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialf= ile, int, swap_flags) si->flags =3D 0; spin_unlock(&swap_lock); vfree(swap_map); - kvfree(zeromap); if (cluster_info) free_cluster_info(cluster_info, maxpages); if (inced_nr_rotate_swap) --=20 2.47.3