Skip to contentSkip to conversation

mm: fix regression with deferred struct page init

PATCH In review Juergen Gross 3 participants 7 messages Jun 20, 2019 – Jun 28, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: fix regression with deferred struct page init

Commit 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections") is causing a regression on some systems when the kernel is booted as Xen dom0.

The system will just hang in early boot.

Reason is an endless loop in get_page_from_freelist() in case the first zone looked at has no free memory. deferred_grow_zone() is always returning true due to the following code snipplet:

  /* If the zone is empty somebody else may have cleared out the zone */
  if (!deferred_init_mem_pfn_range_in_zone(&i, zone, &spfn, &epfn,
                                           first_deferred_pfn)) {
          pgdat->first_deferred_pfn = ULONG_MAX;
          pgdat_resize_unlock(pgdat, &flags);
          return true;
  }

This in turn results in the loop as get_page_from_freelist() is assuming forward progress can be made by doing some more struct page initialization.

Cc Alexander Duyck <[email protected]>
Fixes 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections")
---
 mm/page_alloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
index d66bc8abe0af..8e3bc949ebcc 100644
@@ -1826,7 +1826,8 @@ deferred_grow_zone(struct zone *zone, unsigned int order)
 						 first_deferred_pfn)) {
 		pgdat->first_deferred_pfn = ULONG_MAX;
 		pgdat_resize_unlock(pgdat, &flags);
-		return true;
+		/* Retry only once. */
+		return first_deferred_pfn != ULONG_MAX;
 	}
 
 	/*
Signature · 1 line
2.16.4
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · Juergen Gross

Commit 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections") is causing a regression on some systems when the kernel is booted as Xen dom0.

The system will just hang in early boot.

Reason is an endless loop in get_page_from_freelist() in case the first zone looked at has no free memory. deferred_grow_zone() is always returning true due to the following code snipplet:

  /* If the zone is empty somebody else may have cleared out the zone */
  if (!deferred_init_mem_pfn_range_in_zone(&i, zone, &spfn, &epfn,
                                           first_deferred_pfn)) {
          pgdat->first_deferred_pfn = ULONG_MAX;
          pgdat_resize_unlock(pgdat, &flags);
          return true;
  }
Quoted 8 lines

This in turn results in the loop as get_page_from_freelist() is assuming forward progress can be made by doing some more struct page initialization.

Cc Alexander Duyck <[email protected]>
Fixes 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections")
Quoted 18 lines
---
 mm/page_alloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
index d66bc8abe0af..8e3bc949ebcc 100644
@@ -1826,7 +1826,8 @@ deferred_grow_zone(struct zone *zone, unsigned int order)
 						 first_deferred_pfn)) {
 		pgdat->first_deferred_pfn = ULONG_MAX;
 		pgdat_resize_unlock(pgdat, &flags);
-		return true;
+		/* Retry only once. */
+		return first_deferred_pfn != ULONG_MAX;
 	}
 
 	/*
#2 lore raw
In reply to Juergen Gross

Gentle ping.

I'd really like to have that in 5.2 in order to avoid the regression introduced with 5.2-rc1.

Juergen

Quoted 45 lines · Juergen Gross

Commit 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections") is causing a regression on some systems when the kernel is booted as Xen dom0.

The system will just hang in early boot.

Reason is an endless loop in get_page_from_freelist() in case the first zone looked at has no free memory. deferred_grow_zone() is always returning true due to the following code snipplet:

   /* If the zone is empty somebody else may have cleared out the zone */
   if (!deferred_init_mem_pfn_range_in_zone(&i, zone, &spfn, &epfn,
                                            first_deferred_pfn)) {
           pgdat->first_deferred_pfn = ULONG_MAX;
           pgdat_resize_unlock(pgdat, &flags);
           return true;
   }

This in turn results in the loop as get_page_from_freelist() is assuming forward progress can be made by doing some more struct page initialization.

Cc Alexander Duyck <[email protected]>
Fixes 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections")
---
  mm/page_alloc.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
index d66bc8abe0af..8e3bc949ebcc 100644
@@ -1826,7 +1826,8 @@ deferred_grow_zone(struct zone *zone, unsigned int order)
  						 first_deferred_pfn)) {
  		pgdat->first_deferred_pfn = ULONG_MAX;
  		pgdat_resize_unlock(pgdat, &flags);
-		return true;
+		/* Retry only once. */
+		return first_deferred_pfn != ULONG_MAX;
  	}
 
  	/*
#3 lore raw
Quoted 4 lines · Juergen Gross

Gentle ping.

I'd really like to have that in 5.2 in order to avoid the regression introduced with 5.2-rc1.

Adding some maintainers directly...

Juergen

Quoted 56 lines

Juergen

Quoted 36 lines · Juergen Gross

Commit 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections") is causing a regression on some systems when the kernel is booted as Xen dom0.

The system will just hang in early boot.

Reason is an endless loop in get_page_from_freelist() in case the first zone looked at has no free memory. deferred_grow_zone() is always returning true due to the following code snipplet:

   /* If the zone is empty somebody else may have cleared out the zone */ if (!deferred_init_mem_pfn_range_in_zone(&i, zone, &spfn, &epfn, first_deferred_pfn)) { pgdat->first_deferred_pfn = ULONG_MAX; pgdat_resize_unlock(pgdat, &flags);
           return true;
   }

This in turn results in the loop as get_page_from_freelist() is assuming forward progress can be made by doing some more struct page initialization.

Cc Alexander Duyck <[email protected]>
Fixes 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections")

