From nobody Sun Feb 8 02:41:36 2026 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (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 178A113E8B9 for ; Thu, 27 Jun 2024 10:57:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719485856; cv=none; b=VPPvtW50ihlzAJ/JKO4DxvOxvXMeEaejN0YpSyuyzrcD4781kB3a4HOAGBZH/AFoayGaebG7n2K24sZhKKEWNuoMuU0HjLUkakxjZ8yoHdUSPVl2fY7K40L5aEku2L2csPkoU74vy8CcEEyAnhZsipEv5Vp7IvvWuLxPNOS+i2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719485856; c=relaxed/simple; bh=mIlS4otReTXqtFx0zqLhNK3zdBqkJJXBOv/2ceD2DS0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qEJiztU/qFyfGpnRUGB4jNZEKhVqur9VAArhfybr47dhVeOhB+j1eQm7aF12qQW5WAqZKcJUNxX/8iZ6SiYcJzVYvqEfITSlZDsxGjZSFMakVLBmM8149AzV126zMc7SFY1Hb6dYwtXCpvYvh72v/y/ALybKNy1VogrGD4c/TgA= 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=QVorP/dY; arc=none smtp.client-ip=209.85.160.172 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="QVorP/dY" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-44637e13866so7603541cf.3 for ; Thu, 27 Jun 2024 03:57:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719485854; x=1720090654; 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=TkzTW/11bPuGoCkFDaajiq8WxKpIkXClRk/0ynrGzvk=; b=QVorP/dYycrK5qzk0KkJ754N/SKBin03Y9dLG7f4hicoCUn++/JUwGexw3mmclpUe3 GhAU0/QnHZe95b/nryZH0fD/XLIONVuiKggV9O4UXF7Qqm+4KDgaeSRfBM6SXKy9mQY5 xwJYe/QX+h2lzXmyGQfZbLMcLHodAMwwDGbRPLS6nwLHsS9NlLBt1RB7ik9M0NfhDB2t h/3HwzqBl0+R2UMSdlntOl2bhSbjXzf40iroJ1jj3EPCcoLdd0SQAvqL+LPlB8ZxoV6c tPrdfYQI5onsLJc0XXU7DWOaa/FR4ZqYJW6Y3+lcXKpdvyoWiV1mW09ZsphCpDykX8uU y6MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719485854; x=1720090654; 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=TkzTW/11bPuGoCkFDaajiq8WxKpIkXClRk/0ynrGzvk=; b=stgwseYO3ClatOpuOQoajri4KwmMMoBFOXDi8hx3QKtY5vGI3CQCFxn8bRKMNIcwAZ 5Ewqs+fUXqfaBXJDnvGcM39ezVyCV6bwQPRTB5lhGYBVSj/8AgJfRAXUyNQxn64kbYOp St8SNrcDboEYGI4xmnzr48Rn9FGo9yHdD5c0c3FsCOL9e2kTJdMboKWZHVitqX00Hirb UD6o7SiB124d5c9LBVqJ0X3ql2KeyjsEnyjrQ4aR7c9G6DHMAIohilsgZlkjkZC2Cpxp BwWvQb166OT2J60dsZwCK4Gg49vs+QtkdfN60WumD+eJ7wcJ0rfgGXvzCIi9g1og1CxY EtTA== X-Forwarded-Encrypted: i=1; AJvYcCU+RWZRePeH77P+lVWNyRGsHDo45qGGQ18YdAp9j+NTbk+Qarh0XUDZZvDOI5fSvwKVe8G9bviijU0K9rCNr1pbyd4G1pu62ofHKkRz X-Gm-Message-State: AOJu0YyBFvRZjUbKXfvt5dGdbpRIz0oF/VkjYFKcJvvGvylPPgEplHbN kFPQ2BjZJjKaH1GvBcfWuqjUwD09IzKSA5kwoDntuPm6n0jmhht8 X-Google-Smtp-Source: AGHT+IG1BjfEOxsFo5R+ptwaWh5pstieIxvFw0KT+PkhQXtF7aARv9WfbDIto8OWrrisoVsji9V5dA== X-Received: by 2002:a05:622a:15d3:b0:445:5ae:ba84 with SMTP id d75a77b69052e-44505aec008mr64953341cf.15.1719485853832; Thu, 27 Jun 2024 03:57:33 -0700 (PDT) Received: from localhost (fwdproxy-ash-004.fbsv.net. [2a03:2880:20ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-44641eb4699sm4796381cf.38.2024.06.27.03.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 03:57:33 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, shakeel.butt@linux.dev, david@redhat.com, ying.huang@intel.com, hughd@google.com, willy@infradead.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 , Andi Kleen Subject: [PATCH v7 1/2] mm: store zero pages to be swapped out in a bitmap Date: Thu, 27 Jun 2024 11:55:29 +0100 Message-ID: <20240627105730.3110705-2-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240627105730.3110705-1-usamaarif642@gmail.com> References: <20240627105730.3110705-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/20171018104832epcms5p1b2232e2236258de3d03d1= 344dde9fce0@epcms5p1/ Signed-off-by: Usama Arif Reviewed-by: Chengming Zhou Reviewed-by: Yosry Ahmed Reviewed-by: Nhat Pham Cc: David Hildenbrand Cc: "Huang, Ying" Cc: Hugh Dickins Cc: Johannes Weiner Cc: Matthew Wilcox (Oracle) Cc: Shakeel Butt Cc: Usama Arif Cc: Andi Kleen Signed-off-by: Andrew Morton Acked-by: Johannes Weiner --- include/linux/swap.h | 1 + mm/page_io.c | 113 ++++++++++++++++++++++++++++++++++++++++++- mm/swapfile.c | 20 ++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 3df75d62a835..ed03d421febd 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 6c1c1828bb88..480b8f221d90 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -172,6 +172,88 @@ 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 *data; + unsigned int pos, last_pos =3D PAGE_SIZE / sizeof(*data) - 1; + bool ret =3D false; + + data =3D kmap_local_folio(folio, i * PAGE_SIZE); + if (data[last_pos]) + goto out; + for (pos =3D 0; pos < PAGE_SIZE / sizeof(*data); pos++) { + if (data[pos]) + goto out; + } + ret =3D true; +out: + kunmap_local(data); + 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_zero_fill(struct folio *folio) +{ + unsigned int i; + + for (i =3D 0; i < folio_nr_pages(folio); i++) + clear_highpage(folio_page(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)); + set_bit(swp_offset(entry), sis->zeromap); + } +} + +static void swap_zeromap_folio_clear(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)); + clear_bit(swp_offset(entry), sis->zeromap); + } +} + +/* + * Return the index of the first subpage which is not zero-filled + * according to swap_info_struct->zeromap. + * If all pages are zero-filled according to zeromap, it will return + * folio_nr_pages(folio). + */ +static unsigned int 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 i; + } + return i; +} + /* * We may have stale swap cache pages in memory: notice * them here and get rid of the unnecessary final write. @@ -195,6 +277,13 @@ 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_unlock(folio); + return 0; + } + swap_zeromap_folio_clear(folio); if (zswap_store(folio)) { folio_unlock(folio); return 0; @@ -424,6 +513,26 @@ static void sio_read_complete(struct kiocb *iocb, long= ret) mempool_free(sio, sio_pool); } =20 +static bool swap_read_folio_zeromap(struct folio *folio) +{ + unsigned int idx =3D swap_zeromap_folio_test(folio); + + if (idx =3D=3D 0) + return false; + + /* + * Swapping in a large folio that is partially in the zeromap is not + * currently handled. Return true without marking the folio uptodate so + * that an IO error is emitted (e.g. do_swap_page() will sigbus). + */ + if (WARN_ON_ONCE(idx < folio_nr_pages(folio))) + return true; + + folio_zero_fill(folio); + folio_mark_uptodate(folio); + return true; +} + static void swap_read_folio_fs(struct folio *folio, struct swap_iocb **plu= g) { struct swap_info_struct *sis =3D swp_swap_info(folio->swap); @@ -514,7 +623,9 @@ void swap_read_folio(struct folio *folio, struct swap_i= ocb **plug) } delayacct_swapin_start(); =20 - if (zswap_load(folio)) { + if (swap_read_folio_zeromap(folio)) { + folio_unlock(folio); + } else if (zswap_load(folio)) { folio_unlock(folio); } else if (data_race(sis->flags & SWP_FS_OPS)) { swap_read_folio_fs(folio, plug); diff --git a/mm/swapfile.c b/mm/swapfile.c index 9c6d8e557c0f..028d33f3a76d 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -747,6 +747,14 @@ static void swap_range_free(struct swap_info_struct *s= i, unsigned long offset, unsigned long begin =3D offset; unsigned long end =3D offset + nr_entries - 1; void (*swap_slot_free_notify)(struct block_device *, unsigned long); + unsigned int i; + + /* + * Use atomic clear_bit operations only on zeromap instead of non-atomic + * bitmap_clear to prevent adjacent bits corruption due to simultaneous w= rites. + */ + for (i =3D 0; i < nr_entries; i++) + clear_bit(offset + i, si->zeromap); =20 if (offset < si->lowest_bit) si->lowest_bit =3D offset; @@ -2635,6 +2643,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, special= file) free_percpu(p->cluster_next_cpu); p->cluster_next_cpu =3D NULL; vfree(swap_map); + kvfree(p->zeromap); kvfree(cluster_info); /* Destroy swap account information */ swap_cgroup_swapoff(p->type); @@ -3161,6 +3170,17 @@ SYSCALL_DEFINE2(swapon, const char __user *, special= file, int, swap_flags) 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. + */ + p->zeromap =3D kvmalloc_array(BITS_TO_LONGS(maxpages), sizeof(unsigned lo= ng), + GFP_KERNEL | __GFP_ZERO); + 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 Sun Feb 8 02:41:36 2026 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (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 23E1213F431 for ; Thu, 27 Jun 2024 10:57:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719485857; cv=none; b=BSbfxFCGwgcF752BFCQB43NTgsNojdxslIMOaDTWuN1IHRUUR7ESIEbhR4ducWjsskfgfms6J7DUnUqK54UcT5dZbp4KS9olM2sn5KTUdlWsZoEVdAy2+heGb3IWCG5ztw/Yd+a4cOWOm06PiHeyTUmREP6mHhSuu0sOdCQT50M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719485857; c=relaxed/simple; bh=/M+wnG7FpQGgd6bzM9t2TpaND0U3poF8mndXCvU1kq0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f522tAHgzvZkJymdz0zZY5beIA07PNbJbqV9PHI4FiZuuXD2Zcv/TbAGrE094uDwiitMuNMoLbl+fTXgClcL8EP3ZZHzr43Rlx2YBrVsB/PJknseb3+BRYPw5nBPzjBMS6NmnjP8k6fmmZpMf5VX8kJmvSvNRwWuGDXsCPziQsA= 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=RwUolHuQ; arc=none smtp.client-ip=209.85.222.177 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="RwUolHuQ" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-79c0bc8092dso238746185a.2 for ; Thu, 27 Jun 2024 03:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719485855; x=1720090655; 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=/jytiD3F6dVDoVcn3tgOCkYr8qgKU/Kw/DG4oKzaeY4=; b=RwUolHuQHcMfUE0qPQSUr62HSAcHxsqZKCHLVEHxjzKzXPJ+wQJOEVkZHvDoOSJXFg 0U9UKB+Wssuc/8htYuFQnf4A+Bx3Ud1glFpRw0jcG/s26yd+BI6eSsLFNZB7uJlyWdQT XV8R/svOJoT+OpNCpbbJ3MDCmXWH9zmsS/8Ar79W/e3KbYCG6UCY2JfoUjTZ8QJEsl3W MEU+RjOb3jfr5LFJzZAcy8XxkJKwuwMgvpI4wwM65bu4xjdFq8MH05q9g6p5ysenVmbO poN2unO8RCqeI/pJ/Z7Wk9cEiVyJqWlXUmqoE2M8eTonCWp0TZwmGZeeO8J/U+01rPmd dS7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719485855; x=1720090655; 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=/jytiD3F6dVDoVcn3tgOCkYr8qgKU/Kw/DG4oKzaeY4=; b=aOMoCglE+CwkkZa4EZflYwVgDCaomuaa4n76twaZtNs5GRdnyHmUAzEp6AzHQ4YF3F g1D7/4eNVQp5IKVxIAoixwbpSADUdhh+ovX91X3uIyEgqMsYl5T5iI4rqqUJDiFZlFDK mF5mds0vlUNi29djw6Rj4unZjKwQkJsALNeup5WqZh87Z/hCxQYSB31FOcQ1xl6TS/R3 EOSeTmNHonfIJyZmmMvIvhdpYGPuT1K6tfPRmyxEMQwPuUEfwf95zDKf0DWf9KfO9cnT eXNnAxCt4qzKeX9JPfOmbDqC7U2KpKPCjvZLS7+H5M2jVoc+CKh7SRZhXLDbvqp0YDX3 p9IQ== X-Forwarded-Encrypted: i=1; AJvYcCVBR1U/hfW3ijEUcRlp+4IN0eHytmbxzYimL5LBe86MhlU4kUe+96SmqwsvyCpY9FDIBYxcCdkKH1d9VS/+GRq76sqUehqz72nLCQuP X-Gm-Message-State: AOJu0YwjdNjYfQ51whp7K2acP3HFI6KYTb8X++cY+RlIDhTUjzkYXAOa bofhW+43mopfXzg5wBQTK/001NTIA6uzgbddlm0Hh9Ajruzp0pWg X-Google-Smtp-Source: AGHT+IFRSA2E/3cS18UczoHmhGiJ1yqas1kMncm42FdVDN8CvhCvuezJ9y6/uHNF847ZRU8aorvsYg== X-Received: by 2002:a05:620a:404d:b0:794:b302:96b5 with SMTP id af79cd13be357-79be0c62f1bmr1704032485a.36.1719485854953; Thu, 27 Jun 2024 03:57:34 -0700 (PDT) Received: from localhost (fwdproxy-ash-012.fbsv.net. [2a03:2880:20ff:c::face:b00c]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79d5c8ba5b1sm43902985a.108.2024.06.27.03.57.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 03:57:34 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, shakeel.butt@linux.dev, david@redhat.com, ying.huang@intel.com, hughd@google.com, willy@infradead.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 , Andi Kleen Subject: [PATCH v7 2/2] mm: remove code to handle same filled pages Date: Thu, 27 Jun 2024 11:55:30 +0100 Message-ID: <20240627105730.3110705-3-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240627105730.3110705-1-usamaarif642@gmail.com> References: <20240627105730.3110705-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 Reviewed-by: Chengming Zhou Acked-by: Yosry Ahmed Reviewed-by: Nhat Pham Cc: Andi Kleen Cc: David Hildenbrand Cc: "Huang, Ying" Cc: Hugh Dickins Cc: Johannes Weiner Cc: Matthew Wilcox (Oracle) Cc: Shakeel Butt Signed-off-by: Andrew Morton Acked-by: Johannes Weiner --- mm/zswap.c | 86 +++++------------------------------------------------- 1 file changed, 8 insertions(+), 78 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index a546c01602aa..e25a6808c2ed 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 @@ -188,11 +186,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. */ @@ -200,10 +196,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; }; @@ -820,13 +813,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); @@ -1268,11 +1257,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); } @@ -1376,42 +1360,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 **********************************/ @@ -1423,7 +1371,6 @@ bool zswap_store(struct folio *folio) struct zswap_entry *entry, *old; struct obj_cgroup *objcg =3D NULL; struct mem_cgroup *memcg =3D NULL; - unsigned long value; =20 VM_WARN_ON_ONCE(!folio_test_locked(folio)); VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); @@ -1456,13 +1403,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) @@ -1480,7 +1420,6 @@ bool zswap_store(struct folio *folio) if (!zswap_compress(folio, entry)) goto put_pool; =20 -store_entry: entry->swpentry =3D swp; entry->objcg =3D objcg; =20 @@ -1528,13 +1467,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: @@ -1597,10 +1532,7 @@ bool zswap_load(struct folio *folio) if (!entry) return false; =20 - if (entry->length) - zswap_decompress(entry, folio); - else - zswap_fill_folio(folio, entry->value); + zswap_decompress(entry, folio); =20 count_vm_event(ZSWPIN); if (entry->objcg) @@ -1703,8 +1635,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