Re: [PATCH] [RFC] CMA: clear buffer-head lru before page migration

From: Joonsoo Kim
Date: Mon Jul 14 2014 - 02:56:41 EST


On Tue, Jul 08, 2014 at 06:46:31PM +0200, Michal Nazarewicz wrote:
> On Mon, Jul 07 2014, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
> > What I proposed is that CMA call invalidate_bh_lrus() right at the
> > outset. Something along the lines of
> >
> > --- a/mm/page_alloc.c~a
> > +++ a/mm/page_alloc.c
> > @@ -6329,6 +6329,14 @@ int alloc_contig_range(unsigned long sta
> > };
> > INIT_LIST_HEAD(&cc.migratepages);
> >
> > +#ifdef CONFIG_CMA
> > + /*
> > + * Comment goes here
> > + */
> > + if (migratetype == MIGRATE_CMA)
> > + invalidate_bh_lrus();
> > +#endif
> > +
>
> This seems reasonable, except I think it should go after
> start_isolate_page_range call because otherwise there's no guarantee
> that someone won't grab those pages back.
>
> Also to avoid the #ifdef perhaps we want this as well:

I think that we just want to remove ifdef CONFIG_CMA on above code
snippet, because invalidate_bh_lrus() would also help user of
alloc_contig_range() with MIGRATE_MOVABLE.

>
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 6cbd1b6..2640a55 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -64,10 +64,11 @@ enum {
> };
>
> #ifdef CONFIG_CMA
> -# define is_migrate_cma(migratetype) unlikely((migratetype) == MIGRATE_CMA)
> +# define __is_migrate_cma(migratetype) ((migratetype) == MIGRATE_CMA)
> #else
> -# define is_migrate_cma(migratetype) false
> +# define __is_migrate_cma(migratetype) false
> #endif
> +#define is_migrate_cma(migratetype) unlikely(__is_migrate_cma(migratetype))
>
> #define for_each_migratetype_order(order, type) \
> for (order = 0; order < MAX_ORDER; order++) \
>
> and then use âif (__is_migrate_cma(migratetype))â.
>
> > /*
> > * What we do here is we mark all pageblocks in range as
> > * MIGRATE_ISOLATE. Because pageblock and max order pages may
> >
> >
> > - I'd have thought that it would make sense to do this for huge pages
> > as well (MIGRATE_MOVABLE) but nobody really seems to know.
> >
> > - There's a patch floating around ("Allow increasing the buffer-head
> > per-CPU LRU size") which will double the size of the bh lrus, so this
> > all becomes more important.
> >
> > - alloc_contig_range() does lru_add_drain_all() and drain_all_pages()
> > *after* performing the allocation. I can't work out why this is the
> > case and of course it is undocumented. If this is indeed not a bug
> > then probably the invalidate_bh_lrus() should happen in the same
> > place.
>
> The purpose is to get free non-buddy pages (so pages on PCP lists for
> instance) back onto the buddy list. It's safe to move those calls above
> the call to __alloc_contig_migrate_range, but I don't think it will
> change anything (except of course the fact that if migration fails,
> we'll do the draining for nothing).

At a glance, we don't need that drain_all_pages(), because
drain_all_pages() is also called by set_migratetype_isolate() after changing
migratetype.

And, it is better to move up lru_add_drain_all() to ahead of
__alloc_contig_migrate_range(), because some pages could be skipped
to migrate due to this lru page caching mechanism.

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/