Re: [PATCH 2/2] page-allocator: Maintain rolling count of pages to free from the PCP

From: Minchan Kim
Date: Fri Aug 28 2009 - 11:04:56 EST


Hi, Mel.

On Fri, Aug 28, 2009 at 5:44 PM, Mel Gorman<mel@xxxxxxxxx> wrote:
> When round-robin freeing pages from the PCP lists, empty lists may be
> encountered. In the event one of the lists has more pages than another,
> there may be numerous checks for list_empty() which is undesirable. This
> patch maintains a count of pages to free which is incremented when empty
> lists are encountered. The intention is that more pages will then be freed
> from fuller lists than the empty ones reducing the number of empty list
> checks in the free path.
>
> Signed-off-by: Mel Gorman <mel@xxxxxxxxx>
> ---
> Âmm/page_alloc.c | Â 23 ++++++++++++++---------
> Â1 files changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 65eedb5..9b86977 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -536,32 +536,37 @@ static void free_pcppages_bulk(struct zone *zone, int count,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct per_cpu_pages *pcp)
> Â{
> Â Â Â Âint migratetype = 0;
> + Â Â Â int batch_free = 0;
>
> Â Â Â Âspin_lock(&zone->lock);
> Â Â Â Âzone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
> Â Â Â Âzone->pages_scanned = 0;
>
> Â Â Â Â__mod_zone_page_state(zone, NR_FREE_PAGES, count);
> - Â Â Â while (count--) {
> + Â Â Â while (count) {
> Â Â Â Â Â Â Â Âstruct page *page;
> Â Â Â Â Â Â Â Âstruct list_head *list;
>
> Â Â Â Â Â Â Â Â/*
> - Â Â Â Â Â Â Â Â* Remove pages from lists in a round-robin fashion. This spinning
> - Â Â Â Â Â Â Â Â* around potentially empty lists is bloody awful, alternatives that
> - Â Â Â Â Â Â Â Â* don't suck are welcome
> + Â Â Â Â Â Â Â Â* Remove pages from lists in a round-robin fashion. A batch_free
> + Â Â Â Â Â Â Â Â* count is maintained that is incremented when an empty list is
> + Â Â Â Â Â Â Â Â* encountered. This is so more pages are freed off fuller lists
> + Â Â Â Â Â Â Â Â* instead of spinning excessively around empty lists
> Â Â Â Â Â Â Â Â */
> Â Â Â Â Â Â Â Âdo {
> + Â Â Â Â Â Â Â Â Â Â Â batch_free++;
> Â Â Â Â Â Â Â Â Â Â Â Âif (++migratetype == MIGRATE_PCPTYPES)
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âmigratetype = 0;
> Â Â Â Â Â Â Â Â Â Â Â Âlist = &pcp->lists[migratetype];
> Â Â Â Â Â Â Â Â} while (list_empty(list));

How about increasing the weight by batch_free ?

batch_free = 1 << (batch_free - 1);

It's assumed that if batch_free is big, it means
there are contiguous empty lists.
Then it is likely to need more time to refill empty lists than
one list refill. So I think it can decrease spinning empty list
a little more.

>
> - Â Â Â Â Â Â Â page = list_entry(list->prev, struct page, lru);
> - Â Â Â Â Â Â Â /* have to delete it as __free_one_page list manipulates */
> - Â Â Â Â Â Â Â list_del(&page->lru);
> - Â Â Â Â Â Â Â trace_mm_page_pcpu_drain(page, 0, migratetype);
> - Â Â Â Â Â Â Â __free_one_page(page, zone, 0, migratetype);
> + Â Â Â Â Â Â Â do {
> + Â Â Â Â Â Â Â Â Â Â Â page = list_entry(list->prev, struct page, lru);
> + Â Â Â Â Â Â Â Â Â Â Â /* must delete as __free_one_page list manipulates */
> + Â Â Â Â Â Â Â Â Â Â Â list_del(&page->lru);
> + Â Â Â Â Â Â Â Â Â Â Â __free_one_page(page, zone, 0, migratetype);
> + Â Â Â Â Â Â Â Â Â Â Â trace_mm_page_pcpu_drain(page, 0, migratetype);
> + Â Â Â Â Â Â Â } while (--count && --batch_free && !list_empty(list));
> Â Â Â Â}
> Â Â Â Âspin_unlock(&zone->lock);
> Â}
> --
> 1.6.3.3
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@xxxxxxxxxx ÂFor more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>
>



--
Kind regards,
Minchan Kim
--
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/