From patchwork Thu May 30 10:19:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13680132 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 C5AD0C25B74 for ; Thu, 30 May 2024 10:21:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 216C76B0096; Thu, 30 May 2024 06:21:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 177C16B0098; Thu, 30 May 2024 06:21:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E961F6B0099; Thu, 30 May 2024 06:21:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C1CC46B0096 for ; Thu, 30 May 2024 06:21:49 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8A2BAA2658 for ; Thu, 30 May 2024 10:21:49 +0000 (UTC) X-FDA: 82174671138.05.04BEBA7 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf19.hostedemail.com (Postfix) with ESMTP id C34391A0015 for ; Thu, 30 May 2024 10:21:47 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Xnziqy8g; spf=pass (imf19.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.222.178 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=1717064507; 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=r8d6cDNDU6GShGq9eK0Fgxfj+4gyetgt78E216drysY=; b=c2gG+jZzpLjA6B7rmSYAd7TuUWYJImTltRIsD2YWO+qXeZ5YB2kAgmvR2WKJltX8piWagH mgu5OBMQb0ASVM1S1JmYVtoYTBUitrRaT6TPQibt5ntBkakhsv4XRk+W4p1T2vl7lZ50Qr GlAAnZuLciuJesj+0TRoW1mnWCA1NaQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717064507; a=rsa-sha256; cv=none; b=dKJaBTqFjJ3PspXao+uxOd9YAElZ1YdH8itkkq5URmp3Hdj7XgFVgQ0oyJrXL+6ZJnztko VZF7D0peJah6Ou1AXdU6B5KsQ60xs3j4sAy6t/t4aYK+fcTTyfbITdjy4H0bDF5oRG5Fjz JXWul/J5ruCvgxwsLTu27VjRn7ZmXnM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Xnziqy8g; spf=pass (imf19.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.222.178 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-794c3aed567so54252485a.2 for ; Thu, 30 May 2024 03:21:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717064507; x=1717669307; 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=r8d6cDNDU6GShGq9eK0Fgxfj+4gyetgt78E216drysY=; b=Xnziqy8gtxjmoov3HlcISedbd6UIrUXu5HfB6nrpxWYHQrDKZsBMJI9bakIrM1VRuz UgDStccNac88ZpmRv3eoe8KtiktpMvIIsdjYilBUHEkR+rDVITS/oRZqJ6FuLWwEHAVH Ts5ivOPsKhjVAB8WTgEZhpNA8+Dl4VaW8yAWwQ9s6jdXQFhbRu3ckLBBnZbbzwepxd4N AR303LySA2q4Tm6vl9SEhVLW93N7ZmcSt7WgDQgMYvQrAocTPCQ8LMXYf1fVfjpe/H1I 3CI1xx5oN9SLZNDiUKQPSzEh1jO1Tyukfn7RvZJDVEo3Ckcld+J6innSyEIKB+KbYEhW hDfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717064507; x=1717669307; 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=r8d6cDNDU6GShGq9eK0Fgxfj+4gyetgt78E216drysY=; b=hgfxl3Ybg4MvnL4GyrvPoMH2wxxpvIGJJZ4hmXtmdAoyLndBDnGXGa1YLaHt2xWtxi md2YSvzAna3Te4OEf53RNHiy7OVEg2VhZMLusulPbxpwRLug48q9A2x+NH+P/bStIJ1q VO4xhaYQsO08RR2XLXonSgaLH+huczmsCzjXSgnI7HWuYF6exXPjZzAmSVKAohQnNDKD YNrl549nv56v6suryXiwaSaoM1VfIueHxvOfPXXb5PYhiyiWz5qI4orKc4Ybn7OEewf2 XoIpujRr/QdBerVSBl2RPs1wjGfqXR1NoEc5+c5Wuc0IHgSsqMYREWyE8pLCA2efvhsN Kb0Q== X-Forwarded-Encrypted: i=1; AJvYcCUWE6SnPtJm+kQE6noiGa5Kp5skeyVesU0cT3EOP9yc/tBjVgegh5LIo2nT0+5QSls1+ZDmRZWVgp85OIvJngrTdzo= X-Gm-Message-State: AOJu0YwpFYYLqoq4SiWlC5d4P4Q3H44z7WvsZdQDAKRxCajqaUWdygTg k4DAWWyb98suGaiNFkwDydd0fV3eM5FvTGYbuF91qwnN6bIpHWWx X-Google-Smtp-Source: AGHT+IF6BgR0E1H6Yi7Z0olWyUfqvRPLWZXsZcDuztfZzFojo07FrRO9l8l3SwT6pG7Yaa1MM+8V+g== X-Received: by 2002:a05:6214:4189:b0:6ab:6ddc:4ba1 with SMTP id 6a1803df08f44-6ae0ccd3deamr16187306d6.60.1717064506651; Thu, 30 May 2024 03:21:46 -0700 (PDT) Received: from localhost (fwdproxy-nao-008.fbsv.net. [2a03:2880:23ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ae12306f5bsm3351556d6.118.2024.05.30.03.21.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 03:21:46 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org Cc: hannes@cmpxchg.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 2/2] mm: remove code to handle same filled pages Date: Thu, 30 May 2024 11:19:08 +0100 Message-ID: <20240530102126.357438-3-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240530102126.357438-1-usamaarif642@gmail.com> References: <20240530102126.357438-1-usamaarif642@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C34391A0015 X-Rspam-User: X-Stat-Signature: 1t7dgt8pgbon89fos5z8ausmnaf9773e X-HE-Tag: 1717064507-556018 X-HE-Meta: U2FsdGVkX19u7Euc/thY1txVef3hY5jYBrGuq5RUghEG4XkzIArjVIK7kRnKGcmwTqhB9oahJUdTPjDWFkv2vtWObAtM044fGaYrpKF+93py6NpyVG7S86UGKwDI5qR4OT4uAGqoUgvYoZ+GGLmlsB7wG4Mmprn7vvrfGOgbffjTwPuBgklLNGWg/xkUvgBBQRP8RMsMHgxk2tfFh35vbexn33+xezlYPVPhu2XQEnimNJR2Dg2E+8NxkTucDia/mJYBTofxA+MzFjXZsSF98zgDbe9psi0flVxse30bR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ldz5mbNalW1xj98uPVenfxz+2M02GDxne37o0uEqSwjaW8GE= 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 | 79 +++++------------------------------------------------- 1 file changed, 7 insertions(+), 72 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index b9b35ef86d9b..50c8d402516f 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 **********************************/ @@ -1450,13 +1398,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) @@ -1522,13 +1463,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: @@ -1682,8 +1619,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; }