Skip to contentSkip to conversation

zswap: add reclaim trigger and stat for debugging

PATCH In review Ananda Badmaev 2 participants 2 messages Jun 2, 2021 – Jun 9, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zswap: add reclaim trigger and stat for debugging

- Added 'total_pages_reclaimed' stat to debugfs in zswap.
- Added ability to reclaim pages from zswap using debugfs.
- Added u64 reclaim counter to shrink_worker()

---
 mm/zswap.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
mm/zswap.c +30 -1
index 20763267a219..680a4e413f53 100644
@@ -53,6 +53,9 @@ static atomic_t zswap_same_filled_pages = ATOMIC_INIT(0);
  * certain event is occurring.
 */
 
+/* Total pages evicted */
+static u32 zswap_total_reclaimed;
+
 /* Pool limit was hit (see zswap_max_pool_percent) */
 static u64 zswap_pool_limit_hit;
 /* Pages written back when pool limit was reached */
@@ -576,9 +579,11 @@ static void shrink_worker(struct work_struct *w)
 {
 	struct zswap_pool *pool = container_of(w, typeof(*pool),
 						shrink_work);
+	unsigned int pages_reclaimed = 0;
 
-	if (zpool_shrink(pool->zpool, 1, NULL))
+	if (zpool_shrink(pool->zpool, 1, &pages_reclaimed))
 		zswap_reject_reclaim_fail++;
+	zswap_total_reclaimed += pages_reclaimed;
 	zswap_pool_put(pool);
 }
 
@@ -1397,6 +1402,24 @@ static struct frontswap_ops zswap_frontswap_ops = {
 
 static struct dentry *zswap_debugfs_root;
 
+static ssize_t reclaim_pages_trigger(struct file *file, const char __user *buf,
+									size_t count, loff_t *f_pos)
+{
+	struct zswap_pool *pool;
+
+	/* reclaim pages from userspace using shrink_worker */
+	pool = zswap_pool_last_get();
+	if (pool)
+		queue_work(shrink_wq, &pool->shrink_work);
+	return count;
+}
+
+static const struct file_operations reclaim_pages_fops = {
+	.owner = THIS_MODULE,
+	.write = reclaim_pages_trigger,
+	.open  = simple_open
+};
+
 static int __init zswap_debugfs_init(void)
 {
 	if (!debugfs_initialized())
@@ -1425,6 +1448,12 @@ static int __init zswap_debugfs_init(void)
 	debugfs_create_atomic_t("same_filled_pages", 0444,
 				zswap_debugfs_root, &zswap_same_filled_pages);
 
+	debugfs_create_u32("total_pages_reclaimed", 0444,
+				zswap_debugfs_root, &zswap_total_reclaimed);
+
+	debugfs_create_file("reclaim_pages_trigger", 0744, zswap_debugfs_root,
+						NULL, &reclaim_pages_fops);
+
 	return 0;
 }
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 3 lines · Ananda Badmaev

- Added 'total_pages_reclaimed' stat to debugfs in zswap.
- Added ability to reclaim pages from zswap using debugfs.
- Added u64 reclaim counter to shrink_worker()

I wonder how this is really useful from a user perspective. Wouldn't it make sense to shrink automatically, e.g., when reclaiming memory because low on free memory (OOM?)?

Signature · 3 lines
Thanks,

David / dhildenb