linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v5 1/8] mm: Make a place for a common balloon code
       [not found] <20221019095620.124909-1-alexander.atanasov@virtuozzo.com>
@ 2022-10-19  9:56 ` Alexander Atanasov
  2022-10-19  9:56 ` [RFC PATCH v5 2/8] mm: Enable balloon drivers to report inflated memory Alexander Atanasov
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: Alexander Atanasov @ 2022-10-19  9:56 UTC (permalink / raw)
  To: Michael Ellerman, Nicholas Piggin, Christophe Leroy, Nadav Amit,
	VMware PV-Drivers Reviewers, Arnd Bergmann, Greg Kroah-Hartman,
	Michael S. Tsirkin, David Hildenbrand, Jason Wang, Andrew Morton
  Cc: kernel, Alexander Atanasov, linux-kernel, linuxppc-dev,
	virtualization, linux-mm

The file already contains code that is common along balloon
drivers so rename it to reflect its contents.
mm/balloon_compaction.c -> mm/balloon.c
include/linux/balloon_compaction.h -> include/linux/balloon.h
Remove it from files that do not actually use it.
Drop externs from function declarations.

Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
Acked-by: Nadav Amit <namit@vmware.com>
---
 MAINTAINERS                                       |  4 ++--
 arch/powerpc/platforms/pseries/cmm.c              |  2 +-
 drivers/misc/vmw_balloon.c                        |  2 +-
 drivers/virtio/virtio_balloon.c                   |  2 +-
 include/linux/{balloon_compaction.h => balloon.h} | 12 +++++-------
 mm/Makefile                                       |  2 +-
 mm/{balloon_compaction.c => balloon.c}            |  4 +---
 mm/migrate.c                                      |  1 -
 mm/vmscan.c                                       |  1 -
 9 files changed, 12 insertions(+), 18 deletions(-)
 rename include/linux/{balloon_compaction.h => balloon.h} (93%)
 rename mm/{balloon_compaction.c => balloon.c} (99%)

diff --git a/MAINTAINERS b/MAINTAINERS
index cf0f18502372..3f5a4e409562 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -21744,8 +21744,8 @@ L:	virtualization@lists.linux-foundation.org
 S:	Maintained
 F:	drivers/virtio/virtio_balloon.c
 F:	include/uapi/linux/virtio_balloon.h
-F:	include/linux/balloon_compaction.h
-F:	mm/balloon_compaction.c
+F:	include/linux/balloon.h
+F:	mm/balloon.c
 
 VIRTIO CRYPTO DRIVER
 M:	Gonglei <arei.gonglei@huawei.com>
diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c
index 5f4037c1d7fe..1d40f6416d6a 100644
--- a/arch/powerpc/platforms/pseries/cmm.c
+++ b/arch/powerpc/platforms/pseries/cmm.c
@@ -19,7 +19,7 @@
 #include <linux/stringify.h>
 #include <linux/swap.h>
 #include <linux/device.h>
-#include <linux/balloon_compaction.h>
+#include <linux/balloon.h>
 #include <asm/firmware.h>
 #include <asm/hvcall.h>
 #include <asm/mmu.h>
diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 61a2be712bf7..91d4d2a285c5 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -29,7 +29,7 @@
 #include <linux/rwsem.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
-#include <linux/balloon_compaction.h>
+#include <linux/balloon.h>
 #include <linux/vmw_vmci_defs.h>
 #include <linux/vmw_vmci_api.h>
 #include <asm/hypervisor.h>
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 3f78a3a1eb75..d0c27c680721 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -13,7 +13,7 @@
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/module.h>
-#include <linux/balloon_compaction.h>
+#include <linux/balloon.h>
 #include <linux/oom.h>
 #include <linux/wait.h>
 #include <linux/mm.h>
diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon.h
similarity index 93%
rename from include/linux/balloon_compaction.h
rename to include/linux/balloon.h
index 5ca2d5699620..46ac8f61f607 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon.h
@@ -1,7 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 /*
- * include/linux/balloon_compaction.h
- *
  * Common interface definitions for making balloon pages movable by compaction.
  *
  * Balloon page migration makes use of the general non-lru movable page
@@ -59,13 +57,13 @@ struct balloon_dev_info {
 			struct page *page, enum migrate_mode mode);
 };
 
-extern struct page *balloon_page_alloc(void);
-extern void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
+struct page *balloon_page_alloc(void);
+void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
 				 struct page *page);
-extern struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info);
-extern size_t balloon_page_list_enqueue(struct balloon_dev_info *b_dev_info,
+struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info);
+size_t balloon_page_list_enqueue(struct balloon_dev_info *b_dev_info,
 				      struct list_head *pages);
-extern size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
+size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
 				     struct list_head *pages, size_t n_req_pages);
 
 static inline void balloon_devinfo_init(struct balloon_dev_info *balloon)
diff --git a/mm/Makefile b/mm/Makefile
index 8e105e5b3e29..f73a9b200c91 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -116,7 +116,7 @@ obj-$(CONFIG_ZSMALLOC)	+= zsmalloc.o
 obj-$(CONFIG_Z3FOLD)	+= z3fold.o
 obj-$(CONFIG_GENERIC_EARLY_IOREMAP) += early_ioremap.o
 obj-$(CONFIG_CMA)	+= cma.o
-obj-$(CONFIG_MEMORY_BALLOON) += balloon_compaction.o
+obj-$(CONFIG_MEMORY_BALLOON) += balloon.o
 obj-$(CONFIG_PAGE_EXTENSION) += page_ext.o
 obj-$(CONFIG_PAGE_TABLE_CHECK) += page_table_check.o
 obj-$(CONFIG_CMA_DEBUGFS) += cma_debug.o
diff --git a/mm/balloon_compaction.c b/mm/balloon.c
similarity index 99%
rename from mm/balloon_compaction.c
rename to mm/balloon.c
index 22c96fed70b5..22b3e876bc78 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon.c
@@ -1,7 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * mm/balloon_compaction.c
- *
  * Common interface for making balloon pages movable by compaction.
  *
  * Copyright (C) 2012, Red Hat, Inc.  Rafael Aquini <aquini@redhat.com>
@@ -9,7 +7,7 @@
 #include <linux/mm.h>
 #include <linux/slab.h>
 #include <linux/export.h>
-#include <linux/balloon_compaction.h>
+#include <linux/balloon.h>
 
 static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info,
 				     struct page *page)
diff --git a/mm/migrate.c b/mm/migrate.c
index 1379e1912772..74c21b1cb2ec 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -41,7 +41,6 @@
 #include <linux/pfn_t.h>
 #include <linux/memremap.h>
 #include <linux/userfaultfd_k.h>
-#include <linux/balloon_compaction.h>
 #include <linux/page_idle.h>
 #include <linux/page_owner.h>
 #include <linux/sched/mm.h>
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 04d8b88e5216..5a4e17bf4193 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -59,7 +59,6 @@
 #include <asm/div64.h>
 
 #include <linux/swapops.h>
-#include <linux/balloon_compaction.h>
 #include <linux/sched/sysctl.h>
 
 #include "internal.h"
-- 
2.31.1


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

* [RFC PATCH v5 2/8] mm: Enable balloon drivers to report inflated memory
       [not found] <20221019095620.124909-1-alexander.atanasov@virtuozzo.com>
  2022-10-19  9:56 ` [RFC PATCH v5 1/8] mm: Make a place for a common balloon code Alexander Atanasov
@ 2022-10-19  9:56 ` Alexander Atanasov
  2022-10-19  9:56 ` [RFC PATCH v5 3/8] mm: Display inflated memory to users Alexander Atanasov
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: Alexander Atanasov @ 2022-10-19  9:56 UTC (permalink / raw)
  To: Michael S. Tsirkin, David Hildenbrand, Andrew Morton
  Cc: kernel, Alexander Atanasov, virtualization, linux-kernel, linux-mm

Add counters to be updated by the balloon drivers.

Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
---
 include/linux/balloon.h |  6 ++++++
 mm/balloon.c            | 15 +++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/linux/balloon.h b/include/linux/balloon.h
index 46ac8f61f607..dd8fb8ac5737 100644
--- a/include/linux/balloon.h
+++ b/include/linux/balloon.h
@@ -57,6 +57,12 @@ struct balloon_dev_info {
 			struct page *page, enum migrate_mode mode);
 };
 
+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);
+
 struct page *balloon_page_alloc(void);
 void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
 				 struct page *page);
diff --git a/mm/balloon.c b/mm/balloon.c
index 22b3e876bc78..59f606bf4390 100644
--- a/mm/balloon.c
+++ b/mm/balloon.c
@@ -9,6 +9,21 @@
 #include <linux/export.h>
 #include <linux/balloon.h>
 
+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);
+
 static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info,
 				     struct page *page)
 {
-- 
2.31.1


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

* [RFC PATCH v5 3/8] mm: Display inflated memory to users
       [not found] <20221019095620.124909-1-alexander.atanasov@virtuozzo.com>
  2022-10-19  9:56 ` [RFC PATCH v5 1/8] mm: Make a place for a common balloon code Alexander Atanasov
  2022-10-19  9:56 ` [RFC PATCH v5 2/8] mm: Enable balloon drivers to report inflated memory Alexander Atanasov
@ 2022-10-19  9:56 ` Alexander Atanasov
  2022-10-19  9:56 ` [RFC PATCH v5 4/8] mm: Display inflated memory in logs Alexander Atanasov
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: Alexander Atanasov @ 2022-10-19  9:56 UTC (permalink / raw)
  To: Jonathan Corbet
  Cc: kernel, Alexander Atanasov, linux-kernel, linux-fsdevel, linux-doc

Add InflatedTotal and InflatedFree to /proc/meminfo

Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
---
 Documentation/filesystems/proc.rst |  6 ++++++
 fs/proc/meminfo.c                  | 10 ++++++++++
 2 files changed, 16 insertions(+)

diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
index 898c99eae8e4..d88828a27383 100644
--- a/Documentation/filesystems/proc.rst
+++ b/Documentation/filesystems/proc.rst
@@ -992,6 +992,8 @@ Example output. You may not have all of these fields.
     VmallocUsed:       40444 kB
     VmallocChunk:          0 kB
     Percpu:            29312 kB
+    InflatedTotal:   2097152 kB
+    InflatedFree:          0 kB
     HardwareCorrupted:     0 kB
     AnonHugePages:   4149248 kB
     ShmemHugePages:        0 kB
@@ -1142,6 +1144,10 @@ VmallocChunk
 Percpu
               Memory allocated to the percpu allocator used to back percpu
               allocations. This stat excludes the cost of metadata.
+InflatedTotal and InflatedFree
+               Amount of memory that is inflated by the balloon driver.
+               Due to differences among the drivers inflated memory
+               is subtracted from TotalRam or from MemFree.
 HardwareCorrupted
               The amount of RAM/memory in KB, the kernel identifies as
               corrupted.
diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 5101131e6047..d9e059b0b25d 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -16,6 +16,9 @@
 #ifdef CONFIG_CMA
 #include <linux/cma.h>
 #endif
+#ifdef CONFIG_MEMORY_BALLOON
+#include <linux/balloon.h>
+#endif
 #include <asm/page.h>
 #include "internal.h"
 
@@ -155,6 +158,13 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 		    global_zone_page_state(NR_FREE_CMA_PAGES));
 #endif
 
+#ifdef CONFIG_MEMORY_BALLOON
+	seq_printf(m,  "InflatedTotal:  %8ld kB\n",
+		atomic_long_read(&mem_balloon_inflated_total_kb));
+	seq_printf(m,  "InflatedFree:   %8ld kB\n",
+		atomic_long_read(&mem_balloon_inflated_free_kb));
+#endif
+
 	hugetlb_report_meminfo(m);
 
 	arch_report_meminfo(m);
-- 
2.31.1


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

* [RFC PATCH v5 4/8] mm: Display inflated memory in logs
       [not found] <20221019095620.124909-1-alexander.atanasov@virtuozzo.com>
                   ` (2 preceding siblings ...)
  2022-10-19  9:56 ` [RFC PATCH v5 3/8] mm: Display inflated memory to users Alexander Atanasov
@ 2022-10-19  9:56 ` Alexander Atanasov
  2022-10-19  9:56 ` [RFC PATCH v5 5/8] drivers: virtio: balloon - report inflated memory Alexander Atanasov
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: Alexander Atanasov @ 2022-10-19  9:56 UTC (permalink / raw)
  Cc: kernel, Alexander Atanasov, linux-kernel

Add InflatedTotal and InflatedFree to show_mem(...) so
it is visible in the logs.

Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
---
 lib/show_mem.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/show_mem.c b/lib/show_mem.c
index 0d7585cde2a6..20b5964d498e 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.h>
+#endif
 
 void __show_mem(unsigned int filter, nodemask_t *nodemask, int max_zone_idx)
 {
@@ -41,4 +44,9 @@ void __show_mem(unsigned int filter, nodemask_t *nodemask, int max_zone_idx)
 #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
 }
-- 
2.31.1


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

* [RFC PATCH v5 5/8] drivers: virtio: balloon - report inflated memory
       [not found] <20221019095620.124909-1-alexander.atanasov@virtuozzo.com>
                   ` (3 preceding siblings ...)
  2022-10-19  9:56 ` [RFC PATCH v5 4/8] mm: Display inflated memory in logs Alexander Atanasov
@ 2022-10-19  9:56 ` Alexander Atanasov
  2022-10-19  9:56 ` [RFC PATCH v5 6/8] drivers: vmware: " Alexander Atanasov
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: Alexander Atanasov @ 2022-10-19  9:56 UTC (permalink / raw)
  To: Michael S. Tsirkin, David Hildenbrand, Jason Wang
  Cc: kernel, Alexander Atanasov, virtualization, linux-kernel

Update the inflated memory in the mm core when it changes.

Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
---
 drivers/virtio/virtio_balloon.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index d0c27c680721..e9c3642eef17 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -450,10 +450,15 @@ static void virtballoon_changed(struct virtio_device *vdev)
 static void update_balloon_size(struct virtio_balloon *vb)
 {
 	u32 actual = vb->num_pages;
+	long inflated_kb = actual << (VIRTIO_BALLOON_PFN_SHIFT - 10);
 
 	/* Legacy balloon config space is LE, unlike all other devices. */
 	virtio_cwrite_le(vb->vdev, struct virtio_balloon_config, actual,
 			 &actual);
+	if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
+		balloon_set_inflated_free(inflated_kb);
+	else
+		balloon_set_inflated_total(inflated_kb);
 }
 
 static void update_balloon_stats_func(struct work_struct *work)
-- 
2.31.1


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

* [RFC PATCH v5 6/8] drivers: vmware: balloon - report inflated memory
       [not found] <20221019095620.124909-1-alexander.atanasov@virtuozzo.com>
                   ` (4 preceding siblings ...)
  2022-10-19  9:56 ` [RFC PATCH v5 5/8] drivers: virtio: balloon - report inflated memory Alexander Atanasov
@ 2022-10-19  9:56 ` Alexander Atanasov
  2022-10-19 10:26   ` Greg Kroah-Hartman
  2022-10-21  6:50   ` Nadav Amit
  2022-10-19  9:56 ` [RFC PATCH v5 7/8] drivers: hyperv: " Alexander Atanasov
  2022-10-19  9:56 ` [RFC PATCH v5 8/8] documentation: create a document about how balloon drivers operate Alexander Atanasov
  7 siblings, 2 replies; 17+ messages in thread
From: Alexander Atanasov @ 2022-10-19  9:56 UTC (permalink / raw)
  To: Nadav Amit, VMware PV-Drivers Reviewers, Arnd Bergmann,
	Greg Kroah-Hartman
  Cc: kernel, Alexander Atanasov, linux-kernel

Update the inflated memory in the mm core on change.

Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
---
 drivers/misc/vmw_balloon.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 91d4d2a285c5..3bfd845898f5 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -1507,6 +1507,7 @@ static void vmballoon_work(struct work_struct *work)
 	queue_delayed_work(system_freezable_wq,
 			   dwork, round_jiffies_relative(HZ));
 
+	balloon_set_inflated_free(atomic64_read(&b->size) << 2);
 }
 
 /**
-- 
2.31.1


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

* [RFC PATCH v5 7/8] drivers: hyperv: balloon - report inflated memory
       [not found] <20221019095620.124909-1-alexander.atanasov@virtuozzo.com>
                   ` (5 preceding siblings ...)
  2022-10-19  9:56 ` [RFC PATCH v5 6/8] drivers: vmware: " Alexander Atanasov
@ 2022-10-19  9:56 ` Alexander Atanasov
  2022-10-19  9:56 ` [RFC PATCH v5 8/8] documentation: create a document about how balloon drivers operate Alexander Atanasov
  7 siblings, 0 replies; 17+ messages in thread
From: Alexander Atanasov @ 2022-10-19  9:56 UTC (permalink / raw)
  To: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu, Dexuan Cui
  Cc: kernel, Alexander Atanasov, linux-hyperv, linux-kernel

Update the inflated memory in the mm core on change.

Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
---
 drivers/hv/hv_balloon.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index fdf6decacf06..280622ee0e9b 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -24,6 +24,7 @@
 #include <linux/notifier.h>
 #include <linux/percpu_counter.h>
 #include <linux/page_reporting.h>
+#include <linux/balloon.h>
 
 #include <linux/hyperv.h>
 #include <asm/hyperv-tlfs.h>
@@ -1280,6 +1281,14 @@ static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm,
 	return i * alloc_unit;
 }
 
+static void report_ballooned_pages(struct hv_dynmem_device *dm)
+{
+	u32 actual = dm->num_pages_ballooned;
+	long inflated_kb = actual << (HV_HYP_PAGE_SHIFT - 10);
+
+	balloon_set_inflated_total(inflated_kb);
+}
+
 static void balloon_up(struct work_struct *dummy)
 {
 	unsigned int num_pages = dm_device.balloon_wrk.num_pages;
@@ -1368,6 +1377,7 @@ static void balloon_up(struct work_struct *dummy)
 		}
 	}
 
+	report_ballooned_pages(&dm_device);
 }
 
 static void balloon_down(struct hv_dynmem_device *dm,
@@ -1387,6 +1397,8 @@ static void balloon_down(struct hv_dynmem_device *dm,
 	pr_debug("Freed %u ballooned pages.\n",
 		prev_pages_ballooned - dm->num_pages_ballooned);
 
+	report_ballooned_pages(dm);
+
 	if (req->more_pages == 1)
 		return;
 
-- 
2.31.1


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

* [RFC PATCH v5 8/8] documentation: create a document about how balloon drivers operate
       [not found] <20221019095620.124909-1-alexander.atanasov@virtuozzo.com>
                   ` (6 preceding siblings ...)
  2022-10-19  9:56 ` [RFC PATCH v5 7/8] drivers: hyperv: " Alexander Atanasov
@ 2022-10-19  9:56 ` Alexander Atanasov
  2022-10-19 13:53   ` Jonathan Corbet
  7 siblings, 1 reply; 17+ messages in thread
From: Alexander Atanasov @ 2022-10-19  9:56 UTC (permalink / raw)
  To: Jonathan Corbet; +Cc: kernel, Alexander Atanasov, linux-doc, linux-kernel

Describe ballooning and how it works. Explain the two values
and why they are there.
Point the places where a user can see more balloon information and
how each driver operates.

Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
---
 Documentation/mm/balloon.rst | 138 +++++++++++++++++++++++++++++++++++
 1 file changed, 138 insertions(+)
 create mode 100644 Documentation/mm/balloon.rst

diff --git a/Documentation/mm/balloon.rst b/Documentation/mm/balloon.rst
new file mode 100644
index 000000000000..9fe9e7b228de
--- /dev/null
+++ b/Documentation/mm/balloon.rst
@@ -0,0 +1,138 @@
+===========================================
+Balloon: usage information visible by guest
+===========================================
+Background:
+===========
+The ballooning mechanism allows VM guests to reduce their memory size
+(thus relinquishing memory to the Host) and to increase it back (thus
+taking back memory from the Host).
+During OOM guest issues or guest low-performance issues
+investigations it is important to know if the Host has grabbed some of the
+Guest memory via the ballooning mechanism.
+
+Implementation description:
+===========================
+/proc/meminfo::
+
+  InflatedTotal:   2097152 kB
+  InflatedFree:          0 kB
+
+The difference comes from the way drivers account for inflated memory:
+ - Drivers that call adjust_managed_page_count InflateTotal
+ - Drivers that do NOT call adjust_managed_page_count InflateFree
+
+ * It is possible for one driver to operate in both modes depending on config options.
+
+
+The balloon statistics are also printed by show_mem() function, which
+is called on OOM condition or Alt+SysRQ+m is pressed.
+The show_mem() string is similar to /proc/meminfo and it is like::
+
+  Balloon InflatedTotal:XXXkB InflatedFree:YYYkB
+
+Additional balloon information is available via debugfs:
+ - KVM          features file: /sys/devices/pci\*/\*/virtio\*/features
+ - Hyper-V balloon guest file: /sys/kernel/debug/hv-balloon
+ - VMware  balloon guest file: /sys/kernel/debug/vmmemctl
+
+KVM balloon
+-----------
+The ballooning is implemented via virtio balloon device.
+Depending on the options the ballooned memory is accounted for in two ways:
+
+1. If deflate on OOM is enabled - ballooned memory is accounted as used.
+2. If deflate on OOM is not enabled - ballooned memory is subtracted
+   from total RAM.
+
+Q: How to check if "deflate on OOM" feature is enabled?
+A: Check balloon "features" file content.
+To decipher balloon bits are defined in include/uapi/linux/virtio_balloon.h
+Currently "deflate on OOM" feature is stored in the 2nd bit::
+  #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 2 /* Deflate balloon on OOM */
+Examples::
+
+  Without deflate on OOM:
+  # cat /sys/devices/pci0000:00/0000:00:03.0/virtio0/features
+  0100000000000000000000000000110010000000000000000000000000000000
+  With deflate on OOM:
+  # cat /sys/devices/pci0000:00/0000:00:03.0/virtio0/features
+  0110000000000000000000000000110010000000000000000000000000000000
+How to find virtio balloon device among other virtio devices?
+(check if the "virtio_balloon" module is loaded)::
+  # ls -l /sys/bus/virtio/drivers/virtio_balloon/virtio*
+    /sys/bus/virtio/drivers/virtio_balloon/virtio3 ->
+        ../../../../devices/pci0000:00/0000:00:07.0/virtio3
+
+To check virtio_balloon features::
+
+  # cat /sys/bus/virtio/drivers/virtio_balloon/virtio*/features
+  0110000000000000000000000000110010000000000000000000000000000000
+Balloon guest statistics output example::
+
+  # cat /sys/kernel/debug/virtio-balloon
+  InflatedTotal: 0 kB
+  InflatedFree: 0 kB
+
+- If "InflatedTotal" is not zero, it means the "deflate on OOM" feature is
+  **not** set and the provided amount of memory is subtracted from the total RAM
+  inside the Guest.
+- If "InflatedFree" is not zero, it means "deflate on OOM" feature is set and
+  the provided amount of memory is accounted as "used" inside the Guest.
+- Both "InflatedTotal" and "InflatedFree" cannot be non-zero at the same time.
+
+Hyper-V balloon
+---------------
+Balloon guest statistics output example::
+
+  # cat /sys/kernel/debug/hv-balloon
+  host_version : 2.0                // Hyper-V version the Guest is running under
+  capabilities : enabled hot_add
+  state : 1 (Initialized)
+  page_size : 4096
+  pages_added : 0                   // pages that are hot_add-ed to the Guest
+  pages_onlined : 0                 // pages that are added and then put online
+                                    // as available/used
+  pages_ballooned_out : 0           // pages the Host have taken back
+  vm_pages_commited : 795365        // total pages used by the Guest userspace
+  total_pages_commited : 977790     // total pages used by the Guest user+kernel
+  max_dynamic_page_count: 268435456 // maximum pages the Guest can have added
+                                    // via hot_add
+Hyper-V balloon driver changes the total RAM size reported by the Guest,
+thus the "InflatedTotal" counter will be non-zero in memory statistic
+reported during OOM or upon Alt+SysRQ+m.
+
+VMWare balloon
+---------------
+Balloon guest statistics output example::
+
+  # cat /sys/kernel/debug/vmmemctl
+  balloon capabilities: 0x1e
+  used capabilities: 0x6
+  is resetting: n
+  target: 0 pages
+  current: 0 pages
+  rateSleepAlloc: 2048 pages/sec
+  timer: 118
+  doorbell: 0
+  start: 1 ( 0 failed)
+  guestType: 1 ( 0 failed)
+  2m-lock: 0 ( 0 failed)
+  lock: 0 ( 0 failed)
+  2m-unlock: 0 ( 0 failed)
+  unlock: 0 ( 0 failed)
+  target: 118 ( 0 failed)
+  prim2mAlloc: 0 ( 0 failed)
+  primNoSleepAlloc: 0 ( 0 failed)
+  primCanSleepAlloc: 0 ( 0 failed)
+  prim2mFree: 0
+  primFree: 0
+  err2mAlloc: 0
+  errAlloc: 0
+  err2mFree: 0
+  errFree: 0
+  doorbellSet: 0
+  doorbellUnset: 1
+
+VMware balloon driver makes ballooned pages accounted as "used" in the
+Guest OS thus the "InflatedFree" counter will be non-zero in memory
+the statistic reported during OOM or upon Alt+SysRQ+m.
-- 
2.31.1


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

* Re: [RFC PATCH v5 6/8] drivers: vmware: balloon - report inflated memory
  2022-10-19  9:56 ` [RFC PATCH v5 6/8] drivers: vmware: " Alexander Atanasov
