Linux cgroups development
 help / color / mirror / Atom feed
From: Nhat Pham <nphamcs@gmail.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	"Chris Li" <chrisl@kernel.org>,
	"Kairui Song" <kasong@tencent.com>,
	"Kemeng Shi" <shikemeng@huaweicloud.com>,
	"Baoquan He" <baoquan.he@linux.dev>,
	"Barry Song" <baohua@kernel.org>,
	"Youngjun Park" <youngjun.park@lge.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Yosry Ahmed" <yosry@kernel.org>,
	"Chengming Zhou" <chengming.zhou@linux.dev>,
	"Qi Zheng" <qi.zheng@linux.dev>,
	"Shakeel Butt" <shakeel.butt@linux.dev>,
	"Axel Rasmussen" <axelrasmussen@google.com>,
	"Yuanchu Xie" <yuanchu@google.com>, "Wei Xu" <weixugc@google.com>,
	"Baolin Wang" <baolin.wang@linux.alibaba.com>,
	"Michal Hocko" <mhocko@kernel.org>,
	"David Hildenbrand" <david@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Hugh Dickins" <hughd@google.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Roman Gushchin" <roman.gushchin@linux.dev>,
	"Muchun Song" <muchun.song@linux.dev>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Karl Mehltretter" <kmehltretter@gmail.com>,
	"Dapeng Mi" <dapeng1.mi@linux.intel.com>,
	"Marco Elver" <elver@google.com>,
	"Ethan Nelson-Moore" <enelsonmoore@gmail.com>,
	"Borislav Petkov (AMD)" <bp@alien8.de>,
	"Jeff Layton" <jlayton@kernel.org>,
	linux-doc@vger.kernel.org, cgroups@vger.kernel.org,
	"Tejun Heo" <tj@kernel.org>, "Michal Koutný" <mkoutny@suse.com>
Subject: [PATCH v7 12/20] mm, swap: add debugfs counters for vswap
Date: Thu,  3 Dec 2026 14:00:02 -0800	[thread overview]
Message-ID: <20261203220010.1302207-13-nphamcs@gmail.com> (raw)
In-Reply-To: <20261203220010.1302207-1-nphamcs@gmail.com>

Add /sys/kernel/debug/vswap/ with two counters:

* used: virtual swap slots (pages) currently allocated
* alloc_reject: cumulative pages whose vswap slot allocation failed

Signed-off-by: Nhat Pham <nphamcs@gmail.com>
---
 mm/swapfile.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index ab65b84a51c7..afc48d33cc40 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/blkdev.h>
+#include <linux/debugfs.h>
 #include <linux/mm.h>
 #include <linux/sched/mm.h>
 #include <linux/sched/task.h>
@@ -145,6 +146,7 @@ static DEFINE_PER_CPU(struct percpu_vswap_cluster, percpu_vswap_cluster) = {
 	.lock = INIT_LOCAL_LOCK(),
 };
 
+static atomic_long_t vswap_alloc_reject = ATOMIC_LONG_INIT(0);
 static void vswap_mark_cache_only(struct swap_cluster_info *ci,
 				  unsigned int ci_off);
 static void vswap_clear_cache_only(struct swap_cluster_info *ci,
@@ -2072,6 +2074,7 @@ static bool vswap_alloc(struct folio *folio)
 
 	this_cpu_write(percpu_vswap_cluster.offset[order], SWAP_ENTRY_INVALID);
 	local_unlock(&percpu_vswap_cluster.lock);
+	atomic_long_add(folio_nr_pages(folio), &vswap_alloc_reject);
 	return false;
 }
 
@@ -4847,9 +4850,25 @@ early_param("vswap", early_vswap);
 /* vswap does no IO on its own. */
 static const struct swap_ops vswap_ops = { };
 
