From patchwork Mon Jun 24 14:01:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13709549 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 3B384C2D0D1 for ; Mon, 24 Jun 2024 14:04:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 624936B0196; Mon, 24 Jun 2024 10:04:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 585786B01A4; Mon, 24 Jun 2024 10:04:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 278426B0196; Mon, 24 Jun 2024 10:04:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EDE6A6B0190 for ; Mon, 24 Jun 2024 10:04:46 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 90FED121041 for ; Mon, 24 Jun 2024 14:04:46 +0000 (UTC) X-FDA: 82265952972.02.482169D Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf09.hostedemail.com (Postfix) with ESMTP id 9560D140032 for ; Mon, 24 Jun 2024 14:04:44 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dbyEDfXQ; spf=pass (imf09.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.160.173 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=1719237871; 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=/jytiD3F6dVDoVcn3tgOCkYr8qgKU/Kw/DG4oKzaeY4=; b=ZbnE+11g72tFBc6z9kLBVG09E8+csi9JoSd8p0HDXdNcs0WmQUW9JFAKtUmbwQ1vPF5PZY 72+yEI2DUBUWc0HwznAOwJgxxfKUbDC2PyEDBC3Wz8h6/WEsuWabRfY5oCU0nuaHPjYSCv NVcLmu/N++Eau6b5kZMFIv0uo59ZBck= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719237871; a=rsa-sha256; cv=none; b=zrrZIIy3DbknkatG0jDC45s+HHHOaarLfoL1lOEG+rexbfPP7G+/8kLZ06wW4jNqcBdNBP NN68ql7PwFB3s+XAvRM/mcoxpYplP6SOIVDXW+UMvKPeiv+vVo48BGnEFp3W1mDXS5TWL/ /xRaUemx/x0GzOa7oNFBEGcQK2vj8g0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dbyEDfXQ; spf=pass (imf09.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-444af5c09e8so29344041cf.2 for ; Mon, 24 Jun 2024 07:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719237883; x=1719842683; 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=/jytiD3F6dVDoVcn3tgOCkYr8qgKU/Kw/DG4oKzaeY4=; b=dbyEDfXQsqCR8Pe6GapfZug1G4FkjbGjMoFmsWrWHUJu2fXUoat9rwa0srbRhkyTYB j4n+U4skUfCqooK1fyaTkqXNUHmJNPqqFQvqLlyJHtILUipZn/Jt214v5VTzTJKMBD0q p5/kH2ExZxT/B3ekXa0oYkBFGeo673AthbIPL3FOf7HlqXsjolJEPJ3bwMgxIyo00aLU Qx5chpPRIRtAd140DO/85B87fj3D2lViLTxHxQKjvk78Gv44S+cAuMTfcSNL56pZSaJb tt+hwpgp4vSrKLkKFi5+qTkV1yYX5GNyn+42MUdMGwOZbfLcXBBPQz7tNR4uc4YBqbgJ 4PJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719237883; x=1719842683; 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=rLCkrZ14p1PcLt80gJ3piiQ5qEVOqXI8PikZpZT3eCZBxD9B0luGP7B5dEPABQmMyK euh0NPIlEoyy3SwbD0UgfG58EjLVsUqKsDv8n0TQT43W5DEyhqZHm+VTdKm70SwfS8+R c+7M3PMrZBKhKbrVEOSw0sSSvI6zHp16yo+RSBaW5U7u00AS6eyBQ5N44SrjrETevzvo S8OpeqQ9H1gg3ezVwRXFmVybnxHqG/7QOaF+aD2EN5L7BmpBS/fV5J4wPC8JjZ+q9T2F FFwaHfFQPKKGb7ujQufOhF0lqkeqnzOcjxddY8MW/3WF7apsUYyxccPsSuejtRZm/DLC Bplw== X-Forwarded-Encrypted: i=1; AJvYcCXnUEwYKhYl78O0w4Qcvd9VexqSlrLPD3RVN422gbw0QltXQtqyM3PLqOMyas2mcD4henJ/C9hs/JM7iR3lOnNsU8c= X-Gm-Message-State: AOJu0YwZHqgAGL5HOYW9xa0RUACuvfOFiinY6QGgiBXDN5qpzahle7jV MLLcghy3gk8mv4Tk39oVYc6sRkrnZNXyxYKYeuh7c9GcGw4hUCgf X-Google-Smtp-Source: AGHT+IH8eTzsM0NGhqpdclxPrtt3LxQ2HVXUK/jftjkCUoBUbWBrGhWoW+mmzJQ4EWpKi5yUZJT85A== X-Received: by 2002:ad4:4e2c:0:b0:6b5:403:ea7b with SMTP id 6a1803df08f44-6b5365393admr55125736d6.54.1719237883502; Mon, 24 Jun 2024 07:04:43 -0700 (PDT) Received: from localhost (fwdproxy-ash-126.fbsv.net. [2a03:2880:20ff:7e::face:b00c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b52d28dba1sm24165156d6.88.2024.06.24.07.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 07:04:43 -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 v6 2/2] mm: remove code to handle same filled pages Date: Mon, 24 Jun 2024 15:01:29 +0100 Message-ID: <20240624140427.1334871-3-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240624140427.1334871-1-usamaarif642@gmail.com> References: <20240624140427.1334871-1-usamaarif642@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9560D140032 X-Stat-Signature: 8x8ftdk5ekencgju35js1sgwqsqk86pj X-HE-Tag: 1719237884-981609 X-HE-Meta: U2FsdGVkX1/IrK1hwi0dFCbdkzwfZZGt0DKeqDSE1oWA+gZxXhkPnZLRVqeQ00u+yUntTzgF2l9bQ7dYl4pMUsC5aWzFMrgDdip01tlMLc41Og3rZsx9znB+bOruMCwVFORVxV2jeD9xcRxakjjpN6vBqHWu5vQG/H3erCjtziYJ8BOPAX1np8fwylpj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X1RHDeKWGZuJbsGJ18qIw1vs9i5eiZXRu4BNNBMqonyV/Rv6RTM8Lb97sHfAakLMwRAjEycpqHT5Be6rdTQdsxq9Tqm4c2gv/NhYRZqPNaYr9G3GHOhlHFZmxipCRogt8SEITi3kb9pZcvxfvtQxQRPIHot+nMT52YJ+a5x9m8MfsgbyuK7gbzURDczNgS9iM8bF3nk9RDhpqq/CZEoeIUTmKkj2u89FU8uHKZeHWkSDkCTO1BZ6Xu4ROYN891gMlfzoCgIoBzpGk7/Z9vl7S3gZ8WSNgSF1cCCfg8f6pq8r9syHqN90KGFQU= 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 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 --- 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 = 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 @@ -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 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. */ @@ -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_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); @@ -1268,11 +1257,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); } @@ -1376,42 +1360,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 **********************************/ @@ -1423,7 +1371,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)); @@ -1456,13 +1403,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) @@ -1480,7 +1420,6 @@ bool zswap_store(struct folio *folio) if (!zswap_compress(folio, entry)) goto put_pool; -store_entry: entry->swpentry = swp; entry->objcg = objcg; @@ -1528,13 +1467,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: @@ -1597,10 +1532,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) @@ -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); return 0; }