@ 2022-10-19 10:26   ` Greg Kroah-Hartman
  2022-10-19 10:38     ` Alexander Atanasov
  2022-10-21  6:50   ` Nadav Amit
  1 sibling, 1 reply; 17+ messages in thread
From: Greg Kroah-Hartman @ 2022-10-19 10:26 UTC (permalink / raw)
  To: Alexander Atanasov
  Cc: Nadav Amit, VMware PV-Drivers Reviewers, Arnd Bergmann, kernel,
	linux-kernel

On Wed, Oct 19, 2022 at 12:56:18PM +0300, Alexander Atanasov wrote:
> Update the inflated memory in the mm core on change.

That says what this does, but not why it is needed.

Please expand on this.

Also, is this actually fixing a bug?  Is it a new feature?  Something
else?

thanks,

greg k-h

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

* Re: [RFC PATCH v5 6/8] drivers: vmware: balloon - report inflated memory
  2022-10-19 10:26   ` Greg Kroah-Hartman
@ 2022-10-19 10:38     ` Alexander Atanasov
  2022-10-19 10:49       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 17+ messages in thread
From: Alexander Atanasov @ 2022-10-19 10:38 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Nadav Amit, VMware PV-Drivers Reviewers, Arnd Bergmann, kernel,
	linux-kernel

On 19.10.22 13:26, Greg Kroah-Hartman wrote:
> On Wed, Oct 19, 2022 at 12:56:18PM +0300, Alexander Atanasov wrote:
>> Update the inflated memory in the mm core on change.
> 
> That says what this does, but not why it is needed.
> 
> Please expand on this.
> 
> Also, is this actually fixing a bug?  Is it a new feature?  Something
> else?

The whole series is about adding a new feature - providing access to the 
balloon inflated memory amount - it's in the cover letter. Should I 
repeat it for every driver that implements it?

I've organized it classically:
- prepare
- add infra
- use the infra

What can I improve here?

-- 
Regards,
Alexander Atanasov


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

* Re: [RFC PATCH v5 6/8] drivers: vmware: balloon - report inflated memory
  2022-10-19 10:38     ` Alexander Atanasov
