mm/memory_hotplug: Export generic_online_page()
Subsystems (4)
cover mm/memory_hotplug: Export generic_online_page()
Based on linux/next + "[PATCH 0/3] Remove __online_page_set_limits()"
Let's replace the __online_page...() functions by generic_online_page(). Hyper-V only wants to delay the actual onlining of un-backed pages, so we can simpy re-use the generic function.
Only compile-tested.
David Hildenbrand (3):
mm/memory_hotplug: Export generic_online_page()
hv_balloon: Use generic_online_page() mm/memory_hotplug: Remove __online_page_free() and
__online_page_increment_counters()
drivers/hv/hv_balloon.c | 3 +-- include/linux/memory_hotplug.h | 4 +--- mm/memory_hotplug.c | 17 ++--------------- 3 files changed, 4 insertions(+), 20 deletions(-)
Signature · 1 line
2.21.0
PATCH 1/3 mm/memory_hotplug: Export generic_online_page()
Let's expose generic_online_page() so online_page_callback users can simply fallback to the generic implementation when actually deciding to online the pages.
--- include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/memory_hotplug.h +1 -0
@@ -102,6 +102,7 @@ extern unsigned long __offline_isolated_pages(unsigned long start_pfn,typedef void (*online_page_callback_t )(struct page *page,unsigned int order); +extern void generic_online_page (struct page *page,unsigned int order);extern int set_online_page_callback (online_page_callback_t callback);extern int restore_online_page_callback (online_page_callback_t callback);
mm/memory_hotplug.c +2 -3
@@ -49,8 +49,6 @@* and restore_online_page_callback() for generic callback restore. */ -static void generic_online_page (struct page *page,unsigned int order); -static online_page_callback_t online_page_callback = generic_online_page;static DEFINE_MUTEX (online_page_callback_lock);
@@ -616,7 +614,7 @@ void __online_page_free(struct page *page) }EXPORT_SYMBOL_GPL (__online_page_free); -static void generic_online_page (struct page *page,unsigned int order) +void generic_online_page (struct page *page,unsigned int order) {kernel_map_pages (page,1 << order,1 );__free_pages_core (page, order);
@@ -626,6 +624,7 @@ static void generic_online_page(struct page *page, unsigned int order)totalhigh_pages_add (1UL << order);#endif } +EXPORT_SYMBOL_GPL (generic_online_page);static int online_pages_range (unsigned long start_pfn,unsigned long nr_pages,void *arg)
Signature · 1 line
2.21.0
PATCH 2/3 hv_balloon: Use generic_online_page()
In reply to David HildenbrandLet's use the generic onlining function - which will now also take care of calling kernel_map_pages().
--- drivers/hv/hv_balloon.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/hv/hv_balloon.c +1 -2
@@ -680,8 +680,7 @@ static void hv_page_online_one(struct hv_hotadd_state *has, struct page *pg)__ClearPageOffline (pg);/* This frame is currently backed; online the page. */ -__online_page_increment_counters (pg); -__online_page_free (pg); +generic_online_page (pg,0 );lockdep_assert_held (&dm_device.ha_lock); dm_device.num_pages_onlined++;
Signature · 1 line
2.21.0
PATCH 3/3 mm/memory_hotplug: Remove __online_page_free() and __online_page_increment_counters()
In reply to David HildenbrandLet's drop the now unused functions.
--- include/linux/memory_hotplug.h | 3 --- mm/memory_hotplug.c | 12 ------------ 2 files changed, 15 deletions(-)
include/linux/memory_hotplug.h +0 -3
@@ -106,9 +106,6 @@ extern void generic_online_page(struct page *page, unsigned int order);extern int set_online_page_callback (online_page_callback_t callback);extern int restore_online_page_callback (online_page_callback_t callback); -extern void __online_page_increment_counters (struct page *page); -extern void __online_page_free (struct page *page); -extern int try_online_node (int nid); extern int arch_add_memory(int nid, u64 start, u64 size,
mm/memory_hotplug.c +0 -12
@@ -602,18 +602,6 @@ int restore_online_page_callback(online_page_callback_t callback) }EXPORT_SYMBOL_GPL (restore_online_page_callback); -void __online_page_increment_counters (struct page *page) -{ -adjust_managed_page_count (page,1 ); -} -EXPORT_SYMBOL_GPL (__online_page_increment_counters); - -void __online_page_free (struct page *page) -{ -__free_reserved_page (page); -} -EXPORT_SYMBOL_GPL (__online_page_free); -void generic_online_page (struct page *page,unsigned int order) {kernel_map_pages (page,1 << order,1 );
Signature · 1 line
2.21.0
Quoted 16 lines · David Hildenbrand
Based on linux/next + "[PATCH 0/3] Remove
__online_page_set_limits()"Let's replace the __online_page...() functions by
generic_online_page(). Hyper-V only wants to delay the actual onlining of un-backed pages, so we can simpy re-use the generic function.Only compile-tested.
Cc Souptick Joarder <[email protected]>David Hildenbrand (3):
mm/memory_hotplug: Exportgeneric_online_page()
hv_balloon: Usegeneric_online_page()mm/memory_hotplug: Remove__online_page_free()and
__online_page_increment_counters()
Quoted 5 lines
drivers/hv/hv_balloon.c | 3 +-- include/linux/memory_hotplug.h | 4 +--- mm/memory_hotplug.c | 17 ++--------------- 3 files changed, 4 insertions(+), 20 deletions(-)
Ping, any comments on this one?
Signature · 3 lines
Thanks, David / dhildenb
Michal Hocko
Acked-byQuoted 17 lines · David Hildenbrand
Quoted 16 lines · David Hildenbrand
Based on linux/next + "[PATCH 0/3] Remove
__online_page_set_limits()"Let's replace the __online_page...() functions by
generic_online_page(). Hyper-V only wants to delay the actual onlining of un-backed pages, so we can simpy re-use the generic function.Only compile-tested.
Cc Souptick Joarder <[email protected]>David Hildenbrand (3):
mm/memory_hotplug: Exportgeneric_online_page()
hv_balloon: Usegeneric_online_page()mm/memory_hotplug: Remove__online_page_free()and
__online_page_increment_counters()
Quoted 7 lines
Quoted 5 lines
drivers/hv/hv_balloon.c | 3 +-- include/linux/memory_hotplug.h | 4 +--- mm/memory_hotplug.c | 17 ++--------------- 3 files changed, 4 insertions(+), 20 deletions(-)Ping, any comments on this one?
Unification makes a lot of sense to me. You can add
I will most likely won't surprise if I asked for more here though ;) I have to confess I really detest the whole concept of a hidden callback with a very weird API. Is this something we can do about? I do realize that adding a callback would require either cluttering the existing APIs but maybe we can come up with something more clever. Or maybe existing external users of online callback can do that as a separate step after the online is completed - or is this impossible due to locking guarantees?
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 24 lines · Michal Hocko
Quoted 23 lines · David Hildenbrand
Quoted 21 lines · David Hildenbrand
Based on linux/next + "[PATCH 0/3] Remove
__online_page_set_limits()"Let's replace the __online_page...() functions by
generic_online_page(). Hyper-V only wants to delay the actual onlining of un-backed pages, so we can simpy re-use the generic function.Only compile-tested.
Cc Souptick Joarder <[email protected]>David Hildenbrand (3):
mm/memory_hotplug: Exportgeneric_online_page()
hv_balloon: Usegeneric_online_page()mm/memory_hotplug: Remove__online_page_free()and
__online_page_increment_counters()drivers/hv/hv_balloon.c | 3 +-- include/linux/memory_hotplug.h | 4 +--- mm/memory_hotplug.c | 17 ++--------------- 3 files changed, 4 insertions(+), 20 deletions(-)
Quoted 6 lines
Quoted 1 line
Ping, any comments on this one?
Unification makes a lot of sense to me. You can add
Acked-by Michal Hocko <[email protected]>I will most likely won't surprise if I asked for more here though ;)
I'm not surprised, but definitely not in a negative sense ;) I was asking myself if we could somehow rework this, too.
Quoted 8 lines
I have to confess I really detest the whole concept of a hidden callback with a very weird API. Is this something we can do about? I do realize that adding a callback would require either cluttering the existing APIs but maybe we can come up with something more clever. Or maybe existing external users of online callback can do that as a separate step after the online is completed - or is this impossible due to locking guarantees?
The use case of this (somewhat special) callback really is to avoid selected (unbacked in the hypervisor) pages to get put to the buddy just now, but instead to defer that (sometimes, defer till infinity ;) ). Especially, to hinder these pages from getting touched at all. Pages that won't be put to the buddy will usually get PG_offline set (e.g., Hyper-V and XEN) - the only two users I am aware of.
For Hyper-V (and also eventually virtio-mem), it is important to set PG_offline before marking the section to be online (SECTION_IS_ONLINE). Only this way, PG_offline is properly set on all pfn_to_online_page() pages, meaning "don't touch this page" - e.g., used to skip over such pages when suspending or by makedumpfile to skip over such offline pages when creating a memory dump.
So if we would e.g., try to piggy-back onto the memory_notify() infrastructure, we could
1. Online all pages to the buddy (dropping the callback)
2. E.g., memory_notify(MEM_ONLINE_PAGES, &arg);
-> in the notifier, pull pages from the buddy, mark sections online
3. Set all involved sections online (online_mem_sections())
However, I am not sure what actually happens after 1. - we are only holding the device hotplug lock and the memory hotplug lock, so the pages can just get allocated. Also, it sounds like more work and code for the same end result (okay, if the rework is really necessary, though).
So yeah, while the current callback might not be optimal, I don't see an easy and clean way to rework this. With the change in this series we are at least able to simply defer doing what would have been done without the callback - not perfect but better.
Do you have anything in mind that could work out and make this nicer?
Signature · 3 lines
Thanks, David / dhildenb
Quoted 51 lines · David Hildenbrand
Quoted 24 lines · Michal Hocko
Quoted 23 lines · David Hildenbrand
Quoted 21 lines · David Hildenbrand
Based on linux/next + "[PATCH 0/3] Remove
__online_page_set_limits()"Let's replace the __online_page...() functions by
generic_online_page(). Hyper-V only wants to delay the actual onlining of un-backed pages, so we can simpy re-use the generic function.Only compile-tested.
Cc Souptick Joarder <[email protected]>David Hildenbrand (3):
mm/memory_hotplug: Exportgeneric_online_page()
hv_balloon: Usegeneric_online_page()mm/memory_hotplug: Remove__online_page_free()and
__online_page_increment_counters()drivers/hv/hv_balloon.c | 3 +-- include/linux/memory_hotplug.h | 4 +--- mm/memory_hotplug.c | 17 ++--------------- 3 files changed, 4 insertions(+), 20 deletions(-)Quoted 6 lines
Quoted 1 line
Ping, any comments on this one?
Unification makes a lot of sense to me. You can add
Acked-by Michal Hocko <[email protected]>I will most likely won't surprise if I asked for more here though ;)
I'm not surprised, but definitely not in a negative sense ;) I was asking myself if we could somehow rework this, too.
Quoted 8 lines
I have to confess I really detest the whole concept of a hidden callback with a very weird API. Is this something we can do about? I do realize that adding a callback would require either cluttering the existing APIs but maybe we can come up with something more clever. Or maybe existing external users of online callback can do that as a separate step after the online is completed - or is this impossible due to locking guarantees?
The use case of this (somewhat special) callback really is to avoid selected (unbacked in the hypervisor) pages to get put to the buddy just now, but instead to defer that (sometimes, defer till infinity ;) ). Especially, to hinder these pages from getting touched at all. Pages that won't be put to the buddy will usually get
PG_offlineset (e.g., Hyper-V and XEN) - the only two users I am aware of.
Quoted 6 lines
For Hyper-V (and also eventually virtio-mem), it is important to set
PG_offlinebefore marking the section to be online (SECTION_IS_ONLINE). Only this way,PG_offlineis properly set on allpfn_to_online_page()pages, meaning "don't touch this page" - e.g., used to skip over such pages when suspending or by makedumpfile to skip over such offline pages when creating a memory dump.
Thanks for the clarification. I have never really studied what those callbacks are doing really.
Quoted 6 lines
So if we would e.g., try to piggy-back onto the
memory_notify()infrastructure, we could
1. Online all pages to the buddy (dropping the callback)
2. E.g.,memory_notify(MEM_ONLINE_PAGES, &arg);
-> in the notifier, pull pages from the buddy, mark sections online
3. Set all involved sections online (online_mem_sections())
This doesn't really sound any better. For one pages are immediately usable when they hit the buddy allocator so this is racy and thus not reliable.
Quoted 11 lines
However, I am not sure what actually happens after 1. - we are only holding the device hotplug lock and the memory hotplug lock, so the pages can just get allocated. Also, it sounds like more work and code for the same end result (okay, if the rework is really necessary, though).
So yeah, while the current callback might not be optimal, I don't see an easy and clean way to rework this. With the change in this series we are at least able to simply defer doing what would have been done without the callback - not perfect but better.
Do you have anything in mind that could work out and make this nicer?
I am wondering why those pages get onlined when they are, in fact, supposed to be offline.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 83 lines · Michal Hocko
Quoted 51 lines · David Hildenbrand
Quoted 24 lines · Michal Hocko
Quoted 23 lines · David Hildenbrand
Quoted 21 lines · David Hildenbrand
Based on linux/next + "[PATCH 0/3] Remove
__online_page_set_limits()"Let's replace the __online_page...() functions by
generic_online_page(). Hyper-V only wants to delay the actual onlining of un-backed pages, so we can simpy re-use the generic function.Only compile-tested.
Cc Souptick Joarder <[email protected]>David Hildenbrand (3):
mm/memory_hotplug: Exportgeneric_online_page()
hv_balloon: Usegeneric_online_page()mm/memory_hotplug: Remove__online_page_free()and
__online_page_increment_counters()drivers/hv/hv_balloon.c | 3 +-- include/linux/memory_hotplug.h | 4 +--- mm/memory_hotplug.c | 17 ++--------------- 3 files changed, 4 insertions(+), 20 deletions(-)Quoted 6 lines
Quoted 1 line
Ping, any comments on this one?
Unification makes a lot of sense to me. You can add
Acked-by Michal Hocko <[email protected]>I will most likely won't surprise if I asked for more here though ;)
I'm not surprised, but definitely not in a negative sense ;) I was asking myself if we could somehow rework this, too.
Quoted 8 lines
I have to confess I really detest the whole concept of a hidden callback with a very weird API. Is this something we can do about? I do realize that adding a callback would require either cluttering the existing APIs but maybe we can come up with something more clever. Or maybe existing external users of online callback can do that as a separate step after the online is completed - or is this impossible due to locking guarantees?
The use case of this (somewhat special) callback really is to avoid selected (unbacked in the hypervisor) pages to get put to the buddy just now, but instead to defer that (sometimes, defer till infinity ;) ). Especially, to hinder these pages from getting touched at all. Pages that won't be put to the buddy will usually get
PG_offlineset (e.g., Hyper-V and XEN) - the only two users I am aware of.Quoted 6 lines
For Hyper-V (and also eventually virtio-mem), it is important to set
PG_offlinebefore marking the section to be online (SECTION_IS_ONLINE). Only this way,PG_offlineis properly set on allpfn_to_online_page()pages, meaning "don't touch this page" - e.g., used to skip over such pages when suspending or by makedumpfile to skip over such offline pages when creating a memory dump.Thanks for the clarification. I have never really studied what those callbacks are doing really.
Quoted 6 lines
So if we would e.g., try to piggy-back onto the
memory_notify()infrastructure, we could
1. Online all pages to the buddy (dropping the callback)
2. E.g.,memory_notify(MEM_ONLINE_PAGES, &arg);
-> in the notifier, pull pages from the buddy, mark sections online
3. Set all involved sections online (online_mem_sections())This doesn't really sound any better. For one pages are immediately usable when they hit the buddy allocator so this is racy and thus not reliable.
Quoted 10 lines
However, I am not sure what actually happens after 1. - we are only holding the device hotplug lock and the memory hotplug lock, so the pages can just get allocated. Also, it sounds like more work and code for the same end result (okay, if the rework is really necessary, though).
So yeah, while the current callback might not be optimal, I don't see an easy and clean way to rework this. With the change in this series we are at least able to simply defer doing what would have been done without the callback - not perfect but better.
Quoted 5 lines
Quoted 1 line
Do you have anything in mind that could work out and make this nicer?
I am wondering why those pages get onlined when they are, in fact, supposed to be offline.
It's the current way of emulating sub-memory-block hotplug on top of the memory bock device API we have. Hyper-V and XEN have been using that for a long time.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 86 lines · David Hildenbrand
Quoted 85 lines · Michal Hocko
Quoted 51 lines · David Hildenbrand
Quoted 24 lines · Michal Hocko
Quoted 23 lines · David Hildenbrand
Quoted 21 lines · David Hildenbrand
Based on linux/next + "[PATCH 0/3] Remove
__online_page_set_limits()"Let's replace the __online_page...() functions by
generic_online_page(). Hyper-V only wants to delay the actual onlining of un-backed pages, so we can simpy re-use the generic function.Only compile-tested.
Cc Souptick Joarder <[email protected]>David Hildenbrand (3):
mm/memory_hotplug: Exportgeneric_online_page()
hv_balloon: Usegeneric_online_page()mm/memory_hotplug: Remove__online_page_free()and
__online_page_increment_counters()drivers/hv/hv_balloon.c | 3 +-- include/linux/memory_hotplug.h | 4 +--- mm/memory_hotplug.c | 17 ++--------------- 3 files changed, 4 insertions(+), 20 deletions(-)Quoted 6 lines
Quoted 1 line
Ping, any comments on this one?
Unification makes a lot of sense to me. You can add
Acked-by Michal Hocko <[email protected]>I will most likely won't surprise if I asked for more here though ;)
I'm not surprised, but definitely not in a negative sense ;) I was asking myself if we could somehow rework this, too.
Quoted 8 lines
I have to confess I really detest the whole concept of a hidden callback with a very weird API. Is this something we can do about? I do realize that adding a callback would require either cluttering the existing APIs but maybe we can come up with something more clever. Or maybe existing external users of online callback can do that as a separate step after the online is completed - or is this impossible due to locking guarantees?
The use case of this (somewhat special) callback really is to avoid selected (unbacked in the hypervisor) pages to get put to the buddy just now, but instead to defer that (sometimes, defer till infinity ;) ). Especially, to hinder these pages from getting touched at all. Pages that won't be put to the buddy will usually get
PG_offlineset (e.g., Hyper-V and XEN) - the only two users I am aware of.Quoted 6 lines
For Hyper-V (and also eventually virtio-mem), it is important to set
PG_offlinebefore marking the section to be online (SECTION_IS_ONLINE). Only this way,PG_offlineis properly set on allpfn_to_online_page()pages, meaning "don't touch this page" - e.g., used to skip over such pages when suspending or by makedumpfile to skip over such offline pages when creating a memory dump.Thanks for the clarification. I have never really studied what those callbacks are doing really.
Quoted 6 lines
So if we would e.g., try to piggy-back onto the
memory_notify()infrastructure, we could
1. Online all pages to the buddy (dropping the callback)
2. E.g.,memory_notify(MEM_ONLINE_PAGES, &arg);
-> in the notifier, pull pages from the buddy, mark sections online
3. Set all involved sections online (online_mem_sections())This doesn't really sound any better. For one pages are immediately usable when they hit the buddy allocator so this is racy and thus not reliable.
Quoted 11 lines
However, I am not sure what actually happens after 1. - we are only holding the device hotplug lock and the memory hotplug lock, so the pages can just get allocated. Also, it sounds like more work and code for the same end result (okay, if the rework is really necessary, though).
So yeah, while the current callback might not be optimal, I don't see an easy and clean way to rework this. With the change in this series we are at least able to simply defer doing what would have been done without the callback - not perfect but better.
Do you have anything in mind that could work out and make this nicer?
Quoted 8 lines
Quoted 3 lines
I am wondering why those pages get onlined when they are, in fact, supposed to be offline.
It's the current way of emulating sub-memory-block hotplug on top of the memory bock device API we have. Hyper-V and XEN have been using that for a long time.
So one idea would be to let clients set pages to PG_offline during MEM_GOING_ONLINE. We could then skip any PG_offline pages when onlining pages, not onlining them to the buddy.
But then, there still has to be a way to online pages when required - e.g., generic_online_page(). At least the callback could go.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 1 line · David Hildenbrand
On 23.09.19 13:15, Michal Hocko wrote:
[...]
Quoted 7 lines
Quoted 3 lines
I am wondering why those pages get onlined when they are, in fact, supposed to be offline.
It's the current way of emulating sub-memory-block hotplug on top of the memory bock device API we have. Hyper-V and XEN have been using that for a long time.
Do they really have to use the existing block interface when they in fact do not operate on the block granularity? Zone device memory already acts on sub section/block boundaries.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 7 lines · Michal Hocko
Quoted 1 line · David Hildenbrand
On 23.09.19 13:15, Michal Hocko wrote:
[...]
Quoted 4 lines
Quoted 3 lines
I am wondering why those pages get onlined when they are, in fact, supposed to be offline.
Quoted 8 lines
Quoted 3 lines
It's the current way of emulating sub-memory-block hotplug on top of the memory bock device API we have. Hyper-V and XEN have been using that for a long time.
Do they really have to use the existing block interface when they in fact do not operate on the block granularity? Zone device memory already acts on sub section/block boundaries.
Yes, we need memory blocks, especially for user space to properly online them (as we discussed a while back, to decide on a zone) and for udev events, to e.g., properly reload kexec when memory blocks get added/removed/onlined/offlined.
ZONE_DEVICE is special as it doesn't have to worry about onlining/offlining/dumping. Also, it doesn't care about SECTION_IS_ONLINE, but figuring out how to detect which sub sections/blocks have a valid memmap is still something to get fixed and is still getting discussed on MM.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 17 lines · David Hildenbrand
Quoted 7 lines · Michal Hocko
Quoted 1 line · David Hildenbrand
On 23.09.19 13:15, Michal Hocko wrote:
[...]
Quoted 4 lines
Quoted 3 lines
I am wondering why those pages get onlined when they are, in fact, supposed to be offline.
Quoted 8 lines
Quoted 3 lines
It's the current way of emulating sub-memory-block hotplug on top of the memory bock device API we have. Hyper-V and XEN have been using that for a long time.
Do they really have to use the existing block interface when they in fact do not operate on the block granularity? Zone device memory already acts on sub section/block boundaries.
Quoted 4 lines
Yes, we need memory blocks, especially for user space to properly online them (as we discussed a while back, to decide on a zone) and for udev events, to e.g., properly reload kexec when memory blocks get added/removed/onlined/offlined.
Just to make sure I really follow. We need a user interface to control where the memory gets onlined but it is the driver which determines which part of the block really gets onlined, right?
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 18 lines · Michal Hocko
Quoted 17 lines · David Hildenbrand
Quoted 15 lines · Michal Hocko
Quoted 1 line · David Hildenbrand
On 23.09.19 13:15, Michal Hocko wrote:
[...]
Quoted 7 lines
Quoted 3 lines
I am wondering why those pages get onlined when they are, in fact, supposed to be offline.
It's the current way of emulating sub-memory-block hotplug on top of the memory bock device API we have. Hyper-V and XEN have been using that for a long time.
Do they really have to use the existing block interface when they in fact do not operate on the block granularity? Zone device memory already acts on sub section/block boundaries.
Quoted 9 lines
Quoted 4 lines
Yes, we need memory blocks, especially for user space to properly online them (as we discussed a while back, to decide on a zone) and for udev events, to e.g., properly reload kexec when memory blocks get added/removed/onlined/offlined.
Just to make sure I really follow. We need a user interface to control where the memory gets onlined but it is the driver which determines which part of the block really gets onlined, right?
Yes, it's the drivers job to decide which part of the memory block can actually get used, and when.
It's a little bit like the driver immediately allocates unbacked memory again, to free that memory to the buddy once requested. (similar to how ballooning works).
Signature · 3 lines
Thanks, David / dhildenb