From: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: kernel@openvz.org,
Alexander Atanasov <alexander.atanasov@virtuozzo.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH v3 2/4] Enable balloon drivers to report inflated memory
Date: Mon, 22 Aug 2022 14:37:45 +0300 [thread overview]
Message-ID: <20220822113747.3630776-3-alexander.atanasov@virtuozzo.com> (raw)
In-Reply-To: <20220822113747.3630776-1-alexander.atanasov@virtuozzo.com>
Add counters to be updated by the balloon drivers.
Create balloon notifier to propagate changes.
Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
---
include/linux/balloon.h | 18 ++++++++++++++++++
mm/balloon.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/include/linux/balloon.h b/include/linux/balloon.h
index 46ac8f61f607..59657da77d95 100644
--- a/include/linux/balloon.h
+++ b/include/linux/balloon.h
@@ -57,6 +57,24 @@ 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);
+
+#define BALLOON_CHANGED_TOTAL 0
+#define BALLOON_CHANGED_FREE 1
+
+int register_balloon_notifier(struct notifier_block *nb);
+void unregister_balloon_notifier(struct notifier_block *nb);
+
+#define balloon_notifier(fn, pri) ({ \
+ static struct notifier_block fn##_mem_nb __meminitdata =\
+ { .notifier_call = fn, .priority = pri }; \
+ register_balloon_notifier(&fn##_mem_nb); \
+})
+
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..8e1d5855fef8 100644
--- a/mm/balloon.c
+++ b/mm/balloon.c
@@ -7,8 +7,44 @@
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/export.h>
+#include <linux/notifier.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);
+SRCU_NOTIFIER_HEAD_STATIC(balloon_chain);
+
+int register_balloon_notifier(struct notifier_block *nb)
+{
+ return srcu_notifier_chain_register(&balloon_chain, nb);
+}
+EXPORT_SYMBOL(register_balloon_notifier);
+
+void unregister_balloon_notifier(struct notifier_block *nb)
+{
+ srcu_notifier_chain_unregister(&balloon_chain, nb);
+}
+EXPORT_SYMBOL(unregister_balloon_notifier);
+
+static int balloon_notify(unsigned long val)
+{
+ return srcu_notifier_call_chain(&balloon_chain, val, NULL);
+}
+
+void balloon_set_inflated_total(long inflated_kb)
+{
+ atomic_long_set(&mem_balloon_inflated_total_kb, inflated_kb);
+ balloon_notify(BALLOON_CHANGED_TOTAL);
+}
+EXPORT_SYMBOL(balloon_set_inflated_total);
+
+void balloon_set_inflated_free(long inflated_kb)
+{
+ atomic_long_set(&mem_balloon_inflated_free_kb, inflated_kb);
+ balloon_notify(BALLOON_CHANGED_FREE);
+}
+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
prev parent reply other threads:[~2022-08-22 11:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220822113747.3630776-1-alexander.atanasov@virtuozzo.com>
2022-08-22 11:37 ` [PATCH v3 1/4] Make place for common balloon code Alexander Atanasov
2022-08-22 15:58 ` Nadav Amit
2022-08-22 11:37 ` Alexander Atanasov [this message]
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=20220822113747.3630776-3-alexander.atanasov@virtuozzo.com \
--to=alexander.atanasov@virtuozzo.com \
--cc=akpm@linux-foundation.org \
--cc=kernel@openvz.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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