@ 2022-10-19 10:49       ` Greg Kroah-Hartman
  2022-10-19 11:06         ` Alexander Atanasov
  0 siblings, 1 reply; 17+ messages in thread
From: Greg Kroah-Hartman @ 2022-10-19 10:49 UTC (permalink / raw)
  To: Alexander Atanasov
  Cc: Nadav Amit, VMware PV-Drivers Reviewers, Arnd Bergmann, kernel,
	linux-kernel

On Wed, Oct 19, 2022 at 01:38:13PM +0300, Alexander Atanasov wrote:
> On 19.10.22 13:26, Greg Kroah-Hartman wrote:
> > On Wed, Oct 19, 2022 at 12:56:18PM +0300, Alexander Atanasov wrote:
> > > Update the inflated memory in the mm core on change.
> > 
> > That says what this does, but not why it is needed.
> > 
> > Please expand on this.
> > 
> > Also, is this actually fixing a bug?  Is it a new feature?  Something
> > else?
> 
> The whole series is about adding a new feature - providing access to the
> balloon inflated memory amount - it's in the cover letter. Should I repeat
> it for every driver that implements it?

Each commit needs to justify why it is needed on its own.  You do not
provide the needed information here at all to be able to review and
understand if this commit is even correct or needed.

thanks,