+static int vswap_used_get(void *data, u64 *val)
+{
+	*val = swap_usage_in_pages(vswap_si);
+	return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(vswap_used_fops, vswap_used_get, NULL, "%llu\n");
+
+static int vswap_alloc_reject_get(void *data, u64 *val)
+{
+	*val = atomic_long_read(&vswap_alloc_reject);
+	return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(vswap_alloc_reject_fops, vswap_alloc_reject_get, NULL,
+			 "%llu\n");
+
 static int __init vswap_init(void)
 {
 	struct swap_info_struct *si;
+	struct dentry *root;
 	unsigned long maxpages;
 	int err;
 
@@ -4893,6 +4912,12 @@ static int __init vswap_init(void)
 	mutex_unlock(&swapon_mutex);
 
 	vswap_si = si;
+
+	root = debugfs_create_dir("vswap", NULL);
+	debugfs_create_file("used", 0444, root, NULL, &vswap_used_fops);
+	debugfs_create_file("alloc_reject", 0444, root, NULL,
+			    &vswap_alloc_reject_fops);
+
 	pr_info("vswap: created virtual swap device (%lu pages)\n", maxpages);
 
 	/* Last: everything above must be visible before routing starts. */
-- 
2.53.1-Meta


  parent reply	other threads:[~2026-12-03 22:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 21:59 [PATCH v7 00/20] mm: mandatory virtual swap Nhat Pham
2026-12-03 21:59 ` [PATCH v7 01/20] mm/swap: prepare dynamic clusters for vswap Nhat Pham
2026-12-03 21:59 ` [PATCH v7 02/20] mm, swap: prepare the swap IO path " Nhat Pham
2026-12-03 21:59 ` [PATCH v7 03/20] mm/swap: prepare zswap and zero storage for virtual entries Nhat Pham
2026-12-03 21:59 ` [PATCH v7 04/20] mm/swap: allocate virtual swap slots Nhat Pham
2026-12-03 21:59 ` [PATCH v7 05/20] mm/swap: return physical entries from the swap allocator Nhat Pham
2026-12-03 21:59 ` [PATCH v7 06/20] mm/swap: resolve physical backing for reads and device flags Nhat Pham
2026-12-03 21:59 ` [PATCH v7 07/20] mm/swap: prepare physical swapoff for virtual backing Nhat Pham
2026-12-03 21:59 ` [PATCH v7 08/20] mm/swap: support physical swap as a vswap backend Nhat Pham
2026-12-03 21:59 ` [PATCH v7 09/20] mm, swap: enable THP swapin for vswap entries Nhat Pham
2026-12-03 22:00 ` [PATCH v7 10/20] mm, swap: write back vswap zswap entries to physical swap Nhat Pham
2026-12-03 22:00 ` [PATCH v7 11/20] mm, swap: reclaim physical slots backing cache-only vswap entries Nhat Pham
2026-12-03 22:00 ` Nhat Pham [this message]
2026-12-03 22:00 ` [PATCH v7 13/20] mm, swap: only charge physical swap entries Nhat Pham
2026-12-03 22:00 ` [PATCH v7 14/20] mm, swap: defer memcg_table allocation for physical swap clusters Nhat Pham
2026-12-03 22:00 ` [PATCH v7 15/20] mm, swap: add vmstat and memcg counters for vswap Nhat Pham
2026-12-03 22:00 ` [PATCH v7 16/20] mm/swap: make vswap mandatory Nhat Pham
2026-12-03 22:00 ` [PATCH v7 17/20] mm/swap: drop direct physical swapcache handling Nhat Pham
2026-12-03 22:00 ` [PATCH v7 18/20] mm/zswap: store compressed entries only in the vtable Nhat Pham
2026-12-03 22:00 ` [PATCH v7 19/20] mm/swap: reclaim physical backing through reverse mappings Nhat Pham
2026-12-03 22:00 ` [PATCH v7 20/20] mm/swap: move virtual swap metadata into vswap clusters Nhat Pham
2026-12-03 22:14 ` [PATCH v7 00/20] mm: mandatory virtual swap Yosry Ahmed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203220010.1302207-13-nphamcs@gmail.com \
    --to=nphamcs@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=baoquan.he@linux.dev \
    --cc=bp@alien8.de \
    --cc=cgroups@vger.kernel.org \
    --cc=chengming.zhou@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=david@kernel.org \
    --cc=elver@google.com \
    --cc=enelsonmoore@gmail.com \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=jlayton@kernel.org \
    --cc=kasong@tencent.com \
    --cc=kmehltretter@gmail.com \
    --cc=liam@infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=mkoutny@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=qi.zheng@linux.dev \
    --cc=rdunlap@infradead.org \
    --cc=roman.gushchin@linux.dev \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=shikemeng@huaweicloud.com \
    --cc=skhan@linuxfoundation.org \
    --cc=tj@kernel.org \
    --cc=vbabka@kernel.org \
    --cc=weixugc@google.com \
    --cc=yosry@kernel.org \
    --cc=youngjun.park@lge.com \
    --cc=yuanchu@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox