[RFC PATCH v5 0/8] Make balloon drivers' memory changes known to the rest of the kernel

Alexander Atanasov posted 8 patches 1 year, 6 months ago
Only 0 patches received!
Documentation/filesystems/proc.rst            |   6 +
Documentation/mm/balloon.rst                  | 138 ++++++++++++++++++
MAINTAINERS                                   |   4 +-
arch/powerpc/platforms/pseries/cmm.c          |   2 +-
drivers/hv/hv_balloon.c                       |  12 ++
drivers/misc/vmw_balloon.c                    |   3 +-
drivers/virtio/virtio_balloon.c               |   7 +-
fs/proc/meminfo.c                             |  10 ++
.../linux/{balloon_compaction.h => balloon.h} |  18 ++-
lib/show_mem.c                                |   8 +
mm/Makefile                                   |   2 +-
mm/{balloon_compaction.c => balloon.c}        |  19 ++-
mm/migrate.c                                  |   1 -
mm/vmscan.c                                   |   1 -
14 files changed, 213 insertions(+), 18 deletions(-)
create mode 100644 Documentation/mm/balloon.rst
rename include/linux/{balloon_compaction.h => balloon.h} (91%)
rename mm/{balloon_compaction.c => balloon.c} (94%)
[RFC PATCH v5 0/8] Make balloon drivers' memory changes known to the rest of the kernel
Posted by Alexander Atanasov 1 year, 6 months ago
Currently balloon drivers (Virtio,XEN, HyperV, VMWare, ...)
inflate and deflate the guest memory size but there is no
way to know how much the memory size is changed by them.

Make it possible for the drivers to report the values to mm core.

Display reported InflatedTotal and InflatedFree in /proc/meminfo
and print these values on OOM and sysrq from show_mem().

The two values are the result of the two modes the drivers work
with using adjust_managed_page_count or without.

In earlier versions, there was a notifier for these changes
but after discussion - it is better to implement it in separate
patch series. Since it came out as larger work than initially expected.

Amount of inflated memory can be used:
 - totalram_pages() users working with drivers not using
    adjust_managed_page_count
 - si_meminfo(..) users can improve calculations
 - by userspace software that monitors memory pressure

Alexander Atanasov (8):
  mm: Make a place for a common balloon code
  mm: Enable balloon drivers to report inflated memory
  mm: Display inflated memory to users
  mm: Display inflated memory in logs
  drivers: virtio: balloon - report inflated memory
  drivers: vmware: balloon - report inflated memory
  drivers: hyperv: balloon - report inflated memory
  documentation: create a document about how balloon drivers operate

 Documentation/filesystems/proc.rst            |   6 +
 Documentation/mm/balloon.rst                  | 138 ++++++++++++++++++
 MAINTAINERS                                   |   4 +-
 arch/powerpc/platforms/pseries/cmm.c          |   2 +-
 drivers/hv/hv_balloon.c                       |  12 ++
 drivers/misc/vmw_balloon.c                    |   3 +-
 drivers/virtio/virtio_balloon.c               |   7 +-
 fs/proc/meminfo.c                             |  10 ++
 .../linux/{balloon_compaction.h => balloon.h} |  18 ++-
 lib/show_mem.c                                |   8 +
 mm/Makefile                                   |   2 +-
 mm/{balloon_compaction.c => balloon.c}        |  19 ++-
 mm/migrate.c                                  |   1 -
 mm/vmscan.c                                   |   1 -
 14 files changed, 213 insertions(+), 18 deletions(-)
 create mode 100644 Documentation/mm/balloon.rst
 rename include/linux/{balloon_compaction.h => balloon.h} (91%)
 rename mm/{balloon_compaction.c => balloon.c} (94%)

v4->v5:
 - removed notifier
 - added documentation
 - vmware update after op is done , outside of the mutex
v3->v4:
 - add support in hyperV and vmware balloon drivers
 - display balloon memory in show_mem so it is logged on OOM and on sysrq
v2->v3:
 - added missed EXPORT_SYMBOLS
Reported-by: kernel test robot <lkp@intel.com>
 - instead of balloon_common.h just use balloon.h (yes, naming is hard)
 - cleaned up balloon.h - remove from files that do not use it and
   remove externs from function declarations