greg k-h

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

* Re: [RFC PATCH v5 6/8] drivers: vmware: balloon - report inflated memory
  2022-10-19 10:49       ` Greg Kroah-Hartman
@ 2022-10-19 11:06         ` Alexander Atanasov
  0 siblings, 0 replies; 17+ messages in thread
From: Alexander Atanasov @ 2022-10-19 11:06 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Nadav Amit, VMware PV-Drivers Reviewers, Arnd Bergmann, kernel,
	linux-kernel

On 19.10.22 13:49, Greg Kroah-Hartman wrote:
> On Wed, Oct 19, 2022 at 01:38:13PM +0300, Alexander Atanasov wrote:
>> On 19.10.22 13:26, Greg Kroah-Hartman wrote:
>>> On Wed, Oct 19, 2022 at 12:56:18PM +0300, Alexander Atanasov wrote:
>>>> Update the inflated memory in the mm core on change.
>>>
>>> That says what this does, but not why it is needed.
>>>
>>> Please expand on this.
>>>
>>> Also, is this actually fixing a bug?  Is it a new feature?  Something
>>> else?
>>
>> The whole series is about adding a new feature - providing access to the
>> balloon inflated memory amount - it's in the cover letter. Should I repeat
>> it for every driver that implements it?
> 
> Each commit needs to justify why it is needed on its own.  You do not
> provide the needed information here at all to be able to review and
> understand if this commit is even correct or needed.

