From nobody Thu Feb 12 17:28:59 2026 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (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 7E1917F498 for ; Mon, 10 Jun 2024 12:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718021909; cv=none; b=ain6KACvMP4LLUxn/wOxc79K9TEys5n7lXXGv/inKxYsh/I1dEfGzalYoz0YApr8pouD5fmX18Vv1B577kOtlsphugCziLIXkUh8HdWWrbidyhagsD/qe/WtgseSb7X8B4yZuPj1fvr7bvzgbZhGiavrdr0j4B1vTRZdeSkrB2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718021909; c=relaxed/simple; bh=9+X5chMM78ZCXcGy2haYPPGQLERHdK5PIRCndYkt8Rk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YBbT2G9dWeSnTZAPKwAhwdy/+3ihm0WRjnZOhug+C+aCp70TSFwXxDBf5YAA4ZgkGKYVq+GfDbLjkRKqhxytNIb+wt0oK+GU7OdRfgDOM9DdE+QaKsmCUkt9yAbULLXrZ9zhSsQEofZquQU4kCnYnyE6JzGpcgh4jsjTizU4UQs= 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=KZpHlgAu; arc=none smtp.client-ip=209.85.219.45 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="KZpHlgAu" Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-6b072522bd5so8012836d6.2 for ; Mon, 10 Jun 2024 05:18:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718021905; x=1718626705; 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=enp1TRQZwGsuV9i2AxeXdZVfnUfEdxfgu+pXvPIz5hY=; b=KZpHlgAu5lfw0WfGhR0zDkZIBjLgvOo8zIhFjKA7yJqlBEpa8ZBbLsViKHp0k96PtY jXlQ+kvSaScgmXlN2KKlEaJHUlvFE73xDpzScXHkl56dC1sOLg/7oUBz5CK4oeRNY5+O fJQYMS9+dEQYVAAvdCL/slkgvx6I7O8nC2LYUbNSvIT3A6xF2WWHnVTfoxzBtHkf/sPW qtt/K3SHiV+rSwdvIY2CknSAwuI3ltJfTNuc8U7pitR3py4QYI4fATjYM1bHD7D4G1MN nG5BMbNmkJEyiArGSgaUnWprmJsclKCV619UTt8bpArRR/YEHvDWofu5sqwPo+NMia53 AA3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718021905; x=1718626705; 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=enp1TRQZwGsuV9i2AxeXdZVfnUfEdxfgu+pXvPIz5hY=; b=LnYkjuACLxvVDO5NbhiMeyo3QKem8at+kjadJvFnEg81TvsTCJHy3a3J9sbYLwXpel AOPYHyNr14VC7p2jXzxCTaERA7BDmMmCYJn/poQqLgWkEafQQ/sOEQeOou5slpCjGhZA u6ihWZoD5Xb4SvqKD5+9dMeWWuIiSU4JBEvPcE+OJzNA/agabs8RtN7roMJvZDgclv0s huTq+o9fiDev7fwGHjSlGZt5yFmW9vr/fyv/9qzIoEyi/sP0olBaLcSxbtPT3cL/6+xw 7LZtSOGz3VDoczdgqsc8VZKsTCWscfb7e6NojUcNtHKTfShOY4g/FDsLBg3f9Rn4r16X HB3Q== X-Forwarded-Encrypted: i=1; AJvYcCWx7OQjegta1LMYcUNpO+ZICKl/tZAsyj/ATBs4I7F6GcGjE31kJi5rs44t2CgJZPYq1XRGJT4xviMEcyUDa3VTSgXznv49LZFkMcsj X-Gm-Message-State: AOJu0YzhwJz04JCWcPQflQjmKqdzAbvn0MSBwW+hWCp5jGAkvSnxH6Tc gc/n1ksYNW0qa7E3caMChDQT635gXDjKIlHL182b3fBtqfpVP6HldAEQeuKfTVz8uQ== X-Google-Smtp-Source: AGHT+IER/6/Ev/fin7kHekd/wvr1haZ/PJS9r0VJYzapmkP25Xc4EV0tD+B/2Rh4HpReLXXohs1EQQ== X-Received: by 2002:a05:6214:5990:b0:6b0:7206:e7a4 with SMTP id 6a1803df08f44-6b07206ebd7mr69801746d6.3.1718021905323; Mon, 10 Jun 2024 05:18:25 -0700 (PDT) Received: from localhost (fwdproxy-ash-000.fbsv.net. [2a03:2880:20ff::face:b00c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b0683044dbsm27042936d6.75.2024.06.10.05.18.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 05:18:24 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, 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 Subject: [PATCH v3 1/2] mm: store zero pages to be swapped out in a bitmap Date: Mon, 10 Jun 2024 13:15:59 +0100 Message-ID: <20240610121820.328876-2-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240610121820.328876-1-usamaarif642@gmail.com> References: <20240610121820.328876-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 | 92 +++++++++++++++++++++++++++++++++++++++++++- mm/swapfile.c | 21 +++++++++- 3 files changed, 111 insertions(+), 3 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..2cac1e11fb85 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -172,6 +172,82 @@ 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); + } +} + +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 +271,15 @@ 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; + } + swap_zeromap_folio_clear(folio); if (zswap_store(folio)) { folio_start_writeback(folio); folio_unlock(folio); @@ -515,8 +600,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..90451174fe34 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -453,6 +453,8 @@ static unsigned int cluster_list_del_first(struct swap_= cluster_list *list, static void swap_cluster_schedule_discard(struct swap_info_struct *si, unsigned int idx) { + unsigned int i; + /* * If scan_swap_map_slots() can't find a free cluster, it will check * si->swap_map directly. To make sure the discarding cluster isn't @@ -461,6 +463,13 @@ static void swap_cluster_schedule_discard(struct swap_= info_struct *si, */ memset(si->swap_map + idx * SWAPFILE_CLUSTER, SWAP_MAP_BAD, SWAPFILE_CLUSTER); + /* + * zeromap can see updates from concurrent swap_writepage() and swap_read= _folio() + * call on other slots, hence use atomic clear_bit for zeromap instead of= the + * non-atomic bitmap_clear. + */ + for (i =3D 0; i < SWAPFILE_CLUSTER; i++) + clear_bit(idx * SWAPFILE_CLUSTER + i, si->zeromap); =20 cluster_list_add_tail(&si->discard_clusters, si->cluster_info, idx); =20 @@ -482,7 +491,7 @@ static void __free_cluster(struct swap_info_struct *si,= unsigned long idx) static void swap_do_scheduled_discard(struct swap_info_struct *si) { struct swap_cluster_info *info, *ci; - unsigned int idx; + unsigned int idx, i; =20 info =3D si->cluster_info; =20 @@ -498,6 +507,8 @@ 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); + for (i =3D 0; i < SWAPFILE_CLUSTER; i++) + clear_bit(idx * SWAPFILE_CLUSTER + i, si->zeromap); unlock_cluster(ci); } } @@ -1336,6 +1347,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; + clear_bit(offset, p->zeromap); dec_cluster_info_page(p, p->cluster_info, offset); unlock_cluster(ci); =20 @@ -2597,6 +2609,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 +3136,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 Thu Feb 12 17:28:59 2026 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (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 DCE5F7F7DA for ; Mon, 10 Jun 2024 12:18:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718021909; cv=none; b=ACtz/+D7FZazM9ozlZYgbqhi4ltwauxcFUUCHWWkXr7kxlGpQPEuL/Xvunfvy+EAwBW60da1zY55NuKXl9ZfCjRxXQm/4GyLM5/r9EKBOO6frwQ2yGwQItrjVDb0x4i3ZtKHOirse6WASgmYGxiJXc33JDINLLbqvXtfLG3zSHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718021909; c=relaxed/simple; bh=HefF2syNjxvt876eLES/u8vyCE/hTUTrXSNifQKmNQg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XRp/AjZzgmQaHYOdqX23T+3FuIxIdbf66bukkYJdgC3UfJ02iTcVYsdJyGoMYb6O9OSe+4QgLXc2f1XR8arWM6dILUsDHlXCYPlJn81BaH2sw+XFRyPzz7KeZ9hx/yyFtHc+IVmUUnheWuPnCOT3zIBF7w09ATboNHfOp3Nk+kk= 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=nZRQm/7n; arc=none smtp.client-ip=209.85.160.176 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="nZRQm/7n" Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-4411fc45fbcso1184341cf.3 for ; Mon, 10 Jun 2024 05:18:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718021907; x=1718626707; 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=U09nDqdyDjm09ov5OxqAlgrZTEnMx+ri6277Ej4J+SE=; b=nZRQm/7nt71FoS2ge5XSDBaCXCUmnfAb0iFG/IyNIBECcTt/0Q79OzCncMLI8rv1Lj 9NcIU4Yh5vJL9HQr3+N+b0GfWf25Jsg1TXW7XfFQ7mU1MQi8IFfEdQRWQmmoUm1He4Zt ZS0Rv4YOHXLvMKEykQMrzAhwKg5OQ1krAUogID54mr7jOhm2O0y+4HyWsl1tWhIG5WUv 0Whg8LH/R8fZj485dC33TjtToDlZAb7CbuxxETbby+IiS8u1rBJ/XQ0LjmMZDSgNlXBd 0uXt1I4BDn/0BnxC+fLMblCgamcIs55vWdK0lraRQ0PTX0WGMdW1ujSvjoU5GWg+ZuhL zicQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718021907; x=1718626707; 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=U09nDqdyDjm09ov5OxqAlgrZTEnMx+ri6277Ej4J+SE=; b=mJnbkP+xIwutTKGbtzVO/DScI6ZWccAb0yVwvrQzBDzSAK3BTNMMly21JnRYQyzBHT p7vO1ruEaWCSDf8AE8mjMJXuVgBEVhGdZofuk/vjajqpfgrLskS1R7RrzRGKo42Ol0i6 LJQNE2lFwv07GqfsHQvEnwlw4az9v5Yu7P+lw/+biwAhSJISI/K48VQoV0Fy8NI6qg6l QkbhQPp53iUq4SMFP+6uyzgYOBUJSPjyo8Vw0eoEY9RNFlRcn1WJsnHIi0Njjcica++j cT1VnRcQRaI9K8hojrjdYhFhNjFFZJyFbt43ki6O9y08i1sGS+1b8ACwnrSEL4z/cEBo aczQ== X-Forwarded-Encrypted: i=1; AJvYcCXMOjteIRyYWcnD0Z6xb3CGE4B7CGMZkhDe8vvxPwRifDZ7LSaStoS1txQMxsBXEYXLIEyWDdgpyY4xDfuPWVUSTBtd22x2XGNdFP8I X-Gm-Message-State: AOJu0YxgA56E/oEUPk+uGPMQQ34w7AGU+dyOHXOwEnNDDnDVt38cBQ/b 5+LNrtRFZqCS9XWj4mUFnPhaAo8wDz7aYQD5xgBW1pXvKY3RZsDV X-Google-Smtp-Source: AGHT+IHQjlqF6rwlkFyoaljIk9O9zBO+WkkXZoER6nk04i+5Kfvv4yHDqz5cR5JdPILe0xHkL/rhfQ== X-Received: by 2002:a05:622a:4c:b0:440:5fa0:5f2b with SMTP id d75a77b69052e-4405fa060c0mr59056201cf.44.1718021906662; Mon, 10 Jun 2024 05:18:26 -0700 (PDT) Received: from localhost (fwdproxy-ash-117.fbsv.net. [2a03:2880:20ff:75::face:b00c]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-440c9fed96asm9816111cf.17.2024.06.10.05.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 05:18:26 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, 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 Subject: [PATCH v3 2/2] mm: remove code to handle same filled pages Date: Mon, 10 Jun 2024 13:16:00 +0100 Message-ID: <20240610121820.328876-3-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240610121820.328876-1-usamaarif642@gmail.com> References: <20240610121820.328876-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 | 86 +++++------------------------------------------------- 1 file changed, 8 insertions(+), 78 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index b9b35ef86d9b..ca8df9c99abf 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 **********************************/ @@ -1417,7 +1365,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)); @@ -1450,13 +1397,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) @@ -1474,7 +1414,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 @@ -1522,13 +1461,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: @@ -1577,10 +1512,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) @@ -1682,8 +1614,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