From nobody Tue Dec 16 14:36:04 2025 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (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 046A1176ADD for ; Thu, 30 May 2024 10:21:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064507; cv=none; b=D+hCFYUAmvtYHbQeoYcqfXvI7RCkCvVkDFh7qvih/SKiYaMBloEoTgMzdQMjjmwSG3ivGGR1z9YrEuRCa+QvJOZFFIKILwIf/Gc0ajQQBtoea0UBPsJtdNpsi/Pjk4klszMZdqixeAHLhvxJcGdAAgTWC+sacm/4TDjuYRQWcwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064507; c=relaxed/simple; bh=F+OGsN0Vk5KwJaBSUrp5JmBtGHDQki/mImXGQEw45w8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=adoa48cz4og65Tvdlvr2wMHZdaNOda/N24nuL7b1bDq0E++QOyz6C8Ox6p+mo5TAduD+90G0yx1m/hoL0DBx9SVe7UnYYP/6BhA1xTjkUcazeWgnm4ynXHLto6bLgiloDjqQk2jniPjTLSOnKiJQqyJIHCQLCqDt1Mf9Uq7Sb8M= 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=GMvcM5WP; arc=none smtp.client-ip=209.85.219.171 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="GMvcM5WP" Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-dfa65af5367so283082276.1 for ; Thu, 30 May 2024 03:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717064505; x=1717669305; 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=Uv2ZaVw6OgZTxb8YIYWTp0HwSOfDS6TRl5l+DF4nA8U=; b=GMvcM5WPKqoPw0lEXWpD/c3fgPR+8FvHJNAC1kQ0ajfPhr/71ji6ixr9zEmqQTU2E4 mpMep4GgpVlGYGcVWjrCTtFzPiFkPdhJTf24UlmwGv1RazEpT/2hXXMHMY3bWnymZiWw 86gQEQ1G/Hmk0+MKPaArtCFOcw5PA8T2n+9Dqlmwrr2LiqRZXr/nvUNnP73uuyI2RFny fbPEYpKHdyObmNSPD0LXcWYnM7IHIREmbCf9jzZ7QcqKgQD53ZTYVlXmGVT7laZNLj21 I7ErLgDiaTduo5TWp4vjc2X+glw6bubN19c90qegNtULv46tuc0JPauyRE8KBuhbM3aQ Gt9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717064505; x=1717669305; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Uv2ZaVw6OgZTxb8YIYWTp0HwSOfDS6TRl5l+DF4nA8U=; b=OSOwtPc1vpuInvPIfecXT48875kCgGMgUIHKqQncgXP0N6AcaVnjmBy6BqZ6+B93F6 fYu+mGo3idPlI4QEOpf4hZbrLbItLpCFlIqaO+WLRaF0BXVvWnVcizub4xBBIK3ZzP+6 wsVryYn+M/gV3smnSItvuq6fUT1+LUgiDQVgI/y2jC8EwLew9SIiXdWGK35H3mIaFQka h7on54Ljl7183TGdg7DcJCdLjfEogadX080GjpYjvKsl3buEoOOn9TxZdqGnezN7vLoM 0JIG8q+kfGKSqVsIzzVeNJY09C7Gv68T+INBPqaV+HdIcczWt79k6wtG2mvujFaFOpFM Zd/g== X-Forwarded-Encrypted: i=1; AJvYcCVIVpBLxyIgqhcun3KCZv3A7Jn18+EEFGc3to9ricshHjLuTBrLhSLCxEKL4lWrFpED24zkOQmPNJi9hbvD9CYlbt3yu15eaLib3Qbt X-Gm-Message-State: AOJu0YzlcR95Zkw+Tv1/4qjtWlLCCY9d778+Ud7gaxQCsMyHeFwyKsHp cyoxVlYGn5uwnvhTaoo3Cx43LMyCzZnIfMO48UQpQ34zj9K/JlG/ X-Google-Smtp-Source: AGHT+IG2E/LBvRU71yDXoonabPkGi2UQCArX8XpUUuRFH+o0Gt0qc8K+S8vP/fgQu4t2rbZd7Wnm1g== X-Received: by 2002:a25:8389:0:b0:de5:5a6f:a52a with SMTP id 3f1490d57ef6-dfa5a5f219emr2032469276.26.1717064504809; Thu, 30 May 2024 03:21:44 -0700 (PDT) Received: from localhost (fwdproxy-nao-002.fbsv.net. [2a03:2880:23ff:2::face:b00c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ae24d5ea8dsm1524366d6.65.2024.05.30.03.21.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 03:21:44 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Usama Arif Subject: [PATCH 1/2] mm: store zero pages to be swapped out in a bitmap Date: Thu, 30 May 2024 11:19:07 +0100 Message-ID: <20240530102126.357438-2-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240530102126.357438-1-usamaarif642@gmail.com> References: <20240530102126.357438-1-usamaarif642@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" Approximately 10-20% of pages to be swapped out are zero pages [1]. Rather than reading/writing these pages to flash resulting in increased I/O and flash wear, a bitmap can be used to mark these pages as zero at write time, and the pages can be filled at read time if the bit corresponding to the page is set. With this patch, NVMe writes in Meta server fleet decreased by almost 10% with conventional swap setup (zswap disabled). [1]https://lore.kernel.org/all/20171018104832epcms5p1b2232e2236258de3d03d13= 44dde9fce0@epcms5p1/ Signed-off-by: Usama Arif --- include/linux/swap.h | 1 + mm/page_io.c | 86 ++++++++++++++++++++++++++++++++++++++++++-- mm/swapfile.c | 10 ++++++ 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index a11c75e897ec..e88563978441 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -299,6 +299,7 @@ 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; /* vmalloc'ed bitmap to track zero pages */ struct swap_cluster_info *cluster_info; /* cluster info. Only for SSD */ struct swap_cluster_list free_clusters; /* free clusters list */ unsigned int lowest_bit; /* index of first free in swap_map */ diff --git a/mm/page_io.c b/mm/page_io.c index a360857cf75d..ab043b4ad577 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -172,6 +172,77 @@ int generic_swapfile_activate(struct swap_info_struct = *sis, goto out; } =20 +static bool is_folio_page_zero_filled(struct folio *folio, int i) +{ + unsigned long *page; + unsigned int pos; + bool ret =3D false; + + page =3D kmap_local_folio(folio, i * PAGE_SIZE); + for (pos =3D 0; pos < PAGE_SIZE / sizeof(*page); pos++) { + if (page[pos] !=3D 0) + goto out; + } + ret =3D true; +out: + kunmap_local(page); + return ret; +} + +static bool is_folio_zero_filled(struct folio *folio) +{ + unsigned int i; + + for (i =3D 0; i < folio_nr_pages(folio); i++) { + if (!is_folio_page_zero_filled(folio, i)) + return false; + } + return true; +} + +static void folio_page_zero_fill(struct folio *folio, int i) +{ + unsigned long *page; + + page =3D kmap_local_folio(folio, i * PAGE_SIZE); + memset_l(page, 0, PAGE_SIZE / sizeof(unsigned long)); + kunmap_local(page); +} + +static void folio_zero_fill(struct folio *folio) +{ + unsigned int i; + + for (i =3D 0; i < folio_nr_pages(folio); i++) + folio_page_zero_fill(folio, i); +} + +static void swap_zeromap_folio_set(struct folio *folio) +{ + struct swap_info_struct *sis =3D swp_swap_info(folio->swap); + swp_entry_t entry; + unsigned int i; + + for (i =3D 0; i < folio_nr_pages(folio); i++) { + entry =3D page_swap_entry(folio_page(folio, i)); + bitmap_set(sis->zeromap, swp_offset(entry), 1); + } +} + +static bool swap_zeromap_folio_test(struct folio *folio) +{ + struct swap_info_struct *sis =3D swp_swap_info(folio->swap); + swp_entry_t entry; + unsigned int i; + + for (i =3D 0; i < folio_nr_pages(folio); i++) { + entry =3D page_swap_entry(folio_page(folio, i)); + if (!test_bit(swp_offset(entry), sis->zeromap)) + return false; + } + return true; +} + /* * We may have stale swap cache pages in memory: notice * them here and get rid of the unnecessary final write. @@ -195,6 +266,14 @@ int swap_writepage(struct page *page, struct writeback= _control *wbc) folio_unlock(folio); return ret; } + + if (is_folio_zero_filled(folio)) { + swap_zeromap_folio_set(folio); + folio_start_writeback(folio); + folio_unlock(folio); + folio_end_writeback(folio); + return 0; + } if (zswap_store(folio)) { folio_start_writeback(folio); folio_unlock(folio); @@ -515,8 +594,11 @@ void swap_read_folio(struct folio *folio, bool synchro= nous, psi_memstall_enter(&pflags); } delayacct_swapin_start(); - - if (zswap_load(folio)) { + if (swap_zeromap_folio_test(folio)) { + folio_zero_fill(folio); + folio_mark_uptodate(folio); + folio_unlock(folio); + } else if (zswap_load(folio)) { folio_mark_uptodate(folio); folio_unlock(folio); } else if (data_race(sis->flags & SWP_FS_OPS)) { diff --git a/mm/swapfile.c b/mm/swapfile.c index f1e559e216bd..3f00a1cce5ba 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -461,6 +461,7 @@ static void swap_cluster_schedule_discard(struct swap_i= nfo_struct *si, */ memset(si->swap_map + idx * SWAPFILE_CLUSTER, SWAP_MAP_BAD, SWAPFILE_CLUSTER); + bitmap_clear(si->zeromap, idx * SWAPFILE_CLUSTER, SWAPFILE_CLUSTER); =20 cluster_list_add_tail(&si->discard_clusters, si->cluster_info, idx); =20 @@ -498,6 +499,7 @@ static void swap_do_scheduled_discard(struct swap_info_= struct *si) __free_cluster(si, idx); memset(si->swap_map + idx * SWAPFILE_CLUSTER, 0, SWAPFILE_CLUSTER); + bitmap_clear(si->zeromap, idx * SWAPFILE_CLUSTER, SWAPFILE_CLUSTER); unlock_cluster(ci); } } @@ -1336,6 +1338,7 @@ static void swap_entry_free(struct swap_info_struct *= p, swp_entry_t entry) count =3D p->swap_map[offset]; VM_BUG_ON(count !=3D SWAP_HAS_CACHE); p->swap_map[offset] =3D 0; + bitmap_clear(p->zeromap, offset, 1); dec_cluster_info_page(p, p->cluster_info, offset); unlock_cluster(ci); =20 @@ -2597,6 +2600,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, special= file) free_percpu(p->cluster_next_cpu); p->cluster_next_cpu =3D NULL; vfree(swap_map); + bitmap_free(p->zeromap); kvfree(cluster_info); /* Destroy swap account information */ swap_cgroup_swapoff(p->type); @@ -3123,6 +3127,12 @@ SYSCALL_DEFINE2(swapon, const char __user *, special= file, int, swap_flags) goto bad_swap_unlock_inode; } =20 + p->zeromap =3D bitmap_zalloc(maxpages, GFP_KERNEL); + if (!p->zeromap) { + error =3D -ENOMEM; + goto bad_swap_unlock_inode; + } + if (p->bdev && bdev_stable_writes(p->bdev)) p->flags |=3D SWP_STABLE_WRITES; =20 --=20 2.43.0 From nobody Tue Dec 16 14:36:04 2025 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (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 CB8F117D354 for ; Thu, 30 May 2024 10:21:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064509; cv=none; b=SrbEuBL9MCAVyj9Y1NkgULYLfKXSqwXISIF6ubYlw+6jljOdnVnTrZcxgd7tGLNvet0kDAShjfSmwm++jnCHL5VwgLwtSlKdhWcwgLPuykxDlQ8llk8jHKm/2+eyAzpZkDqVWsfXY+oAHSZxhyxpxA4roHTM1OV6d8MIiIoXnWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064509; c=relaxed/simple; bh=FzOjSWF8jC9Mn0zbpKpMbjI6I3RxJXwXykNKxdZDtBU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QhIbR+LYfVpLs6Q0nSivQ87H74zl/F24ZFexmFOqYgwlPTqA4kkCEMnpE2uzUhyAnVVUbnihZzVRTM+5YlT/9dr2q4WDqlgOruBIVGQ3RWljB8jcROdTRq6hH3y5KZ0/XzhipMOJWj4SrroNqmcC/YuEPjSA3h4JRmLekzHJthw= 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=AFmAxhTm; arc=none smtp.client-ip=209.85.219.51 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="AFmAxhTm" Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6ae1471db80so1578656d6.1 for ; Thu, 30 May 2024 03:21:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717064507; x=1717669307; 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=r8d6cDNDU6GShGq9eK0Fgxfj+4gyetgt78E216drysY=; b=AFmAxhTmSf7YR267Abr1OeOI4xIqpXgJWSYkQpNoN1nW5fVWdiYwopqgwSPxCscteu hHVKDypjvXEp/5m1zR7nPOLDN1QnQukRCchEDw4lCFwn1V7sQalnvClMY3Q/OwAvGKbe P1QwBt2K639CAbqtmndGM0s00DyVlXCHQekuMxERKV74nzxTyV1FGy6z12P9TKcYRzyb bFFtwHY3YBkeWJPG2FKnePG8dlvW1MlZAXFo1vcPb+YW/fIsWZpn0m7GlyfsKgCrlLjD ZnBdwCA38hF7Leh/oWjZ0gIsvBRShG6MicBf7cy3yOmu0+9sSx7zmwmA/98c+IoJkgj2 hJ2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717064507; x=1717669307; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r8d6cDNDU6GShGq9eK0Fgxfj+4gyetgt78E216drysY=; b=p16nJOMO0lwKusocO3dv8QoFNkNAMq64SMOTKA0FsnYVvr+lOHUS9It9iu525b+Fd7 bFKxDqkH0JfwfFCZfvwaQXkpkdZ2SvvDQ/6yYtQVDXG9e9bCFlkl0qtcitRxBRQ0QiYS 5afABHsEuiGru0b4NJrAcMtFXTOmY/q2j80LlXC2MukwDa+S2+0rCc90LtWa6OxTWjlV Yz2Pshxf6mAWnITl5tGuRel+W+apyRM27aE9obzaX6Nz/eUsfrfAOiLpEvb4+QZl1blx IoY5fTWZ7ctENPOrF69mF9f4hR4yDBgHwBDCE3FhiXYRW9TeguZomTQv9zZMrWDujROI koOg== X-Forwarded-Encrypted: i=1; AJvYcCWAsKiZVdO/r3vBy9cWWwVu4dj4KCn6+0wVF+RXrSR63sjB8LtiF0RXcXLF+vFCskpej7GxR74X2PK2iK39iGByiWKqibQgS/gNcjiH X-Gm-Message-State: AOJu0YxKC2YfnKa013kQHpUFzSiKbDxVrQyKhxK4D4nYyOe32q52CBYy 6KCS+XSIDQOModPqIpCJIAnPhRPsLBjSyZuNCo+SXPyUR/V6MjX9 X-Google-Smtp-Source: AGHT+IF6BgR0E1H6Yi7Z0olWyUfqvRPLWZXsZcDuztfZzFojo07FrRO9l8l3SwT6pG7Yaa1MM+8V+g== X-Received: by 2002:a05:6214:4189:b0:6ab:6ddc:4ba1 with SMTP id 6a1803df08f44-6ae0ccd3deamr16187306d6.60.1717064506651; Thu, 30 May 2024 03:21:46 -0700 (PDT) Received: from localhost (fwdproxy-nao-008.fbsv.net. [2a03:2880:23ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ae12306f5bsm3351556d6.118.2024.05.30.03.21.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 03:21:46 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Usama Arif Subject: [PATCH 2/2] mm: remove code to handle same filled pages Date: Thu, 30 May 2024 11:19:08 +0100 Message-ID: <20240530102126.357438-3-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240530102126.357438-1-usamaarif642@gmail.com> References: <20240530102126.357438-1-usamaarif642@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" With an earlier commit to handle zero-filled pages in swap directly, and with only 1% of the same-filled pages being non-zero, zswap no longer needs to handle same-filled pages and can just work on compressed pages. Signed-off-by: Usama Arif --- mm/zswap.c | 79 +++++------------------------------------------------- 1 file changed, 7 insertions(+), 72 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index b9b35ef86d9b..50c8d402516f 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -44,8 +44,6 @@ **********************************/ /* The number of compressed pages currently stored in zswap */ atomic_t zswap_stored_pages =3D ATOMIC_INIT(0); -/* The number of same-value filled pages currently stored in zswap */ -static atomic_t zswap_same_filled_pages =3D ATOMIC_INIT(0); =20 /* * The statistics below are not protected from concurrent access for @@ -182,11 +180,9 @@ static struct shrinker *zswap_shrinker; * * swpentry - associated swap entry, the offset indexes into the red-black= tree * length - the length in bytes of the compressed page data. Needed during - * decompression. For a same value filled page length is 0, and b= oth - * pool and lru are invalid and must be ignored. + * decompression. * pool - the zswap_pool the entry's data is in * handle - zpool allocation handle that stores the compressed page data - * value - value of the same-value filled pages which have same content * objcg - the obj_cgroup that the compressed memory is charged to * lru - handle to the pool's lru used to evict pages. */ @@ -194,10 +190,7 @@ struct zswap_entry { swp_entry_t swpentry; unsigned int length; struct zswap_pool *pool; - union { - unsigned long handle; - unsigned long value; - }; + unsigned long handle; struct obj_cgroup *objcg; struct list_head lru; }; @@ -814,13 +807,9 @@ static struct zpool *zswap_find_zpool(struct zswap_ent= ry *entry) */ static void zswap_entry_free(struct zswap_entry *entry) { - if (!entry->length) - atomic_dec(&zswap_same_filled_pages); - else { - zswap_lru_del(&zswap_list_lru, entry); - zpool_free(zswap_find_zpool(entry), entry->handle); - zswap_pool_put(entry->pool); - } + zswap_lru_del(&zswap_list_lru, entry); + zpool_free(zswap_find_zpool(entry), entry->handle); + zswap_pool_put(entry->pool); if (entry->objcg) { obj_cgroup_uncharge_zswap(entry->objcg, entry->length); obj_cgroup_put(entry->objcg); @@ -1262,11 +1251,6 @@ static unsigned long zswap_shrinker_count(struct shr= inker *shrinker, * This ensures that the better zswap compresses memory, the fewer * pages we will evict to swap (as it will otherwise incur IO for * relatively small memory saving). - * - * The memory saving factor calculated here takes same-filled pages into - * account, but those are not freeable since they almost occupy no - * space. Hence, we may scale nr_freeable down a little bit more than we - * should if we have a lot of same-filled pages. */ return mult_frac(nr_freeable, nr_backing, nr_stored); } @@ -1370,42 +1354,6 @@ static void shrink_worker(struct work_struct *w) } while (zswap_total_pages() > thr); } =20 -/********************************* -* same-filled functions -**********************************/ -static bool zswap_is_folio_same_filled(struct folio *folio, unsigned long = *value) -{ - unsigned long *data; - unsigned long val; - unsigned int pos, last_pos =3D PAGE_SIZE / sizeof(*data) - 1; - bool ret =3D false; - - data =3D kmap_local_folio(folio, 0); - val =3D data[0]; - - if (val !=3D data[last_pos]) - goto out; - - for (pos =3D 1; pos < last_pos; pos++) { - if (val !=3D data[pos]) - goto out; - } - - *value =3D val; - ret =3D true; -out: - kunmap_local(data); - return ret; -} - -static void zswap_fill_folio(struct folio *folio, unsigned long value) -{ - unsigned long *data =3D kmap_local_folio(folio, 0); - - memset_l(data, value, PAGE_SIZE / sizeof(unsigned long)); - kunmap_local(data); -} - /********************************* * main API **********************************/ @@ -1450,13 +1398,6 @@ bool zswap_store(struct folio *folio) goto reject; } =20 - if (zswap_is_folio_same_filled(folio, &value)) { - entry->length =3D 0; - entry->value =3D value; - atomic_inc(&zswap_same_filled_pages); - goto store_entry; - } - /* if entry is successfully added, it keeps the reference */ entry->pool =3D zswap_pool_current_get(); if (!entry->pool) @@ -1522,13 +1463,9 @@ bool zswap_store(struct folio *folio) return true; =20 store_failed: - if (!entry->length) - atomic_dec(&zswap_same_filled_pages); - else { - zpool_free(zswap_find_zpool(entry), entry->handle); + zpool_free(zswap_find_zpool(entry), entry->handle); put_pool: - zswap_pool_put(entry->pool); - } + zswap_pool_put(entry->pool); freepage: zswap_entry_cache_free(entry); reject: @@ -1682,8 +1619,6 @@ static int zswap_debugfs_init(void) zswap_debugfs_root, NULL, &total_size_fops); debugfs_create_atomic_t("stored_pages", 0444, zswap_debugfs_root, &zswap_stored_pages); - debugfs_create_atomic_t("same_filled_pages", 0444, - zswap_debugfs_root, &zswap_same_filled_pages); =20 return 0; } --=20 2.43.0