Ok, understood. I will keep that in mind. Thanks.


-- 
Regards,
Alexander Atanasov


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

* Re: [RFC PATCH v5 8/8] documentation: create a document about how balloon drivers operate
  2022-10-19  9:56 ` [RFC PATCH v5 8/8] documentation: create a document about how balloon drivers operate Alexander Atanasov
@ 2022-10-19 13:53   ` Jonathan Corbet
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Corbet @ 2022-10-19 13:53 UTC (permalink / raw)
  To: Alexander Atanasov; +Cc: kernel, Alexander Atanasov, linux-doc, linux-kernel

Alexander Atanasov <alexander.atanasov@virtuozzo.com> writes:

> Describe ballooning and how it works. Explain the two values
> and why they are there.
> Point the places where a user can see more balloon information and
> how each driver operates.
>
> Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
> ---
>  Documentation/mm/balloon.rst | 138 +++++++++++++++++++++++++++++++++++
>  1 file changed, 138 insertions(+)
>  create mode 100644 Documentation/mm/balloon.rst

When you add a new RST file, you also need to add it to index.rst so
that it becomes part of the docs build.

Thanks,

jon

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

* Re: [RFC PATCH v5 6/8] drivers: vmware: balloon - report inflated memory
  2022-10-19  9:56 ` [RFC PATCH v5 6/8] drivers: vmware: " Alexander Atanasov
  2022-10-19 10:26   ` Greg Kroah-Hartman
@ 2022-10-21  6:50   ` Nadav Amit
  2022-10-21  7:25     ` Alexander Atanasov
  1 sibling, 1 reply; 17+ messages in thread
From: Nadav Amit @ 2022-10-21  6:50 UTC (permalink / raw)
  To: Alexander Atanasov
  Cc: Pv-drivers, Arnd Bergmann, Greg Kroah-Hartman, kernel, linux-kernel

On Oct 19, 2022, at 12:56 PM, Alexander Atanasov <alexander.atanasov@virtuozzo.com> wrote:

> Update the inflated memory in the mm core on change.
> 
> Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
> ---
> drivers/misc/vmw_balloon.c | 1 +
> 1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
> index 91d4d2a285c5..3bfd845898f5 100644
> --- a/drivers/misc/vmw_balloon.c
> +++ b/drivers/misc/vmw_balloon.c
> @@ -1507,6 +1507,7 @@ static void vmballoon_work(struct work_struct *work)
> 	queue_delayed_work(system_freezable_wq,
> 			   dwork, round_jiffies_relative(HZ));
> 
> +	balloon_set_inflated_free(atomic64_read(&b->size) << 2);
> }

I don’t like it in general (I think that something like that should go into
some common infra).

But more concretely there are at least 2 problems here. First, queueing the
work should come last. Second, there are other places that change the
balloon size (e.g., vmballoon_reset()), which are not handled by this patch.

If you added calls to balloon_set_inflated_free() from these places, you can
get races while calling balloon_set_inflated_free() and the last value that
would be latched would be the wrong one. I don’t see anything in the logic
or comments that clarify how something like that should be resolved.


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

