mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
To: David Hildenbrand <david@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>
Cc: kernel@openvz.org, virtualization@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org, stevensd@chromium.org,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Juergen Gross <jgross@suse.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu@kernel.org>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	Nadav Amit <namit@vmware.com>, Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Johannes Weiner <hannes@cmpxchg.org>
Subject: Re: [RFC] how the ballooned memory should be accounted by the drivers inside the guests? (was:[PATCH v6 1/2] Create debugfs file with virtio balloon usage information)
Date: Tue, 2 Aug 2022 11:53:42 +0300	[thread overview]
Message-ID: <2dfad5c8-59d2-69a1-cc4c-d530c12ceea9@virtuozzo.com> (raw)
In-Reply-To: <71e73194-1683-b65f-7b84-c0c719010aef@redhat.com>

Hi,

I put some more people on the CC, questions for you at the end , TIA.

On 01/08/2022 23:12, David Hildenbrand wrote:
>> / # cat /sys/kernel/debug/virtio-balloon
>> inflated: -2097152 kB
> What's the rationale of making it negative?

As suggested earlier indicate how the memory is accounted in the two 
different cases. Negative means it is subtracted from MemTotal . 
Positive means it is accounted as used .

>> To join the threads:
>>
>>>> Always account inflated memory as used for both cases - with and
>>>> without deflate on oom. Do not change total ram which can confuse
>>>> userspace and users.
>>> Sorry, but NAK.
>> Ok.
>>
>>> This would affect existing users / user space / balloon stats. For example
>>> HV just recently switch to properly using adjust_managed_page_count()
>>
>> I am wondering what's the rationale behind this i have never seen such users
>> that expect it to work like this. Do you have any pointers to such users, so
>> i can understood why they do so ?
> We adjust total pages and managed pages to simulate what memory is
> actually available to the system (just like during memory hot(un)plug).
> Even though the pages are "allocated" by the driver, they are actually
> unusable for the system, just as if they would have been offlined.
> Strictly speaking, the guest OS can kill as many processes as it wants,
> it cannot reclaim that memory, as it's logically no longer available.
>
> There is nothing (valid, well, except driver unloading) the guest can do
> to reuse these pages. The hypervisor has to get involved first to grant
> access to some of these pages again (deflate the balloon).
>
> It's different with deflate-on-oom: the guest will *itself* decide to
> reuse inflated pages to deflate them. So the allocated pages can become
> back usable easily. There was a recent discussion for virtio-balloon to
> change that behavior when it's known that the hypervisor essentially
> implements "deflate-on-oom" by looking at guest memory stats and
> adjusting the balloon size accordingly; however, as long as we don't
> know what the hypervisor does or doesn't do, we have to keep the
> existing behavior.
>
> Note that most balloon drivers under Linux share that behavior.
>
> In case of Hyper-V I remember a customer BUG report that requested that
> exact behavior, however, I'm not able to locate the BZ quickly.
> [1] https://lists.linuxfoundation.org/pipermail/virtualization/2021-November/057767.html
> (note that I can't easily find the original mail in the archives)

VMWare does not, Xen do, HV do (but it didn't) - Virtio does both.

For me the confusion comes from mixing ballooning and hot plug.

Ballooning is like a heap inside the guest from which the host can 
allocate/deallocate pages, if there is a mechanism for the guest to ask 
the host for more/to free/ pages or the host have a heuristic to monitor 
the guest and inflate/deflate the guest it is a matter of implementation.

Hot plug is adding  to MemTotal and it is not a random event either in 
real or virtual environment -  so you can act upon it. MemTotal  goes 
down on hot unplug and if pages get marked as faulty RAM.

Historically MemTotal is a stable value ( i agree with most of David 
Stevens points) and user space is expecting it to be stable , 
initialized at startup and it does not expect it to change.

Used is what changes and that is what user space expects to change.

Delfate on oom might have been a mistake but it is there and if anything 
depends on changing MemTotal  it will be broken by that option.  How 
that can be fixed?

I agree that the host can not reclaim what is marked as used  but should 
it be able to ? May be it will be good to teach oom killer that there 
can be such ram that can not be reclaimed.

> Note: I suggested under [1] to expose inflated pages via /proc/meminfo
> directly. We could do that consistently over all balloon drivers ...
> doesn't sound too crazy.

Initally i wanted to do exactly this BUT:
- some drivers prefer to expose some more internal information in the file.
- a lot of user space is using meminfo so better keep it as is to avoid breaking something, ballooning is not very frequently used.


Please, share your view on how the ballooned memory should be accounted by the drivers inside the guests so we can work towards consistent behaviour:

Should the inflated memory be accounted as Used or MemTotal be adjusted?

Should the inflated memory be added to /proc/meminfo ?

-- 
Regards,
Alexander Atanasov


  reply	other threads:[~2022-08-02  8:53 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-05  8:36 [PATCH v4 1/1] Create debugfs file with virtio balloon usage information Alexander Atanasov
2022-07-05  8:59 ` Michael S. Tsirkin
2022-07-05  9:01   ` Alexander Atanasov
2022-08-09 10:35     ` Michael S. Tsirkin
2022-08-09 13:33       ` Alexander Atanasov
2022-07-13 16:25   ` Alexander Atanasov
2022-07-14 11:35 ` David Hildenbrand
2022-07-14 13:20   ` Alexander Atanasov
2022-07-14 13:24     ` David Hildenbrand
2022-07-14 13:35       ` Alexander Atanasov
2022-07-14 13:20   ` [PATCH v5 " Alexander Atanasov
2022-07-18 11:35     ` David Hildenbrand
2022-07-25 11:27       ` Alexander Atanasov
2022-07-25 11:36         ` David Hildenbrand
2022-07-26 14:08           ` [PATCH v6 1/2] " Alexander Atanasov
2022-07-26 14:10             ` [PATCH v6 2/2] Unify how inflated memory is accounted in virtio balloon driver Alexander Atanasov
2022-08-01 15:13               ` David Hildenbrand
2022-08-09 10:42               ` Michael S. Tsirkin
2022-08-01 15:18             ` [PATCH v6 1/2] Create debugfs file with virtio balloon usage information David Hildenbrand
2022-08-01 16:34               ` Alexander Atanasov
2022-08-01 20:12                 ` David Hildenbrand
2022-08-02  8:53                   ` Alexander Atanasov [this message]
2022-08-02 13:48                     ` [RFC] how the ballooned memory should be accounted by the drivers inside the guests? (was:[PATCH v6 1/2] Create debugfs file with virtio balloon usage information) David Hildenbrand
2022-08-09  9:36                       ` Alexander Atanasov
2022-08-09  9:49                         ` [PATCH v1 1/2] Enable balloon drivers to report inflated memory Alexander Atanasov
2022-08-09  9:53                           ` [PATCH v1 2/2] Drivers: virtio: balloon: Report " Alexander Atanasov
2022-08-09 17:44                             ` Nadav Amit
2022-08-15 12:52                               ` Alexander Atanasov
2022-08-15 16:05                                 ` Nadav Amit
2022-08-16  7:50                                   ` Alexander Atanasov
2022-08-09 10:32                           ` [PATCH v1 1/2] Enable balloon drivers to report " Michael S. Tsirkin
2022-08-10  5:54                             ` Alexander Atanasov
2022-08-10  6:05                               ` Michael S. Tsirkin
2022-08-10  7:50                                 ` Alexander Atanasov
2022-08-10  9:16                                   ` Michael S. Tsirkin
2022-08-10  3:05                           ` Muchun Song
2022-08-10  5:14                             ` Alexander Atanasov
2022-08-09 10:03                         ` [RFC] how the ballooned memory should be accounted by the drivers inside the guests? (was:[PATCH v6 1/2] Create debugfs file with virtio balloon usage information) David Hildenbrand
2022-08-09 10:44             ` [PATCH v6 1/2] Create debugfs file with virtio balloon usage information Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2dfad5c8-59d2-69a1-cc4c-d530c12ceea9@virtuozzo.com \
    --to=alexander.atanasov@virtuozzo.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=boris.ostrovsky@oracle.com \
    --cc=david@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=haiyangz@microsoft.com \
    --cc=hannes@cmpxchg.org \
    --cc=jasowang@redhat.com \
    --cc=jgross@suse.com \
    --cc=kernel@openvz.org \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=namit@vmware.com \
    --cc=sstabellini@kernel.org \
    --cc=stevensd@chromium.org \
    --cc=sthemmin@microsoft.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=wei.liu@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®