From patchwork Wed Jun 12 12:43:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13694921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD57CC27C53 for ; Wed, 12 Jun 2024 12:47:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17AB46B0096; Wed, 12 Jun 2024 08:47:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 100C56B0098; Wed, 12 Jun 2024 08:47:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E48F56B0099; Wed, 12 Jun 2024 08:47:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B7C426B0096 for ; Wed, 12 Jun 2024 08:47:58 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 36A68120409 for ; Wed, 12 Jun 2024 12:47:58 +0000 (UTC) X-FDA: 82222213836.03.BB667F8 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by imf30.hostedemail.com (Postfix) with ESMTP id 6316D80008 for ; Wed, 12 Jun 2024 12:47:56 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=lGPUHCHg; spf=pass (imf30.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.128.182 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718196476; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=U09nDqdyDjm09ov5OxqAlgrZTEnMx+ri6277Ej4J+SE=; b=xQSZp/zBcEAr4uIeP0944rW72kil4vCVLwCUzuhM6zzVDZRoejdJolRbHJqxVxUKp8x78h Lww50YmwjRnogPdcaTDHEcAFVu/4ki5rdkqGVSZh10UMlH+aV8NfG0bOCT9i0SaBuuc1xW MMQfKnVT9M+7NL6m14QndDx6pm1FH+o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718196476; a=rsa-sha256; cv=none; b=Odq5xyZzwSbkfeHZbd2rU4EaR6xS12Rtmll00uWrAQQwZeo8bqiq8TdUrJWLQEJ2QFKI8y iPW97dbpeOeAtlFW8ogvdRjSL07NP7CSNNUMWMGM2GCSz3bQ3RPAgS+SVaLzrFS8Z8RsvC DOcdpaITO+o7WQK/AYvaTfTe1Scmd7Y= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=lGPUHCHg; spf=pass (imf30.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.128.182 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-627efad69b4so70938437b3.3 for ; Wed, 12 Jun 2024 05:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718196475; x=1718801275; darn=kvack.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=lGPUHCHgg8BV7QxDEtFkxazSVH9UdbtvUNFqGTzIpicdITiLu14MxdDpi9Np5rm+Zd 5TvSVFPguiCKFfgzQJDwLkm3W+Q3ro+P4zjTSCFsKQMeAT5sNbLxdYMEJJOIVJpqT+az fygbFMfpH47a3GjVZBYEFLO9+PGZWtIZVtdnTofywTFR+lUm9ovXiZI3leex8Jxs4Ihf 83tbUzm4JQKWl3V0BtuDNurpNLbFVlKvbs9lzxEs2WNNSCEd9KjFGsbaw+Zub5+jvaaf ACC2V5ISU8kuRguxq87+hB+7A39LK2Uzl4COFfVFvWhP9xrUp54SlcL7EBNNiLBK9o0M n0jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718196475; x=1718801275; 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=HmJAIV+utHtATqZ4QPcNfmcpKU5sPZj6WZsvdxdo1NVuzHRrKUzBy3cbQC2UdkCPzp UniUgfTVStkKQK/DXs+RaGe7THKpF0eDht6QK7JU7rBkSbj86AATK2cO4bLezHSCt8nG gNlOPD2jzbHJatlD5imAdD5F9FRzlDPfs2ae6fX2v1QdRkBwOULfzsWRvFn0zCp4VTpf k3ALaHJxNR3PYAYh9F4xff71+7xkaboXkAVeGOnVZ/hwxuo6jtI1eJBay+7GodHy/9kE J73HusPTmpyWiSQCl0XzYtRoTGvm7RnJRvOzJLbx3pbzTAbSfBfZFVJs9/bEhby8DT8Z NZDA== X-Forwarded-Encrypted: i=1; AJvYcCWXH+L6i8qX+VcF3QW7WPuvqWH8xRTPG2hT0Zt5WPYUgo22RQ+A0C1cV7W38qOJ7KIYuCVQ4g3Id04iJAw7lt92/Kk= X-Gm-Message-State: AOJu0YwegdBelRMscuKwKtzxoGyMITccSspp7t3u6tEFnQ1FrtszA80Z 3kG/oYPMntAoyyGF9ZDSd1WX5FGfflLlSKI+KxYMoLgAcjmmkzbY X-Google-Smtp-Source: AGHT+IGkQ17HzT2wzOFm9lZ1MUlnx3fVT0qSwDvdVstx+8uIKcOGNUUnfvL0eYxQuIWJ1sfFl/Gqdw== X-Received: by 2002:a81:8491:0:b0:630:3061:c22 with SMTP id 00721157ae682-63030610d9fmr7911287b3.20.1718196475331; Wed, 12 Jun 2024 05:47:55 -0700 (PDT) Received: from localhost (fwdproxy-ash-008.fbsv.net. [2a03:2880:20ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b07ed90264sm30056906d6.13.2024.06.12.05.47.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 05:47:54 -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 Subject: [PATCH v4 2/2] mm: remove code to handle same filled pages Date: Wed, 12 Jun 2024 13:43:36 +0100 Message-ID: <20240612124750.2220726-3-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240612124750.2220726-1-usamaarif642@gmail.com> References: <20240612124750.2220726-1-usamaarif642@gmail.com> MIME-Version: 1.0 X-Stat-Signature: edu888n8r89iihy1ga9z6upcoa8zjjn8 X-Rspamd-Queue-Id: 6316D80008 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1718196476-238256 X-HE-Meta: U2FsdGVkX1+uQCFvQ/BAbudWDU52zqNU7ajUufBkZCE9fBjW2b2XkIvT6WITYsvSY3ZEWvKf9eCJHvtAHhlHEEN+9oOibRnHu72cObQTF+oY1RL+rzPITFFX6ws0TO3WZQvn4oRER2CUGNFSo4oMlGoFrMrx+IaGRx6786JFoAwrBgSKKtnI3aXTfB/OtuX2F6CNk/tGjm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/y0kuchlRRvtjxESQFVlSngLGoPbJOBBQYm2kUkgEB55qIQQfJADXmFR3g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 = ATOMIC_INIT(0); -/* The number of same-value filled pages currently stored in zswap */ -static atomic_t zswap_same_filled_pages = ATOMIC_INIT(0); /* * 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 both - * 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_entry *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 shrinker *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); } -/********************************* -* 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 = PAGE_SIZE / sizeof(*data) - 1; - bool ret = false; - - data = kmap_local_folio(folio, 0); - val = data[0]; - - if (val != data[last_pos]) - goto out; - - for (pos = 1; pos < last_pos; pos++) { - if (val != data[pos]) - goto out; - } - - *value = val; - ret = true; -out: - kunmap_local(data); - return ret; -} - -static void zswap_fill_folio(struct folio *folio, unsigned long value) -{ - unsigned long *data = 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 = NULL; struct mem_cgroup *memcg = NULL; - unsigned long value; 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; } - if (zswap_is_folio_same_filled(folio, &value)) { - entry->length = 0; - entry->value = value; - atomic_inc(&zswap_same_filled_pages); - goto store_entry; - } - /* if entry is successfully added, it keeps the reference */ entry->pool = 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; -store_entry: entry->swpentry = swp; entry->objcg = objcg; @@ -1522,13 +1461,9 @@ bool zswap_store(struct folio *folio) return true; 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; - if (entry->length) - zswap_decompress(entry, folio); - else - zswap_fill_folio(folio, entry->value); + zswap_decompress(entry, folio); 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); return 0; }