From: David Hildenbrand <david@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org,
linux-hyperv@vger.kernel.org,
David Hildenbrand <david@redhat.com>,
"K. Y. Srinivasan" <kys@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Stephen Hemminger <sthemmin@microsoft.com>,
Wei Liu <wei.liu@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@kernel.org>,
Oscar Salvador <osalvador@suse.de>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Baoquan He <bhe@redhat.com>, Wei Yang <richard.weiyang@gmail.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>
Subject: [PATCH v2 5/8] hv_balloon: don't check for memhp_auto_online manually
Date: Tue, 17 Mar 2020 11:49:39 +0100 [thread overview]
Message-ID: <20200317104942.11178-6-david@redhat.com> (raw)
In-Reply-To: <20200317104942.11178-1-david@redhat.com>
We get the MEM_ONLINE notifier call if memory is added right from the
kernel via add_memory() or later from user space.
Let's get rid of the "ha_waiting" flag - the wait event has an inbuilt
mechanism (->done) for that. Initialize the wait event only once and
reinitialize before adding memory. Unconditionally call complete() and
wait_for_completion_timeout().
If there are no waiters, complete() will only increment ->done - which
will be reset by reinit_completion(). If complete() has already been
called, wait_for_completion_timeout() will not wait.
There is still the chance for a small race between concurrent
reinit_completion() and complete(). If complete() wins, we would not
wait - which is tolerable (and the race exists in current code as well).
Note: We only wait for "some" memory to get onlined, which seems to be
good enough for now.
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: linux-hyperv@vger.kernel.org
Signed-off-by: David Hildenbrand <david@redhat.com>
---
drivers/hv/hv_balloon.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index a02ce43d778d..af5e09f08130 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -533,7 +533,6 @@ struct hv_dynmem_device {
* State to synchronize hot-add.
*/
struct completion ol_waitevent;
- bool ha_waiting;
/*
* This thread handles hot-add
* requests from the host as well as notifying
@@ -634,10 +633,7 @@ static int hv_memory_notifier(struct notifier_block *nb, unsigned long val,
switch (val) {
case MEM_ONLINE:
case MEM_CANCEL_ONLINE:
- if (dm_device.ha_waiting) {
- dm_device.ha_waiting = false;
- complete(&dm_device.ol_waitevent);
- }
+ complete(&dm_device.ol_waitevent);
break;
case MEM_OFFLINE:
@@ -726,8 +722,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,
has->covered_end_pfn += processed_pfn;
spin_unlock_irqrestore(&dm_device.ha_lock, flags);
- init_completion(&dm_device.ol_waitevent);
- dm_device.ha_waiting = !memhp_auto_online;
+ reinit_completion(&dm_device.ol_waitevent);
nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn));
ret = add_memory(nid, PFN_PHYS((start_pfn)),
@@ -753,15 +748,14 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,
}
/*
- * Wait for the memory block to be onlined when memory onlining
- * is done outside of kernel (memhp_auto_online). Since the hot
- * add has succeeded, it is ok to proceed even if the pages in
- * the hot added region have not been "onlined" within the
- * allowed time.
+ * Wait for memory to get onlined. If the kernel onlined the
+ * memory when adding it, this will return directly. Otherwise,
+ * it will wait for user space to online the memory. This helps
+ * to avoid adding memory faster than it is getting onlined. As
+ * adding succeeded, it is ok to proceed even if the memory was
+ * not onlined in time.
*/
- if (dm_device.ha_waiting)
- wait_for_completion_timeout(&dm_device.ol_waitevent,
- 5*HZ);
+ wait_for_completion_timeout(&dm_device.ol_waitevent, 5 * HZ);
post_status(&dm_device);
}
}
@@ -1707,6 +1701,7 @@ static int balloon_probe(struct hv_device *dev,
#ifdef CONFIG_MEMORY_HOTPLUG
set_online_page_callback(&hv_online_page);
register_memory_notifier(&hv_memory_nb);
+ init_completion(&dm_device.ol_waitevent);
#endif
hv_set_drvdata(dev, &dm_device);
--
2.24.1
WARNING: multiple messages have this Message-ID (diff)
From: David Hildenbrand <david@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-hyperv@vger.kernel.org,
Stephen Hemminger <sthemmin@microsoft.com>,
Baoquan He <bhe@redhat.com>, David Hildenbrand <david@redhat.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Wei Liu <wei.liu@kernel.org>, Michal Hocko <mhocko@kernel.org>,
linux-mm@kvack.org, Wei Yang <richard.weiyang@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
"K. Y. Srinivasan" <kys@microsoft.com>,
linuxppc-dev@lists.ozlabs.org,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Oscar Salvador <osalvador@suse.de>
Subject: [PATCH v2 5/8] hv_balloon: don't check for memhp_auto_online manually
Date: Tue, 17 Mar 2020 11:49:39 +0100 [thread overview]
Message-ID: <20200317104942.11178-6-david@redhat.com> (raw)
In-Reply-To: <20200317104942.11178-1-david@redhat.com>
We get the MEM_ONLINE notifier call if memory is added right from the
kernel via add_memory() or later from user space.
Let's get rid of the "ha_waiting" flag - the wait event has an inbuilt
mechanism (->done) for that. Initialize the wait event only once and
reinitialize before adding memory. Unconditionally call complete() and
wait_for_completion_timeout().
If there are no waiters, complete() will only increment ->done - which
will be reset by reinit_completion(). If complete() has already been
called, wait_for_completion_timeout() will not wait.
There is still the chance for a small race between concurrent
reinit_completion() and complete(). If complete() wins, we would not
wait - which is tolerable (and the race exists in current code as well).
Note: We only wait for "some" memory to get onlined, which seems to be
good enough for now.
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: linux-hyperv@vger.kernel.org
Signed-off-by: David Hildenbrand <david@redhat.com>
---
drivers/hv/hv_balloon.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index a02ce43d778d..af5e09f08130 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -533,7 +533,6 @@ struct hv_dynmem_device {
* State to synchronize hot-add.
*/
struct completion ol_waitevent;
- bool ha_waiting;
/*
* This thread handles hot-add
* requests from the host as well as notifying
@@ -634,10 +633,7 @@ static int hv_memory_notifier(struct notifier_block *nb, unsigned long val,
switch (val) {
case MEM_ONLINE:
case MEM_CANCEL_ONLINE:
- if (dm_device.ha_waiting) {
- dm_device.ha_waiting = false;
- complete(&dm_device.ol_waitevent);
- }
+ complete(&dm_device.ol_waitevent);
break;
case MEM_OFFLINE:
@@ -726,8 +722,7 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,
has->covered_end_pfn += processed_pfn;
spin_unlock_irqrestore(&dm_device.ha_lock, flags);
- init_completion(&dm_device.ol_waitevent);
- dm_device.ha_waiting = !memhp_auto_online;
+ reinit_completion(&dm_device.ol_waitevent);
nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn));
ret = add_memory(nid, PFN_PHYS((start_pfn)),
@@ -753,15 +748,14 @@ static void hv_mem_hot_add(unsigned long start, unsigned long size,
}
/*
- * Wait for the memory block to be onlined when memory onlining
- * is done outside of kernel (memhp_auto_online). Since the hot
- * add has succeeded, it is ok to proceed even if the pages in
- * the hot added region have not been "onlined" within the
- * allowed time.
+ * Wait for memory to get onlined. If the kernel onlined the
+ * memory when adding it, this will return directly. Otherwise,
+ * it will wait for user space to online the memory. This helps
+ * to avoid adding memory faster than it is getting onlined. As
+ * adding succeeded, it is ok to proceed even if the memory was
+ * not onlined in time.
*/
- if (dm_device.ha_waiting)
- wait_for_completion_timeout(&dm_device.ol_waitevent,
- 5*HZ);
+ wait_for_completion_timeout(&dm_device.ol_waitevent, 5 * HZ);
post_status(&dm_device);
}
}
@@ -1707,6 +1701,7 @@ static int balloon_probe(struct hv_device *dev,
#ifdef CONFIG_MEMORY_HOTPLUG
set_online_page_callback(&hv_online_page);
register_memory_notifier(&hv_memory_nb);
+ init_completion(&dm_device.ol_waitevent);
#endif
hv_set_drvdata(dev, &dm_device);
--
2.24.1
next prev parent reply other threads:[~2020-03-17 10:50 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-17 10:49 [PATCH v2 0/8] mm/memory_hotplug: allow to specify a default online_type David Hildenbrand
2020-03-17 10:49 ` David Hildenbrand
2020-03-17 10:49 ` [PATCH v2 1/8] drivers/base/memory: rename MMOP_ONLINE_KEEP to MMOP_ONLINE David Hildenbrand
2020-03-17 10:49 ` David Hildenbrand
2020-03-17 10:49 ` [PATCH v2 2/8] drivers/base/memory: map MMOP_OFFLINE to 0 David Hildenbrand
2020-03-17 10:49 ` David Hildenbrand
2020-03-17 10:49 ` [PATCH v2 3/8] drivers/base/memory: store mapping between MMOP_* and string in an array David Hildenbrand
2020-03-17 10:49 ` David Hildenbrand
2020-03-17 10:49 ` [PATCH v2 4/8] powernv/memtrace: always online added memory blocks David Hildenbrand
2020-03-17 10:49 ` David Hildenbrand
2020-03-17 10:58 ` Michal Hocko
2020-03-17 10:58 ` Michal Hocko
2020-03-17 22:04 ` Wei Yang
2020-03-17 22:04 ` Wei Yang
2020-03-19 9:49 ` Michael Ellerman
2020-03-19 9:49 ` Michael Ellerman
2020-03-17 10:49 ` David Hildenbrand [this message]
2020-03-17 10:49 ` [PATCH v2 5/8] hv_balloon: don't check for memhp_auto_online manually David Hildenbrand
2020-03-17 16:29 ` Vitaly Kuznetsov
2020-03-17 16:29 ` Vitaly Kuznetsov
2020-03-17 16:33 ` David Hildenbrand
2020-03-17 16:33 ` David Hildenbrand
2020-03-17 18:46 ` David Hildenbrand
2020-03-17 18:46 ` David Hildenbrand
2020-03-17 10:49 ` [PATCH v2 6/8] mm/memory_hotplug: unexport memhp_auto_online David Hildenbrand
2020-03-17 10:49 ` David Hildenbrand
2020-03-17 10:59 ` Michal Hocko
2020-03-17 10:59 ` Michal Hocko
2020-03-17 22:24 ` Wei Yang
2020-03-17 22:24 ` Wei Yang
2020-03-17 10:49 ` [PATCH v2 7/8] mm/memory_hotplug: convert memhp_auto_online to store an online_type David Hildenbrand
2020-03-17 10:49 ` David Hildenbrand
2020-03-17 11:00 ` Michal Hocko
2020-03-17 11:00 ` Michal Hocko
2020-03-17 10:49 ` [PATCH v2 8/8] mm/memory_hotplug: allow to specify a default online_type David Hildenbrand
2020-03-17 10:49 ` David Hildenbrand
2020-03-17 11:01 ` Michal Hocko
2020-03-17 11:01 ` Michal Hocko
2020-03-17 11:05 ` David Hildenbrand
2020-03-17 11:05 ` David Hildenbrand
2020-03-17 11:08 ` David Hildenbrand
2020-03-17 11:08 ` David Hildenbrand
2020-03-18 13:05 ` [PATCH v2 0/8] " Baoquan He
2020-03-18 13:05 ` Baoquan He
2020-03-18 13:50 ` David Hildenbrand
2020-03-18 13:50 ` David Hildenbrand
2020-03-18 14:50 ` Baoquan He
2020-03-18 14:50 ` Baoquan He
2020-03-18 13:54 ` Michal Hocko
2020-03-18 13:54 ` Michal Hocko
2020-03-18 14:41 ` Baoquan He
2020-03-18 14:41 ` Baoquan He
2020-03-18 13:58 ` Vitaly Kuznetsov
2020-03-18 13:58 ` Vitaly Kuznetsov
2020-03-18 14:41 ` Baoquan He
2020-03-18 14:41 ` Baoquan He
2020-03-18 15:00 ` Vitaly Kuznetsov
2020-03-18 15:00 ` Vitaly Kuznetsov
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=20200317104942.11178-6-david@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mhocko@kernel.org \
--cc=osalvador@suse.de \
--cc=rafael@kernel.org \
--cc=richard.weiyang@gmail.com \
--cc=sthemmin@microsoft.com \
--cc=vkuznets@redhat.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.