From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Andi Kleen <andi@firstfloor.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] [6/13] Core maskable allocator
Date: Sat, 8 Mar 2008 00:13:22 +0300 [thread overview]
Message-ID: <20080307211322.GD7589@cvg> (raw)
In-Reply-To: <20080307090716.9D3E91B419C@basil.firstfloor.org>
[Andi Kleen - Fri, Mar 07, 2008 at 10:07:16AM +0100]
[...]
| +
| +/**
| + * alloc_pages_mask - Alloc page(s) in a specific address range.
| + * @gfp: Standard GFP mask. See get_free_pages for a list valid flags.
| + * @size: Allocate size worth of pages. Rounded up to PAGE_SIZE.
| + * @mask: Memory must fit into mask physical address.
| + *
| + * Returns a struct page *
| + *
| + * Manage dedicated maskable low memory zone. This zone are isolated
| + * from the normal zones. This is only a single continuous zone.
| + * The main difference to the standard allocator is that it tries
| + * to allocate memory with an physical address fitting in the passed mask.
| + *
| + * Warning: the size is in bytes, not in order like get_free_pages.
| + */
| +struct page *
| +alloc_pages_mask(gfp_t gfp, unsigned size, u64 mask)
| +{
| + unsigned long max_pfn = mask >> PAGE_SHIFT;
| + unsigned pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
| + struct page *p;
| + unsigned left = (gfp & __GFP_REPEAT) ? ~0 : mask_timeout, oleft;
| + unsigned order = get_order(size);
| +
| + BUG_ON(size < MASK_MIN_SIZE); /* You likely passed order by mistake */
| + BUG_ON(gfp & (__GFP_DMA|__GFP_DMA32|__GFP_COMP));
| +
| + /* Add fault injection here */
| +
| +again:
| + count_vm_event(MASK_ALLOC);
| + if (!force_mask) {
| + /* First try normal allocation in suitable zones
| + * RED-PEN if size fits very badly in PS<<order don't do this?
| + */
| + p = alloc_higher_pages(gfp, order, max_pfn);
| +
| + /*
| + * If the mask covers everything don't bother with the low zone
| + * This way we avoid running out of low memory on a higher zones
| + * OOM too.
| + */
| + if (p != NULL || max_pfn >= max_low_pfn) {
Andi, I'm a little confused by _this_ statistics. We could get p = NULL
there and change MASK_HIGH_WASTE even have mask not allocated. Am I
wrong or miss something? Or maybe there should be '&&' instead of '||'?
| + count_vm_event(MASK_HIGHER);
| + count_vm_events(MASK_HIGH_WASTE,
| + (PAGE_SIZE << order) - size);
| + return p;
| + }
| + }
| +
| + might_sleep_if(gfp & __GFP_WAIT);
| + do {
| + int i;
| + long pfn;
| +
| + /* Implement waiter fairness queueing here? */
| +
| + pfn = alloc_mask(pages, max_pfn);
| + if (pfn != -1L) {
| + p = pfn_to_page(pfn);
| +
| + Mprintk("mask page %lx size %d mask %Lx\n",
| + po, size, mask);
| +
| + BUG_ON(pfn + pages > mask_max_pfn);
| +
| + if (page_prep_struct(p))
| + goto again;
| +
| + kernel_map_pages(p, pages, 1);
| +
| + for (i = 0; i < pages; i++) {
| + struct page *n = p + i;
| + BUG_ON(!test_bit(pfn_to_maskbm_index(pfn+i),
| + mask_bitmap));
| + BUG_ON(!PageMaskAlloc(n));
| + arch_alloc_page(n, 0);
| + if (gfp & __GFP_ZERO)
| + clear_page(page_address(n));
| + }
| +
| + count_vm_events(MASK_LOW_WASTE, pages*PAGE_SIZE-size);
| + return p;
| + }
| +
| + if (!(gfp & __GFP_WAIT))
| + break;
| +
| + oleft = left;
| + left = wait_for_mask_free(left);
| + count_vm_events(MASK_WAIT, left - oleft);
| + } while (left > 0);
| +
| + if (!(gfp & __GFP_NOWARN)) {
| + printk(KERN_ERR
| + "%s: Cannot allocate maskable memory size %u gfp %x mask %Lx\n",
| + current->comm, size, gfp, mask);
| + dump_stack();
| + }
| + return NULL;
| +}
| +EXPORT_SYMBOL(alloc_pages_mask);
| +
[...]
- Cyrill -
--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2008-03-07 21:13 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-07 9:07 [PATCH] [0/13] General DMA zone rework Andi Kleen
2008-03-07 9:07 ` [PATCH] [2/13] Make get_order(0) return 0 Andi Kleen
2008-03-07 9:07 ` [PATCH] [3/13] Make kvm bad_page symbol static Andi Kleen
2008-03-07 9:07 ` [PATCH] [4/13] Prepare page_alloc for the maskable allocator Andi Kleen
2008-03-07 18:19 ` Sam Ravnborg
2008-03-07 18:36 ` Cyrill Gorcunov
2008-03-07 19:02 ` Andi Kleen
2008-03-07 9:07 ` [PATCH] [5/13] Add mask allocator statistics to vmstat.[ch] Andi Kleen
2008-03-08 2:24 ` Christoph Lameter
2008-03-07 9:07 ` [PATCH] [6/13] Core maskable allocator Andi Kleen
2008-03-07 10:53 ` Johannes Weiner
2008-03-07 11:14 ` Andi Kleen
2008-03-07 17:05 ` Randy Dunlap
2008-03-07 17:31 ` Andi Kleen
2008-03-07 17:33 ` Randy Dunlap
2008-03-07 17:43 ` Andi Kleen
2008-03-07 17:51 ` Randy Dunlap
2008-03-07 21:13 ` Cyrill Gorcunov [this message]
2008-03-07 23:28 ` Andi Kleen
2008-03-08 5:03 ` KAMEZAWA Hiroyuki
2008-03-08 5:41 ` KAMEZAWA Hiroyuki
2008-03-08 11:41 ` Andi Kleen
2008-03-11 15:34 ` Jonathan Corbet
2008-03-11 15:54 ` Andi Kleen
2008-03-07 9:07 ` [PATCH] [7/13] Implement compat hooks for GFP_DMA Andi Kleen
2008-03-07 9:07 ` [PATCH] [8/13] Enable the mask allocator for x86 Andi Kleen
2008-03-07 18:32 ` Sam Ravnborg
2008-03-07 19:03 ` Andi Kleen
2008-03-07 19:09 ` Sam Ravnborg
2008-03-08 2:37 ` Christoph Lameter
2008-03-08 6:35 ` Yinghai Lu
2008-03-08 7:31 ` Christoph Lameter
2008-03-08 11:54 ` Andi Kleen
2008-03-10 17:13 ` Christoph Lameter
2008-03-07 9:07 ` [PATCH] [9/13] Remove set_dma_reserve Andi Kleen
2008-03-07 9:07 ` [PATCH] [10/13] Switch the 32bit dma_alloc_coherent functions over to use the maskable allocator Andi Kleen
2008-03-07 9:07 ` [PATCH] [11/13] Switch x86-64 dma_alloc_coherent over to " Andi Kleen
2008-03-07 9:07 ` [PATCH] [12/13] Add vmstat statistics for new swiotlb code Andi Kleen
2008-03-08 2:38 ` Christoph Lameter
2008-03-07 9:07 ` [PATCH] [13/13] Convert x86-64 swiotlb to use the mask allocator directly Andi Kleen
2008-03-07 15:18 ` [PATCH] [0/13] General DMA zone rework Rene Herman
2008-03-07 15:22 ` Rene Herman
2008-03-07 15:31 ` Andi Kleen
2008-03-07 15:34 ` Andi Kleen
2008-03-07 20:51 ` Luiz Fernando N. Capitulino
2008-03-08 0:46 ` Andi Kleen
2008-03-10 18:03 ` Luiz Fernando N. Capitulino
2008-03-10 18:08 ` Andi Kleen
2008-03-11 17:26 ` Luiz Fernando N. Capitulino
2008-03-11 17:35 ` Andi Kleen
2008-03-11 18:00 ` Luiz Fernando N. Capitulino
2008-03-11 18:49 ` Andi Kleen
2008-03-11 19:36 ` Luiz Fernando N. Capitulino
2008-03-08 2:42 ` Christoph Lameter
2008-03-08 11:57 ` Andi Kleen
2008-03-10 17:14 ` Christoph Lameter
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=20080307211322.GD7589@cvg \
--to=gorcunov@gmail.com \
--cc=andi@firstfloor.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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;
as well as URLs for NNTP newsgroup(s).