---
  mm/page_alloc.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +0 -0
index d66bc8abe0af..8e3bc949ebcc 100644

mm/page_alloc.c deferred_grow_zone(struct zone *zone, unsigned · line 1833

Quoted 9 lines
mm/page_alloc.c +2 -1
@@ -1826,7 +1826,8 @@ deferred_grow_zone(struct zone *zone, unsigned 
 int order)
                            first_deferred_pfn)) {
           pgdat->first_deferred_pfn = ULONG_MAX;
           pgdat_resize_unlock(pgdat, &flags);
-        return true;
+        /* Retry only once. */
+        return first_deferred_pfn != ULONG_MAX;
       }
       /*

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v1 1/1
#4 lore raw
In reply to Juergen Gross
Quoted 8 lines · Juergen Gross

Commit 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections") is causing a regression on some systems when the kernel is booted as Xen dom0.

The system will just hang in early boot.

Reason is an endless loop in get_page_from_freelist() in case the first zone looked at has no free memory. deferred_grow_zone() is always

Could you explain how we ended up with the zone having no memory? Is xen "stealing" memblock memory without adding it to memory.reserved? In other words, how do we end up with an empty zone that has non zero end_pfn?

Quoted 10 lines

returning true due to the following code snipplet:

  /* If the zone is empty somebody else may have cleared out the zone */
  if (!deferred_init_mem_pfn_range_in_zone(&i, zone, &spfn, &epfn,
                                           first_deferred_pfn)) {
          pgdat->first_deferred_pfn = ULONG_MAX;
          pgdat_resize_unlock(pgdat, &flags);
          return true;
  }
Quoted 3 lines

This in turn results in the loop as get_page_from_freelist() is assuming forward progress can be made by doing some more struct page initialization.

The patch looks correct. The code is subtle but the comment helps.

Quoted 4 lines
Cc Alexander Duyck <[email protected]>
Fixes 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections")
Quoted 20 lines
---
 mm/page_alloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
index d66bc8abe0af..8e3bc949ebcc 100644
@@ -1826,7 +1826,8 @@ deferred_grow_zone(struct zone *zone, unsigned int order)
 						 first_deferred_pfn)) {
 		pgdat->first_deferred_pfn = ULONG_MAX;
 		pgdat_resize_unlock(pgdat, &flags);
-		return true;
+		/* Retry only once. */
+		return first_deferred_pfn != ULONG_MAX;
 	}
 
 	/*
Signature · 1 line
2.16.4
Signature · 2 lines
Michal Hocko
SUSE Labs
#5 lore raw
Quoted 7 lines · Michal Hocko
Quoted 6 lines · Juergen Gross

Commit 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections") is causing a regression on some systems when the kernel is booted as Xen dom0.

The system will just hang in early boot.

Quoted 7 lines
Quoted 2 lines

Reason is an endless loop in get_page_from_freelist() in case the first zone looked at has no free memory. deferred_grow_zone() is always

Could you explain how we ended up with the zone having no memory? Is xen "stealing" memblock memory without adding it to memory.reserved? In other words, how do we end up with an empty zone that has non zero end_pfn?

Why do you think Xen is stealing the memory in an odd way?

Doesn't deferred_init_mem_pfn_range_in_zone() return false when no free memory is found? So exactly if the memory was added to memory.reserved that will happen.

I guess the difference to a bare metal boot is that a Xen dom0 will need probably more memory in early boot phase, so that issue is more likely to occur.

In my case the system had two zones, where the 2nd zone had some free memory. The search never made it to the 2nd zone as the search ended in an endless loop for the 1st zone.

Quoted 15 lines
Quoted 11 lines

returning true due to the following code snipplet:

   /* If the zone is empty somebody else may have cleared out the zone */
   if (!deferred_init_mem_pfn_range_in_zone(&i, zone, &spfn, &epfn,
                                            first_deferred_pfn)) {
           pgdat->first_deferred_pfn = ULONG_MAX;
           pgdat_resize_unlock(pgdat, &flags);
           return true;
   }
Quoted 3 lines

This in turn results in the loop as get_page_from_freelist() is assuming forward progress can be made by doing some more struct page initialization.

Quoted 8 lines

The patch looks correct. The code is subtle but the comment helps.

Quoted 4 lines
Cc Alexander Duyck <[email protected]>
Fixes 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections")

Thanks,

Juergen

#6 lore raw
Quoted 16 lines · Juergen Gross
Quoted 7 lines · Michal Hocko
Quoted 6 lines · Juergen Gross

Commit 0e56acae4b4dd4a9 ("mm: initialize MAX_ORDER_NR_PAGES at a time instead of doing larger sections") is causing a regression on some systems when the kernel is booted as Xen dom0.

The system will just hang in early boot.

Quoted 7 lines
Quoted 2 lines

Reason is an endless loop in get_page_from_freelist() in case the first zone looked at has no free memory. deferred_grow_zone() is always

Could you explain how we ended up with the zone having no memory? Is xen "stealing" memblock memory without adding it to memory.reserved? In other words, how do we end up with an empty zone that has non zero end_pfn?

Quoted 5 lines

Why do you think Xen is stealing the memory in an odd way?

Doesn't deferred_init_mem_pfn_range_in_zone() return false when no free memory is found? So exactly if the memory was added to memory.reserved that will happen.

You are right. I managed to confuse myself and thought that __next_mem_range return index to both memblock types. But I am wrong here and it excludes type_b regions. I should have read the documentation. My bad and sorry for the confusion.

Signature · 2 lines
Michal Hocko
SUSE Labs