mm/hugetlb: memory offline issues with hugepages
Subsystems (3)
v4 cover mm/hugetlb: memory offline issues with hugepages
This addresses several issues with hugepages and memory offline. While the first patch fixes a panic, and is therefore rather important, the last patch is just a performance optimization.
The second patch fixes a theoretical issue with reserved hugepages, while still leaving some ugly usability issue, see description.
Changes in v4:
- Add check for free vs. reserved hugepages
- Revalidate checks in dissolve_free_huge_page() after taking the lock
- Split up into 3 patches
Changes in v3:
- Add Fixes: c8721bbb
- Add Cc: stable
- Elaborate on losing the gigantic page vs. failing memory offline
- Move page_count() check out of dissolve_free_huge_page()
Changes in v2:
- Update comment in dissolve_free_huge_pages()
- Change locking in dissolve_free_huge_page()
Gerald Schaefer (3):
mm/hugetlb: fix memory offline with hugepage size > memory block size mm/hugetlb: check for reserved hugepages during memory offline mm/hugetlb: improve locking in dissolve_free_huge_pages()
include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 47 +++++++++++++++++++++++++++++++++++------------ mm/memory_hotplug.c | 4 +++- 3 files changed, 41 insertions(+), 16 deletions(-)
Signature · 7 lines
2.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v4 1/3 mm/hugetlb: fix memory offline with hugepage size > memory block size
dissolve_free_huge_pages() will either run into the VM_BUG_ON() or a list corruption and addressing exception when trying to set a memory block offline that is part (but not the first part) of a "gigantic" hugetlb page with a size > memory block size.
When no other smaller hugetlb page sizes are present, the VM_BUG_ON() will trigger directly. In the other case we will run into an addressing exception later, because dissolve_free_huge_page() will not work on the head page of the compound hugetlb page which will result in a NULL hstate from page_hstate().
To fix this, first remove the VM_BUG_ON() because it is wrong, and then use the compound head page in dissolve_free_huge_page(). This means that an unused pre-allocated gigantic page that has any part of itself inside the memory block that is going offline will be dissolved completely. Losing an unused gigantic hugepage is preferable to failing the memory offline, for example in the situation where a (possibly faulty) memory DIMM needs to go offline.
--- mm/hugetlb.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
mm/hugetlb.c +7 -6
@@ -1443,13 +1443,14 @@ static void dissolve_free_huge_page(struct page *page) {spin_lock (&hugetlb_lock);if (PageHuge (page) && !page_count (page)) { -struct hstate *h =page_hstate (page); -int nid =page_to_nid (page); -list_del (&page->lru); +struct page *head =compound_head (page); +struct hstate *h =page_hstate (head); +int nid =page_to_nid (head); +list_del (&head->lru); h->free_huge_pages--; h->free_huge_pages_node[nid]--; h->max_huge_pages--; -update_and_free_page (h, page); +update_and_free_page (h, head); }spin_unlock (&hugetlb_lock); }
@@ -1457,7 +1458,8 @@ static void dissolve_free_huge_page(struct page *page)/* * Dissolve free hugepages in a given pfn range. Used by memory hotplug to * make specified memory blocks removable from the system. -* Note that start_pfn should aligned with (minimum) hugepage size. +* Note that this will dissolve a free gigantic hugepage completely, if any +* part of it lies within the given range. */ void dissolve_free_huge_pages (unsigned long start_pfn,unsigned long end_pfn) {
@@ -1466,7 +1468,6 @@ void dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn)if (!hugepages_supported ())return ; -VM_BUG_ON (!IS_ALIGNED (start_pfn,1 << minimum_order));for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << minimum_order)dissolve_free_huge_page (pfn_to_page (pfn)); }
Signature · 7 lines
2.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v4 2/3 mm/hugetlb: check for reserved hugepages during memory offline
In reply to Gerald SchaeferIn dissolve_free_huge_pages(), free hugepages will be dissolved without making sure that there are enough of them left to satisfy hugepage reservations.
Fix this by adding a return value to dissolve_free_huge_pages() and checking h->free_huge_pages vs. h->resv_huge_pages. Note that this may lead to the situation where dissolve_free_huge_page() returns an error and all free hugepages that were dissolved before that error are lost, while the memory block still cannot be set offline.
--- include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 26 +++++++++++++++++++++----- mm/memory_hotplug.c | 4 +++- 3 files changed, 27 insertions(+), 9 deletions(-)
include/linux/hugetlb.h +3 -3
@@ -450,8 +450,8 @@ static inline pgoff_t basepage_index(struct page *page)return __basepage_index (page); } -extern void dissolve_free_huge_pages (unsigned long start_pfn, -unsigned long end_pfn); +extern int dissolve_free_huge_pages (unsigned long start_pfn, +unsigned long end_pfn);static inline bool hugepage_migration_supported (struct hstate *h) {#ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
@@ -518,7 +518,7 @@ static inline pgoff_t basepage_index(struct page *page) {return page->index; } -#define dissolve_free_huge_pages (s, e) do {} while (0) +#define dissolve_free_huge_pages (s, e) 0#define hugepage_migration_supported (h) false static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
mm/hugetlb.c +21 -5
@@ -1437,22 +1437,32 @@ static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed,/* * Dissolve a given free hugepage into free buddy pages. This function does -* nothing for in-use (including surplus) hugepages. +* nothing for in-use (including surplus) hugepages. Returns -EBUSY if the +* number of free hugepages would be reduced below the number of reserved +* hugepages. */ -static void dissolve_free_huge_page (struct page *page) +static int dissolve_free_huge_page (struct page *page) { +int rc =0 ; +spin_lock (&hugetlb_lock);if (PageHuge (page) && !page_count (page)) {struct page *head =compound_head (page);struct hstate *h =page_hstate (head);int nid =page_to_nid (head); +if (h->free_huge_pages - h->resv_huge_pages ==0 ) { + rc = -EBUSY ; + goto out; + }list_del (&head->lru); h->free_huge_pages--; h->free_huge_pages_node[nid]--; h->max_huge_pages--;update_and_free_page (h, head); } +out:spin_unlock (&hugetlb_lock); +return rc; }/*
@@ -1460,16 +1470,22 @@ static void dissolve_free_huge_page(struct page *page)* make specified memory blocks removable from the system. * Note that this will dissolve a free gigantic hugepage completely, if any * part of it lies within the given range. +* Also note that if dissolve_free_huge_page() returns with an error, all +* free hugepages that were dissolved before that error are lost. */ -void dissolve_free_huge_pages (unsigned long start_pfn,unsigned long end_pfn) +int dissolve_free_huge_pages (unsigned long start_pfn,unsigned long end_pfn) {unsigned long pfn; +int rc =0 ;if (!hugepages_supported ()) -return ; +return rc;for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << minimum_order) -dissolve_free_huge_page (pfn_to_page (pfn)); +if (rc =dissolve_free_huge_page (pfn_to_page (pfn))) +break ; + +return rc; }/*
mm/memory_hotplug.c +3 -1
@@ -1945,7 +1945,9 @@ static int __ref __offline_pages(unsigned long start_pfn,* dissolve free hugepages in the memory block before doing offlining * actually in order to make hugetlbfs's object counting consistent. */ -dissolve_free_huge_pages (start_pfn, end_pfn); + ret =dissolve_free_huge_pages (start_pfn, end_pfn); +if (ret) + goto failed_removal;/* check again */ offlined_pages =check_pages_isolated (start_pfn, end_pfn);if (offlined_pages <0 ) {
Signature · 7 lines
2.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v4 3/3 mm/hugetlb: improve locking in dissolve_free_huge_pages()
In reply to Gerald SchaeferFor every pfn aligned to minimum_order, dissolve_free_huge_pages() will call dissolve_free_huge_page() which takes the hugetlb spinlock, even if the page is not huge at all or a hugepage that is in-use.
Improve this by doing the PageHuge() and page_count() checks already in dissolve_free_huge_pages() before calling dissolve_free_huge_page(). In dissolve_free_huge_page(), when holding the spinlock, those checks need to be revalidated.
--- mm/hugetlb.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
mm/hugetlb.c +9 -3
@@ -1476,14 +1476,20 @@ static int dissolve_free_huge_page(struct page *page)int dissolve_free_huge_pages (unsigned long start_pfn,unsigned long end_pfn) {unsigned long pfn; +struct page *page;int rc =0 ;if (!hugepages_supported ())return rc; -for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << minimum_order) -if (rc =dissolve_free_huge_page (pfn_to_page (pfn))) -break ; +for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << minimum_order) { + page =pfn_to_page (pfn); +if (PageHuge (page) && !page_count (page)) { + rc =dissolve_free_huge_page (page); +if (rc) +break ; + } + }return rc; }
Signature · 7 lines
2.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 27 lines · Gerald Schaefer
This addresses several issues with hugepages and memory offline. While the first patch fixes a panic, and is therefore rather important, the last patch is just a performance optimization.
The second patch fixes a theoretical issue with reserved hugepages, while still leaving some ugly usability issue, see description.
Changes in v4:
- Add check for free vs. reserved hugepages
- Revalidate checks indissolve_free_huge_page()after taking the lock
- Split up into 3 patchesChanges in v3:
- Add Fixes:c8721bbb
- Add Cc: stable
- Elaborate on losing the gigantic page vs. failing memory offline
- Movepage_count()check out ofdissolve_free_huge_page()Changes in v2:
- Update comment indissolve_free_huge_pages()
- Change locking indissolve_free_huge_page()Gerald Schaefer (3):
mm/hugetlb: fix memory offline with hugepage size > memory block size mm/hugetlb: check for reserved hugepages during memory offline mm/hugetlb: improve locking indissolve_free_huge_pages()
Quoted 4 lines
include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 47 +++++++++++++++++++++++++++++++++++------------ mm/memory_hotplug.c | 4 +++- 3 files changed, 41 insertions(+), 16 deletions(-)
I'm happy with these patches fixing/improving hugetlb offline code, thank you very much, Gerald and reviewers/testers!
For patchset ...
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v4 1/3] mm/hugetlb: fix memory offline with hugepage size > memory block size
In reply to Gerald SchaeferQuoted 19 lines · Gerald Schaefer
dissolve_free_huge_pages()will either run into theVM_BUG_ON()or a list corruption and addressing exception when trying to set a memory block offline that is part (but not the first part) of a "gigantic" hugetlb page with a size > memory block size.When no other smaller hugetlb page sizes are present, the
VM_BUG_ON()will trigger directly. In the other case we will run into an addressing exception later, becausedissolve_free_huge_page()will not work on the head page of the compound hugetlb page which will result in a NULL hstate frompage_hstate().To fix this, first remove the
VM_BUG_ON()because it is wrong, and then use the compound head page indissolve_free_huge_page(). This means that an unused pre-allocated gigantic page that has any part of itself inside the memory block that is going offline will be dissolved completely. Losing an unused gigantic hugepage is preferable to failing the memory offline, for example in the situation where a (possibly faulty) memory DIMM needs to go offline.
Quoted 3 lines
Fixes c8721bbb ("mm: memory-hotplug: enable memory hotplug to handle hugepage")Cc <[email protected]>Signed-off-by Gerald Schaefer <[email protected]>
Quoted 47 lines
--- mm/hugetlb.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)mm/hugetlb.c +7
-6@@ -1443,13 +1443,14 @@ static void dissolve_free_huge_page(struct page *page) {spin_lock (&hugetlb_lock);if (PageHuge (page) && !page_count (page)) { -struct hstate *h =page_hstate (page); -int nid =page_to_nid (page); -list_del (&page->lru); +struct page *head =compound_head (page); +struct hstate *h =page_hstate (head); +int nid =page_to_nid (head); +list_del (&head->lru); h->free_huge_pages--; h->free_huge_pages_node[nid]--; h->max_huge_pages--; -update_and_free_page (h, page); +update_and_free_page (h, head); }spin_unlock (&hugetlb_lock); }@@ -1457,7 +1458,8 @@ static void dissolve_free_huge_page(struct page *page)/* * Dissolve free hugepages in a given pfn range. Used by memory hotplug to * make specified memory blocks removable from the system. -* Note that start_pfn should aligned with (minimum) hugepage size. +* Note that this will dissolve a free gigantic hugepage completely, if any +* part of it lies within the given range. */ void dissolve_free_huge_pages (unsigned long start_pfn,unsigned long end_pfn) {@@ -1466,7 +1468,6 @@ void dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn)if (!hugepages_supported ())return ; -VM_BUG_ON (!IS_ALIGNED (start_pfn,1 << minimum_order));for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << minimum_order)dissolve_free_huge_page (pfn_to_page (pfn)); }Signature · 1 line
2.8.4
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v4 2/3] mm/hugetlb: check for reserved hugepages during memory offline
In reply to Gerald SchaeferQuoted 3 lines · Gerald Schaefer
In
dissolve_free_huge_pages(), free hugepages will be dissolved without making sure that there are enough of them left to satisfy hugepage reservations.
otherwise a poor process with a reservation might get unexpected SIGBUS, right?
Quoted 5 lines
Fix this by adding a return value to
dissolve_free_huge_pages()and checkingh->free_huge_pagesvs.h->resv_huge_pages. Note that this may lead to the situation wheredissolve_free_huge_page()returns an error and all free hugepages that were dissolved before that error are lost, while the memory block still cannot be set offline.
Hmm, OK offline failure is certainly a better option than an application failure.
Quoted 2 lines
Fixes c8721bbb ("mm: memory-hotplug: enable memory hotplug to handle hugepage")Signed-off-by Gerald Schaefer <[email protected]>
Quoted 112 lines
--- include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 26 +++++++++++++++++++++----- mm/memory_hotplug.c | 4 +++- 3 files changed, 27 insertions(+), 9 deletions(-)include/linux/hugetlb.h +3
-3@@ -450,8 +450,8 @@ static inline pgoff_t basepage_index(struct page *page)return __basepage_index (page); } -extern void dissolve_free_huge_pages (unsigned long start_pfn, -unsigned long end_pfn); +extern int dissolve_free_huge_pages (unsigned long start_pfn, +unsigned long end_pfn);static inline bool hugepage_migration_supported (struct hstate *h) {#ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION @@ -518,7 +518,7 @@ static inline pgoff_t basepage_index(struct page *page) {return page->index; } -#define dissolve_free_huge_pages (s, e) do {} while (0) +#define dissolve_free_huge_pages (s, e) 0#define hugepage_migration_supported (h) false static inline spinlock_t *huge_pte_lockptr(struct hstate *h,mm/hugetlb.c +21
-5@@ -1437,22 +1437,32 @@ static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed,/* * Dissolve a given free hugepage into free buddy pages. This function does -* nothing for in-use (including surplus) hugepages. +* nothing for in-use (including surplus) hugepages. Returns -EBUSY if the +* number of free hugepages would be reduced below the number of reserved +* hugepages. */ -static void dissolve_free_huge_page (struct page *page) +static int dissolve_free_huge_page (struct page *page) { +int rc =0 ; +spin_lock (&hugetlb_lock);if (PageHuge (page) && !page_count (page)) {struct page *head =compound_head (page);struct hstate *h =page_hstate (head);int nid =page_to_nid (head); +if (h->free_huge_pages - h->resv_huge_pages ==0 ) { + rc = -EBUSY ; + goto out; + }list_del (&head->lru); h->free_huge_pages--; h->free_huge_pages_node[nid]--; h->max_huge_pages--;update_and_free_page (h, head); } +out:spin_unlock (&hugetlb_lock); +return rc; }/* @@ -1460,16 +1470,22 @@ static void dissolve_free_huge_page(struct page *page)* make specified memory blocks removable from the system. * Note that this will dissolve a free gigantic hugepage completely, if any * part of it lies within the given range. +* Also note that if dissolve_free_huge_page() returns with an error, all +* free hugepages that were dissolved before that error are lost. */ -void dissolve_free_huge_pages (unsigned long start_pfn,unsigned long end_pfn) +int dissolve_free_huge_pages (unsigned long start_pfn,unsigned long end_pfn) {unsigned long pfn; +int rc =0 ;if (!hugepages_supported ()) -return ; +return rc;for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << minimum_order) -dissolve_free_huge_page (pfn_to_page (pfn)); +if (rc =dissolve_free_huge_page (pfn_to_page (pfn))) +break ; + +return rc; }/* mm/memory_hotplug.c +3
-1@@ -1945,7 +1945,9 @@ static int __ref __offline_pages(unsigned long start_pfn,* dissolve free hugepages in the memory block before doing offlining * actually in order to make hugetlbfs's object counting consistent. */ -dissolve_free_huge_pages (start_pfn, end_pfn); + ret =dissolve_free_huge_pages (start_pfn, end_pfn); +if (ret) + goto failed_removal;/* check again */ offlined_pages =check_pages_isolated (start_pfn, end_pfn);if (offlined_pages <0 ) {Signature · 1 line
2.8.4
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v4 3/3] mm/hugetlb: improve locking in dissolve_free_huge_pages()
In reply to Gerald SchaeferQuoted 10 lines · Gerald Schaefer
For every pfn aligned to
minimum_order,dissolve_free_huge_pages()will calldissolve_free_huge_page()which takes the hugetlb spinlock, even if the page is not huge at all or a hugepage that is in-use.Improve this by doing the
PageHuge()andpage_count()checks already indissolve_free_huge_pages()before callingdissolve_free_huge_page(). Indissolve_free_huge_page(), when holding the spinlock, those checks need to be revalidated.Signed-off-by Gerald Schaefer <[email protected]>
Quoted 34 lines
--- mm/hugetlb.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)mm/hugetlb.c +9
-3@@ -1476,14 +1476,20 @@ static int dissolve_free_huge_page(struct page *page)int dissolve_free_huge_pages (unsigned long start_pfn,unsigned long end_pfn) {unsigned long pfn; +struct page *page;int rc =0 ;if (!hugepages_supported ())return rc; -for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << minimum_order) -if (rc =dissolve_free_huge_page (pfn_to_page (pfn))) -break ; +for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << minimum_order) { + page =pfn_to_page (pfn); +if (PageHuge (page) && !page_count (page)) { + rc =dissolve_free_huge_page (page); +if (rc) +break ; + } + }return rc; }Signature · 1 line
2.8.4
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v4 2/3] mm/hugetlb: check for reserved hugepages during memory offline
In reply to Michal HockoQuoted 7 lines · Michal Hocko
Quoted 3 lines · Gerald Schaefer
In
dissolve_free_huge_pages(), free hugepages will be dissolved without making sure that there are enough of them left to satisfy hugepage reservations.otherwise a poor process with a reservation might get unexpected SIGBUS, right?
Yes, that is correct.
Quoted 9 lines
Quoted 6 lines
Fix this by adding a return value to
dissolve_free_huge_pages()and checkingh->free_huge_pagesvs.h->resv_huge_pages. Note that this may lead to the situation wheredissolve_free_huge_page()returns an error and all free hugepages that were dissolved before that error are lost, while the memory block still cannot be set offline.Hmm, OK offline failure is certainly a better option than an application failure.
I agree.
However, if the reason for the offline is that a dimm within the huge page is starting to fail, then one could make an argument that forced offline of the huge page would be more desirable. We really don't know the reason for the offline. So, I think the approach of this patch is best.
--
Mike Kravetz
Quoted 109 lines
Quoted 3 lines
Fixes c8721bbb ("mm: memory-hotplug: enable memory hotplug to handle hugepage")Signed-off-by Gerald Schaefer <[email protected]>Acked-by Michal Hocko <[email protected]>Quoted 104 lines
--- include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 26 +++++++++++++++++++++----- mm/memory_hotplug.c | 4 +++- 3 files changed, 27 insertions(+), 9 deletions(-)include/linux/hugetlb.h +3
-3@@ -450,8 +450,8 @@ static inline pgoff_t basepage_index(struct page *page)return __basepage_index (page); } -extern void dissolve_free_huge_pages (unsigned long start_pfn, -unsigned long end_pfn); +extern int dissolve_free_huge_pages (unsigned long start_pfn, +unsigned long end_pfn);static inline bool hugepage_migration_supported (struct hstate *h) {#ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION @@ -518,7 +518,7 @@ static inline pgoff_t basepage_index(struct page *page) {return page->index; } -#define dissolve_free_huge_pages (s, e) do {} while (0) +#define dissolve_free_huge_pages (s, e) 0#define hugepage_migration_supported (h) false static inline spinlock_t *huge_pte_lockptr(struct hstate *h,mm/hugetlb.c +21
-5@@ -1437,22 +1437,32 @@ static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed,/* * Dissolve a given free hugepage into free buddy pages. This function does -* nothing for in-use (including surplus) hugepages. +* nothing for in-use (including surplus) hugepages. Returns -EBUSY if the +* number of free hugepages would be reduced below the number of reserved +* hugepages. */ -static void dissolve_free_huge_page (struct page *page) +static int dissolve_free_huge_page (struct page *page) { +int rc =0 ; +spin_lock (&hugetlb_lock);if (PageHuge (page) && !page_count (page)) {struct page *head =compound_head (page);struct hstate *h =page_hstate (head);int nid =page_to_nid (head); +if (h->free_huge_pages - h->resv_huge_pages ==0 ) { + rc = -EBUSY ; + goto out; + }list_del (&head->lru); h->free_huge_pages--; h->free_huge_pages_node[nid]--; h->max_huge_pages--;update_and_free_page (h, head); } +out:spin_unlock (&hugetlb_lock); +return rc; }/* @@ -1460,16 +1470,22 @@ static void dissolve_free_huge_page(struct page *page)* make specified memory blocks removable from the system. * Note that this will dissolve a free gigantic hugepage completely, if any * part of it lies within the given range. +* Also note that if dissolve_free_huge_page() returns with an error, all +* free hugepages that were dissolved before that error are lost. */ -void dissolve_free_huge_pages (unsigned long start_pfn,unsigned long end_pfn) +int dissolve_free_huge_pages (unsigned long start_pfn,unsigned long end_pfn) {unsigned long pfn; +int rc =0 ;if (!hugepages_supported ()) -return ; +return rc;for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << minimum_order) -dissolve_free_huge_page (pfn_to_page (pfn)); +if (rc =dissolve_free_huge_page (pfn_to_page (pfn))) +break ; + +return rc; }/* mm/memory_hotplug.c +0
-1@@ -1945,7 +1945,9 @@ static int __ref __offline_pages(unsigned long start_pfn,* dissolve free hugepages in the memory block before doing offlining * actually in order to make hugetlbfs's object counting consistent. */ -dissolve_free_huge_pages (start_pfn, end_pfn);
Quoted 9 lines
Quoted 8 lines
mm/memory_hotplug.c +3
-0+ ret =dissolve_free_huge_pages (start_pfn, end_pfn); +if (ret) + goto failed_removal;/* check again */ offlined_pages =check_pages_isolated (start_pfn, end_pfn);if (offlined_pages <0 ) {Signature · 1 line
2.8.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v4 2/3] mm/hugetlb: check for reserved hugepages during memory offline
Quoted 2 lines · Mike Kravetz
Quoted 1 line · Michal Hocko
On Mon 26-09-16 19:28:10, Gerald Schaefer wrote:
[...]
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Fix this by adding a return value to
dissolve_free_huge_pages()and checkingh->free_huge_pagesvs.h->resv_huge_pages. Note that this may lead to the situation wheredissolve_free_huge_page()returns an error and all free hugepages that were dissolved before that error are lost, while the memory block still cannot be set offline.Hmm, OK offline failure is certainly a better option than an application failure.
Quoted 6 lines
I agree.
However, if the reason for the offline is that a dimm within the huge page is starting to fail, then one could make an argument that forced offline of the huge page would be more desirable. We really don't know the reason for the offline. So, I think the approach of this patch is best.
I though that memory which was already reported to be faulty would be marked HWPoison and removed from the allocator. But it's been quite some time since I've looked in that area...
Signature · 2 lines
Michal Hocko SUSE Labs