* Re: [RFC PATCH v5 6/8] drivers: vmware: balloon - report inflated memory
  2022-10-21  6:50   ` Nadav Amit
@ 2022-10-21  7:25     ` Alexander Atanasov
  2022-10-21  7:31       ` Nadav Amit
  0 siblings, 1 reply; 17+ messages in thread
From: Alexander Atanasov @ 2022-10-21  7:25 UTC (permalink / raw)
  To: Nadav Amit
  Cc: Pv-drivers, Arnd Bergmann, Greg Kroah-Hartman, kernel, linux-kernel

On 21.10.22 9:50, Nadav Amit wrote:
> On Oct 19, 2022, at 12:56 PM, Alexander Atanasov <alexander.atanasov@virtuozzo.com> wrote:
> 
>> Update the inflated memory in the mm core on change.
>>
>> Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
>> ---
>> drivers/misc/vmw_balloon.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
>> index 91d4d2a285c5..3bfd845898f5 100644
>> --- a/drivers/misc/vmw_balloon.c
>> +++ b/drivers/misc/vmw_balloon.c
>> @@ -1507,6 +1507,7 @@ static void vmballoon_work(struct work_struct *work)
>> 	queue_delayed_work(system_freezable_wq,
>> 			   dwork, round_jiffies_relative(HZ));
>>
>> +	balloon_set_inflated_free(atomic64_read(&b->size) << 2);
>> }
> 
> I don’t like it in general (I think that something like that should go into
> some common infra).

My goal is to create that infra, sure there is a place for improvement.
I think of it as a commit point so plugging it into something existing 
does not fit or at least i don't see how.

> But more concretely there are at least 2 problems here. First, queueing the
> work should come last. Second, there are other places that change the
> balloon size (e.g., vmballoon_reset()), which are not handled by this patch.
> 
> If you added calls to balloon_set_inflated_free() from these places, you can
> get races while calling balloon_set_inflated_free() and the last value that
> would be latched would be the wrong one. I don’t see anything in the logic
> or comments that clarify how something like that should be resolved.
>


Ok,I will move it before the enqueue call.
But are you sure about this the reset?
vmballoon_reset(...) is called only from vmballoon_work(...) which does 
the update ? what i am missing?


-- 
Regards,
Alexander Atanasov


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

* Re: [RFC PATCH v5 6/8] drivers: vmware: balloon - report inflated memory
  2022-10-21  7:25     ` Alexander Atanasov
@ 2022-10-21  7:31       ` Nadav Amit
  2022-10-21  8:02         ` Alexander Atanasov
  0 siblings, 1 reply; 17+ messages in thread
From: Nadav Amit @ 2022-10-21  7:31 UTC (permalink / raw)
  To: Alexander Atanasov
  Cc: Pv-drivers, Arnd Bergmann, Greg Kroah-Hartman, kernel, linux-kernel

On Oct 21, 2022, at 10:25 AM, Alexander Atanasov <alexander.atanasov@virtuozzo.com> wrote:

> 
> Ok,I will move it before the enqueue call.
> But are you sure about this the reset?
> vmballoon_reset(...) is called only from vmballoon_work(...) which does
> the update ? what i am missing?

My bad. But when the module is unloaded, vmballoon_pop() is called.


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

* Re: [RFC PATCH v5 6/8] drivers: vmware: balloon - report inflated memory
  2022-10-21  7:31       ` Nadav Amit
@ 2022-10-21  8:02         ` Alexander Atanasov
  0 siblings, 0 replies; 17+ messages in thread
From: Alexander Atanasov @ 2022-10-21  8:02 UTC (permalink / raw)
  To: Nadav Amit
  Cc: Pv-drivers, Arnd Bergmann, Greg Kroah-Hartman, kernel, linux-kernel

On 21.10.22 10:31, Nadav Amit wrote:
> On Oct 21, 2022, at 10:25 AM, Alexander Atanasov <alexander.atanasov@virtuozzo.com> wrote:
> 
>>
>> Ok,I will move it before the enqueue call.
>> But are you sure about this the reset?
>> vmballoon_reset(...) is called only from vmballoon_work(...) which does
>> the update ? what i am missing?
> 
> My bad. But when the module is unloaded, vmballoon_pop() is called.

Yes, i missed the unload -  i will just set it to zero there.


-- 
Regards,
Alexander Atanasov


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

end of thread, other threads:[~2022-10-21  8:03 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20221019095620.124909-1-alexander.atanasov@virtuozzo.com>
2022-10-19  9:56 ` [RFC PATCH v5 1/8] mm: Make a place for a common balloon code Alexander Atanasov
2022-10-19  9:56 ` [RFC PATCH v5 2/8] mm: Enable balloon drivers to report inflated memory Alexander Atanasov
2022-10-19  9:56 ` [RFC PATCH v5 3/8] mm: Display inflated memory to users Alexander Atanasov
2022-10-19  9:56 ` [RFC PATCH v5 4/8] mm: Display inflated memory in logs Alexander Atanasov
2022-10-19  9:56 ` [RFC PATCH v5 5/8] drivers: virtio: balloon - report inflated memory Alexander Atanasov
2022-10-19  9:56 ` [RFC PATCH v5 6/8] drivers: vmware: " Alexander Atanasov
2022-10-19 10:26   ` Greg Kroah-Hartman
2022-10-19 10:38     ` Alexander Atanasov
2022-10-19 10:49       ` Greg Kroah-Hartman
2022-10-19 11:06         ` Alexander Atanasov
2022-10-21  6:50   ` Nadav Amit
2022-10-21  7:25     ` Alexander Atanasov
2022-10-21  7:31       ` Nadav Amit
2022-10-21  8:02         ` Alexander Atanasov
2022-10-19  9:56 ` [RFC PATCH v5 7/8] drivers: hyperv: " Alexander Atanasov
2022-10-19  9:56 ` [RFC PATCH v5 8/8] documentation: create a document about how balloon drivers operate Alexander Atanasov
2022-10-19 13:53   ` Jonathan Corbet

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).