From: Christoph Lameter <clameter@sgi.com>
To: Christoph Hellwig <hch@lst.de>, Mel Gorman <mel@skynet.ie>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: David Chinner <dgc@sgi.com>, Jens Axboe <jens.axboe@oracle.com>
Subject: [07/17] GFP_VFALLBACK: Allow fallback of compound pages to virtual mappings
Date: Tue, 18 Sep 2007 20:36:12 -0700 [thread overview]
Message-ID: <20070919033641.933657553@sgi.com> (raw)
In-Reply-To: 20070919033605.785839297@sgi.com
[-- Attachment #1: vcompound_core --]
[-- Type: text/plain, Size: 7244 bytes --]
This adds a new gfp flag
__GFP_VFALLBACK
If specified during a higher order allocation then the system will fall
back to vmap and attempt to create a virtually contiguous area instead of
a physically contiguous area. In many cases the virtually contiguous area
can stand in for the physically contiguous area (with some loss of
performance).
The pages used for VFALLBACK are marked with a new flag
PageVcompound(page). The mark is necessary since we have to know upon
free if we have to destroy a virtual mapping. No additional flag is
consumed through the use of PG_swapcache together with PG_compound
(similar to PageHead() and PageTail()).
Signed-off-by: Christoph Lameter <clameter@sgi.com>
---
include/linux/gfp.h | 5 +
include/linux/page-flags.h | 18 +++++++
mm/page_alloc.c | 113 ++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 130 insertions(+), 6 deletions(-)
Index: linux-2.6/mm/page_alloc.c
===================================================================
--- linux-2.6.orig/mm/page_alloc.c 2007-09-18 17:03:54.000000000 -0700
+++ linux-2.6/mm/page_alloc.c 2007-09-18 18:25:46.000000000 -0700
@@ -1230,6 +1230,86 @@ try_next_zone:
}
/*
+ * Virtual Compound Page support.
+ *
+ * Virtual Compound Pages are used to fall back to order 0 allocations if large
+ * linear mappings are not available and __GFP_VFALLBACK is set. They are
+ * formatted according to compound page conventions. I.e. following
+ * page->first_page if PageTail(page) is set can be used to determine the
+ * head page.
+ */
+struct page *vcompound_alloc(gfp_t gfp_mask, int order,
+ struct zonelist *zonelist, unsigned long alloc_flags)
+{
+ void *addr;
+ struct page *page;
+ int i;
+ int nr_pages = 1 << order;
+ struct page **pages = kzalloc((nr_pages + 1) * sizeof(struct page *),
+ gfp_mask & GFP_LEVEL_MASK);
+
+ if (!pages)
+ return NULL;
+
+ for (i = 0; i < nr_pages; i++) {
+ page = get_page_from_freelist(gfp_mask & ~__GFP_VFALLBACK,
+ 0, zonelist, alloc_flags);
+ if (!page)
+ goto abort;
+
+ /* Sets PageCompound which makes PageHead(page) true */
+ __SetPageVcompound(page);
+ if (i) {
+ page->first_page = pages[0];
+ __SetPageTail(page);
+ }
+ pages[i] = page;
+ }
+
+ addr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
+ if (!addr)
+ goto abort;
+
+ return pages[0];
+
+abort:
+ for (i = 0; i < nr_pages; i++) {
+ page = pages[i];
+ if (!page)
+ continue;
+ __ClearPageTail(page);
+ __ClearPageHead(page);
+ __ClearPageVcompound(page);
+ __free_page(page);
+ }
+ kfree(pages);
+ return NULL;
+}
+
+static void vcompound_free(void *addr)
+{
+ struct page **pages = vunmap(addr);
+ int i;
+
+ /*
+ * First page will have zero refcount since it maintains state
+ * for the compound and was decremented before we got here.
+ */
+ __ClearPageHead(pages[0]);
+ __ClearPageVcompound(pages[0]);
+ free_hot_page(pages[0]);
+
+ for (i = 1; pages[i]; i++) {
+ struct page *page = pages[i];
+
+ __ClearPageTail(page);
+ __ClearPageVcompound(page);
+ __free_page(page);
+ }
+ kfree(pages);
+}
+
+/*
* This is the 'heart' of the zoned buddy allocator.
*/
struct page * fastcall
@@ -1324,12 +1404,12 @@ nofail_alloc:
goto nofail_alloc;
}
}
- goto nopage;
+ goto try_vcompound;
}
/* Atomic allocations - we can't balance anything */
if (!wait)
- goto nopage;
+ goto try_vcompound;
cond_resched();
@@ -1360,6 +1440,11 @@ nofail_alloc:
*/
page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, order,
zonelist, ALLOC_WMARK_HIGH|ALLOC_CPUSET);
+
+ if (!page && order && (gfp_mask & __GFP_VFALLBACK))
+ page = vcompound_alloc(gfp_mask, order,
+ zonelist, alloc_flags);
+
if (page)
goto got_pg;
@@ -1391,6 +1476,14 @@ nofail_alloc:
goto rebalance;
}
+try_vcompound:
+ /* Last chance before failing the allocation */
+ if (order && (gfp_mask & __GFP_VFALLBACK)) {
+ page = vcompound_alloc(gfp_mask, order,
+ zonelist, alloc_flags);
+ if (page)
+ goto got_pg;
+ }
nopage:
if (!(gfp_mask & __GFP_NOWARN) && printk_ratelimit()) {
printk(KERN_WARNING "%s: page allocation failure."
@@ -1450,8 +1543,12 @@ fastcall void __free_pages(struct page *
if (put_page_testzero(page)) {
if (order == 0)
free_hot_page(page);
- else
- __free_pages_ok(page, order);
+ else {
+ if (unlikely(PageVcompound(page)))
+ vcompound_free(vmalloc_address(page));
+ else
+ __free_pages_ok(page, order);
+ }
}
}
@@ -1460,8 +1557,12 @@ EXPORT_SYMBOL(__free_pages);
fastcall void free_pages(unsigned long addr, unsigned int order)
{
if (addr != 0) {
- VM_BUG_ON(!virt_addr_valid((void *)addr));
- __free_pages(virt_to_page((void *)addr), order);
+ if (unlikely(is_vmalloc_addr((void *)addr)))
+ vcompound_free((void *)addr);
+ else {
+ VM_BUG_ON(!virt_addr_valid((void *)addr));
+ __free_pages(virt_to_page((void *)addr), order);
+ }
}
}
Index: linux-2.6/include/linux/gfp.h
===================================================================
--- linux-2.6.orig/include/linux/gfp.h 2007-09-18 17:03:54.000000000 -0700
+++ linux-2.6/include/linux/gfp.h 2007-09-18 17:03:58.000000000 -0700
@@ -43,6 +43,7 @@ struct vm_area_struct;
#define __GFP_REPEAT ((__force gfp_t)0x400u) /* Retry the allocation. Might fail */
#define __GFP_NOFAIL ((__force gfp_t)0x800u) /* Retry for ever. Cannot fail */
#define __GFP_NORETRY ((__force gfp_t)0x1000u)/* Do not retry. Might fail */
+#define __GFP_VFALLBACK ((__force gfp_t)0x2000u)/* Permit fallback to vmalloc */
#define __GFP_COMP ((__force gfp_t)0x4000u)/* Add compound page metadata */
#define __GFP_ZERO ((__force gfp_t)0x8000u)/* Return zeroed page on success */
#define __GFP_NOMEMALLOC ((__force gfp_t)0x10000u) /* Don't use emergency reserves */
@@ -86,6 +87,10 @@ struct vm_area_struct;
#define GFP_THISNODE ((__force gfp_t)0)
#endif
+/*
+ * Allocate large page but allow fallback to a virtually mapped page
+ */
+#define GFP_VFALLBACK (GFP_KERNEL | __GFP_VFALLBACK)
/* Flag - indicates that the buffer will be suitable for DMA. Ignored on some
platforms, used as appropriate on others */
Index: linux-2.6/include/linux/page-flags.h
===================================================================
--- linux-2.6.orig/include/linux/page-flags.h 2007-09-18 17:03:54.000000000 -0700
+++ linux-2.6/include/linux/page-flags.h 2007-09-18 17:03:58.000000000 -0700
@@ -248,6 +248,24 @@ static inline void __ClearPageTail(struc
#define __SetPageHead(page) __SetPageCompound(page)
#define __ClearPageHead(page) __ClearPageCompound(page)
+/*
+ * PG_swapcache is used in combination with PG_compound to indicate
+ * that a compound page was allocated via vmalloc.
+ */
+#define PG_vcompound_mask ((1L << PG_compound) | (1L << PG_swapcache))
+#define PageVcompound(page) ((page->flags & PG_vcompound_mask) \
+ == PG_vcompound_mask)
+
+static inline void __SetPageVcompound(struct page *page)
+{
+ page->flags |= PG_vcompound_mask;
+}
+
+static inline void __ClearPageVcompound(struct page *page)
+{
+ page->flags &= ~PG_vcompound_mask;
+}
+
#ifdef CONFIG_SWAP
#define PageSwapCache(page) test_bit(PG_swapcache, &(page)->flags)
#define SetPageSwapCache(page) set_bit(PG_swapcache, &(page)->flags)
--
next prev parent reply other threads:[~2007-09-19 3:36 UTC|newest]
Thread overview: 110+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-19 3:36 [00/17] [RFC] Virtual Compound Page Support Christoph Lameter
2007-09-19 3:36 ` [01/17] Vmalloc: Move vmalloc_to_page to mm/vmalloc Christoph Lameter
2007-09-19 3:36 ` [02/17] Vmalloc: add const Christoph Lameter
2007-09-19 3:36 ` [03/17] is_vmalloc_addr(): Check if an address is within the vmalloc boundaries Christoph Lameter
2007-09-19 6:32 ` David Rientjes
2007-09-19 7:24 ` Anton Altaparmakov
2007-09-19 8:09 ` David Rientjes
2007-09-19 8:44 ` Anton Altaparmakov
2007-09-19 9:19 ` David Rientjes
2007-09-19 13:23 ` Anton Altaparmakov
2007-09-19 17:29 ` Christoph Lameter
2007-09-19 17:52 ` Anton Altaparmakov
2007-09-19 17:29 ` Christoph Lameter
2007-09-19 17:52 ` Anton Altaparmakov
2007-09-19 3:36 ` [04/17] vmalloc: clean up page array indexing Christoph Lameter
2007-09-19 3:36 ` [05/17] vunmap: return page array Christoph Lameter
2007-09-19 8:05 ` KAMEZAWA Hiroyuki
2007-09-19 22:15 ` Christoph Lameter
2007-09-20 0:47 ` KAMEZAWA Hiroyuki
2007-09-19 3:36 ` [06/17] vmalloc_address(): Determine vmalloc address from page struct Christoph Lameter
2007-09-19 3:36 ` Christoph Lameter [this message]
2007-09-19 3:36 ` [08/17] Pass vmalloc address in page->private Christoph Lameter
2007-09-19 3:36 ` [09/17] VFALLBACK: Debugging aid Christoph Lameter
2007-09-19 3:36 ` [10/17] Use GFP_VFALLBACK for sparsemem Christoph Lameter
2007-09-19 3:36 ` [11/17] GFP_VFALLBACK for zone wait table Christoph Lameter
2007-09-19 3:36 ` [12/17] Virtual Compound page allocation from interrupt context Christoph Lameter
2007-09-19 3:36 ` [13/17] Virtual compound page freeing in " Christoph Lameter
2007-09-18 20:36 ` Nick Piggin
2007-09-20 17:50 ` Christoph Lameter
2007-09-19 3:36 ` [14/17] Allow bit_waitqueue to wait on a bit in a vmalloc area Christoph Lameter
2007-09-19 4:12 ` Gabriel C
2007-09-19 17:40 ` Christoph Lameter
2007-09-19 3:36 ` [15/17] SLUB: Support virtual fallback via SLAB_VFALLBACK Christoph Lameter
2007-09-27 21:42 ` Nick Piggin
2007-09-28 17:33 ` Christoph Lameter
2007-09-28 5:14 ` Nick Piggin
2007-10-01 20:50 ` Christoph Lameter
2007-10-02 8:43 ` Nick Piggin
2007-10-04 16:16 ` SLUB performance regression vs SLAB Matthew Wilcox
2007-10-04 17:38 ` Christoph Lameter
2007-10-04 17:50 ` Arjan van de Ven
2007-10-04 17:58 ` Christoph Lameter
2007-10-04 18:26 ` Peter Zijlstra
2007-10-04 20:48 ` David Miller
2007-10-04 20:58 ` Matthew Wilcox
2007-10-04 21:05 ` David Miller
2007-10-04 21:11 ` Christoph Lameter
2007-10-04 18:32 ` Matthew Wilcox
2007-10-04 17:49 ` Christoph Lameter
2007-10-04 19:28 ` Matthew Wilcox
2007-10-04 19:05 ` Christoph Lameter
2007-10-04 19:46 ` Siddha, Suresh B
2007-10-04 20:55 ` David Miller
2007-10-04 21:02 ` Chuck Ebbert
2007-10-04 21:11 ` David Miller
2007-10-04 21:47 ` Chuck Ebbert
2007-10-04 22:07 ` David Miller
2007-10-04 22:23 ` David Chinner
2007-10-05 6:48 ` Jens Axboe
2007-10-05 9:19 ` Pekka Enberg
2007-10-05 9:28 ` Jens Axboe
2007-10-05 11:12 ` Andi Kleen
2007-10-05 12:39 ` Jens Axboe
2007-10-05 19:31 ` Christoph Lameter
2007-10-05 19:32 ` Christoph Lameter
2007-10-05 11:56 ` Matthew Wilcox
2007-10-05 12:37 ` Jens Axboe
2007-10-05 19:27 ` Christoph Lameter
2007-10-05 20:32 ` Peter Zijlstra
2007-10-05 21:31 ` David Miller
2007-10-04 21:05 ` Matthew Wilcox
2007-10-05 2:43 ` Christoph Lameter
2007-10-05 2:53 ` Arjan van de Ven
2007-09-28 17:55 ` [15/17] SLUB: Support virtual fallback via SLAB_VFALLBACK Peter Zijlstra
2007-09-28 18:20 ` Christoph Lameter
2007-09-28 18:25 ` Peter Zijlstra
2007-09-28 18:41 ` Christoph Lameter
2007-09-28 20:22 ` Nick Piggin
2007-09-28 21:14 ` Mel Gorman
2007-09-28 20:59 ` Mel Gorman
2007-09-29 8:13 ` Andrew Morton
2007-09-29 8:47 ` Peter Zijlstra
2007-09-29 8:53 ` Peter Zijlstra
2007-09-29 9:01 ` Andrew Morton
2007-09-29 9:14 ` Peter Zijlstra
2007-09-29 9:27 ` Andrew Morton
2007-09-28 20:19 ` Nick Piggin
2007-09-29 19:20 ` Andrew Morton
2007-09-29 19:09 ` Nick Piggin
2007-09-30 20:12 ` Andrew Morton
2007-09-30 4:16 ` Nick Piggin
2007-09-29 9:00 ` Andrew Morton
2007-10-01 20:55 ` Christoph Lameter
2007-10-01 21:30 ` Andrew Morton
2007-10-01 21:38 ` Christoph Lameter
2007-10-01 21:45 ` Andrew Morton
2007-10-01 21:52 ` Christoph Lameter
2007-10-02 9:19 ` Peter Zijlstra
2007-09-29 8:45 ` Peter Zijlstra
2007-10-01 21:01 ` Christoph Lameter
2007-10-02 8:37 ` Nick Piggin
2007-09-28 21:05 ` Mel Gorman
2007-10-01 21:10 ` Christoph Lameter
2007-09-19 3:36 ` [16/17] Allow virtual fallback for buffer_heads Christoph Lameter
2007-09-19 3:36 ` [17/17] Allow virtual fallback for dentries Christoph Lameter
2007-09-19 7:34 ` [00/17] [RFC] Virtual Compound Page Support Anton Altaparmakov
2007-09-19 8:34 ` Eric Dumazet
2007-09-19 17:33 ` Christoph Lameter
2007-09-19 8:24 ` Andi Kleen
2007-09-19 17:36 ` 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=20070919033641.933657553@sgi.com \
--to=clameter@sgi.com \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mel@skynet.ie \
/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).