v1->v2:
 - reworked from simple /proc/meminfo addition

Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Nadav Amit <namit@vmware.com>
Cc: pv-drivers@vmware.com
Cc: Jason Wang <jasowang@redhat.com>
Cc: virtualization@lists.linux-foundation.org
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: linux-hyperv@vger.kernel.org
Cc: Juergen Gross <jgross@suse.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Cc: xen-devel@lists.xenproject.org

base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780
-- 
2.31.1
Re: [RFC PATCH v5 0/8] Make balloon drivers' memory changes known to the rest of the kernel
Posted by Konstantin Khlebnikov 1 year, 6 months ago
On Wed, 19 Oct 2022 at 12:57, Alexander Atanasov <
alexander.atanasov@virtuozzo.com> wrote:

> Currently balloon drivers (Virtio,XEN, HyperV, VMWare, ...)
> inflate and deflate the guest memory size but there is no
> way to know how much the memory size is changed by them.
>
> Make it possible for the drivers to report the values to mm core.
>
> Display reported InflatedTotal and InflatedFree in /proc/meminfo
> and print these values on OOM and sysrq from show_mem().
>
> The two values are the result of the two modes the drivers work
> with using adjust_managed_page_count or without.
>
> In earlier versions, there was a notifier for these changes
> but after discussion - it is better to implement it in separate
> patch series. Since it came out as larger work than initially expected.
>
> Amount of inflated memory can be used:
>  - totalram_pages() users working with drivers not using
>     adjust_managed_page_count
>  - si_meminfo(..) users can improve calculations
>  - by userspace software that monitors memory pressure
>

Sorry, I see no reason for that series.
Balloon inflation adjusts totalram_pages. That's enough.

There is no reason to know the amount of non-existent ballooned memory
inside.
Management software which works outside should care about that.

For debugging you could get current balloon size from /proc/vmstat
(balloon_inflate - balloon_deflate).
Also (I guess) /proc/kpageflags has a bit for that.

Anyway it's easy to monitor balloon inflation by seeing changes of total
memory size.


>
> Alexander Atanasov (8):
>   mm: Make a place for a common balloon code
>   mm: Enable balloon drivers to report inflated memory
>   mm: Display inflated memory to users
>   mm: Display inflated memory in logs
>   drivers: virtio: balloon - report inflated memory
>   drivers: vmware: balloon - report inflated memory
>   drivers: hyperv: balloon - report inflated memory
>   documentation: create a document about how balloon drivers operate
>
>  Documentation/filesystems/proc.rst            |   6 +
>  Documentation/mm/balloon.rst                  | 138 ++++++++++++++++++
>  MAINTAINERS                                   |   4 +-
>  arch/powerpc/platforms/pseries/cmm.c          |   2 +-
>  drivers/hv/hv_balloon.c                       |  12 ++
>  drivers/misc/vmw_balloon.c                    |   3 +-
>  drivers/virtio/virtio_balloon.c               |   7 +-
>  fs/proc/meminfo.c                             |  10 ++
>  .../linux/{balloon_compaction.h => balloon.h} |  18 ++-
>  lib/show_mem.c                                |   8 +
>  mm/Makefile                                   |   2 +-
>  mm/{balloon_compaction.c => balloon.c}        |  19 ++-
>  mm/migrate.c                                  |   1 -
>  mm/vmscan.c                                   |   1 -
>  14 files changed, 213 insertions(+), 18 deletions(-)
>  create mode 100644 Documentation/mm/balloon.rst
>  rename include/linux/{balloon_compaction.h => balloon.h} (91%)
>  rename mm/{balloon_compaction.c => balloon.c} (94%)
>
> v4->v5:
>  - removed notifier
>  - added documentation
>  - vmware update after op is done , outside of the mutex
> v3->v4:
>  - add support in hyperV and vmware balloon drivers
>  - display balloon memory in show_mem so it is logged on OOM and on sysrq
> v2->v3:
>  - added missed EXPORT_SYMBOLS
> Reported-by: kernel test robot <lkp@intel.com>
>  - instead of balloon_common.h just use balloon.h (yes, naming is hard)
>  - cleaned up balloon.h - remove from files that do not use it and
>    remove externs from function declarations
> v1->v2:
>  - reworked from simple /proc/meminfo addition
>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Wei Liu <wei.liu@kernel.org>
> Cc: Nadav Amit <namit@vmware.com>
> Cc: pv-drivers@vmware.com
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: virtualization@lists.linux-foundation.org
> Cc: "K. Y. Srinivasan" <kys@microsoft.com>
> Cc: Haiyang Zhang <haiyangz@microsoft.com>
> Cc: Stephen Hemminger <sthemmin@microsoft.com>
> Cc: Dexuan Cui <decui@microsoft.com>
> Cc: linux-hyperv@vger.kernel.org
> Cc: Juergen Gross <jgross@suse.com>
> Cc: Stefano Stabellini <sstabellini@kernel.org>
> Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> Cc: xen-devel@lists.xenproject.org
>
> base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780
> --
> 2.31.1
>
>
Re: [RFC PATCH v5 0/8] Make balloon drivers' memory changes known to the rest of the kernel
Posted by Alexander Atanasov 1 year, 6 months ago
On 19.10.22 13:53, Konstantin Khlebnikov wrote:
> On Wed, 19 Oct 2022 at 12:57, Alexander Atanasov 
> <alexander.atanasov@virtuozzo.com 
> <mailto:alexander.atanasov@virtuozzo.com>> wrote:
> 
>     Currently balloon drivers (Virtio,XEN, HyperV, VMWare, ...)
>     inflate and deflate the guest memory size but there is no
>     way to know how much the memory size is changed by them.
> 
>     Make it possible for the drivers to report the values to mm core.
> 
>     Display reported InflatedTotal and InflatedFree in /proc/meminfo
>     and print these values on OOM and sysrq from show_mem().
> 
>     The two values are the result of the two modes the drivers work
>     with using adjust_managed_page_count or without.
> 
>     In earlier versions, there was a notifier for these changes
>     but after discussion - it is better to implement it in separate
>     patch series. Since it came out as larger work than initially expected.
> 
>     Amount of inflated memory can be used:
>       - totalram_pages() users working with drivers not using
>          adjust_managed_page_count
>       - si_meminfo(..) users can improve calculations
>       - by userspace software that monitors memory pressure
> 
> 
> Sorry, I see no reason for that series.
> Balloon inflation adjusts totalram_pages. That's enough.

