linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Michal Nazarewicz" <mina86@mina86.com>
To: Marek Szyprowski <m.szyprowski@samsung.com>, Mel Gorman <mel@csn.ul.ie>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-media@vger.kernel.org, linux-mm@kvack.org,
	linaro-mm-sig@lists.linaro.org,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Russell King <linux@arm.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	Ankita Garg <ankita@in.ibm.com>,
	Daniel Walker <dwalker@codeaurora.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Jesse Barker <jesse.barker@linaro.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Shariq Hasnain <shariq.hasnain@linaro.org>,
	Chunsang Jeong <chunsang.jeong@linaro.org>,
	Dave Hansen <dave@linux.vnet.ibm.com>
Subject: Re: [PATCH 02/11] mm: compaction: introduce isolate_{free,migrate}pages_range().
Date: Mon, 12 Dec 2011 16:22:39 +0100	[thread overview]
Message-ID: <op.v6dub1ms3l0zgt@mpn-glaptop> (raw)
In-Reply-To: <20111212140728.GC3277@csn.ul.ie>

> On Fri, Nov 18, 2011 at 05:43:09PM +0100, Marek Szyprowski wrote:
>> From: Michal Nazarewicz <mina86@mina86.com>
>> diff --git a/mm/compaction.c b/mm/compaction.c
>> index 899d956..6afae0e 100644
>> --- a/mm/compaction.c
>> +++ b/mm/compaction.c
>> @@ -54,51 +54,64 @@ static unsigned long release_freepages(struct list_head *freelist)
>>  	return count;
>>  }
>>
>> -/* Isolate free pages onto a private freelist. Must hold zone->lock */
>> -static unsigned long isolate_freepages_block(struct zone *zone,
>> -				unsigned long blockpfn,
>> -				struct list_head *freelist)
>> +/**
>> + * isolate_freepages_range() - isolate free pages, must hold zone->lock.
>> + * @zone:	Zone pages are in.
>> + * @start:	The first PFN to start isolating.
>> + * @end:	The one-past-last PFN.
>> + * @freelist:	A list to save isolated pages to.
>> + *
>> + * If @freelist is not provided, holes in range (either non-free pages
>> + * or invalid PFNs) are considered an error and function undos its
>> + * actions and returns zero.
>> + *
>> + * If @freelist is provided, function will simply skip non-free and
>> + * missing pages and put only the ones isolated on the list.
>> + *
>> + * Returns number of isolated pages.  This may be more then end-start
>> + * if end fell in a middle of a free page.
>> + */
>> +static unsigned long
>> +isolate_freepages_range(struct zone *zone,
>> +			unsigned long start, unsigned long end,
>> +			struct list_head *freelist)

On Mon, 12 Dec 2011 15:07:28 +0100, Mel Gorman <mel@csn.ul.ie> wrote:
> Use start_pfn and end_pfn to keep it consistent with the rest of
> compaction.c.

Will do.

