From: Michal Nazarewicz <mina86@mina86.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Michal Nazarewicz <m.nazarewicz@samsung.com>,
Andrew Morton <akpm@linux-foundation.org>,
Ankita Garg <ankita@in.ibm.com>,
BooJin Kim <boojin.kim@samsung.com>,
Daniel Walker <dwalker@codeaurora.org>,
Johan MOSSBERG <johan.xx.mossberg@stericsson.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Mel Gorman <mel@csn.ul.ie>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
linux-mm@kvack.org, Kyungmin Park <kyungmin.park@samsung.com>
Subject: Re: [PATCHv7 08/10] mm: cma: Contiguous Memory Allocator added
Date: Tue, 14 Dec 2010 11:23:15 +0100 [thread overview]
Message-ID: <87zks8fyb0.fsf@erwin.mina86.com> (raw)
In-Reply-To: <20101214102401.37bf812d.kamezawa.hiroyu@jp.fujitsu.com> (KAMEZAWA Hiroyuki's message of "Tue, 14 Dec 2010 10:24:01 +0900")
> On Mon, 13 Dec 2010 12:26:49 +0100
> Michal Nazarewicz <m.nazarewicz@samsung.com> wrote:
>> +/************************* Initialise CMA *************************/
>> +
>> +static struct cma_grabbed {
>> + unsigned long start;
>> + unsigned long size;
>> +} cma_grabbed[8] __initdata;
>> +static unsigned cma_grabbed_count __initdata;
>> +
>> +int cma_init(unsigned long start, unsigned long size)
>> +{
>> + pr_debug("%s(%p+%p)\n", __func__, (void *)start, (void *)size);
>> +
>> + if (!size)
>> + return -EINVAL;
>> + if ((start | size) & ((MAX_ORDER_NR_PAGES << PAGE_SHIFT) - 1))
>> + return -EINVAL;
>> + if (start + size < start)
>> + return -EOVERFLOW;
>> +
>> + if (cma_grabbed_count == ARRAY_SIZE(cma_grabbed))
>> + return -ENOSPC;
>> +
>> + cma_grabbed[cma_grabbed_count].start = start;
>> + cma_grabbed[cma_grabbed_count].size = size;
>> + ++cma_grabbed_count;
>> + return 0;
>> +}
>> +
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> writes:
> Is it guaranteed that there are no memory holes, or zone overlap
> in the range ? I think correctness of the range must be checked.
I keep thinking about it myself. The idea is that you get memory range
reserved using memblock (or some such) thus it should not contain any
memory holes. I'm not entirely sure about spanning different zones.
I'll add the checking code.
>> +#define MIGRATION_RETRY 5
>> +static int __cm_migrate(unsigned long start, unsigned long end)
>> +{
[...]
>> +}
>> +
>> +static int __cm_alloc(unsigned long start, unsigned long size)
>> +{
>> + unsigned long end, _start, _end;
>> + int ret;
>> +
[...]
>> +
>> + start = phys_to_pfn(start);
>> + end = start + (size >> PAGE_SHIFT);
>> +
>> + pr_debug("\tisolate range(%lx, %lx)\n",
>> + pfn_to_maxpage(start), pfn_to_maxpage_up(end));
>> + ret = __start_isolate_page_range(pfn_to_maxpage(start),
>> + pfn_to_maxpage_up(end), MIGRATE_CMA);
>> + if (ret)
>> + goto done;
>> +
>> + pr_debug("\tmigrate range(%lx, %lx)\n", start, end);
>> + ret = __cm_migrate(start, end);
>> + if (ret)
>> + goto done;
>> +
[...]
>> +
>> + pr_debug("\tfinding buddy\n");
>> + ret = 0;
>> + while (!PageBuddy(pfn_to_page(start & (~0UL << ret))))
>> + if (WARN_ON(++ret >= MAX_ORDER))
>> + return -EINVAL;
>> +
>> + _start = start & (~0UL << ret);
>> + pr_debug("\talloc freed(%lx, %lx)\n", _start, end);
>> + _end = alloc_contig_freed_pages(_start, end, 0);
>> +
>> + /* Free head and tail (if any) */
>> + pr_debug("\tfree contig(%lx, %lx)\n", _start, start);
>> + free_contig_pages(pfn_to_page(_start), start - _start);
>> + pr_debug("\tfree contig(%lx, %lx)\n", end, _end);
>> + free_contig_pages(pfn_to_page(end), _end - end);
>> +
>> + ret = 0;
>> +
>> +done:
>> + pr_debug("\tundo isolate range(%lx, %lx)\n",
>> + pfn_to_maxpage(start), pfn_to_maxpage_up(end));
>> + __undo_isolate_page_range(pfn_to_maxpage(start),
>> + pfn_to_maxpage_up(end), MIGRATE_CMA);
>> +
>> + pr_debug("ret = %d\n", ret);
>> + return ret;
>> +}
>> +
>> +static void __cm_free(unsigned long start, unsigned long size)
>> +{
>> + pr_debug("%s(%p+%p)\n", __func__, (void *)start, (void *)size);
>> +
>> + free_contig_pages(pfn_to_page(phys_to_pfn(start)),
>> + size >> PAGE_SHIFT);
>> +}
> Hmm, it seems __cm_alloc() and __cm_migrate() has no special codes for CMA.
> I'd like reuse this for my own contig page allocator.
> So, could you make these function be more generic (name) ?
> as
> __alloc_range(start, size, mirate_type);
>
> Then, what I have to do is only to add "search range" functions.
Sure thing. I'll post it tomorrow or Friday. How about
alloc_contig_range() maybe?
--
Pozdrawiam _ _
.o. | Wasal Jasnie Oswieconej Pani Informatyki o' \,=./ `o
..o | Michal "mina86" Nazarewicz <mina86*tlen.pl> (o o)
ooo +---<jid:mina86-jabber.org>---<tlen:mina86>---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 policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2010-12-14 10:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-13 11:26 [PATCHv7 00/10] Contiguous Memory Allocator Michal Nazarewicz
2010-12-13 11:26 ` [PATCHv7 01/10] mm: migrate.c: fix compilation error Michal Nazarewicz
2010-12-13 11:26 ` [PATCHv7 02/10] lib: bitmap: Added alignment offset for bitmap_find_next_zero_area() Michal Nazarewicz
2010-12-13 11:26 ` [PATCHv7 03/10] lib: genalloc: Generic allocator improvements Michal Nazarewicz
2010-12-13 11:26 ` [PATCHv7 04/10] mm: move some functions from memory_hotplug.c to page_isolation.c Michal Nazarewicz
2010-12-13 11:26 ` [PATCHv7 05/10] mm: alloc_contig_free_pages() added Michal Nazarewicz
2010-12-13 11:26 ` [PATCHv7 06/10] mm: MIGRATE_CMA migration type added Michal Nazarewicz
2010-12-14 1:15 ` KAMEZAWA Hiroyuki
2010-12-14 10:18 ` Michal Nazarewicz
2010-12-13 11:26 ` [PATCHv7 07/10] mm: MIGRATE_CMA isolation functions added Michal Nazarewicz
2010-12-13 11:26 ` [PATCHv7 08/10] mm: cma: Contiguous Memory Allocator added Michal Nazarewicz
2010-12-14 1:24 ` KAMEZAWA Hiroyuki
2010-12-14 10:23 ` Michal Nazarewicz [this message]
2010-12-14 23:50 ` KAMEZAWA Hiroyuki
2010-12-13 11:26 ` [PATCHv7 09/10] mm: cma: Test device and application added Michal Nazarewicz
2010-12-13 11:26 ` [PATCHv7 10/10] ARM: cma: Added CMA to Aquila, Goni and c210 universal boards 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=87zks8fyb0.fsf@erwin.mina86.com \
--to=mina86@mina86.com \
--cc=akpm@linux-foundation.org \
--cc=ankita@in.ibm.com \
--cc=boojin.kim@samsung.com \
--cc=dwalker@codeaurora.org \
--cc=johan.xx.mossberg@stericsson.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kyungmin.park@samsung.com \
--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=m.nazarewicz@samsung.com \
--cc=m.szyprowski@samsung.com \
--cc=mel@csn.ul.ie \
--cc=paulmck@linux.vnet.ibm.com \
/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