That is not true in all cases - some do some do not.

> 
> There is no reason to know the amount of non-existent ballooned memory 
> inside.

Why? Memory managment is becoming more and more dynamic - to make it 
easy and accurate you need to know that amount. The kernel itself
on boot pre-allocates caches and sets limits based on total ram at boot 
time when balloon steals half of the memory these initial calculations 
become very wrong. To redo them correctly these amounts need to be 
known. The idea of doing this is thru a notifier chain in a separte series.

> Management software which works outside should care about that.
> 
> For debugging you could get current balloon size from /proc/vmstat 
> (balloon_inflate - balloon_deflate).

Currently you can do that only if using VMWare balloon.

> Also (I guess) /proc/kpageflags has a bit for that.
> 
> Anyway it's easy to monitor balloon inflation by seeing changes of total 
> memory size.

Not all drivers do that - VMWare and virtio (in one case) for example do 
not. I proposed to unify them but since it can break existing users it 
was NAKed.

> 
>     Alexander Atanasov (8):
>        mm: Make a place for a common balloon code
>        mm: Enable balloon drivers to report inflated memory
>        mm: Display inflated memory to users
>        mm: Display inflated memory in logs
>        drivers: virtio: balloon - report inflated memory
>        drivers: vmware: balloon - report inflated memory
>        drivers: hyperv: balloon - report inflated memory
>        documentation: create a document about how balloon drivers operate
> 
>       Documentation/filesystems/proc.rst            |   6 +
>       Documentation/mm/balloon.rst                  | 138 ++++++++++++++++++
>       MAINTAINERS                                   |   4 +-
>       arch/powerpc/platforms/pseries/cmm.c          |   2 +-
>       drivers/hv/hv_balloon.c                       |  12 ++
>       drivers/misc/vmw_balloon.c                    |   3 +-
>       drivers/virtio/virtio_balloon.c               |   7 +-
>       fs/proc/meminfo.c                             |  10 ++
>       .../linux/{balloon_compaction.h => balloon.h} |  18 ++-
>       lib/show_mem.c                                |   8 +
>       mm/Makefile                                   |   2 +-
>       mm/{balloon_compaction.c => balloon.c}        |  19 ++-
>       mm/migrate.c                                  |   1 -
>       mm/vmscan.c                                   |   1 -
>       14 files changed, 213 insertions(+), 18 deletions(-)
>       create mode 100644 Documentation/mm/balloon.rst
>       rename include/linux/{balloon_compaction.h => balloon.h} (91%)
>       rename mm/{balloon_compaction.c => balloon.c} (94%)
> 
>     v4->v5:
>       - removed notifier
>       - added documentation
>       - vmware update after op is done , outside of the mutex
>     v3->v4:
>       - add support in hyperV and vmware balloon drivers
>       - display balloon memory in show_mem so it is logged on OOM and on
>     sysrq
>     v2->v3:
>       - added missed EXPORT_SYMBOLS
>     Reported-by: kernel test robot <lkp@intel.com <mailto:lkp@intel.com>>
>       - instead of balloon_common.h just use balloon.h (yes, naming is hard)
>       - cleaned up balloon.h - remove from files that do not use it and
>         remove externs from function declarations
>     v1->v2:
>       - reworked from simple /proc/meminfo addition
> 
>     Cc: Michael S. Tsirkin <mst@redhat.com <mailto:mst@redhat.com>>
>     Cc: David Hildenbrand <david@redhat.com <mailto:david@redhat.com>>
>     Cc: Wei Liu <wei.liu@kernel.org <mailto:wei.liu@kernel.org>>
>     Cc: Nadav Amit <namit@vmware.com <mailto:namit@vmware.com>>
>     Cc: pv-drivers@vmware.com <mailto:pv-drivers@vmware.com>
>     Cc: Jason Wang <jasowang@redhat.com <mailto:jasowang@redhat.com>>
>     Cc: virtualization@lists.linux-foundation.org
>     <mailto:virtualization@lists.linux-foundation.org>
>     Cc: "K. Y. Srinivasan" <kys@microsoft.com <mailto:kys@microsoft.com>>
>     Cc: Haiyang Zhang <haiyangz@microsoft.com
>     <mailto:haiyangz@microsoft.com>>
>     Cc: Stephen Hemminger <sthemmin@microsoft.com
>     <mailto:sthemmin@microsoft.com>>
>     Cc: Dexuan Cui <decui@microsoft.com <mailto:decui@microsoft.com>>
>     Cc: linux-hyperv@vger.kernel.org <mailto:linux-hyperv@vger.kernel.org>
>     Cc: Juergen Gross <jgross@suse.com <mailto:jgross@suse.com>>
>     Cc: Stefano Stabellini <sstabellini@kernel.org
>     <mailto:sstabellini@kernel.org>>
>     Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com
>     <mailto:oleksandr_tyshchenko@epam.com>>
>     Cc: xen-devel@lists.xenproject.org
>     <mailto:xen-devel@lists.xenproject.org>
> 
>     base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780
>     -- 
>     2.31.1
> 

