From patchwork Mon Jun 10 12:16:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13691955 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 164E3C27C55 for ; Mon, 10 Jun 2024 12:18:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 261906B00A7; Mon, 10 Jun 2024 08:18:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 211AA6B00A8; Mon, 10 Jun 2024 08:18:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F32A66B00A9; Mon, 10 Jun 2024 08:18:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C884C6B00A7 for ; Mon, 10 Jun 2024 08:18:29 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6EF6E40F83 for ; Mon, 10 Jun 2024 12:18:29 +0000 (UTC) X-FDA: 82214881938.11.EC7F6BF Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by imf27.hostedemail.com (Postfix) with ESMTP id A1E3D40019 for ; Mon, 10 Jun 2024 12:18:27 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AVfz1+2K; spf=pass (imf27.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718021907; a=rsa-sha256; cv=none; b=4shn9akoY748FRddvx6/ByK9U6LZvsYZnvVj41m8wpxmrVgcjvDJUxySZ1/j5rSE35Wkf7 d4Gni8DXxNgTSluOWXnkGq12R0ZmUwaufTX0TVLJf5XD2CjDm8W70G1awH0/Pfs2KcUgy9 Cet5hs+cfmz8YFH7Ww8IlkD6OvE3dV8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AVfz1+2K; spf=pass (imf27.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.160.175 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=1718021907; 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=DXiBWXHL7CwKxeZukNI7HIW+CIUeGgh6jd5x/88roGDw5jXPmbQZPNxA+eIuS90eun25Ny SaJ2VWXOV02lR3W1A8oFbmRpRynCup5l+v115LrsMsOkuMkhG20zoHjwYMxh9gvM+LADAS A8sZ9GmZVfyGc01kvcRUvyctZbgGB9o= Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-4405e343dd8so7936081cf.1 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=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=AVfz1+2K4k3i07ba0dHAYwpeOA0wj9gcaAcDkAG4IuwgFL/L/Cm56T2VZVSobpleYP 76oDaj7mD1LUBR3qehAUAm9KcD4BIUv6c0KE1dTzKXPrgR+tgHoeeZE2Z7GEr9B/3GnO kuVppqBxEQvPXbjbgW51EY31HCbh/JyDL7pxVmnMSW7vvUPOzZ5E48y5QIsNFtAQROMR b4uDvUvwR5o2rawKUlqx69b2oKAr1BXtB4aWPNNdj2s+X4csh+B/G/6AQhv0qyguLei3 jcXSaCl0KhcTZn9EQHtBPzwNcBp566WS+dcXjNEkL7UYSKYID9ccmQP/RdaXI5ImJP4t +YBQ== 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=df/IMdkC5kyWeYDY9n5W4aNQvppLh07CJkvRsnGOdEbB/i26e4KLsRGxP7x6bAeObD vAGPIobASIXjhH7u8npbs8aFKP/0hFEyvnqt2sC6SgZCDOk7dLozSfGxC5XVyWAlmFYp of+EH/mIdrAO0zLFizVm54a4xTVkzdFzgibOvQ0f7v9GX8ktSsQ4G7G4dfSIvBJD+gIi 4PXQ+Cq/H63aUZ5Ip+uYoC0V4UX892CGRw8Su6CW4FmQzilBI/NSqJBgD6ULKUBxtsA9 pDf+xwlQWZLQ+eIXXlso1RHa9VEE9hR6jcVbeq06uPOd4XxvayoE1bcz7JEw+EcXU71C mCxA== X-Forwarded-Encrypted: i=1; AJvYcCVSZGhleUDuzypwo1zF94/JBV9n9hYLLGI6lcm3gFyvu+iIFTkKnHNeURRVt1Dab7LpEgG0OYG75oYdIIol+Eb+RkQ= X-Gm-Message-State: AOJu0Yx3MWHXH8lVWcd5rrJAc54fSyRLx1XuAw/M6VnhYqWu646Mrda8 PDGJhPIMhW2wnVToRDFDb9AEqWAZmg06tdK3VnoRA+8yomMVx8dl 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> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A1E3D40019 X-Stat-Signature: o9zhqa6co1odrho8w57fgpzzs145mb1j X-HE-Tag: 1718021907-485054 X-HE-Meta: U2FsdGVkX1//KWWlfny3eGMDsYE7F3oWrAY9w7wWw4Ti1l3FRlcNeHsX6PS2n56MXI0dtwYtGlnChOQVBYFuBC6OXsHlq29T8rk5c3EKTBKWWqFoxTek+pnlFEkzQuAYL/qJXMfANKNkCEuPgsb7BSBzLQnvopNeMjFwqrye2gxhdiUOlLl4ebLMx2opBxACiCeJmHvpv4aJgQqgU40L+K/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XsK6f66sMz8Z1SqZrwIr+n1pOsAO4/MEJ2fUFN/jeEOLjS6TbVwyysX/BW/d8n7qYCMgTjywtc1mw5GYbR3+L+W7OygMk2aATXGRdeILHZJIrDrMeVDnHLF1fWypTO95iSGP83at/fdN4iCGw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000023, 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; }