From: "Michael S. Tsirkin" <mst@redhat.com>
To: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
Cc: Jonathan Corbet <corbet@lwn.net>,
Andrew Morton <akpm@linux-foundation.org>,
kernel@openvz.org, David Hildenbrand <david@redhat.com>,
Wei Liu <wei.liu@kernel.org>, Nadav Amit <namit@vmware.com>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-doc@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v1 1/2] Enable balloon drivers to report inflated memory
Date: Tue, 9 Aug 2022 06:32:47 -0400 [thread overview]
Message-ID: <20220809063111-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20220809094933.2203087-1-alexander.atanasov@virtuozzo.com>
On Tue, Aug 09, 2022 at 12:49:32PM +0300, Alexander Atanasov wrote:
> Display reported in /proc/meminfo as:
>
> Inflated(total) or Inflated(free)
>
> depending on the driver.
>
> Drivers use the sign bit to indicate where they do account
> the inflated memory.
>
> Amount of inflated memory can be used by:
> - as a hint for the oom a killer
> - user space software that monitors memory pressure
>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Wei Liu <wei.liu@kernel.org>
> Cc: Nadav Amit <namit@vmware.com>
>
> Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
> ---
> Documentation/filesystems/proc.rst | 5 +++++
> fs/proc/meminfo.c | 11 +++++++++++
> include/linux/mm.h | 4 ++++
> mm/page_alloc.c | 4 ++++
> 4 files changed, 24 insertions(+)
>
> diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
> index 1bc91fb8c321..064b5b3d5bd8 100644
> --- a/Documentation/filesystems/proc.rst
> +++ b/Documentation/filesystems/proc.rst
> @@ -986,6 +986,7 @@ Example output. You may not have all of these fields.
> VmallocUsed: 40444 kB
> VmallocChunk: 0 kB
> Percpu: 29312 kB
> + Inflated(total): 2097152 kB
> HardwareCorrupted: 0 kB
> AnonHugePages: 4149248 kB
> ShmemHugePages: 0 kB
> @@ -1133,6 +1134,10 @@ VmallocChunk
> Percpu
> Memory allocated to the percpu allocator used to back percpu
> allocations. This stat excludes the cost of metadata.
> +Inflated(total) or Inflated(free)
> + Amount of memory that is inflated by the balloon driver.
> + Due to differences among balloon drivers inflated memory
> + is either 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 6e89f0e2fd20..ebbe52ccbb93 100644
> --- a/fs/proc/meminfo.c
> +++ b/fs/proc/meminfo.c
> @@ -38,6 +38,9 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
> unsigned long pages[NR_LRU_LISTS];
> unsigned long sreclaimable, sunreclaim;
> int lru;
> +#ifdef CONFIG_MEMORY_BALLOON
> + long inflated_kb;
> +#endif
>
> si_meminfo(&i);
> si_swapinfo(&i);
> @@ -153,6 +156,14 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
> global_zone_page_state(NR_FREE_CMA_PAGES));
> #endif
>
> +#ifdef CONFIG_MEMORY_BALLOON
> + inflated_kb = atomic_long_read(&mem_balloon_inflated_kb);
> + if (inflated_kb >= 0)
> + seq_printf(m, "Inflated(total): %8ld kB\n", inflated_kb);
> + else
> + seq_printf(m, "Inflated(free): %8ld kB\n", -inflated_kb);
> +#endif
> +
> hugetlb_report_meminfo(m);
>
> arch_report_meminfo(m);
This seems too baroque for my taste.
Why not just have two counters for the two pruposes?
And is there any value in having this atomic?
We want a consistent value but just READ_ONCE seems sufficient ...
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 7898e29bcfb5..b190811dc16e 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -2582,6 +2582,10 @@ extern int watermark_boost_factor;
> extern int watermark_scale_factor;
> extern bool arch_has_descending_max_zone_pfns(void);
>
> +#ifdef CONFIG_MEMORY_BALLOON
> +extern atomic_long_t mem_balloon_inflated_kb;
> +#endif
> +
> /* nommu.c */
> extern atomic_long_t mmap_pages_allocated;
> extern int nommu_shrink_inode_mappings(struct inode *, size_t, size_t);
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index b0bcab50f0a3..12359179a3a2 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -194,6 +194,10 @@ EXPORT_SYMBOL(init_on_alloc);
> DEFINE_STATIC_KEY_MAYBE(CONFIG_INIT_ON_FREE_DEFAULT_ON, init_on_free);
> EXPORT_SYMBOL(init_on_free);
>
> +#ifdef CONFIG_MEMORY_BALLOON
> +atomic_long_t mem_balloon_inflated_kb = ATOMIC_LONG_INIT(0);
> +#endif
> +
> static bool _init_on_alloc_enabled_early __read_mostly
> = IS_ENABLED(CONFIG_INIT_ON_ALLOC_DEFAULT_ON);
> static int __init early_init_on_alloc(char *buf)
> --
> 2.31.1
>
>
next prev parent reply other threads:[~2022-08-09 10:33 UTC|newest]
Thread overview: 54+ 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 8:59 ` Michael S. Tsirkin
2022-07-05 9:01 ` Alexander Atanasov
2022-08-09 10:35 ` Michael S. Tsirkin
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 11:35 ` David Hildenbrand
2022-07-14 13:20 ` Alexander Atanasov
2022-07-14 13:24 ` David Hildenbrand
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-18 11:35 ` David Hildenbrand
2022-07-25 11:27 ` Alexander Atanasov
2022-07-25 11:36 ` David Hildenbrand
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-01 15:13 ` David Hildenbrand
2022-08-09 10:42 ` Michael S. Tsirkin
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 15:18 ` David Hildenbrand
2022-08-01 16:34 ` Alexander Atanasov
2022-08-01 20:12 ` David Hildenbrand
2022-08-01 20:12 ` David Hildenbrand
2022-08-02 8:53 ` [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) Alexander Atanasov
2022-08-02 13:48 ` David Hildenbrand
2022-08-02 13:48 ` 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 via Virtualization
2022-08-09 17:44 ` Nadav Amit
2022-08-15 12:52 ` Alexander Atanasov
2022-08-15 16:05 ` Nadav Amit via Virtualization
2022-08-15 16:05 ` Nadav Amit
2022-08-16 7:50 ` Alexander Atanasov
2022-08-09 10:32 ` Michael S. Tsirkin [this message]
2022-08-10 5:54 ` [PATCH v1 1/2] Enable balloon drivers to report " 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:03 ` David Hildenbrand
2022-08-09 10:44 ` [PATCH v6 1/2] Create debugfs file with virtio balloon usage information Michael S. Tsirkin
2022-08-09 10:44 ` 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=20220809063111-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.atanasov@virtuozzo.com \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--cc=kernel@openvz.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=namit@vmware.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.