-- 
Regards,
Alexander Atanasov


Re: [RFC PATCH v5 0/8] Make balloon drivers' memory changes known to the rest of the kernel
Posted by Denis V. Lunev 1 year, 6 months ago
On 10/19/22 12:53, Konstantin Khlebnikov wrote:
> On Wed, 19 Oct 2022 at 12:57, Alexander Atanasov 
> <alexander.atanasov@virtuozzo.com> wrote:
>
>     Currently balloon drivers (Virtio,XEN, HyperV, VMWare, ...)
>     inflate and deflate the guest memory size but there is no
>     way to know how much the memory size is changed by them.
>
>     Make it possible for the drivers to report the values to mm core.
>
>     Display reported InflatedTotal and InflatedFree in /proc/meminfo
>     and print these values on OOM and sysrq from show_mem().
>
>     The two values are the result of the two modes the drivers work
>     with using adjust_managed_page_count or without.
>
>     In earlier versions, there was a notifier for these changes
>     but after discussion - it is better to implement it in separate
>     patch series. Since it came out as larger work than initially
>     expected.
>
>     Amount of inflated memory can be used:
>      - totalram_pages() users working with drivers not using
>         adjust_managed_page_count
>      - si_meminfo(..) users can improve calculations
>      - by userspace software that monitors memory pressure
>
>
> Sorry, I see no reason for that series.
> Balloon inflation adjusts totalram_pages. That's enough.
>
no, they are not at least under some circumstances, f.e.
virtio balloon does not do that with VIRTIO_BALLOON_F_DEFLATE_ON_OOM
set

