linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] zswap: add reclaim trigger and stat for debugging
@ 2021-06-02  9:27 Ananda Badmaev
  2021-06-09 10:48 ` David Hildenbrand
  0 siblings, 1 reply; 2+ messages in thread
From: Ananda Badmaev @ 2021-06-02  9:27 UTC (permalink / raw)
  To: linux-mm; +Cc: 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()
---
 mm/zswap.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/mm/zswap.c b/mm/zswap.c
index 20763267a219..680a4e413f53 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -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;
 }
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] zswap: add reclaim trigger and stat for debugging
  2021-06-02  9:27 [PATCH] zswap: add reclaim trigger and stat for debugging Ananda Badmaev
@ 2021-06-09 10:48 ` David Hildenbrand
  0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2021-06-09 10:48 UTC (permalink / raw)
  To: Ananda Badmaev, linux-mm

On 02.06.21 11:27, Ananda Badmaev wrote:
> - 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?)?


-- 
Thanks,

David / dhildenb



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-09 10:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02  9:27 [PATCH] zswap: add reclaim trigger and stat for debugging Ananda Badmaev
2021-06-09 10:48 ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).