[Devel] [PATCH 1/4] Enable balloon drivers to report inflated memory

Alexander Atanasov alexander.atanasov at virtuozzo.com
Mon Oct 17 14:35:21 MSK 2022


Add counters to be updated by the balloon drivers.
Print balloon stats when logging kernel memory usage.

https://jira.sw.ru/browse/PSBM-142436
Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
---
 include/linux/balloon_compaction.h |  6 ++++++
 lib/show_mem.c                     |  8 ++++++++
 mm/balloon_compaction.c            | 15 +++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
index 338aa27e4773..04c7a5c1dedd 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -207,4 +207,10 @@ static inline struct page *balloon_page_pop(struct list_head *pages)
 	list_del(&page->lru);
 	return page;
 }
+
+extern atomic_long_t mem_balloon_inflated_total_kb;
+extern atomic_long_t mem_balloon_inflated_free_kb;
+void balloon_set_inflated_total(long inflated_kb);
+void balloon_set_inflated_free(long inflated_kb);
+
 #endif /* _LINUX_BALLOON_COMPACTION_H */
diff --git a/lib/show_mem.c b/lib/show_mem.c
index 1c26c14ffbb9..dee20eb0ee6d 100644
--- a/lib/show_mem.c
+++ b/lib/show_mem.c
@@ -7,6 +7,9 @@
 
 #include <linux/mm.h>
 #include <linux/cma.h>
+#ifdef CONFIG_MEMORY_BALLOON
+#include <linux/balloon_compaction.h>
+#endif
 
 void show_mem(unsigned int filter, nodemask_t *nodemask)
 {
@@ -41,4 +44,9 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)
 #ifdef CONFIG_MEMORY_FAILURE
 	printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
 #endif
+#ifdef CONFIG_MEMORY_BALLOON
+	printk("Balloon InflatedTotal:%ldkB InflatedFree:%ldkB\n",
+		atomic_long_read(&mem_balloon_inflated_total_kb),
+		atomic_long_read(&mem_balloon_inflated_free_kb));
+#endif
 }
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index 907fefde2572..bb6b706ffca1 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -257,4 +257,19 @@ const struct address_space_operations balloon_aops = {
 };
 EXPORT_SYMBOL_GPL(balloon_aops);
 
+atomic_long_t mem_balloon_inflated_total_kb = ATOMIC_LONG_INIT(0);
+atomic_long_t mem_balloon_inflated_free_kb = ATOMIC_LONG_INIT(0);
+
+void balloon_set_inflated_total(long inflated_kb)
+{
+	atomic_long_set(&mem_balloon_inflated_total_kb, inflated_kb);
+}
+EXPORT_SYMBOL(balloon_set_inflated_total);
+
+void balloon_set_inflated_free(long inflated_kb)
+{
+	atomic_long_set(&mem_balloon_inflated_free_kb, inflated_kb);
+}
+EXPORT_SYMBOL(balloon_set_inflated_free);
+
 #endif /* CONFIG_BALLOON_COMPACTION */
-- 
2.31.1



More information about the Devel mailing list