From: Andi Kleen <andi@firstfloor.org>
To: gcc-patches@gcc.gnu.org
Cc: Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 3/3] Add a fragmentation fallback in ggc-page
Date: Fri, 21 Oct 2011 08:33:00 -0000 [thread overview]
Message-ID: <1319176370-26071-4-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1319176370-26071-1-git-send-email-andi@firstfloor.org>
From: Andi Kleen <ak@linux.intel.com>
There were some concerns that the earlier munmap patch could lead
to address space being freed that cannot be allocated again
by ggc due to fragmentation. This patch adds a fragmentation
fallback to solve this: when a GGC_QUIRE_SIZE sized allocation fails,
try again with a page sized allocation.
Passes bootstrap and testing on x86_64-linux with the fallback
forced artificially.
gcc/:
2011-10-20 Andi Kleen <ak@linux.intel.com>
* ggc-page (alloc_anon): Add check argument.
(alloc_page): Add fallback to 1 page allocation.
Adjust alloc_anon calls to new argument.
---
gcc/ggc-page.c | 23 +++++++++++++++--------
1 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/gcc/ggc-page.c b/gcc/ggc-page.c
index eb0eeef..91cd450 100644
--- a/gcc/ggc-page.c
+++ b/gcc/ggc-page.c
@@ -482,7 +482,7 @@ static int ggc_allocated_p (const void *);
static page_entry *lookup_page_table_entry (const void *);
static void set_page_table_entry (void *, page_entry *);
#ifdef USING_MMAP
-static char *alloc_anon (char *, size_t);
+static char *alloc_anon (char *, size_t, bool check);
#endif
#ifdef USING_MALLOC_PAGE_GROUPS
static size_t page_group_index (char *, char *);
@@ -661,7 +661,7 @@ debug_print_page_list (int order)
compile error unless exactly one of the HAVE_* is defined. */
static inline char *
-alloc_anon (char *pref ATTRIBUTE_UNUSED, size_t size)
+alloc_anon (char *pref ATTRIBUTE_UNUSED, size_t size, bool check)
{
#ifdef HAVE_MMAP_ANON
char *page = (char *) mmap (pref, size, PROT_READ | PROT_WRITE,
@@ -674,6 +674,8 @@ alloc_anon (char *pref ATTRIBUTE_UNUSED, size_t size)
if (page == (char *) MAP_FAILED)
{
+ if (!check)
+ return NULL;
perror ("virtual memory exhausted");
exit (FATAL_EXIT_CODE);
}
@@ -776,13 +778,18 @@ alloc_page (unsigned order)
extras on the freelist. (Can only do this optimization with
mmap for backing store.) */
struct page_entry *e, *f = G.free_pages;
- int i;
+ int i, entries;
- page = alloc_anon (NULL, G.pagesize * GGC_QUIRE_SIZE);
+ page = alloc_anon (NULL, G.pagesize * GGC_QUIRE_SIZE, false);
+ if (page == NULL)
+ {
+ page = alloc_anon(NULL, G.pagesize, true);
+ entries = 1;
+ }
/* This loop counts down so that the chain will be in ascending
memory order. */
- for (i = GGC_QUIRE_SIZE - 1; i >= 1; i--)
+ for (i = entries - 1; i >= 1; i--)
{
e = XCNEWVAR (struct page_entry, page_entry_size);
e->order = order;
@@ -795,7 +802,7 @@ alloc_page (unsigned order)
G.free_pages = f;
}
else
- page = alloc_anon (NULL, entry_size);
+ page = alloc_anon (NULL, entry_size, true);
#endif
#ifdef USING_MALLOC_PAGE_GROUPS
else
@@ -1648,14 +1655,14 @@ init_ggc (void)
believe, is an unaligned page allocation, which would cause us to
hork badly if we tried to use it. */
{
- char *p = alloc_anon (NULL, G.pagesize);
+ char *p = alloc_anon (NULL, G.pagesize, true);
struct page_entry *e;
if ((size_t)p & (G.pagesize - 1))
{
/* How losing. Discard this one and try another. If we still
can't get something useful, give up. */
- p = alloc_anon (NULL, G.pagesize);
+ p = alloc_anon (NULL, G.pagesize, true);
gcc_assert (!((size_t)p & (G.pagesize - 1)));
}
--
1.7.5.4
next prev parent reply other threads:[~2011-10-21 5:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-21 7:29 Updated ggc anti fragmentation patchkit Andi Kleen
2011-10-21 8:00 ` [PATCH 2/3] Free large chunks in ggc Andi Kleen
2011-10-21 10:39 ` Richard Guenther
2011-10-21 18:48 ` Andi Kleen
2011-10-23 13:42 ` Richard Guenther
2011-10-23 14:33 ` Richard Guenther
2011-10-23 20:03 ` Andi Kleen
2011-10-21 8:16 ` [PATCH 1/3] Add missing page rounding of a page_entry Andi Kleen
2011-10-21 10:04 ` Richard Guenther
2011-10-21 10:29 ` Jakub Jelinek
2011-10-21 18:08 ` Andi Kleen
2011-10-21 8:33 ` Andi Kleen [this message]
2011-10-21 9:06 ` [PATCH 3/3] Add a fragmentation fallback in ggc-page Jakub Jelinek
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=1319176370-26071-4-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=ak@linux.intel.com \
--cc=gcc-patches@gcc.gnu.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 read-only IMAP folder(s) and NNTP newsgroup(s).