mm / virtio: Provide support for paravirtual waste page treatment
Subsystems (8)
cover mm / virtio: Provide support for paravirtual waste page treatment
This series provides an asynchronous means of hinting to a hypervisor that a guest page is no longer in use and can have the data associated with it dropped. To do this I have implemented functionality that allows for what I am referring to as "waste page treatment".
I have based many of the terms and functionality off of waste water treatment, the idea for the similarity occured to me after I had reached the point of referring to the hints as "bubbles", as the hints used the same approach as the balloon functionality but would disappear if they were touched, as a result I started to think of the virtio device as an aerator. The general idea with all of this is that the guest should be treating the unused pages so that when they end up heading "downstream" to either another guest, or back at the host they will not need to be written to swap.
So for a bit of background for the treatment process, it is based on a sequencing batch reactor (SBR)[1]. The treatment process itself has five stages. The first stage is the fill, with this we take the raw pages and add them to the reactor. The second stage is react, in this stage we hand the pages off to the Virtio Balloon driver to have hints attached to them and for those hints to be sent to the hypervisor. The third stage is settle, in this stage we are waiting for the hypervisor to process the pages, and we should receive an interrupt when it is completed. The fourth stage is to decant, or drain the reactor of pages. Finally we have the idle stage which we will go into if the reference count for the reactor gets down to 0 after a drain, or if a fill operation fails to obtain any pages and the reference count has hit 0. Otherwise we return to the first state and start the cycle over again.
This patch set is still far more intrusive then I would really like for what it has to do. Currently I am splitting the nr_free_pages into two values and having to add a pointer and an index to track where we area in the treatment process for a given free_area. I'm also not sure I have covered all possible corner cases where pages can get into the free_area or move from one migratetype to another.
Also I am still leaving a number of things hard-coded such as limiting the lowest order processed to PAGEBLOCK_ORDER, and have left it up to the guest to determine what size of reactor it wants to allocate to process the hints.
Another consideration I am still debating is if I really want to process the aerator_cycle() function in interrupt context or if I should have it running in a thread somewhere else.
[1]: https://en.wikipedia.org/wiki/Sequencing_batch_reactor
---
Alexander Duyck (11):
mm: Move MAX_ORDER definition closer to pageblock_order
mm: Adjust shuffle code to allow for future coalescing
mm: Add support for Treated Buddy pages
mm: Split nr_free into nr_free_raw and nr_free_treated
mm: Propogate Treated bit when splitting
mm: Add membrane to free area to use as divider between treated and raw pages
mm: Add support for acquiring first free "raw" or "untreated" page in zone
mm: Add support for creating memory aeration
mm: Count isolated pages as "treated"
virtio-balloon: Add support for aerating memory via bubble hinting
mm: Add free page notification hook
arch/x86/include/asm/page.h | 11 + drivers/virtio/Kconfig | 1 drivers/virtio/virtio_balloon.c | 89 ++++++++++ include/linux/gfp.h | 10 + include/linux/memory_aeration.h | 54 ++++++ include/linux/mmzone.h | 100 +++++++++-- include/linux/page-flags.h | 32 +++ include/linux/pageblock-flags.h | 8 + include/uapi/linux/virtio_balloon.h | 1 mm/Kconfig | 5 + mm/Makefile | 1 mm/aeration.c | 324 +++++++++++++++++++++++++++++++++++ mm/compaction.c | 4 mm/page_alloc.c | 220 ++++++++++++++++++++---- mm/shuffle.c | 24 --- mm/shuffle.h | 35 ++++ mm/vmstat.c | 5 - 17 files changed, 838 insertions(+), 86 deletions(-) create mode 100644 include/linux/memory_aeration.h create mode 100644 mm/aeration.c
--
RFC PATCH 1/11 mm: Move MAX_ORDER definition closer to pageblock_order
From: Alexander Duyck <[email protected]>
The definition of MAX_ORDER being contained in mmzone.h is problematic when wanting to just get access to things like pageblock_order since pageblock_order is defined on some architectures as being based on MAX_ORDER and it isn't included in pageblock-flags.h.
Move the definition of MAX_ORDER into pageblock-flags.h so that it is defined in the same header as pageblock_order. By doing this we don't need to also include mmzone.h. The definition of MAX_ORDER will still be accessible to any file that includes mmzone.h as it includes pageblock-flags.h.
--- include/linux/mmzone.h | 8 -------- include/linux/pageblock-flags.h | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-)
include/linux/mmzone.h +0 -8
@@ -22,14 +22,6 @@#include <linux/page-flags.h> #include <asm/page.h> -/* Free memory management - zoned buddy allocator. */ -#ifndef CONFIG_FORCE_MAX_ZONEORDER -#define MAX_ORDER 11 -#else -#define MAX_ORDER CONFIG_FORCE_MAX_ZONEORDER -#endif -#define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1)) -/* * PAGE_ALLOC_COSTLY_ORDER is the order at which allocations are deemed * costly to service. That is between allocation orders which should
include/linux/pageblock-flags.h +8 -0
@@ -40,6 +40,14 @@ enum pageblock_bits { NR_PAGEBLOCK_BITS }; +/* Free memory management - zoned buddy allocator. */ +#ifndef CONFIG_FORCE_MAX_ZONEORDER +#define MAX_ORDER 11 +#else +#define MAX_ORDER CONFIG_FORCE_MAX_ZONEORDER +#endif +#define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1)) +#ifdef CONFIG_HUGETLB_PAGE #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE
RFC PATCH 2/11 mm: Adjust shuffle code to allow for future coalescing
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
This patch is meant to 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.
--- include/linux/mmzone.h | 12 -------- mm/page_alloc.c | 70 +++++++++++++++++++++++++++--------------------- mm/shuffle.c | 24 ---------------- mm/shuffle.h | 35 ++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 67 deletions(-)
include/linux/mmzone.h +0 -12
@@ -108,18 +108,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)
mm/page_alloc.c +39 -31
91 lines not on this page · raw message
mm/shuffle.c +0 -24
@@ -4,7 +4,6 @@#include <linux/mm.h> #include <linux/init.h> #include <linux/mmzone.h> -#include <linux/random.h> #include <linux/moduleparam.h> #include "internal.h" #include "shuffle.h"
@@ -182,26 +181,3 @@ void __meminit __shuffle_free_memory(pg_data_t *pgdat)for (z = pgdat->node_zones; z < pgdat->node_zones +MAX_NR_ZONES ; z++)shuffle_zone (z); } - -void add_to_free_area_random (struct page *page,struct free_area *area, -int migratetype) -{ -static u64 rand; -static u8 rand_bits; - -/* -* The lack of locking is deliberate. If 2 threads race to -* update the rand state it just adds to the entropy. -*/ -if (rand_bits ==0 ) { - rand_bits =64 ; - rand =get_random_u64 (); - } - -if (rand &1 ) -add_to_free_area (page, area, migratetype); -else -add_to_free_area_tail (page, area, migratetype); - rand_bits--; - rand >>=1 ; -}
mm/shuffle.h +35 -0
@@ -3,6 +3,7 @@#ifndef _MM_SHUFFLE_H#define _MM_SHUFFLE_H#include <linux/jump_label.h> +#include <linux/random.h> /* * SHUFFLE_ENABLE is called from the command line enabling path, or by
@@ -43,6 +44,35 @@ static inline bool is_shuffle_order(int order)return false; return order >= SHUFFLE_ORDER; } + +static inline bool is_shuffle_tail_page (int order) +{ +static u64 rand; +static u8 rand_bits; +u64 rand_old; + +if (!is_shuffle_order (order)) +return false; + +/* +* The lack of locking is deliberate. If 2 threads race to +* update the rand state it just adds to the entropy. +*/ +if (rand_bits-- ==0 ) { + rand_bits =64 ; + rand =get_random_u64 (); + } + +/* +* Test highest order bit while shifting our random value. This +* should result in us testing for the carry flag following the +* shift. +*/ + rand_old = rand; + rand <<=1 ; + +return rand < rand_old; +}#else static inline void shuffle_free_memory (pg_data_t *pgdat) {
@@ -60,5 +90,10 @@ static inline bool is_shuffle_order(int order) {return false; } + +static inline bool is_shuffle_tail_page (int order) +{ +return false; +}#endif #endif /* _MM_SHUFFLE_H */
RFC PATCH 3/11 mm: Add support for Treated Buddy pages
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
This patch is adding support for flagging pages as "Treated" within the buddy allocator.
If memory aeration is not enabled then the value will always be treated as false and the set/clear operations will have no effect.
--- include/linux/mmzone.h | 1 + include/linux/page-flags.h | 32 ++++++++++++++++++++++++++++++++ mm/page_alloc.c | 5 +++++ 3 files changed, 38 insertions(+)
include/linux/mmzone.h +1 -0
@@ -127,6 +127,7 @@ static inline void del_page_from_free_area(struct page *page, {list_del (&page->lru);__ClearPageBuddy (page); +__ResetPageTreated (page);set_page_private (page,0 ); area->nr_free--; }
include/linux/page-flags.h +32 -0
@@ -722,12 +722,32 @@ static inline int page_has_type(struct page *page)VM_BUG_ON_PAGE (!PageType (page,0 ), page); \ page->page_type &= ~PG_##lname; \ } \ +static __always_inline void __ResetPage##uname(struct page *page) \ +{ \ + VM_BUG_ON_PAGE(!PageType(page, 0), page); \ + page->page_type |= PG_##lname; \ +} \ static __always_inline void __ClearPage##uname(struct page *page) \ { \ VM_BUG_ON_PAGE(!Page##uname(page), page); \ page->page_type |= PG_##lname; \ } +#define PAGE_TYPE_OPS_DISABLED (uname) \ +static __always_inline int Page##uname(struct page *page) \ +{ \ + return false; \ +} \ +static __always_inline void __SetPage##uname(struct page *page) \ +{ \ +} \ +static __always_inline void __ResetPage##uname(struct page *page) \ +{ \ +} \ +static __always_inline void __ClearPage##uname(struct page *page) \ +{ \ +} +/* * PageBuddy() indicates that the page is free and in the buddy system * (see mm/page_alloc.c).
@@ -744,6 +764,18 @@ static inline int page_has_type(struct page *page)PAGE_TYPE_OPS (Offline, offline)/* +* PageTreated() is an alias for Offline, however it is not meant to be an +* exclusive value. It should be combined with PageBuddy() when seen as it +* is meant to indicate that the page has been scrubbed while waiting in +* the buddy system. + */ +#ifdef CONFIG_AERATION +PAGE_TYPE_OPS(Treated, offline) +#else +PAGE_TYPE_OPS_DISABLED(Treated) +#endif + +/* * If kmemcg is enabled, the buddy allocator will set PageKmemcg() on * pages allocated with __GFP_ACCOUNT. It gets cleared on page free. */
mm/page_alloc.c +5 -0
@@ -942,6 +942,11 @@ static inline void __free_one_page(struct page *page, goto done_merging;if (!page_is_buddy (page, buddy, order)) goto done_merging; + +/* If buddy is not treated, then do not mark page treated */ +if (!PageTreated (buddy)) +__ResetPageTreated (page); +/* * Our buddy is free or it is CONFIG_DEBUG_PAGEALLOC guard page, * merge with it and move up one order.
RFC PATCH 4/11 mm: Split nr_free into nr_free_raw and nr_free_treated
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
Split the nr_free value into two values that track where the pages were inserted into the list. The idea is that we can use this later to track which pages were treated and added to the free list versus the raw pages which were just added to the head of the list.
--- include/linux/mmzone.h | 36 ++++++++++++++++++++++++++++++++---- mm/compaction.c | 4 ++-- mm/page_alloc.c | 14 +++++++++----- mm/vmstat.c | 5 +++-- 4 files changed, 46 insertions(+), 13 deletions(-)
include/linux/mmzone.h +32 -4
@@ -89,7 +89,8 @@ static inline bool is_migrate_movable(int mt)struct free_area {struct list_head free_list[MIGRATE_TYPES ]; -unsigned long nr_free; +unsigned long nr_free_raw; +unsigned long nr_free_treated; };/* Used for pages not on another list */
@@ -97,7 +98,7 @@ static inline void add_to_free_area(struct page *page, struct free_area *area, int migratetype) {list_add (&page->lru, &area->free_list[migratetype]); - area->nr_free++; + area->nr_free_raw++; }/* Used for pages not on another list */
@@ -105,13 +106,31 @@ static inline void add_to_free_area_tail(struct page *page, struct free_area *ar int migratetype) {list_add_tail (&page->lru, &area->free_list[migratetype]); - area->nr_free++; + area->nr_free_raw++; }/* Used for pages which are on another list */ static inline void move_to_free_area (struct page *page,struct free_area *area,int migratetype) { +/* +* Since we are moving the page out of one migrate type and into +* another the page will be added to the head of the new list. +* +* To avoid creating an island of raw pages floating between two +* sections of treated pages we should reset the page type and +* just re-treat the page when we process the destination. +* +* No need to trigger a notification for this since the page itself +* is actually treated and we are just doing this for logistical +* reasons. +*/ +if (PageTreated (page)) { +__ResetPageTreated (page); + area->nr_free_treated--; + area->nr_free_raw++; + } +list_move (&page->lru, &area->free_list[migratetype]); }
@@ -125,11 +144,15 @@ static inline struct page *get_page_from_free_area(struct free_area *area,static inline void del_page_from_free_area (struct page *page,struct free_area *area) { +if (PageTreated (page)) + area->nr_free_treated--; +else + area->nr_free_raw--; +list_del (&page->lru);__ClearPageBuddy (page);__ResetPageTreated (page);set_page_private (page,0 ); - area->nr_free--; }static inline bool free_area_empty (struct free_area *area,int migratetype)
@@ -137,6 +160,11 @@ static inline bool free_area_empty(struct free_area *area, int migratetype)return list_empty (&area->free_list[migratetype]); } +static inline unsigned long nr_pages_in_free_area (struct free_area *area) +{ +return area->nr_free_raw + area->nr_free_treated; +} +struct pglist_data ;/*
mm/compaction.c +2 -2
@@ -1318,7 +1318,7 @@ static int next_search_order(struct compact_control *cc, int order)unsigned long flags;unsigned int order_scanned =0 ; -if (!area->nr_free) +if (!nr_pages_in_free_area (area))continue ;spin_lock_irqsave (&cc->zone->lock, flags);
@@ -1674,7 +1674,7 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc)unsigned long flags;struct page *freepage; -if (!area->nr_free) +if (!nr_pages_in_free_area (area))continue ;spin_lock_irqsave (&cc->zone->lock, flags);
mm/page_alloc.c +9 -5
@@ -2418,7 +2418,7 @@ int find_suitable_fallback(struct free_area *area, unsigned int order,int i;int fallback_mt; -if (area->nr_free ==0 ) +if (!nr_pages_in_free_area (area))return -1 ; *can_steal = false;
@@ -3393,7 +3393,7 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,struct free_area *area = &z->free_area[o];int mt; -if (!area->nr_free) +if (!nr_pages_in_free_area (area))continue ;for (mt =0 ; mt <MIGRATE_PCPTYPES ; mt++) {
@@ -5325,7 +5325,7 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask)struct free_area *area = &zone->free_area[order];int type; - nr[order] = area->nr_free; + nr[order] =nr_pages_in_free_area (area); total += nr[order] << order; types[order] =0 ;
@@ -5944,9 +5944,13 @@ void __ref memmap_init_zone_device(struct zone *zone,static void __meminit zone_init_free_lists (struct zone *zone) {unsigned int order, t; -for_each_migratetype_order (order, t) { + +for_each_migratetype_order (order, t)INIT_LIST_HEAD (&zone->free_area[order].free_list[t]); - zone->free_area[order].nr_free =0 ; + +for (order =MAX_ORDER ; order--; ) { + zone->free_area[order].nr_free_raw =0 ; + zone->free_area[order].nr_free_treated =0 ; } }
mm/vmstat.c +3 -2
@@ -1031,7 +1031,7 @@ static void fill_contig_page_info(struct zone *zone,unsigned long blocks;/* Count number of free blocks */ - blocks = zone->free_area[order].nr_free; + blocks =nr_pages_in_free_area (&zone->free_area[order]); info->free_blocks_total += blocks;/* Count free base pages */
@@ -1353,7 +1353,8 @@ static void frag_show_print(struct seq_file *m, pg_data_t *pgdat,seq_printf (m,"Node %d, zone %8s " , pgdat->node_id, zone->name);for (order =0 ; order <MAX_ORDER ; ++order) -seq_printf (m,"%6lu " , zone->free_area[order].nr_free); +seq_printf (m,"%6lu " , +nr_pages_in_free_area (&zone->free_area[order]));seq_putc (m,'\n' ); }
RFC PATCH 5/11 mm: Propogate Treated bit when splitting
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
When we are going to call "expand" to split a page into subpages we should mark those subpages as being "Treated" if the parent page was a "Treated" page. By doing this we can avoid potentially providing hints on a page that was already hinted at a larger page size as being unused.
--- include/linux/mmzone.h | 8 ++++++-- mm/page_alloc.c | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-)
include/linux/mmzone.h +6 -2
@@ -97,16 +97,20 @@ struct free_area {static inline void add_to_free_area (struct page *page,struct free_area *area,int migratetype) { +if (PageTreated (page)) + area->nr_free_treated++; +else + area->nr_free_raw++; +list_add (&page->lru, &area->free_list[migratetype]); - area->nr_free_raw++; }/* Used for pages not on another list */ static inline void add_to_free_area_tail (struct page *page,struct free_area *area,int migratetype) { -list_add_tail (&page->lru, &area->free_list[migratetype]); area->nr_free_raw++; +list_add_tail (&page->lru, &area->free_list[migratetype]); }/* Used for pages which are on another list */
mm/page_alloc.c +15 -3
@@ -1965,7 +1965,7 @@ void __init init_cma_reserved_pageblock(struct page *page)*/ static inline void expand (struct zone *zone,struct page *page,int low,int high,struct free_area *area, -int migratetype) +int migratetype,bool treated) {unsigned long size =1 << high;
@@ -1984,8 +1984,17 @@ static inline void expand(struct zone *zone, struct page *page,if (set_page_guard (zone, &page[size], high, migratetype))continue ; -add_to_free_area (&page[size], area, migratetype);set_page_order (&page[size], high); +if (treated) +__SetPageTreated (&page[size]); + +/* +* The list we are placing this page in should be empty +* so it should be safe to place it here without worrying +* about creating a block of raw pages floating in between +* two blocks of treated pages. +*/ +add_to_free_area (&page[size], area, migratetype); } }
@@ -2122,6 +2131,7 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order,unsigned int current_order;struct free_area *area;struct page *page; +bool treated;/* Find a page of the appropriate size in the preferred list */ for (current_order = order; current_order <MAX_ORDER ; ++current_order) {
@@ -2129,8 +2139,10 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order, page =get_page_from_free_area (area, migratetype);if (!page)continue ; + treated =PageTreated (page);del_page_from_free_area (page, area); -expand (zone, page, order, current_order, area, migratetype); +expand (zone, page, order, current_order, area, migratetype, + treated);set_pcppage_migratetype (page, migratetype);return page; }
RFC PATCH 6/11 mm: Add membrane to free area to use as divider between treated and raw pages
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
Add a pointer we shall call "membrane" which represents the upper boundary between the "raw" and "treated" pages. The general idea is that in order for a page to cross from one side of the membrane to the other it will need to go through the aeration treatment.
By doing this we should be able to make certain that we keep the treated pages as one contiguous block within each free list. While treating the pages there may be two, but the two should merge into one before we complete the migratetype and allow it to fall back into the "settling" state.
--- include/linux/mmzone.h | 38 ++++++++++++++++++++++++++++++++++++++ mm/page_alloc.c | 14 ++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-)
include/linux/mmzone.h +38 -0
@@ -87,10 +87,28 @@ static inline bool is_migrate_movable(int mt)get_pfnblock_flags_mask (page,page_to_pfn (page), \ PB_migrate_end,MIGRATETYPE_MASK ) +/* +* The treatment state indicates the current state of the region pointed to +* by the treatment_mt and the membrane pointer. The general idea is that +* when we are in the "SETTLING" state the treatment area is contiguous and +* it is safe to move on to treating another migratetype. If we are in the +* "AERATING" state then the region is being actively processed and we +* would cause issues such as potentially isolating a section of raw pages +* between two sections of treated pages if we were to move onto another +* migratetype. + */ +enum treatment_state { +TREATMENT_SETTLING , +TREATMENT_AERATING , +}; +struct free_area {struct list_head free_list[MIGRATE_TYPES ];unsigned long nr_free_raw;unsigned long nr_free_treated; +struct list_head *membrane; +u8 treatment_mt; +u8 treatment_state; };/* Used for pages not on another list */
@@ -113,6 +131,19 @@ static inline void add_to_free_area_tail(struct page *page, struct free_area *arlist_add_tail (&page->lru, &area->free_list[migratetype]); } +static inline void +add_to_free_area_treated (struct page *page,struct free_area *area, +int migratetype) +{ + area->nr_free_treated++; + +BUG_ON (area->treatment_mt != migratetype); + +/* Insert page above membrane, then move membrane to the page */ +list_add_tail (&page->lru, area->membrane); + area->membrane = &page->lru; +} +/* Used for pages which are on another list */ static inline void move_to_free_area (struct page *page,struct free_area *area,int migratetype)
@@ -135,6 +166,10 @@ static inline void move_to_free_area(struct page *page, struct free_area *area, area->nr_free_raw++; } +/* push membrane back if we removed the upper boundary */ +if (area->membrane == &page->lru) + area->membrane = page->lru.next; +list_move (&page->lru, &area->free_list[migratetype]); }
@@ -153,6 +188,9 @@ static inline void del_page_from_free_area(struct page *page,else area->nr_free_raw--; +if (area->membrane == &page->lru) + area->membrane = page->lru.next; +list_del (&page->lru);__ClearPageBuddy (page);__ResetPageTreated (page);
mm/page_alloc.c +12 -2
@@ -989,6 +989,11 @@ static inline void __free_one_page(struct page *page,set_page_order (page, order); area = &zone->free_area[order]; +if (PageTreated (page)) { +add_to_free_area_treated (page, area, migratetype); +return ; + } +if (buddy_merge_likely (pfn, buddy_pfn, page, order) ||is_shuffle_tail_page (order))add_to_free_area_tail (page, area, migratetype);
@@ -5961,8 +5966,13 @@ static void __meminit zone_init_free_lists(struct zone *zone)INIT_LIST_HEAD (&zone->free_area[order].free_list[t]);for (order =MAX_ORDER ; order--; ) { - zone->free_area[order].nr_free_raw =0 ; - zone->free_area[order].nr_free_treated =0 ; +struct free_area *area = &zone->free_area[order]; + + area->nr_free_raw =0 ; + area->nr_free_treated =0 ; + area->treatment_mt =0 ; + area->treatment_state =TREATMENT_SETTLING ; + area->membrane = &area->free_list[0 ]; } }
RFC PATCH 7/11 mm: Add support for acquiring first free "raw" or "untreated" page in zone
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
In order to be able to "treat" memory in an asynchonous fashion we need a way to acquire a block of memory that isn't already treated, and then flush that back in a way that we will not pick it back up again.
To achieve that this patch adds a pair of functions. One to fill a list with pages to be treated, and another that will flush out the list back to the buddy allocator.
--- include/linux/gfp.h | 6 +++ mm/page_alloc.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+)
include/linux/gfp.h +6 -0
@@ -559,6 +559,12 @@ extern void *page_frag_alloc(struct page_frag_cache *nc,void drain_all_pages (struct zone *zone);void drain_local_pages (struct zone *zone); +#ifdef CONFIG_AERATION +struct page *get_raw_pages (struct zone *zone,unsigned int order, +int migratetype); +void free_treated_page (struct page *page); +#endif +void page_alloc_init_late (void );/*
mm/page_alloc.c +107 -0
113 lines not on this page · raw message
RFC PATCH 8/11 mm: Add support for creating memory aeration
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
Add support for "aerating" memory in a guest by pushing individual pages out. This patch is meant to add generic support for this by adding a common framework that can be used later by drivers such as virtio-balloon.
--- include/linux/memory_aeration.h | 54 +++++++ mm/Kconfig | 5 + mm/Makefile | 1 mm/aeration.c | 320 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 380 insertions(+) create mode 100644 include/linux/memory_aeration.h create mode 100644 mm/aeration.c
include/linux/memory_aeration.h new file +54 -0
@@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_MEMORY_AERATION_H +#define _LINUX_MEMORY_AERATION_H + +#include <linux/pageblock-flags.h> +#include <linux/jump_label.h> +#include <asm/pgtable_types.h> + +struct zone ; + +#define AERATOR_MIN_ORDER pageblock_order + +struct aerator_dev_info { +unsigned long capacity; +struct list_head batch_reactor; +atomic_t refcnt; +void (*react)(struct aerator_dev_info *a_dev_info); +}; + +extern struct static_key aerator_notify_enabled; + +void aerator_cycle (void ); +void __aerator_notify (struct zone *zone,int order); + +/** +* aerator_notify_free - Free page notification that will start page processing +* @page: Last page processed +* @zone: Pointer to current zone of last page processed +* @order: Order of last page added to zone +* +* This function is meant to act as a screener for __aerator_notify which +* will determine if a give zone has crossed over the high-water mark that +* will justify us beginning page treatment. If we have crossed that +* threshold then it will start the process of pulling some pages and +* placing them in the batch_reactor list for treatment. +*/ +static inline void +aerator_notify_free (struct page *page,struct zone *zone,int order) +{ +if (!static_key_false (&aerator_notify_enabled)) +return ; + +if (order <AERATOR_MIN_ORDER ) +return ; + +__aerator_notify (zone, order); +} + +void aerator_shutdown (void ); +int aerator_startup (struct aerator_dev_info *sdev); + +#define AERATOR_ZONE_BITS (BITS_TO_LONGS(MAX_NR_ZONES) * BITS_PER_LONG) +#define AERATOR_HWM_BITS (AERATOR_ZONE_BITS * MAX_NUMNODES) +#endif /*_LINUX_MEMORY_AERATION_H */
mm/Kconfig +5 -0
@@ -236,6 +236,11 @@ config COMPACTION [email protected]. # +# support for memory aeration +config AERATION + bool + +# # support for page migration # config MIGRATION
mm/Makefile +1 -0
@@ -104,3 +104,4 @@ obj-$(CONFIG_HARDENED_USERCOPY) += usercopy.o obj-$(CONFIG_PERCPU_STATS) += percpu-stats.o obj-$(CONFIG_HMM) += hmm.o obj-$(CONFIG_MEMFD_CREATE) += memfd.o +obj-$(CONFIG_AERATION) += aeration.o
mm/aeration.c new file +320 -0
320 lines not on this page · raw message
RFC PATCH 9/11 mm: Count isolated pages as "treated"
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
Treat isolated pages as though they have already been treated. We do this so that we can avoid trying to treat pages that have been marked for isolation. The issue is that we don't want to run into issues where we are treating a page, and when we put it back we find it has been moved into the isolated migratetype, nor would we want to pull pages out of the isolated migratetype and then find that they are now being located in a different migratetype.
To avoid those issues we can specifically mark all isolated pages as being "treated" and avoid special case handling for them since they will never be merged anyway, so we can just add them to the head of the free_list.
In addition we will skip over the isolate migratetype when getting raw pages.
--- include/linux/mmzone.h | 7 +++++++ mm/aeration.c | 8 ++++++-- mm/page_alloc.c | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-)
include/linux/mmzone.h +7 -0
@@ -137,6 +137,13 @@ static inline void add_to_free_area_tail(struct page *page, struct free_area *ar { area->nr_free_treated++; +#ifdef CONFIG_MEMORY_ISOLATION +/* Bypass membrane for isolated pages, all are considered "treated" */ +if (migratetype ==MIGRATE_ISOLATE ) { +list_add (&page->lru, &area->free_list[migratetype]); +return ; + } +#endif BUG_ON (area->treatment_mt != migratetype);/* Insert page above membrane, then move membrane to the page */
mm/aeration.c +6 -2
@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/memory_aeration.h> +#include <linux/mm.h> #include <linux/mmzone.h> +#include <linux/page-isolation.h> #include <linux/gfp.h> #include <linux/export.h> #include <linux/delay.h>
@@ -83,8 +85,10 @@ static int __aerator_fill(struct zone *zone, unsigned int size)* new raw pages can build. In the meantime move on * to the next migratetype. */ -if (++mt >=MIGRATE_TYPES ) - mt =0 ; +do { +if (++mt >=MIGRATE_TYPES ) + mt =0 ; + }while (is_migrate_isolate (mt));/* * Pull pages from free list until we have drained
mm/page_alloc.c +1 -1
@@ -989,7 +989,7 @@ static inline void __free_one_page(struct page *page,set_page_order (page, order); area = &zone->free_area[order]; -if (PageTreated (page)) { +if (is_migrate_isolate (migratetype) ||PageTreated (page)) {add_to_free_area_treated (page, area, migratetype);return ; }
RFC PATCH 10/11 virtio-balloon: Add support for aerating memory via bubble hinting
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
Add support for aerating memory using the bubble hinting feature provided by virtio-balloon. Bubble hinting differs from the regular balloon functionality in that is is much less durable than a standard memory balloon. Instead of creating a list of pages that cannot be accessed the pages are only inaccessible while they are being indicated to the virtio interface. Once the interface has acknowledged them they are placed back into their respective free lists and are once again accessible by the guest system.
--- drivers/virtio/Kconfig | 1 drivers/virtio/virtio_balloon.c | 89 +++++++++++++++++++++++++++++++++++ include/uapi/linux/virtio_balloon.h | 1 3 files changed, 90 insertions(+), 1 deletion(-)
drivers/virtio/Kconfig +1 -0
@@ -47,6 +47,7 @@ config VIRTIO_BALLOON tristate "Virtio balloon driver" depends on VIRTIO select MEMORY_BALLOON + select AERATION ---help--- This driver supports increasing and decreasing the amount of memory within a KVM guest.
drivers/virtio/virtio_balloon.c +88 -1
162 lines not on this page · raw message
include/uapi/linux/virtio_balloon.h +1 -0
@@ -36,6 +36,7 @@#define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 2/* Deflate balloon on OOM */ #define VIRTIO_BALLOON_F_FREE_PAGE_HINT 3/* VQ to report free pages */ #define VIRTIO_BALLOON_F_PAGE_POISON 4/* Guest is using page poisoning */ +#define VIRTIO_BALLOON_F_HINTING 5/* Page hinting virtqueue */ /* Size of a PFN in the balloon interface. */ #define VIRTIO_BALLOON_PFN_SHIFT 12
RFC PATCH 11/11 mm: Add free page notification hook
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
Add a hook so that we are notified when a new page is available. We will use this hook to notify the virtio aeration system when we have achieved enough free higher-order pages to justify the process of pulling some pages and hinting on them.
--- arch/x86/include/asm/page.h | 11 +++++++++++ include/linux/gfp.h | 4 ++++ mm/page_alloc.c | 2 ++ 3 files changed, 17 insertions(+)
arch/x86/include/asm/page.h +11 -0
@@ -18,6 +18,17 @@struct page ; +#ifdef CONFIG_AERATION +#include <linux/memory_aeration.h> + +#define HAVE_ARCH_FREE_PAGE_NOTIFY +static inline void +arch_free_page_notify (struct page *page,struct zone *zone,int order) +{ +aerator_notify_free (page, zone, order); +} + +#endif #include <linux/range.h> extern struct range pfn_mapped[];extern int nr_pfn_mapped;
include/linux/gfp.h +4 -0
@@ -459,6 +459,10 @@ static inline struct zonelist *node_zonelist(int nid, gfp_t flags)#ifndef HAVE_ARCH_FREE_PAGE static inline void arch_free_page (struct page *page,int order) { }#endif +#ifndef HAVE_ARCH_FREE_PAGE_NOTIFY +static inline void +arch_free_page_notify (struct page *page,struct zone *zone,int order) { } +#endif #ifndef HAVE_ARCH_ALLOC_PAGE static inline void arch_alloc_page (struct page *page,int order) { }#endif
mm/page_alloc.c +2 -0
@@ -999,6 +999,8 @@ static inline void __free_one_page(struct page *page,add_to_free_area_tail (page, area, migratetype); elseadd_to_free_area (page ,area ,migratetype ); + +arch_free_page_notify (page, zone, order); }/*
RFC PATCH 1/1 QEMU: Provide a interface for hinting based off of the balloon infrastructure
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
So this is meant to be a simplification of the existing balloon interface to use for providing hints to what memory needs to be freed. I am assuming this is safe to do as the deflate logic does not actually appear to do very much other than tracking what subpages have been released and which ones haven't.
I suspect this is still a bit crude and will need some more work. Suggestions welcome.
--- hw/virtio/trace-events | 1 hw/virtio/virtio-balloon.c | 85 +++++++++++++++++++++++ include/hw/virtio/virtio-balloon.h | 2 - include/standard-headers/linux/virtio_balloon.h | 1 4 files changed, 88 insertions(+), 1 deletion(-)
hw/virtio/trace-events +1 -0
@@ -46,6 +46,7 @@ virtio_balloon_handle_output(const char *name, uint64_t gpa) "section name: %s g virtio_balloon_get_config(uint32_t num_pages, uint32_t actual) "num_pages: %d actual: %d" virtio_balloon_set_config(uint32_t actual, uint32_t oldactual) "actual: %d oldactual: %d" virtio_balloon_to_target(uint64_t target, uint32_t num_pages) "balloon target: 0x%"PRIx64" num_pages: %d" +virtio_bubble_handle_output(const char *name, uint64_t gpa, uint64_t size) "section name: %s gpa: 0x%" PRIx64 " size: %" PRIx64 # virtio-mmio.c virtio_mmio_read(uint64_t offset) "virtio_mmio_read offset 0x%" PRIx64
hw/virtio/virtio-balloon.c +85 -0
115 lines not on this page · raw message
include/hw/virtio/virtio-balloon.h +1 -1
@@ -44,7 +44,7 @@ enum virtio_balloon_free_page_report_status { typedef struct VirtIOBalloon { VirtIODevice parent_obj; - VirtQueue *ivq, *dvq, *svq, *free_page_vq; + VirtQueue *ivq, *dvq, *svq, *hvq, *free_page_vq; uint32_t free_page_report_status; uint32_t num_pages; uint32_t actual;
include/standard-headers/linux/virtio_balloon.h +1 -0
@@ -36,6 +36,7 @@#define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 2/* Deflate balloon on OOM */ #define VIRTIO_BALLOON_F_FREE_PAGE_HINT 3/* VQ to report free pages */ #define VIRTIO_BALLOON_F_PAGE_POISON 4/* Guest is using page poisoning */ +#define VIRTIO_BALLOON_F_HINTING 5/* Page hinting virtqueue */ /* Size of a PFN in the balloon interface. */ #define VIRTIO_BALLOON_PFN_SHIFT 12
Michael S. Tsirkin
maintainerQuoted 5 lines · Alexander Duyck
This series provides an asynchronous means of hinting to a hypervisor that a guest page is no longer in use and can have the data associated with it dropped. To do this I have implemented functionality that allows for what I am referring to as "waste page treatment".
Quoted 9 lines
I have based many of the terms and functionality off of waste water treatment, the idea for the similarity occured to me after I had reached the point of referring to the hints as "bubbles", as the hints used the same approach as the balloon functionality but would disappear if they were touched, as a result I started to think of the virtio device as an aerator. The general idea with all of this is that the guest should be treating the unused pages so that when they end up heading "downstream" to either another guest, or back at the host they will not need to be written to swap.
A lovely analogy.
Quoted 5 lines
So for a bit of background for the treatment process, it is based on a sequencing batch reactor (SBR)[1]. The treatment process itself has five stages. The first stage is the fill, with this we take the raw pages and add them to the reactor. The second stage is react, in this stage we hand the pages off to the Virtio Balloon driver to have hints attached to them
Quoted 8 lines
and for those hints to be sent to the hypervisor. The third stage is settle, in this stage we are waiting for the hypervisor to process the pages, and we should receive an interrupt when it is completed. The fourth stage is to decant, or drain the reactor of pages. Finally we have the idle stage which we will go into if the reference count for the reactor gets down to 0 after a drain, or if a fill operation fails to obtain any pages and the reference count has hit 0. Otherwise we return to the first state and start the cycle over again.
will review the patchset closely shortly.
Quoted 56 lines
This patch set is still far more intrusive then I would really like for what it has to do. Currently I am splitting the
nr_free_pagesinto two values and having to add a pointer and an index to track where we area in the treatment process for a givenfree_area. I'm also not sure I have covered all possible corner cases where pages can get into thefree_areaor move from one migratetype to another.Also I am still leaving a number of things hard-coded such as limiting the lowest order processed to
PAGEBLOCK_ORDER, and have left it up to the guest to determine what size of reactor it wants to allocate to process the hints.Another consideration I am still debating is if I really want to process the
aerator_cycle()function in interrupt context or if I should have it running in a thread somewhere else.[1]: https://en.wikipedia.org/wiki/Sequencing_batch_reactor
---
Alexander Duyck (11):
mm: MoveMAX_ORDERdefinition closer topageblock_order
mm: Adjust shuffle code to allow for future coalescing
mm: Add support for Treated Buddy pages
mm: Splitnr_freeintonr_free_rawandnr_free_treated
mm: Propogate Treated bit when splitting
mm: Add membrane to free area to use as divider between treated and raw pages
mm: Add support for acquiring first free "raw" or "untreated" page in zone
mm: Add support for creating memory aeration
mm: Count isolated pages as "treated"
virtio-balloon: Add support for aerating memory via bubble hinting
mm: Add free page notification hookarch/x86/include/asm/page.h | 11 + drivers/virtio/Kconfig | 1 drivers/virtio/virtio_balloon.c | 89 ++++++++++ include/linux/gfp.h | 10 + include/linux/memory_aeration.h | 54 ++++++ include/linux/mmzone.h | 100 +++++++++-- include/linux/page-flags.h | 32 +++ include/linux/pageblock-flags.h | 8 + include/uapi/linux/virtio_balloon.h | 1 mm/Kconfig | 5 + mm/Makefile | 1 mm/aeration.c | 324 +++++++++++++++++++++++++++++++++++ mm/compaction.c | 4 mm/page_alloc.c | 220 ++++++++++++++++++++---- mm/shuffle.c | 24 --- mm/shuffle.h | 35 ++++ mm/vmstat.c | 5 - 17 files changed, 838 insertions(+), 86 deletions(-) create mode 100644 include/linux/memory_aeration.h create mode 100644 mm/aeration.c--
Quoted 36 lines · Alexander Duyck
This series provides an asynchronous means of hinting to a hypervisor that a guest page is no longer in use and can have the data associated with it dropped. To do this I have implemented functionality that allows for what I am referring to as "waste page treatment".
I have based many of the terms and functionality off of waste water treatment, the idea for the similarity occured to me after I had reached the point of referring to the hints as "bubbles", as the hints used the same approach as the balloon functionality but would disappear if they were touched, as a result I started to think of the virtio device as an aerator. The general idea with all of this is that the guest should be treating the unused pages so that when they end up heading "downstream" to either another guest, or back at the host they will not need to be written to swap.
So for a bit of background for the treatment process, it is based on a sequencing batch reactor (SBR)[1]. The treatment process itself has five stages. The first stage is the fill, with this we take the raw pages and add them to the reactor. The second stage is react, in this stage we hand the pages off to the Virtio Balloon driver to have hints attached to them and for those hints to be sent to the hypervisor. The third stage is settle, in this stage we are waiting for the hypervisor to process the pages, and we should receive an interrupt when it is completed. The fourth stage is to decant, or drain the reactor of pages. Finally we have the idle stage which we will go into if the reference count for the reactor gets down to 0 after a drain, or if a fill operation fails to obtain any pages and the reference count has hit 0. Otherwise we return to the first state and start the cycle over again.
This patch set is still far more intrusive then I would really like for what it has to do. Currently I am splitting the
nr_free_pagesinto two values and having to add a pointer and an index to track where we area in the treatment process for a givenfree_area. I'm also not sure I have covered all possible corner cases where pages can get into thefree_areaor move from one migratetype to another.
Quoted 8 lines
Also I am still leaving a number of things hard-coded such as limiting the lowest order processed to
PAGEBLOCK_ORDER, and have left it up to the guest to determine what size of reactor it wants to allocate to process the hints.Another consideration I am still debating is if I really want to process the
aerator_cycle()function in interrupt context or if I should have it running in a thread somewhere else.
Can you please share some performance numbers?
I will be sharing a less mm-intrusive bitmap-based approach hopefully by next week.
Let's compare the two approaches then, in the meanwhile I will start reviewing your patch-set.
Quoted 41 lines
[1]: https://en.wikipedia.org/wiki/Sequencing_batch_reactor
---
Alexander Duyck (11):
mm: MoveMAX_ORDERdefinition closer topageblock_order
mm: Adjust shuffle code to allow for future coalescing
mm: Add support for Treated Buddy pages
mm: Splitnr_freeintonr_free_rawandnr_free_treated
mm: Propogate Treated bit when splitting
mm: Add membrane to free area to use as divider between treated and raw pages
mm: Add support for acquiring first free "raw" or "untreated" page in zone
mm: Add support for creating memory aeration
mm: Count isolated pages as "treated"
virtio-balloon: Add support for aerating memory via bubble hinting
mm: Add free page notification hookarch/x86/include/asm/page.h | 11 + drivers/virtio/Kconfig | 1 drivers/virtio/virtio_balloon.c | 89 ++++++++++ include/linux/gfp.h | 10 + include/linux/memory_aeration.h | 54 ++++++ include/linux/mmzone.h | 100 +++++++++-- include/linux/page-flags.h | 32 +++ include/linux/pageblock-flags.h | 8 + include/uapi/linux/virtio_balloon.h | 1 mm/Kconfig | 5 + mm/Makefile | 1 mm/aeration.c | 324 +++++++++++++++++++++++++++++++++++ mm/compaction.c | 4 mm/page_alloc.c | 220 ++++++++++++++++++++---- mm/shuffle.c | 24 --- mm/shuffle.h | 35 ++++ mm/vmstat.c | 5 - 17 files changed, 838 insertions(+), 86 deletions(-) create mode 100644 include/linux/memory_aeration.h create mode 100644 mm/aeration.c--
Signature · 2 lines
Regards Nitesh
Quoted 48 lines · Nitesh Narayan Lal
Quoted 36 lines · Alexander Duyck
This series provides an asynchronous means of hinting to a hypervisor that a guest page is no longer in use and can have the data associated with it dropped. To do this I have implemented functionality that allows for what I am referring to as "waste page treatment".
I have based many of the terms and functionality off of waste water treatment, the idea for the similarity occured to me after I had reached the point of referring to the hints as "bubbles", as the hints used the same approach as the balloon functionality but would disappear if they were touched, as a result I started to think of the virtio device as an aerator. The general idea with all of this is that the guest should be treating the unused pages so that when they end up heading "downstream" to either another guest, or back at the host they will not need to be written to swap.
So for a bit of background for the treatment process, it is based on a sequencing batch reactor (SBR)[1]. The treatment process itself has five stages. The first stage is the fill, with this we take the raw pages and add them to the reactor. The second stage is react, in this stage we hand the pages off to the Virtio Balloon driver to have hints attached to them and for those hints to be sent to the hypervisor. The third stage is settle, in this stage we are waiting for the hypervisor to process the pages, and we should receive an interrupt when it is completed. The fourth stage is to decant, or drain the reactor of pages. Finally we have the idle stage which we will go into if the reference count for the reactor gets down to 0 after a drain, or if a fill operation fails to obtain any pages and the reference count has hit 0. Otherwise we return to the first state and start the cycle over again.
This patch set is still far more intrusive then I would really like for what it has to do. Currently I am splitting the
nr_free_pagesinto two values and having to add a pointer and an index to track where we area in the treatment process for a givenfree_area. I'm also not sure I have covered all possible corner cases where pages can get into thefree_areaor move from one migratetype to another.Quoted 8 lines
Also I am still leaving a number of things hard-coded such as limiting the lowest order processed to
PAGEBLOCK_ORDER, and have left it up to the guest to determine what size of reactor it wants to allocate to process the hints.Another consideration I am still debating is if I really want to process the
aerator_cycle()function in interrupt context or if I should have it running in a thread somewhere else.
Quoted 6 lines
Can you please share some performance numbers?
I will be sharing a less mm-intrusive bitmap-based approach hopefully by next week.
Let's compare the two approaches then, in the meanwhile I will start reviewing your patch-set.
The performance can vary quite a bit depending on the configuration. So for example with the memory shuffling enabled I saw an overall improvement in transactions in the page_fault1 test I was running, however I suspect that is just due to the fact that I inlined the bit that was doing the shuffling at the 2nd patch in.
I'm still working on gathering data so you can consider the data provided below as preliminary, and I want to emphasize your mileage may vary as it seems like the config used can make a big difference.
So the results below are for a will-it-scale test of a VM running with 16 VCPUs and 32G of memory. The clean version is without patches applied, and "aerate" is with patches applied. I disabled the memory shuffling in the config for the kernels since it seemed like an unfair comparison with it enabled. Before the test I ran "memhog 32g" to pull in all available memory on the "clean" test and to pull in and flush all the memory on the "aerate" tests. One thing that isn't really making sense to me yet is why the results for the aerate version appear to be better then the clean version when we start getting into higher thread counts. One thing I notice is that clear_page_erms jumps to the top of a perf trace on the host at about the inflection point where the "clean" guest starts to under-perform versus the "aerate" guest. So it is possible that there may be some benefit to having the host clear the pages before the guest processes them.
5.2.0-rc2-next-20190529-clean #53 tasks,processes,processes_idle,threads,threads_idle,linear 0,0,100,0,100,0 1,574916,93.73,574313,93.70,574916 2,1006964,87.47,918228,87.52,1149832 3,1373857,81.23,1170468,82.35,1724748 4,1781250,74.98,1526831,76.77,2299664 5,1973790,68.74,1764815,69.86,2874580 6,2235127,62.53,1912371,65.42,3449496 7,2499192,56.28,1936901,61.63,4024412 8,2581220,50.05,2114032,56.54,4599328 9,2804630,43.81,2202166,52.37,5174244 10,2746340,37.58,2194305,48.31,5749160 11,2694687,31.33,2189028,41.74,6324076 12,2772102,25.16,2176312,40.85,6898992 13,2854235,18.94,2146288,37.61,7473908 14,2720456,12.73,2063334,32.67,8048824 15,2753005,6.51,2103228,26.65,8623740 16,2595824,0.36,2142308,25.96,9198656 tasks,processes,processes_idle,threads,threads_idle,linear 0,0,100,0,100,0 1,568948,93.73,570092,93.72,570092 2,1006781,87.47,911829,87.57,1140184 3,1360418,81.23,1189920,82.22,1710276 4,1749889,74.99,1476555,77.22,2280368 5,1927251,68.76,1681522,70.49,2850460 6,2221112,62.51,1845148,65.74,3420552 7,2497960,56.29,1983406,61.44,3990644 8,2586250,50.01,2062633,56.99,4560736 9,2570559,43.82,1989225,53.14,5130828 10,2692389,37.57,2159570,48.07,5700920 11,2621505,31.33,2214469,43.73,6271012 12,2772863,25.15,2164639,40.35,6841104 13,2839319,18.94,2184126,36.90,7411196 14,2712433,12.77,2048788,31.16,7981288 15,2779543,6.54,2105144,27.29,8551380 16,2605799,0.34,2101187,23.20,9121472
5.2.0-rc2-next-20190529-aerate+ #55 tasks,processes,processes_idle,threads,threads_idle,linear 0,0,100,0,100,0 1,538715,93.73,538909,93.73,538909 2,985096,87.46,899393,87.54,1077818 3,1421187,81.25,1271836,81.88,1616727 4,1745358,75.00,1435337,77.61,2155636 5,2031097,68.76,1766946,70.37,2694545 6,2234646,62.51,1794401,66.94,3233454 7,2455541,56.27,2101020,59.42,3772363 8,2576793,50.09,1810192,59.45,4311272 9,2772082,43.82,2315719,50.58,4850181 10,2794868,37.62,1996644,50.84,5389090 11,2931943,31.36,2147434,42.58,5927999 12,2837655,25.12,2032434,42.79,6466908 13,2881797,18.95,2163387,36.80,7005817 14,2802190,12.73,2049732,30.00,7544726 15,2684374,6.53,2039098,26.48,8083635 16,2695848,0.41,2044131,22.08,8622544 tasks,processes,processes_idle,threads,threads_idle,linear 0,0,100,0,100,0 1,533361,93.72,532973,93.73,533361 2,980085,87.46,904796,87.50,1066722 3,1387100,81.21,1271080,81.41,1600083 4,1720030,74.99,1539417,75.99,2133444 5,1942111,68.74,1530612,73.21,2666805 6,2226552,62.51,1777038,66.97,3200166 7,2469715,56.27,2084451,59.72,3733527 8,2567333,50.04,1820491,59.38,4266888 9,2744551,43.82,2259861,51.73,4800249 10,2768107,37.60,2240844,48.10,5333610 11,2879636,31.37,2134152,46.56,5866971 12,2826859,25.18,1960830,44.07,6400332 13,2905216,19.05,1887735,36.66,6933693 14,2841688,12.79,2047092,30.18,7467054 15,2832234,6.57,2066059,25.31,8000415 16,2758579,0.38,1961050,22.16,8533776
Quoted 15 lines · Alexander Duyck
This series provides an asynchronous means of hinting to a hypervisor that a guest page is no longer in use and can have the data associated with it dropped. To do this I have implemented functionality that allows for what I am referring to as "waste page treatment".
I have based many of the terms and functionality off of waste water treatment, the idea for the similarity occured to me after I had reached the point of referring to the hints as "bubbles", as the hints used the same approach as the balloon functionality but would disappear if they were touched, as a result I started to think of the virtio device as an aerator. The general idea with all of this is that the guest should be treating the unused pages so that when they end up heading "downstream" to either another guest, or back at the host they will not need to be written to swap.
Quoted 13 lines
So for a bit of background for the treatment process, it is based on a sequencing batch reactor (SBR)[1]. The treatment process itself has five stages. The first stage is the fill, with this we take the raw pages and add them to the reactor. The second stage is react, in this stage we hand the pages off to the Virtio Balloon driver to have hints attached to them and for those hints to be sent to the hypervisor. The third stage is settle, in this stage we are waiting for the hypervisor to process the pages, and we should receive an interrupt when it is completed. The fourth stage is to decant, or drain the reactor of pages. Finally we have the idle stage which we will go into if the reference count for the reactor gets down to 0 after a drain, or if a fill operation fails to obtain any pages and the reference count has hit 0. Otherwise we return to the first state and start the cycle over again.
While I like this analogy, I don't like the terminology mixed into linux-mm core.
mm/aeration.c? Bubble? Treated? whut?
Can you come up with a terminology once can understand without a PHD in biology? (if that is even the right field of study, I have no idea)
ALSO: isn't the analogy partially wrong? Nobody would be using "waste water" just because they are low on "clean water". At least not in my city (I hope so ;) ). But maybe I am not getting the whole concept because we are dealing with pages we want to hint to the hypervisor and not with actual "waste".
Quoted 7 lines
This patch set is still far more intrusive then I would really like for what it has to do. Currently I am splitting the
nr_free_pagesinto two values and having to add a pointer and an index to track where we area in the treatment process for a givenfree_area. I'm also not sure I have covered all possible corner cases where pages can get into thefree_areaor move from one migratetype to another.
Yes, it is quite intrusive. Maybe we can minimize the impact/error proneness.
Quoted 9 lines
Also I am still leaving a number of things hard-coded such as limiting the lowest order processed to
PAGEBLOCK_ORDER, and have left it up to the guest to determine what size of reactor it wants to allocate to process the hints.Another consideration I am still debating is if I really want to process the
aerator_cycle()function in interrupt context or if I should have it running in a thread somewhere else.
Did you get to test/benchmark the difference?
Signature · 3 lines
Thanks, David / dhildenb
Quoted 30 lines · David Hildenbrand
Quoted 15 lines · Alexander Duyck
This series provides an asynchronous means of hinting to a hypervisor that a guest page is no longer in use and can have the data associated with it dropped. To do this I have implemented functionality that allows for what I am referring to as "waste page treatment".
I have based many of the terms and functionality off of waste water treatment, the idea for the similarity occured to me after I had reached the point of referring to the hints as "bubbles", as the hints used the same approach as the balloon functionality but would disappear if they were touched, as a result I started to think of the virtio device as an aerator. The general idea with all of this is that the guest should be treating the unused pages so that when they end up heading "downstream" to either another guest, or back at the host they will not need to be written to swap.
Quoted 13 lines
So for a bit of background for the treatment process, it is based on a sequencing batch reactor (SBR)[1]. The treatment process itself has five stages. The first stage is the fill, with this we take the raw pages and add them to the reactor. The second stage is react, in this stage we hand the pages off to the Virtio Balloon driver to have hints attached to them and for those hints to be sent to the hypervisor. The third stage is settle, in this stage we are waiting for the hypervisor to process the pages, and we should receive an interrupt when it is completed. The fourth stage is to decant, or drain the reactor of pages. Finally we have the idle stage which we will go into if the reference count for the reactor gets down to 0 after a drain, or if a fill operation fails to obtain any pages and the reference count has hit 0. Otherwise we return to the first state and start the cycle over again.
Quoted 7 lines
While I like this analogy, I don't like the terminology mixed into linux-mm core.
mm/aeration.c? Bubble? Treated? whut?Can you come up with a terminology once can understand without a PHD in biology? (if that is even the right field of study, I have no idea)
I had started with the bubble, as I had mentioned before. From there I got to aerator because of the fact that we were filling the memory with holes. I figure the first two work pretty well, but I am not really attached to any of the other terms. As far as the rest of the terminology most of it is actually chemistry if I am not mistaken. I could probably just swap out "Treated" with "Aerated" and it would work just as well. I would also need to get away from the more complex terms such as "decant", but for the most part that is just a matter of finding the synonyms such as "drain".
Quoted 5 lines
ALSO: isn't the analogy partially wrong? Nobody would be using "waste water" just because they are low on "clean water". At least not in my city (I hope so ;) ). But maybe I am not getting the whole concept because we are dealing with pages we want to hint to the hypervisor and not with actual "waste".
Actually the analogy isn't for a low condition. The analogy would be for a condition where we have an excess of waste water and don't want to contain it. As such we want to treat it and return it to the water cycle.
As far as the "waste" in the analogy I was thinking more of the page data. When a page has been used we normally mark it as "Dirty", so I thought it would be an apt analogy since those dirty pages would have to be written to long term storage if we didn't do something to invalidate the page data.
Quoted 9 lines
Quoted 6 lines
This patch set is still far more intrusive then I would really like for what it has to do. Currently I am splitting the
nr_free_pagesinto two values and having to add a pointer and an index to track where we area in the treatment process for a givenfree_area. I'm also not sure I have covered all possible corner cases where pages can get into thefree_areaor move from one migratetype to another.Yes, it is quite intrusive. Maybe we can minimize the impact/error proneness.
My hope by submitting this as an RFC was to get input on what directions I might need to head in before I went to far down this current path.
Quoted 10 lines
Quoted 8 lines
Also I am still leaving a number of things hard-coded such as limiting the lowest order processed to
PAGEBLOCK_ORDER, and have left it up to the guest to determine what size of reactor it wants to allocate to process the hints.Another consideration I am still debating is if I really want to process the
aerator_cycle()function in interrupt context or if I should have it running in a thread somewhere else.Did you get to test/benchmark the difference?
I haven't yet.