> There is no reason to know the amount of non-existent ballooned memory 
> inside.
> Management software which works outside should care about that.
>
The problem comes at the moment when we are running
our Linux server inside virtual machine and the customer
comes with crazy questions "where our memory?".

> For debugging you could get current balloon size from /proc/vmstat 
> (balloon_inflate - balloon_deflate).
> Also (I guess) /proc/kpageflags has a bit for that.
>
> Anyway it's easy to monitor balloon inflation by seeing changes of 
> total memory size.
for monitoring - may be. But in order to report total amount
there is no interface so far.

>
>     Alexander Atanasov (8):
>       mm: Make a place for a common balloon code
>       mm: Enable balloon drivers to report inflated memory
>       mm: Display inflated memory to users
>       mm: Display inflated memory in logs
>       drivers: virtio: balloon - report inflated memory
>       drivers: vmware: balloon - report inflated memory
>       drivers: hyperv: balloon - report inflated memory
>       documentation: create a document about how balloon drivers operate
>
>      Documentation/filesystems/proc.rst            |   6 +
>      Documentation/mm/balloon.rst                  | 138
>     ++++++++++++++++++
>      MAINTAINERS                                   |   4 +-
>      arch/powerpc/platforms/pseries/cmm.c          |   2 +-
>      drivers/hv/hv_balloon.c                       |  12 ++
>      drivers/misc/vmw_balloon.c                    |   3 +-
>      drivers/virtio/virtio_balloon.c               |   7 +-
>      fs/proc/meminfo.c                             |  10 ++
>      .../linux/{balloon_compaction.h => balloon.h} |  18 ++-
>      lib/show_mem.c                                |   8 +
>      mm/Makefile                                   |   2 +-
>      mm/{balloon_compaction.c => balloon.c}        |  19 ++-
>      mm/migrate.c                                  |   1 -
>      mm/vmscan.c                                   |   1 -
>      14 files changed, 213 insertions(+), 18 deletions(-)
>      create mode 100644 Documentation/mm/balloon.rst
>      rename include/linux/{balloon_compaction.h => balloon.h} (91%)
>      rename mm/{balloon_compaction.c => balloon.c} (94%)
>
>     v4->v5:
>      - removed notifier
>      - added documentation
>      - vmware update after op is done , outside of the mutex
>     v3->v4:
>      - add support in hyperV and vmware balloon drivers
>      - display balloon memory in show_mem so it is logged on OOM and
>     on sysrq
>     v2->v3:
>      - added missed EXPORT_SYMBOLS
>     Reported-by: kernel test robot <lkp@intel.com>
>      - instead of balloon_common.h just use balloon.h (yes, naming is
>     hard)
>      - cleaned up balloon.h - remove from files that do not use it and
>        remove externs from function declarations
>     v1->v2:
>      - reworked from simple /proc/meminfo addition
>
>     Cc: Michael S. Tsirkin <mst@redhat.com>
>     Cc: David Hildenbrand <david@redhat.com>
>     Cc: Wei Liu <wei.liu@kernel.org>
>     Cc: Nadav Amit <namit@vmware.com>
>     Cc: pv-drivers@vmware.com
>     Cc: Jason Wang <jasowang@redhat.com>
>     Cc: virtualization@lists.linux-foundation.org
>     Cc: "K. Y. Srinivasan" <kys@microsoft.com>
>     Cc: Haiyang Zhang <haiyangz@microsoft.com>
>     Cc: Stephen Hemminger <sthemmin@microsoft.com>
>     Cc: Dexuan Cui <decui@microsoft.com>
>     Cc: linux-hyperv@vger.kernel.org
>     Cc: Juergen Gross <jgross@suse.com>
>     Cc: Stefano Stabellini <sstabellini@kernel.org>
>     Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
>     Cc: xen-devel@lists.xenproject.org
>
>     base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780
>     -- 
>     2.31.1
>


Re: [RFC PATCH v5 0/8] Make balloon drivers' memory changes known to the rest of the kernel
Posted by Konstantin Khlebnikov 1 year, 6 months ago
On Wed, 19 Oct 2022 at 14:06, Denis V. Lunev <den@virtuozzo.com> wrote:

