linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v17 1/9] mm: Adjust shuffle code to allow for future coalescing
       [not found] <<20200211224602.29318.84523.stgit@localhost.localdomain>
@ 2021-03-09  8:13 ` Bodeddula, Balasubramaniam
  2021-03-11  1:05   ` Alexander Duyck
  0 siblings, 1 reply; 3+ messages in thread
From: Bodeddula, Balasubramaniam @ 2021-03-09  8:13 UTC (permalink / raw)
  To: alexander.duyck
  Cc: aarcange, akpm, alexander.h.duyck, dan.j.williams, dave.hansen,
	david, konrad.wilk, kvm, lcapitulino, linux-kernel, linux-mm,
	mgorman, mhocko, mst, nitesh, osalvador, pagupta, pbonzini, riel,
	vbabka, wei.w.wang, willy, yang.zhang.wz, Graf (AWS),
	Alexander, Herrenschmidt, Benjamin

[-- Attachment #1: Type: text/plain, Size: 1020 bytes --]

Hi Alexander,

My team was evaluating FPR and observed that these patches don’t report memory for deallocated hugeapages directly and need to cycle through buddy allocator. For example, say we need to allocate a maximum of 12 * 1G hugepages (by setting nr_hugepages), use 8 * 1G hugepages, and then deallocate 4 * 1G hugepages. Unlike regular 4K pages, this 4G worth of memory will not be reported until we set nr_hugepages to 8 (wait sometime(?) for FPR to do its work) and set it back again to 12. While this works fine in theory, in practice,  setting nr_hugepages to 12 could fail too due to fragmentation (this could depend on other processes memory usage behavior).

If FPR could report this free memory without cycling through buddy allocator, it makes the solution more robust. I am looking for advice on how feasible this approach is and what would be the effort for building this functionality. In general, if there are other thoughts on how we can address this, please do let me know.

Thanks,
bala

[-- Attachment #2: Type: text/html, Size: 2826 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v17 1/9] mm: Adjust shuffle code to allow for future coalescing
  2021-03-09  8:13 ` [PATCH v17 1/9] mm: Adjust shuffle code to allow for future coalescing Bodeddula, Balasubramaniam
@ 2021-03-11  1:05   ` Alexander Duyck
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander Duyck @ 2021-03-11  1:05 UTC (permalink / raw)
  To: Bodeddula, Balasubramaniam
  Cc: aarcange, akpm, alexander.h.duyck, dan.j.williams, dave.hansen,
	david, konrad.wilk, kvm, lcapitulino, linux-kernel, linux-mm,
	mgorman, mhocko, mst, nitesh, osalvador, pagupta, pbonzini, riel,
	vbabka, wei.w.wang, willy, yang.zhang.wz, Graf (AWS),
	Alexander, Herrenschmidt, Benjamin

Hi Bala,

There was a similar effort several months ago that was trying to do
this in conjunction with pre-zeroing of pages. I suspect if you wanted
to you could probably pick up some of their patch set and work with
that. It can be found at:
https://www.spinics.net/lists/linux-mm/msg239735.html

Thanks.

- Alex

On Tue, Mar 9, 2021 at 12:13 AM Bodeddula, Balasubramaniam
<bodeddub@amazon.com> wrote:
>
> Hi Alexander,
>
>
>
> My team was evaluating FPR and observed that these patches don’t report memory for deallocated hugeapages directly and need to cycle through buddy allocator. For example, say we need to allocate a maximum of 12 * 1G hugepages (by setting nr_hugepages), use 8 * 1G hugepages, and then deallocate 4 * 1G hugepages. Unlike regular 4K pages, this 4G worth of memory will not be reported until we set nr_hugepages to 8 (wait sometime(?) for FPR to do its work) and set it back again to 12. While this works fine in theory, in practice,  setting nr_hugepages to 12 could fail too due to fragmentation (this could depend on other processes memory usage behavior).
>
>
>
> If FPR could report this free memory without cycling through buddy allocator, it makes the solution more robust. I am looking for advice on how feasible this approach is and what would be the effort for building this functionality. In general, if there are other thoughts on how we can address this, please do let me know.
>
>
>
> Thanks,
>
> bala


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v17 1/9] mm: Adjust shuffle code to allow for future coalescing
  2020-02-11 22:45 [PATCH v17 0/9] mm / virtio: Provide support for free page reporting Alexander Duyck
@ 2020-02-11 22:46 ` Alexander Duyck
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander Duyck @ 2020-02-11 22:46 UTC (permalink / raw)
  To: kvm, david, mst, linux-kernel, linux-mm, akpm, mgorman
  Cc: yang.zhang.wz, pagupta, konrad.wilk, nitesh, riel, willy,
	lcapitulino, dave.hansen, wei.w.wang, aarcange, pbonzini,
	dan.j.williams, mhocko, alexander.h.duyck, vbabka, osalvador

From: Alexander Duyck <alexander.h.duyck@linux.intel.com>

Move the head/tail adding logic out of the shuffle code and into the
__free_one_page function since ultimately that is where it is really
needed anyway. By doing this we should be able to reduce the overhead
and can consolidate all of the list addition bits in one spot.

Acked-by: Mel Gorman <mgorman@techsingularity.net>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Alexander Duyck <alexander.h.duyck@linux.intel.com>
---
 include/linux/mmzone.h |   12 --------
 mm/page_alloc.c        |   71 ++++++++++++++++++++++++++++--------------------
 mm/shuffle.c           |   12 ++++----
 mm/shuffle.h           |    6 ++++
 4 files changed, 54 insertions(+), 47 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 462f6873905a..bdcd071ab67f 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -116,18 +116,6 @@ static inline void add_to_free_area_tail(struct page *page, struct free_area *ar
 	area->nr_free++;
 }
 
-#ifdef CONFIG_SHUFFLE_PAGE_ALLOCATOR
-/* Used to preserve page allocation order entropy */
-void add_to_free_area_random(struct page *page, struct free_area *area,
-		int migratetype);
-#else
-static inline void add_to_free_area_random(struct page *page,
-		struct free_area *area, int migratetype)
-{
-	add_to_free_area(page, area, migratetype);
-}
-#endif
-
 /* Used for pages which are on another list */
 static inline void move_to_free_area(struct page *page, struct free_area *area,
 			     int migratetype)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 3c4eb750a199..bf36cdfea07a 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -871,6 +871,36 @@ static inline struct capture_control *task_capc(struct zone *zone)
 #endif /* CONFIG_COMPACTION */
 
 /*
+ * If this is not the largest possible page, check if the buddy
+ * of the next-highest order is free. If it is, it's possible
+ * that pages are being freed that will coalesce soon. In case,
+ * that is happening, add the free page to the tail of the list
+ * so it's less likely to be used soon and more likely to be merged
+ * as a higher order page
+ */
+static inline bool
+buddy_merge_likely(unsigned long pfn, unsigned long buddy_pfn,
+		   struct page *page, unsigned int order)
+{
+	struct page *higher_page, *higher_buddy;
+	unsigned long combined_pfn;
+
+	if (order >= MAX_ORDER - 2)
+		return false;
+
+	if (!pfn_valid_within(buddy_pfn))
+		return false;
+
+	combined_pfn = buddy_pfn & pfn;
+	higher_page = page + (combined_pfn - pfn);
+	buddy_pfn = __find_buddy_pfn(combined_pfn, order + 1);
+	higher_buddy = higher_page + (buddy_pfn - combined_pfn);
+
+	return pfn_valid_within(buddy_pfn) &&
+	       page_is_buddy(higher_page, higher_buddy, order + 1);
+}
+
+/*
  * Freeing function for a buddy system allocator.
  *
  * The concept of a buddy system is to maintain direct-mapped table
@@ -899,11 +929,13 @@ static inline void __free_one_page(struct page *page,
 		struct zone *zone, unsigned int order,
 		int migratetype)
 {
-	unsigned long combined_pfn;
+	struct capture_control *capc = task_capc(zone);
 	unsigned long uninitialized_var(buddy_pfn);
-	struct page *buddy;
+	unsigned long combined_pfn;
+	struct free_area *area;
 	unsigned int max_order;
-	struct capture_control *capc = task_capc(zone);
+	struct page *buddy;
+	bool to_tail;
 
 	max_order = min_t(unsigned int, MAX_ORDER, pageblock_order + 1);
 
@@ -972,35 +1004,16 @@ static inline void __free_one_page(struct page *page,
 done_merging:
 	set_page_order(page, order);
 
-	/*
-	 * If this is not the largest possible page, check if the buddy
-	 * of the next-highest order is free. If it is, it's possible
-	 * that pages are being freed that will coalesce soon. In case,
-	 * that is happening, add the free page to the tail of the list
-	 * so it's less likely to be used soon and more likely to be merged
-	 * as a higher order page
-	 */
-	if ((order < MAX_ORDER-2) && pfn_valid_within(buddy_pfn)
-			&& !is_shuffle_order(order)) {
-		struct page *higher_page, *higher_buddy;
-		combined_pfn = buddy_pfn & pfn;
-		higher_page = page + (combined_pfn - pfn);
-		buddy_pfn = __find_buddy_pfn(combined_pfn, order + 1);
-		higher_buddy = higher_page + (buddy_pfn - combined_pfn);
-		if (pfn_valid_within(buddy_pfn) &&
-		    page_is_buddy(higher_page, higher_buddy, order + 1)) {
-			add_to_free_area_tail(page, &zone->free_area[order],
-					      migratetype);
-			return;
-		}
-	}
-
+	area = &zone->free_area[order];
 	if (is_shuffle_order(order))
-		add_to_free_area_random(page, &zone->free_area[order],
-				migratetype);
+		to_tail = shuffle_pick_tail();
 	else
-		add_to_free_area(page, &zone->free_area[order], migratetype);
+		to_tail = buddy_merge_likely(pfn, buddy_pfn, page, order);
 
+	if (to_tail)
+		add_to_free_area_tail(page, area, migratetype);
+	else
+		add_to_free_area(page, area, migratetype);
 }
 
 /*
diff --git a/mm/shuffle.c b/mm/shuffle.c
index b3fe97fd6654..e65d57f39486 100644
--- a/mm/shuffle.c
+++ b/mm/shuffle.c
@@ -183,11 +183,11 @@ void __meminit __shuffle_free_memory(pg_data_t *pgdat)
 		shuffle_zone(z);
 }
 
-void add_to_free_area_random(struct page *page, struct free_area *area,
-		int migratetype)
+bool shuffle_pick_tail(void)
 {
 	static u64 rand;
 	static u8 rand_bits;
+	bool ret;
 
 	/*
 	 * The lack of locking is deliberate. If 2 threads race to
@@ -198,10 +198,10 @@ void add_to_free_area_random(struct page *page, struct free_area *area,
 		rand = get_random_u64();
 	}
 
-	if (rand & 1)
-		add_to_free_area(page, area, migratetype);
-	else
-		add_to_free_area_tail(page, area, migratetype);
+	ret = rand & 1;
+
 	rand_bits--;
 	rand >>= 1;
+
+	return ret;
 }
diff --git a/mm/shuffle.h b/mm/shuffle.h
index 777a257a0d2f..4d79f03b6658 100644
--- a/mm/shuffle.h
+++ b/mm/shuffle.h
@@ -22,6 +22,7 @@ enum mm_shuffle_ctl {
 DECLARE_STATIC_KEY_FALSE(page_alloc_shuffle_key);
 extern void page_alloc_shuffle(enum mm_shuffle_ctl ctl);
 extern void __shuffle_free_memory(pg_data_t *pgdat);
+extern bool shuffle_pick_tail(void);
 static inline void shuffle_free_memory(pg_data_t *pgdat)
 {
 	if (!static_branch_unlikely(&page_alloc_shuffle_key))
@@ -44,6 +45,11 @@ static inline bool is_shuffle_order(int order)
 	return order >= SHUFFLE_ORDER;
 }
 #else
+static inline bool shuffle_pick_tail(void)
+{
+	return false;
+}
+
 static inline void shuffle_free_memory(pg_data_t *pgdat)
 {
 }



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-11  1:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <<20200211224602.29318.84523.stgit@localhost.localdomain>
2021-03-09  8:13 ` [PATCH v17 1/9] mm: Adjust shuffle code to allow for future coalescing Bodeddula, Balasubramaniam
2021-03-11  1:05   ` Alexander Duyck
2020-02-11 22:45 [PATCH v17 0/9] mm / virtio: Provide support for free page reporting Alexander Duyck
2020-02-11 22:46 ` [PATCH v17 1/9] mm: Adjust shuffle code to allow for future coalescing Alexander Duyck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).