From patchwork Mon Mar 11 16:12:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13588993 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 8B993C54E58 for ; Mon, 11 Mar 2024 16:12:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D860A6B00C0; Mon, 11 Mar 2024 12:12:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0ED26B00BD; Mon, 11 Mar 2024 12:12:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFCCE6B00BF; Mon, 11 Mar 2024 12:12:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A2C956B00BC for ; Mon, 11 Mar 2024 12:12:25 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 206D4C04D5 for ; Mon, 11 Mar 2024 16:12:25 +0000 (UTC) X-FDA: 81885250650.19.632F0CE Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by imf17.hostedemail.com (Postfix) with ESMTP id 0997940028 for ; Mon, 11 Mar 2024 16:12:21 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=MpZI8yO9; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf17.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.46 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710173542; 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:references:dkim-signature; bh=8rae8DczRYY1qVTc5krNA5vQiwAZfYKBrfNd8phx9FQ=; b=UVU4Lzd8LNHdZXNjEaGcc2mrRWToiJ3VBiTm/7/+9b91fQk6K9bLu+XuBFFM7mWncSI6JC 5t81U926b0emJMpTt1i113TVbivnvk0UG33WaStX0Q8KwsBhqR4prmU/P/vlBuqCLS58KP /tn+zZVxDEIQ3fz+aiO3DohSNp+nZ/I= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=MpZI8yO9; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf17.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.46 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710173542; a=rsa-sha256; cv=none; b=YnO5aDF2zlwBrd2w0eayGp2FKwEPr22wNwiqp7IJRS6UgnpohQaY/dR6VO5WMJgHtQVyW3 8FVER8xTynZgXm9ov2qem8YXhyU/kh6lP1voL5vR7Lm/yu1SLt9H6jmX/I1IVghwCHSXU1 H94koCJB6xgYSkayVjxmVzKX4C/j5cg= Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-690cffa8a0bso7636676d6.0 for ; Mon, 11 Mar 2024 09:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1710173541; x=1710778341; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8rae8DczRYY1qVTc5krNA5vQiwAZfYKBrfNd8phx9FQ=; b=MpZI8yO9Oq1l6oxM5cAa51QgJZ+X2hyXZYmYoLQW2/YyR+Ol6G4bZpo6b+P8dGqNwA 3crGK6Wl03NZeGEXae63TPggCpt4lmhHQY3D/pVTCdCy8M4CcPnD50o7i3mG5PswJjAS jES18dsrzhozZ1RGY6t/23sLFq2ilCWIxLavf7APW7rxrqGla6uhsYdg2BwA9ERteBmE 3kNsX9e4EXt//0BkmRhchAT6+3nZNd5hJpGFkovg5JADGRdT5gpePdetQPJEGg0wD7xh VLquXF2R5lkhVogjC8xlTs146jfXg6pQjvHMgAutXlfKepGHcXKrj37hQiZw9vP2R/AN vuUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710173541; x=1710778341; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8rae8DczRYY1qVTc5krNA5vQiwAZfYKBrfNd8phx9FQ=; b=Z0NKW3Qytvt13vtBvD4T1rWQBIdZf6622dRX1dV9/bVkckK6HnEA4FwGankDnorDlv ob+lo1Ij04nrBKhaBHE08PWU/5v31jbXMuMUrrSJoE/w+Gkicgs/+ME6j7Y5w/sQyT+/ c3i5ToJ5J17qk+xxrUkwPSPGcct9Xb8Bn9R8K+gdA5T7uIuW3V/fi9ZUjRPiA85T+hFJ T3mkt2Ua5PgCS9aGlE3Ea3EPeUrsPJIeRuFK1A2TaAtGnJqizlHRVtGURBKVCGz5nii6 xv2Ur01IxOkGoCazPadJTmFtQgJW822XoF7PlPUc9FpWJYY9vqPpfzz/vpZieKgggyVa zHsQ== X-Forwarded-Encrypted: i=1; AJvYcCWY1XZVunLb3AuIsM31Zfm3YViU+lBoNUO3zf3z2WpNmD9oJEyBukGpj4EpfhEWEclukdF4wDc//WlsE6SDEceQMlE= X-Gm-Message-State: AOJu0YxAXBMsf3PkgROl/RwiOtZ0NxA1MRqYYLRL8OyeH1xA2ssoraTK y/HMihpKTYsTs2L+jc8ZguB/EuDTpqaM2FY/+hs446JgQ1syz+OIGOABUX/m5B4= X-Google-Smtp-Source: AGHT+IF1lXMtfLql23ntUBZ5Bx3lRSL4pD/LtPVgSinUp2k9OQFjpcIS4RA39FA+WPNkw9m4xQHQ4Q== X-Received: by 2002:a0c:fa82:0:b0:690:aed1:bd8f with SMTP id o2-20020a0cfa82000000b00690aed1bd8fmr7127592qvn.57.1710173540994; Mon, 11 Mar 2024 09:12:20 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-da5e-d3ff-fee7-26e7.res6.spectrum.com. [2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id p6-20020a0cf546000000b00690d2ed0d74sm1115722qvm.115.2024.03.11.09.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 09:12:20 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Yosry Ahmed , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mm: zswap: optimize zswap pool size tracking Date: Mon, 11 Mar 2024 12:12:13 -0400 Message-ID: <20240311161214.1145168-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 0997940028 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ggmefpxifhciudjahsk1b68ne65cswdc X-HE-Tag: 1710173541-680770 X-HE-Meta: U2FsdGVkX19t5WXsUw4YuNzVDGc94RMWas+Ol0Pay/ihtzvlZ9GFWzjFNfA0gl3ww/VaU6ynlMT10pOO/7lBX5FpPzO7j1jVq8opAHpm57Htj/heMFIucUlLTCj05/cyQhMxzL9nIklYNfsmpO4UBqfOWYIXBiZhiG2GOOIvVW29H4bMmk7EZ5rd9HzSZPIbsoIVHOavtIrB78ClMTufSyUsd8OUy9XGFiYugqhyhmjLjA+Uh5gr3JvH3JsLvTItcDrsRESCFxV4IE+BSGeldARZ9Ws+ytL+8waRTRTAxH9yEw/ybxRWOf6d6Dw9JZNW0hgOmgSAvE6RavQ+PSzf78CeC1LSq/IoonCDvjUP545c0rLB0pglx0oZD54U5ONEdTQbfEVfgye+l7qWJbcYck/UuGVXFiNgDJ3Jr5cNu6fodHjaEd7Zom2aVlY2Flpt3qJgQeXUx9lj1tvjmE51cfp8DdfC2CJjuZKwKAmlQPFOHfCK7cMNtInLe4OgMS1s5oL2E13CJZTfcxlpHw5dkyYAOOK8VQEdAX0qTPZBknt3ul+yqaI7IlN2KXP5ydB5iwdmNXIzRDofLDbkpfK7J4nILDxWzFFvc3bEaZxfiLoqvJ+0iHpiiVsS7oxiUYBPeuVXoDjRXIsTUQ9FP/EUg7A4tV4NanxfCzUi08OeWXFdYKru9k7Tz8sEYO3AKe+lRF2ZOP8pHmNDwFlqcS2K15vMQDZSaCzmNqokYPVxC3SMSrwHop/mq3PhCtu7Sn7fWEBzcg9B7dE/CntMPvLJMgXCNPjtWPETiCpqDKL8mjU17PcAFwPdDJp/H4D7th0r/mTqWjvEd14WXem4QdKlrTALbBifyriJaQpDV02wMOWj8NfVPD9HoRwEGmECxWLLpe1aaTA3KgUxeY3rL49XMSHwxIWzsVEtGgyRREtFGi3Hgwa525NJUtSfg46rAWp1lvZOgCze6n766Io+lNb B4IRhBsO 5kbY4x+PW535BGcjN3lmyi52BVhdl/wRJKzSJg/hujaqjeYSriq8oviwBKQoJ52c+fye3BaCbNxCQoqscBQCJm/Knf6u1dHzRiidugi6T+4lrhwkhsfFV+ynaMbKZeC058aEY9/MloYWVpYZVm2A7SPlYL3xaH1aCqYZXXHQ7U9fAMBI= 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: Profiling the munmap() of a zswapped memory region shows 50%(!) of the total cycles currently going into updating the zswap_pool_total_size. There are three consumers of this counter: - store, to enforce the globally configured pool limit - meminfo & debugfs, to report the size to the user - shrink, to determine the batch size for each cycle Instead of aggregating everytime an entry enters or exits the zswap pool, aggregate the value from the zpools on-demand: - Stores aggregate the counter anyway upon success. Aggregating to check the limit instead is the same amount of work. - Meminfo & debugfs might benefit somewhat from a pre-aggregated counter, but aren't exactly hotpaths. - Shrinking can aggregate once for every cycle instead of doing it for every freed entry. As the shrinker might work on tens or hundreds of objects per scan cycle, this is a large reduction in aggregations. The paths that benefit dramatically are swapin, swapoff, and unmaps. There could be millions of pages being processed until somebody asks for the pool size again. This eliminates the pool size updates from those paths entirely. Signed-off-by: Johannes Weiner Acked-by: Yosry Ahmed Reviewed-by: Chengming Zhou Reviewed-by: Nhat Pham --- fs/proc/meminfo.c | 3 +- include/linux/zswap.h | 2 +- mm/zswap.c | 98 +++++++++++++++++++++---------------------- 3 files changed, 49 insertions(+), 54 deletions(-) diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index 45af9a989d40..245171d9164b 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -89,8 +89,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) show_val_kb(m, "SwapTotal: ", i.totalswap); show_val_kb(m, "SwapFree: ", i.freeswap); #ifdef CONFIG_ZSWAP - seq_printf(m, "Zswap: %8lu kB\n", - (unsigned long)(zswap_pool_total_size >> 10)); + show_val_kb(m, "Zswap: ", zswap_total_pages()); seq_printf(m, "Zswapped: %8lu kB\n", (unsigned long)atomic_read(&zswap_stored_pages) << (PAGE_SHIFT - 10)); diff --git a/include/linux/zswap.h b/include/linux/zswap.h index 341aea490070..2a85b941db97 100644 --- a/include/linux/zswap.h +++ b/include/linux/zswap.h @@ -7,7 +7,6 @@ struct lruvec; -extern u64 zswap_pool_total_size; extern atomic_t zswap_stored_pages; #ifdef CONFIG_ZSWAP @@ -27,6 +26,7 @@ struct zswap_lruvec_state { atomic_long_t nr_zswap_protected; }; +unsigned long zswap_total_pages(void); bool zswap_store(struct folio *folio); bool zswap_load(struct folio *folio); void zswap_invalidate(swp_entry_t swp); diff --git a/mm/zswap.c b/mm/zswap.c index 9a3237752082..7c39327a7cc2 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -43,8 +43,6 @@ /********************************* * statistics **********************************/ -/* Total bytes used by the compressed storage */ -u64 zswap_pool_total_size; /* 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 */ @@ -264,45 +262,6 @@ static inline struct zswap_tree *swap_zswap_tree(swp_entry_t swp) pr_debug("%s pool %s/%s\n", msg, (p)->tfm_name, \ zpool_get_type((p)->zpools[0])) -static bool zswap_is_full(void) -{ - return totalram_pages() * zswap_max_pool_percent / 100 < - DIV_ROUND_UP(zswap_pool_total_size, PAGE_SIZE); -} - -static bool zswap_can_accept(void) -{ - return totalram_pages() * zswap_accept_thr_percent / 100 * - zswap_max_pool_percent / 100 > - DIV_ROUND_UP(zswap_pool_total_size, PAGE_SIZE); -} - -static u64 get_zswap_pool_size(struct zswap_pool *pool) -{ - u64 pool_size = 0; - int i; - - for (i = 0; i < ZSWAP_NR_ZPOOLS; i++) - pool_size += zpool_get_total_size(pool->zpools[i]); - - return pool_size; -} - -static void zswap_update_total_size(void) -{ - struct zswap_pool *pool; - u64 total = 0; - - rcu_read_lock(); - - list_for_each_entry_rcu(pool, &zswap_pools, list) - total += get_zswap_pool_size(pool); - - rcu_read_unlock(); - - zswap_pool_total_size = total; -} - /********************************* * pool functions **********************************/ @@ -540,6 +499,28 @@ static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor) return NULL; } +static unsigned long zswap_max_pages(void) +{ + return totalram_pages() * zswap_max_pool_percent / 100; +} + +unsigned long zswap_total_pages(void) +{ + struct zswap_pool *pool; + u64 total = 0; + + rcu_read_lock(); + list_for_each_entry_rcu(pool, &zswap_pools, list) { + int i; + + for (i = 0; i < ZSWAP_NR_ZPOOLS; i++) + total += zpool_get_total_size(pool->zpools[i]); + } + rcu_read_unlock(); + + return total >> PAGE_SHIFT; +} + /********************************* * param callbacks **********************************/ @@ -912,7 +893,6 @@ static void zswap_entry_free(struct zswap_entry *entry) } zswap_entry_cache_free(entry); atomic_dec(&zswap_stored_pages); - zswap_update_total_size(); } /* @@ -1317,7 +1297,7 @@ static unsigned long zswap_shrinker_count(struct shrinker *shrinker, nr_stored = memcg_page_state(memcg, MEMCG_ZSWAPPED); #else /* use pool stats instead of memcg stats */ - nr_backing = zswap_pool_total_size >> PAGE_SHIFT; + nr_backing = zswap_total_pages(); nr_stored = atomic_read(&zswap_nr_stored); #endif @@ -1385,6 +1365,10 @@ static void shrink_worker(struct work_struct *w) { struct mem_cgroup *memcg; int ret, failures = 0; + unsigned long thr; + + /* Reclaim down to the accept threshold */ + thr = zswap_max_pages() * zswap_accept_thr_percent / 100; /* global reclaim will select cgroup in a round-robin fashion. */ do { @@ -1432,10 +1416,9 @@ static void shrink_worker(struct work_struct *w) break; if (ret && ++failures == MAX_RECLAIM_RETRIES) break; - resched: cond_resched(); - } while (!zswap_can_accept()); + } while (zswap_total_pages() > thr); } static int zswap_is_page_same_filled(void *ptr, unsigned long *value) @@ -1476,6 +1459,7 @@ bool zswap_store(struct folio *folio) struct zswap_entry *entry, *dupentry; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; + unsigned long max_pages, cur_pages; VM_WARN_ON_ONCE(!folio_test_locked(folio)); VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); @@ -1487,6 +1471,7 @@ bool zswap_store(struct folio *folio) if (!zswap_enabled) goto check_old; + /* Check cgroup limits */ objcg = get_obj_cgroup_from_folio(folio); if (objcg && !obj_cgroup_may_zswap(objcg)) { memcg = get_mem_cgroup_from_objcg(objcg); @@ -1497,15 +1482,20 @@ bool zswap_store(struct folio *folio) mem_cgroup_put(memcg); } - /* reclaim space if needed */ - if (zswap_is_full()) { + /* Check global limits */ + cur_pages = zswap_total_pages(); + max_pages = zswap_max_pages(); + + if (cur_pages >= max_pages) { zswap_pool_limit_hit++; zswap_pool_reached_full = true; goto shrink; } if (zswap_pool_reached_full) { - if (!zswap_can_accept()) + unsigned long thr = max_pages * zswap_accept_thr_percent / 100; + + if (cur_pages > thr) goto shrink; else zswap_pool_reached_full = false; @@ -1581,7 +1571,6 @@ bool zswap_store(struct folio *folio) /* update stats */ atomic_inc(&zswap_stored_pages); - zswap_update_total_size(); count_vm_event(ZSWPOUT); return true; @@ -1711,6 +1700,13 @@ void zswap_swapoff(int type) static struct dentry *zswap_debugfs_root; +static int debugfs_get_total_size(void *data, u64 *val) +{ + *val = zswap_total_pages() * PAGE_SIZE; + return 0; +} +DEFINE_DEBUGFS_ATTRIBUTE(total_size_fops, debugfs_get_total_size, NULL, "%llu"); + static int zswap_debugfs_init(void) { if (!debugfs_initialized()) @@ -1732,8 +1728,8 @@ static int zswap_debugfs_init(void) zswap_debugfs_root, &zswap_reject_compress_poor); debugfs_create_u64("written_back_pages", 0444, zswap_debugfs_root, &zswap_written_back_pages); - debugfs_create_u64("pool_total_size", 0444, - zswap_debugfs_root, &zswap_pool_total_size); + debugfs_create_file("pool_total_size", 0444, + 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, From patchwork Mon Mar 11 16:12:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13588994 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 AA05EC5475B for ; Mon, 11 Mar 2024 16:12:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EB6A6B00BC; Mon, 11 Mar 2024 12:12:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 19C116B00BE; Mon, 11 Mar 2024 12:12:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D83B46B00BC; Mon, 11 Mar 2024 12:12:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B76D56B00BE for ; Mon, 11 Mar 2024 12:12:25 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8752E1A0194 for ; Mon, 11 Mar 2024 16:12:25 +0000 (UTC) X-FDA: 81885250650.15.77DFFC7 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf14.hostedemail.com (Postfix) with ESMTP id B485410001D for ; Mon, 11 Mar 2024 16:12:23 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=C3VF8snI; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf14.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.173 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710173543; 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=5Tw6Rxk9uZE/KG6yDJZXgFMWxZfv7cDqR1jIP/xjev4=; b=mnbS0iOQEksOTbKStk/dAb6UTFT9NH/GgEdV1MicfvpLBziNieH5XYlcVBfXWQp7SGUpTk aZ2x9xlJm93EN7g5GsPbZEBZdXjg306/2JaCMF53UF/X3MObmf+bIcjUyRkZxgB7dNGggz r8q8pUr03J/7/q1Ui9HppKiQN75Co6Q= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=C3VF8snI; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf14.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.173 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710173543; a=rsa-sha256; cv=none; b=yeigGaZdPzHtHBazAxjJapc0bDYck0bOKBP0a1WZRt7cmV7eQRlhDQkBISIxCfHuxgTD4S 200tRhA2ySevzep+7TqmvnyZXeIJXBbHWqQF59Xqzy1uyK62TftSp3VRyLQxUskh6ZR0EA mijOt+9hKBgGXRQGG8i6a6so/EgeEr4= Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-42ef1822b07so20132591cf.0 for ; Mon, 11 Mar 2024 09:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1710173542; x=1710778342; 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=5Tw6Rxk9uZE/KG6yDJZXgFMWxZfv7cDqR1jIP/xjev4=; b=C3VF8snILule/XIB01qHWhLxelOY8pZNIpmWykeelJZkrI2svo9zVhoGb2skDlDWTb 6O9wqwLRniSi0xoIWQvMwqXC8+9FKUoMD5i3eLdZpu29YwSz8VaKRuENpTOlQ9Pzjho4 RD83NkRYdQ1afvkjsfHUopOWC/g4h9fGkSTxEQ+brZlFIVeaZ34kIVvHIIuHcveX3K7l 4st60Q4jXO8wS5nQ45i01tBq54UNhkerZujByYRLT//DTaGWY5ovZDifPdMZMXB5x4OQ 3a6xqmhTHnmjmYQ38q6K0sSCX2gl48EYyH8xUJNQUBz7d90t3Ygpz1kyUzQ2xzf8VIDk X1ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710173542; x=1710778342; 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=5Tw6Rxk9uZE/KG6yDJZXgFMWxZfv7cDqR1jIP/xjev4=; b=JaDuLDRgxr7S/yNnfaO+mT4T909I5gHhc2ffiUOFcB77bw/BYOVVcYb3E8fqeibVSo +KlycXfrayAun1wdgB8UjY+r149vVQ9rln5HhlkVL8Zhy//kXWOQ8utbNAldc0oSVGQI aJ/PQCPjeoVZL6dJWsjSh5JLLXYsqy19RCwPFQW0vcu+QCtYFGuDTqrH1oS1Igx1gtBC PpJLfQ+dH10EK67qnnm0S9Ms3/G7Cbfqpf+yF/JfM29TcbfCar/1QsInsaBbSi/Rfv+j yXtWT3e4D4/hskGjfi9dlZEBhrj3tuNjvH1fEP+qJ6YgdQLY1sitiGbboYvjxp4DMlKN WVXQ== X-Forwarded-Encrypted: i=1; AJvYcCUPwHsJSY6Tq2zrxJus04BNLObvlSCH4DOZDKW57nZsVbIeAq6lW1zV816BSJ2V3Ht2eq8w7EIW46TeMRXr0mcBmSg= X-Gm-Message-State: AOJu0Yw4edS40LPwl+i+ikuYheAzqU1a/DcFlAtpUJraD7n+GhUWIoh0 UTWjxLH8+V4+JPUYUANPMVtyCjk7k1O8VSJzOd31oRJB4rJEXxAbfz5BvLHm4Ss= X-Google-Smtp-Source: AGHT+IGlq1xhGzojJ3qUchJop6FyehdDDMXdXQh+GuKAfRx5DKp0dyumWzTYON2PFURV+VnQeVQ6Ag== X-Received: by 2002:a05:622a:50e:b0:42e:f6dc:bc7d with SMTP id l14-20020a05622a050e00b0042ef6dcbc7dmr10259718qtx.65.1710173542735; Mon, 11 Mar 2024 09:12:22 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-da5e-d3ff-fee7-26e7.res6.spectrum.com. [2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id jr18-20020a05622a801200b0042f01e612bbsm2839309qtb.37.2024.03.11.09.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 09:12:22 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Yosry Ahmed , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm: zpool: return pool size in pages Date: Mon, 11 Mar 2024 12:12:14 -0400 Message-ID: <20240311161214.1145168-2-hannes@cmpxchg.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240311161214.1145168-1-hannes@cmpxchg.org> References: <20240311161214.1145168-1-hannes@cmpxchg.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: B485410001D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: oj93gfps9pegwarqkyncgkoinbg6i4fe X-HE-Tag: 1710173543-281204 X-HE-Meta: U2FsdGVkX19IcKCMQdCIJMQLBqB+lcVaC0+dq6O2k44UEPW9es7yuVxWo4aLXgzJh2Lg60mtqz+2Io/SsXijDxZxtN24HMcf4gorp+/zwdJqkan0ceTlN7Y2a0MrM19MYrC2mDUK4hHnD5YYkCphDXIseVUzZNAUkx++tEAWiNxqL/zAW+jr27CQVhHYdDj9yBkr0qqmcGcuD1bX9pWthR3p3XXrG/V4KwcjxCbhxMcol6YfrRZTl4EOHarc+RBxq72k/HJMg7+1CTv4NXP+R0pG6HkohE2TGgv6tPJPQ7YJ2XsWI27R6I6uwqCMWoILWNirA6avsbbXnzLCjG6suLqCJgmnjg9AKd4Kho4Lnxqrp8Boh5WhyHjIfoowhS5OK265MsCiSgncRv9gK5Zq+SheNYFhS7Ctuzw2V/mulkxsBSfTRflAbowHHYV/l6LOm1RQE8yvmeJflnaDCPC60GaC916sqCKXl8Gpl0Br5woKfi0qbncLWuMvGsZBJMUeolduXMe3Yy0DLaeQs2sP8Y3v309Sk+4eCgIAr96QW61GCNOpIYCOpNmHYLD9xbxmFRMS4frYuopUOjo/Kq9dZ9Lpp6umfwf7Ss2ThtTShjJA7JzHqrVWtHn1lQlAuCmNweMRDVe7nMVcHhxQS5IrvhRaH/PuCv5Uox8ZJT0B3WnKcL6DloVi7S3UvHmaEV/8Ih1wFokcjsB0GK8U5GyGP9x+cduUKTYFBB11bPJRiZuDO8Vh6Y7m3F5RK0+S4sp3Rv2saumah1MS26yRk4YONjxhYy7sYUE9ma4wN4TBKkvzYSZq5AozF0BZn4kWrPWFPhbXIz+Cn9HrCB0rLu2OYpUcoDAh75yCuJtMs6N53wP9RrtN8yIGD1LwEIQYZA3FJF/m4wgRkZ+ak2j3CRbdYU2HOJ0BNdx5Cz65Lhr6/Bt7wpSqv2SFWt6YeFH3un06b24/cEniqZOOu81TGYv tQqqejAW fLL3amOE0JV1oOEShH/5chbwShfPmZa/o03ZCUhG1FqOX6Rc8mw0lipND5xq0y+twWiPXaNqJyD/xbXr+h8bhz/sjmFu/GuNIudMQX/Wnct6tCD9yJdHaVRwlFvrDWmfk6w7tbQS/+53wrwc69g6plHOJFQcvbzxrIJe4f8V7F8EKUKk= 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: All zswap backends track their pool sizes in pages. Currently they multiply by PAGE_SIZE for zswap, only for zswap to divide again in order to do limit math. Report pages directly. Signed-off-by: Johannes Weiner Acked-by: Yosry Ahmed Reviewed-by: Chengming Zhou Reviewed-by: Nhat Pham --- mm/z3fold.c | 2 +- mm/zbud.c | 2 +- mm/zpool.c | 4 ++-- mm/zsmalloc.c | 2 +- mm/zswap.c | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index 7ab05621052d..9bacacd4168c 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -1404,7 +1404,7 @@ static void z3fold_zpool_unmap(void *pool, unsigned long handle) static u64 z3fold_zpool_total_size(void *pool) { - return z3fold_get_pool_size(pool) * PAGE_SIZE; + return z3fold_get_pool_size(pool); } static struct zpool_driver z3fold_zpool_driver = { diff --git a/mm/zbud.c b/mm/zbud.c index 2190cc1f37b3..b7d8a22bbf5f 100644 --- a/mm/zbud.c +++ b/mm/zbud.c @@ -412,7 +412,7 @@ static void zbud_zpool_unmap(void *pool, unsigned long handle) static u64 zbud_zpool_total_size(void *pool) { - return zbud_get_pool_size(pool) * PAGE_SIZE; + return zbud_get_pool_size(pool); } static struct zpool_driver zbud_zpool_driver = { diff --git a/mm/zpool.c b/mm/zpool.c index 846410479c2f..410808aee7fe 100644 --- a/mm/zpool.c +++ b/mm/zpool.c @@ -324,9 +324,9 @@ void zpool_unmap_handle(struct zpool *zpool, unsigned long handle) * zpool_get_total_size() - The total size of the pool * @zpool: The zpool to check * - * This returns the total size in bytes of the pool. + * This returns the total size in pages of the pool. * - * Returns: Total size of the zpool in bytes. + * Returns: Total size of the zpool in pages. */ u64 zpool_get_total_size(struct zpool *zpool) { diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 7d7cb3eaabe0..398f3856817f 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -401,7 +401,7 @@ static void zs_zpool_unmap(void *pool, unsigned long handle) static u64 zs_zpool_total_size(void *pool) { - return zs_get_total_pages(pool) << PAGE_SHIFT; + return zs_get_total_pages(pool); } static struct zpool_driver zs_zpool_driver = { diff --git a/mm/zswap.c b/mm/zswap.c index 7c39327a7cc2..fe4343e416e0 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -507,7 +507,7 @@ static unsigned long zswap_max_pages(void) unsigned long zswap_total_pages(void) { struct zswap_pool *pool; - u64 total = 0; + unsigned long total = 0; rcu_read_lock(); list_for_each_entry_rcu(pool, &zswap_pools, list) { @@ -518,7 +518,7 @@ unsigned long zswap_total_pages(void) } rcu_read_unlock(); - return total >> PAGE_SHIFT; + return total; } /*********************************