> On 10/19/22 12:53, Konstantin Khlebnikov wrote:
> > On Wed, 19 Oct 2022 at 12:57, Alexander Atanasov
> > <alexander.atanasov@virtuozzo.com> wrote:
> >
> >     Currently balloon drivers (Virtio,XEN, HyperV, VMWare, ...)
> >     inflate and deflate the guest memory size but there is no
> >     way to know how much the memory size is changed by them.
> >
> >     Make it possible for the drivers to report the values to mm core.
> >
> >     Display reported InflatedTotal and InflatedFree in /proc/meminfo
> >     and print these values on OOM and sysrq from show_mem().
> >
> >     The two values are the result of the two modes the drivers work
> >     with using adjust_managed_page_count or without.
> >
> >     In earlier versions, there was a notifier for these changes
> >     but after discussion - it is better to implement it in separate
> >     patch series. Since it came out as larger work than initially
> >     expected.
> >
> >     Amount of inflated memory can be used:
> >      - totalram_pages() users working with drivers not using
> >         adjust_managed_page_count
> >      - si_meminfo(..) users can improve calculations
> >      - by userspace software that monitors memory pressure
> >
> >
> > Sorry, I see no reason for that series.
> > Balloon inflation adjusts totalram_pages. That's enough.
> >
> no, they are not at least under some circumstances, f.e.
> virtio balloon does not do that with VIRTIO_BALLOON_F_DEFLATE_ON_OOM
> set
>

> > There is no reason to know the amount of non-existent ballooned memory
> > inside.
> > Management software which works outside should care about that.
> >
> The problem comes at the moment when we are running
> our Linux server inside virtual machine and the customer
> comes with crazy questions "where our memory?".
>

Ok. In this case balloon management is partially inside VM.
I.e. we could report portion of balloon as potentially available memory.

I guess memory pressure could deflate balloon till some threshold set by
external hypervisor.
So, without knowledge about this threshold there is no correct answer about
size of available memory.
Showing just size of balloon doesn't gives much.


