mm/page_alloc: find_large_buddy() from start_pfn aligned order
Subsystems (2)
PATCH v2 1/1 mm/page_alloc: find_large_buddy() from start_pfn aligned order
We iterate pfn from order 0 to MAX_PAGE_ORDER aligned to find large buddy. While if the order is less than start_pfn aligned order, we would get the same pfn and do the same check again.
Iterate from start_pfn aligned order to reduce duplicated work.
---
v2: add comment on assignment of order
--- mm/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
mm/page_alloc.c +7 -1
@@ -2033,7 +2033,13 @@ static int move_freepages_block(struct zone *zone, struct page *page,/* Look for a buddy that straddles start_pfn */ static unsigned long find_large_buddy (unsigned long start_pfn) { -int order =0 ; +/* +* If start_pfn is not an order-0 PageBuddy, next PageBuddy containing +* start_pfn has minimal order of __ffs(start_pfn) + 1. Start checking +* the order with __ffs(start_pfn). If start_pfn is order-0 PageBuddy, +* the starting order does not matter. +*/ +int order = start_pfn ?__ffs (start_pfn) :MAX_PAGE_ORDER ;struct page *page;unsigned long pfn = start_pfn;
Signature · 1 line
2.34.1
Quoted 6 lines · Wei Yang
We iterate pfn from order 0 to
MAX_PAGE_ORDERaligned to find large buddy. While if the order is less thanstart_pfnaligned order, we would get the same pfn and do the same check again.Iterate from
start_pfnaligned order to reduce duplicated work.
Quoted 8 lines
Signed-off-by Wei Yang <[email protected]>Cc Johannes Weiner <[email protected]>Cc Zi Yan <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>Signed-off-by Andrew Morton <[email protected]>Reviewed-by Zi Yan <[email protected]>
Quoted 26 lines
---
v2: add comment on assignment of order--- mm/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)mm/page_alloc.c +7
-1@@ -2033,7 +2033,13 @@ static int move_freepages_block(struct zone *zone, struct page *page,/* Look for a buddy that straddles start_pfn */ static unsigned long find_large_buddy (unsigned long start_pfn) { -int order =0 ; +/* +* If start_pfn is not an order-0 PageBuddy, next PageBuddy containing +* start_pfn has minimal order of __ffs(start_pfn) + 1. Start checking +* the order with __ffs(start_pfn). If start_pfn is order-0 PageBuddy, +* the starting order does not matter. +*/ +int order = start_pfn ?__ffs (start_pfn) :MAX_PAGE_ORDER ;struct page *page;unsigned long pfn = start_pfn;
Johannes Weiner
reviewerQuoted 27 lines · Wei Yang
We iterate pfn from order 0 to
MAX_PAGE_ORDERaligned to find large buddy. While if the order is less thanstart_pfnaligned order, we would get the same pfn and do the same check again.Iterate from
start_pfnaligned order to reduce duplicated work.Signed-off-by Wei Yang <[email protected]>Cc Johannes Weiner <[email protected]>Cc Zi Yan <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>Signed-off-by Andrew Morton <[email protected]>Reviewed-by Zi Yan <[email protected]>---
v2: add comment on assignment of order--- mm/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)mm/page_alloc.c +0
-0@@ -2033,7 +2033,13 @@ static int move_freepages_block(struct zone *zone, struct page *page,/* Look for a buddy that straddles start_pfn */
mm/page_alloc.c static int move_freepages_block(struct zone *zone, struct page *page, · line 2042
Quoted 10 lines
mm/page_alloc.c +7
-1static unsigned long find_large_buddy (unsigned long start_pfn) { -int order =0 ; +/* +* If start_pfn is not an order-0 PageBuddy, next PageBuddy containing +* start_pfn has minimal order of __ffs(start_pfn) + 1. Start checking +* the order with __ffs(start_pfn). If start_pfn is order-0 PageBuddy, +* the starting order does not matter. +*/ +int order = start_pfn ?__ffs (start_pfn) :MAX_PAGE_ORDER ;
This should be __ffs(start_pfn) - 1, no?
If you have the lowest bit set in the pfn, you should check the order-1 buddy to the left first. But ffs(1) is already 1, which means the loop will check order-2 next.
Zi Yan
reviewerQuoted 41 lines · Johannes Weiner
Quoted 27 lines · Wei Yang
We iterate pfn from order 0 to
MAX_PAGE_ORDERaligned to find large buddy. While if the order is less thanstart_pfnaligned order, we would get the same pfn and do the same check again.Iterate from
start_pfnaligned order to reduce duplicated work.Signed-off-by Wei Yang <[email protected]>Cc Johannes Weiner <[email protected]>Cc Zi Yan <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>Signed-off-by Andrew Morton <[email protected]>Reviewed-by Zi Yan <[email protected]>---
v2: add comment on assignment of order--- mm/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)mm/page_alloc.c +0
-0@@ -2033,7 +2033,13 @@ static int move_freepages_block(struct zone *zone, struct page *page,/* Look for a buddy that straddles start_pfn */ mm/page_alloc.c static int move_freepages_block(struct zone *zone, struct page *page, · line 2042
Quoted 10 lines
mm/page_alloc.c +7
-1static unsigned long find_large_buddy (unsigned long start_pfn) { -int order =0 ; +/* +* If start_pfn is not an order-0 PageBuddy, next PageBuddy containing +* start_pfn has minimal order of __ffs(start_pfn) + 1. Start checking +* the order with __ffs(start_pfn). If start_pfn is order-0 PageBuddy, +* the starting order does not matter. +*/ +int order = start_pfn ?__ffs (start_pfn) :MAX_PAGE_ORDER ;This should be
__ffs(start_pfn)- 1, no?
Quoted 3 lines
If you have the lowest bit set in the pfn, you should check the order-1 buddy to the left first. But ffs(1) is already 1, which means the loop will check order-2 next.
__ffs() seems different from usespace ffs() and is 0-index, so __ffs() is what you mean ffs() - 1.
Best Regards,
Yan, Zi
Quoted 43 lines · Zi Yan
Quoted 41 lines · Johannes Weiner
Quoted 27 lines · Wei Yang
We iterate pfn from order 0 to
MAX_PAGE_ORDERaligned to find large buddy. While if the order is less thanstart_pfnaligned order, we would get the same pfn and do the same check again.Iterate from
start_pfnaligned order to reduce duplicated work.Signed-off-by Wei Yang <[email protected]>Cc Johannes Weiner <[email protected]>Cc Zi Yan <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>Signed-off-by Andrew Morton <[email protected]>Reviewed-by Zi Yan <[email protected]>---
v2: add comment on assignment of order--- mm/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)mm/page_alloc.c +0
-0@@ -2033,7 +2033,13 @@ static int move_freepages_block(struct zone *zone, struct page *page,/* Look for a buddy that straddles start_pfn */ mm/page_alloc.c static int move_freepages_block(struct zone *zone, struct page *page, · line 2042
Quoted 10 lines
mm/page_alloc.c +7
-1static unsigned long find_large_buddy (unsigned long start_pfn) { -int order =0 ; +/* +* If start_pfn is not an order-0 PageBuddy, next PageBuddy containing +* start_pfn has minimal order of __ffs(start_pfn) + 1. Start checking +* the order with __ffs(start_pfn). If start_pfn is order-0 PageBuddy, +* the starting order does not matter. +*/ +int order = start_pfn ?__ffs (start_pfn) :MAX_PAGE_ORDER ;This should be
__ffs(start_pfn)- 1, no?
Quoted 6 lines
Quoted 3 lines
If you have the lowest bit set in the pfn, you should check the order-1 buddy to the left first. But ffs(1) is already 1, which means the loop will check order-2 next.
__ffs()seems different from usespaceffs()and is 0-index, so__ffs()is what you meanffs()- 1.
I'm going back to reading school.
Quoted 6 lines · Wei Yang
We iterate pfn from order 0 to
MAX_PAGE_ORDERaligned to find large buddy. While if the order is less thanstart_pfnaligned order, we would get the same pfn and do the same check again.Iterate from
start_pfnaligned order to reduce duplicated work.
Quoted 8 lines
Signed-off-by Wei Yang <[email protected]>Cc Johannes Weiner <[email protected]>Cc Zi Yan <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>Signed-off-by Andrew Morton <[email protected]>Reviewed-by Zi Yan <[email protected]>