>>  {
>> -	unsigned long zone_end_pfn, end_pfn;
>> -	int nr_scanned = 0, total_isolated = 0;
>> -	struct page *cursor;
>> -
>> -	/* Get the last PFN we should scan for free pages at */
>> -	zone_end_pfn = zone->zone_start_pfn + zone->spanned_pages;
>> -	end_pfn = min(blockpfn + pageblock_nr_pages, zone_end_pfn);
>> +	unsigned long nr_scanned = 0, total_isolated = 0;
>> +	unsigned long pfn = start;
>> +	struct page *page;
>>
>> -	/* Find the first usable PFN in the block to initialse page cursor */
>> -	for (; blockpfn < end_pfn; blockpfn++) {
>> -		if (pfn_valid_within(blockpfn))
>> -			break;
>> -	}
>> -	cursor = pfn_to_page(blockpfn);
>> +	VM_BUG_ON(!pfn_valid(pfn));
>> +	page = pfn_to_page(pfn);
>>
>>  	/* Isolate free pages. This assumes the block is valid */
>> -	for (; blockpfn < end_pfn; blockpfn++, cursor++) {
>> -		int isolated, i;
>> -		struct page *page = cursor;
>> -
>> -		if (!pfn_valid_within(blockpfn))
>> -			continue;
>> -		nr_scanned++;
>> -
>> -		if (!PageBuddy(page))
>> -			continue;
>> +	while (pfn < end) {
>> +		unsigned isolated = 1, i;
>> +

> Do not use implcit types. These are unsigned ints, call them unsigned
> ints.

Will do.

>
>> +		if (!pfn_valid_within(pfn))
>> +			goto skip;
>
> The flow of this function in general with gotos of skipped and next
> is confusing in comparison to the existing function. For example,
> if this PFN is not valid, and no freelist is provided, then we call
> __free_page() on a PFN that is known to be invalid.
>
>> +		++nr_scanned;
>> +
>> +		if (!PageBuddy(page)) {
>> +skip:
>> +			if (freelist)
>> +				goto next;
>> +			for (; start < pfn; ++start)
>> +				__free_page(pfn_to_page(pfn));
>> +			return 0;
>> +		}
>
> So if a PFN is valid and !PageBuddy and no freelist is provided, we
> call __free_page() on it regardless of reference count. That does not
> sound safe.

Sorry about that.  It's a bug in the code which was caught later on.  The
code should read “__free_page(pfn_to_page(start))”.

>>
>>  		/* Found a free page, break it into order-0 pages */
>>  		isolated = split_free_page(page);
>>  		total_isolated += isolated;
>> -		for (i = 0; i < isolated; i++) {
>> -			list_add(&page->lru, freelist);
>> -			page++;
>> +		if (freelist) {
>> +			struct page *p = page;
>> +			for (i = isolated; i; --i, ++p)
>> +				list_add(&p->lru, freelist);
>>  		}
>>
>> -		/* If a page was split, advance to the end of it */
>> -		if (isolated) {
>> -			blockpfn += isolated - 1;
>> -			cursor += isolated - 1;
>> -		}
>> +next:
>> +		pfn += isolated;
>> +		page += isolated;
>
> The name isolated is now confusing because it can mean either
> pages isolated or pages scanned depending on context. Your patch
> appears to be doing a lot more than is necessary to convert
> isolate_freepages_block into isolate_freepages_range and at this point,
> it's unclear why you did that.

When CMA uses this function, it requires all pages in the range to be valid
and free.  (Both conditions should be met but you never know.)  This change
adds a second way isolate_freepages_range() works, which is when freelist is
not specified, abort on invalid or non-free page, but continue as usual if
freelist is provided.

I can try and restructure this function a bit so that there are fewer “gotos”,
but without the above change, CMA won't really be able to use it effectively
(it would have to provide a freelist and then validate if pages on it are
added in order).

>>  	}
>>
>>  	trace_mm_compaction_isolate_freepages(nr_scanned, total_isolated);

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo--

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2011-12-12 15:22 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-18 16:43 [PATCHv17 0/11] Contiguous Memory Allocator Marek Szyprowski
2011-11-18 16:43 ` [PATCH 01/11] mm: page_alloc: handle MIGRATE_ISOLATE in free_pcppages_bulk() Marek Szyprowski
2011-12-12 13:42   ` Mel Gorman
2011-12-12 14:23     ` Michal Nazarewicz
2011-12-12 14:42       ` Mel Gorman
2011-11-18 16:43 ` [PATCH 02/11] mm: compaction: introduce isolate_{free,migrate}pages_range() Marek Szyprowski
2011-12-12 14:07   ` Mel Gorman
2011-12-12 15:22     ` Michal Nazarewicz [this message]
2011-12-12 16:30       ` Mel Gorman
2011-12-12 16:46         ` Michal Nazarewicz
2011-12-12 17:20           ` Mel Gorman
2011-11-18 16:43 ` [PATCH 03/11] mm: mmzone: introduce zone_pfn_same_memmap() Marek Szyprowski
2011-12-12 14:19   ` Mel Gorman
2011-12-12 14:35     ` Michal Nazarewicz
2011-12-12 14:40       ` Mel Gorman
2011-12-12 14:51         ` Michal Nazarewicz
2011-12-12 15:51           ` Mel Gorman
2011-11-18 16:43 ` [PATCH 04/11] mm: compaction: export some of the functions Marek Szyprowski
2011-12-12 14:29   ` Mel Gorman
2011-12-12 14:41     ` Michal Nazarewicz
2011-12-12 15:40       ` Mel Gorman
2011-12-12 15:46         ` Michal Nazarewicz
2011-12-12 16:22         ` Arnd Bergmann
2011-11-18 16:43 ` [PATCH 05/11] mm: page_alloc: introduce alloc_contig_range() Marek Szyprowski
2011-11-18 16:43 ` [PATCH 06/11] mm: mmzone: MIGRATE_CMA migration type added Marek Szyprowski
2011-11-18 16:43 ` [PATCH 07/11] mm: page_isolation: MIGRATE_CMA isolation functions added Marek Szyprowski
2011-11-18 16:43 ` [PATCH 08/11] drivers: add Contiguous Memory Allocator Marek Szyprowski
2011-11-18 16:43 ` [PATCH 09/11] X86: integrate CMA with DMA-mapping subsystem Marek Szyprowski
2011-11-18 16:43 ` [PATCH 10/11] ARM: " Marek Szyprowski
2011-11-18 16:43 ` [PATCH 11/11] ARM: Samsung: use CMA for 2 memory banks for s5p-mfc device Marek Szyprowski
2011-11-18 21:20 ` [Linaro-mm-sig] [PATCHv17 0/11] Contiguous Memory Allocator sandeep patil
2011-11-18 21:26   ` Michal Nazarewicz
2011-11-18 23:30     ` sandeep patil
2011-11-19 18:09       ` Michal Nazarewicz
2011-11-25 16:43 ` [PATCH] mm: cma: hack/workaround for some allocation issues Marek Szyprowski
2011-11-25 21:08   ` Michal Nazarewicz
2011-12-29 12:39 [PATCHv18 0/11] Contiguous Memory Allocator Marek Szyprowski
2011-12-29 12:39 ` [PATCH 02/11] mm: compaction: introduce isolate_{free,migrate}pages_range() Marek Szyprowski
2012-01-10 13:43   ` Mel Gorman
2012-01-10 15:04     ` Michal Nazarewicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=op.v6dub1ms3l0zgt@mpn-glaptop \
    --to=mina86@mina86.com \
    --cc=akpm@linux-foundation.org \
    --cc=ankita@in.ibm.com \
    --cc=arnd@arndb.de \
    --cc=chunsang.jeong@linaro.org \
    --cc=corbet@lwn.net \
    --cc=dave@linux.vnet.ibm.com \
    --cc=dwalker@codeaurora.org \
    --cc=jesse.barker@linaro.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@arm.linux.org.uk \
    --cc=m.szyprowski@samsung.com \
    --cc=mel@csn.ul.ie \
    --cc=shariq.hasnain@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox