Re: [PATCH 6/6] mm/gup: migrate pinned pages out of movable zone

From: Jason Gunthorpe
Date: Wed Dec 02 2020 - 11:36:50 EST


On Wed, Dec 02, 2020 at 12:23:30AM -0500, Pavel Tatashin wrote:
> /*
> * First define the enums in the above macros to be exported to userspace
> diff --git a/mm/gup.c b/mm/gup.c
> index 724d8a65e1df..1d511f65f8a7 100644
> +++ b/mm/gup.c
> @@ -1593,19 +1593,18 @@ static bool check_dax_vmas(struct vm_area_struct **vmas, long nr_pages)
> }
> #endif
>
> -#ifdef CONFIG_CMA
> -static long check_and_migrate_cma_pages(struct mm_struct *mm,
> - unsigned long start,
> - unsigned long nr_pages,
> - struct page **pages,
> - struct vm_area_struct **vmas,
> - unsigned int gup_flags)
> +static long check_and_migrate_movable_pages(struct mm_struct *mm,
> + unsigned long start,
> + unsigned long nr_pages,
> + struct page **pages,
> + struct vm_area_struct **vmas,
> + unsigned int gup_flags)
> {
> unsigned long i;
> unsigned long step;
> bool drain_allow = true;
> bool migrate_allow = true;
> - LIST_HEAD(cma_page_list);
> + LIST_HEAD(page_list);
> long ret = nr_pages;
> struct migration_target_control mtc = {
> .nid = NUMA_NO_NODE,
> @@ -1623,13 +1622,12 @@ static long check_and_migrate_cma_pages(struct mm_struct *mm,
> */
> step = compound_nr(head) - (pages[i] - head);
> /*
> - * If we get a page from the CMA zone, since we are going to
> - * be pinning these entries, we might as well move them out
> - * of the CMA zone if possible.
> + * If we get a movable page, since we are going to be pinning
> + * these entries, try to move them out if possible.
> */
> - if (is_migrate_cma_page(head)) {
> + if (is_migrate_movable(get_pageblock_migratetype(head))) {
> if (PageHuge(head))

It is a good moment to say, I really dislike how this was implemented
in the first place.

Scanning the output of gup just to do the is_migrate_movable() test is
kind of nonsense and slow. It would be better/faster to handle this
directly while gup is scanning the page tables and adding pages to the
list.

Now that this becoming more general, can you take a moment to see if a
better implementation could be possible?

Also, something takes care of the gup fast path too?

Jason