>
> > For debugging you could get current balloon size from /proc/vmstat
> > (balloon_inflate - balloon_deflate).
> > Also (I guess) /proc/kpageflags has a bit for that.
> >
> > Anyway it's easy to monitor balloon inflation by seeing changes of
> > total memory size.
> for monitoring - may be. But in order to report total amount
> there is no interface so far.
>
> >
> >     Alexander Atanasov (8):
> >       mm: Make a place for a common balloon code
> >       mm: Enable balloon drivers to report inflated memory
> >       mm: Display inflated memory to users
> >       mm: Display inflated memory in logs
> >       drivers: virtio: balloon - report inflated memory
> >       drivers: vmware: balloon - report inflated memory
> >       drivers: hyperv: balloon - report inflated memory
> >       documentation: create a document about how balloon drivers operate
> >
> >      Documentation/filesystems/proc.rst            |   6 +
> >      Documentation/mm/balloon.rst                  | 138
> >     ++++++++++++++++++
> >      MAINTAINERS                                   |   4 +-
> >      arch/powerpc/platforms/pseries/cmm.c          |   2 +-
> >      drivers/hv/hv_balloon.c                       |  12 ++
> >      drivers/misc/vmw_balloon.c                    |   3 +-
> >      drivers/virtio/virtio_balloon.c               |   7 +-
> >      fs/proc/meminfo.c                             |  10 ++
> >      .../linux/{balloon_compaction.h => balloon.h} |  18 ++-
> >      lib/show_mem.c                                |   8 +
> >      mm/Makefile                                   |   2 +-
> >      mm/{balloon_compaction.c => balloon.c}        |  19 ++-
> >      mm/migrate.c                                  |   1 -
> >      mm/vmscan.c                                   |   1 -
> >      14 files changed, 213 insertions(+), 18 deletions(-)
> >      create mode 100644 Documentation/mm/balloon.rst
> >      rename include/linux/{balloon_compaction.h => balloon.h} (91%)
> >      rename mm/{balloon_compaction.c => balloon.c} (94%)
> >
> >     v4->v5:
> >      - removed notifier
> >      - added documentation
> >      - vmware update after op is done , outside of the mutex
> >     v3->v4:
> >      - add support in hyperV and vmware balloon drivers
> >      - display balloon memory in show_mem so it is logged on OOM and
> >     on sysrq
> >     v2->v3:
> >      - added missed EXPORT_SYMBOLS
> >     Reported-by: kernel test robot <lkp@intel.com>
> >      - instead of balloon_common.h just use balloon.h (yes, naming is
> >     hard)
> >      - cleaned up balloon.h - remove from files that do not use it and
> >        remove externs from function declarations
> >     v1->v2:
> >      - reworked from simple /proc/meminfo addition
> >
> >     Cc: Michael S. Tsirkin <mst@redhat.com>
> >     Cc: David Hildenbrand <david@redhat.com>
> >     Cc: Wei Liu <wei.liu@kernel.org>
> >     Cc: Nadav Amit <namit@vmware.com>
> >     Cc: pv-drivers@vmware.com
> >     Cc: Jason Wang <jasowang@redhat.com>
> >     Cc: virtualization@lists.linux-foundation.org
> >     Cc: "K. Y. Srinivasan" <kys@microsoft.com>
> >     Cc: Haiyang Zhang <haiyangz@microsoft.com>
> >     Cc: Stephen Hemminger <sthemmin@microsoft.com>
> >     Cc: Dexuan Cui <decui@microsoft.com>
> >     Cc: linux-hyperv@vger.kernel.org
> >     Cc: Juergen Gross <jgross@suse.com>
> >     Cc: Stefano Stabellini <sstabellini@kernel.org>
> >     Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> >     Cc: xen-devel@lists.xenproject.org
> >
> >     base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780
> >     --
> >     2.31.1
> >
>
>
Re: [RFC PATCH v5 0/8] Make balloon drivers' memory changes known to the rest of the kernel
Posted by Alexander Atanasov 1 year, 6 months ago
On 19.10.22 18:39, Konstantin Khlebnikov wrote:
> 
> 
> On Wed, 19 Oct 2022 at 14:06, Denis V. Lunev <den@virtuozzo.com 
> <mailto:den@virtuozzo.com>> wrote:
> 
>     On 10/19/22 12:53, Konstantin Khlebnikov wrote:
>      > On Wed, 19 Oct 2022 at 12:57, Alexander Atanasov
>      > <alexander.atanasov@virtuozzo.com
>     <mailto:alexander.atanasov@virtuozzo.com>> wrote:
>      >
>      >     Currently balloon drivers (Virtio,XEN, HyperV, VMWare, ...)
>      >     inflate and deflate the guest memory size but there is no
>      >     way to know how much the memory size is changed by them.
>      >
>      >     Make it possible for the drivers to report the values to mm core.
>      >
>      >     Display reported InflatedTotal and InflatedFree in /proc/meminfo
>      >     and print these values on OOM and sysrq from show_mem().
>      >
>      >     The two values are the result of the two modes the drivers work
>      >     with using adjust_managed_page_count or without.
>      >
>      >     In earlier versions, there was a notifier for these changes
>      >     but after discussion - it is better to implement it in separate
>      >     patch series. Since it came out as larger work than initially
>      >     expected.
>      >
>      >     Amount of inflated memory can be used:
>      >      - totalram_pages() users working with drivers not using
>      >         adjust_managed_page_count
>      >      - si_meminfo(..) users can improve calculations
>      >      - by userspace software that monitors memory pressure
>      >
>      >
>      > Sorry, I see no reason for that series.
>      > Balloon inflation adjusts totalram_pages. That's enough.
>      >
>     no, they are not at least under some circumstances, f.e.
>     virtio balloon does not do that with VIRTIO_BALLOON_F_DEFLATE_ON_OOM
>     set
> 
> 
>      > There is no reason to know the amount of non-existent ballooned
>     memory
>      > inside.
>      > Management software which works outside should care about that.
>      >
>     The problem comes at the moment when we are running
>     our Linux server inside virtual machine and the customer
>     comes with crazy questions "where our memory?".
> 
> 
> Ok. In this case balloon management is partially inside VM.
> I.e. we could report portion of balloon as potentially available memory.
> 
> I guess memory pressure could deflate balloon till some threshold set by 
> external hypervisor.
> So, without knowledge about this threshold there is no correct answer 
> about size of available memory.
> Showing just size of balloon doesn't gives much.

You need the current and the adjustment to get the absolute top.
If you check only totalram_pages() it is the current. To get the 
absolute maximum you need to know how much the balloon adjusted it.

The drivers that do not adjust totalram_pages() and leave the inflated 
memory as used assume that this memory can be reclaimed at anytime.
But that assumption is not completely true and provides the system with 
false totalram value. Why - VMWare does not have oom_notifier at all (it 
is possible to have sone other mechanism, i do not know), Virtio balloon 
reclaims 1MB on OOM _if_ it can.

-- 
Regards,
Alexander Atanasov