From: Ingo Molnar <mingo@elte.hu>
To: Hugh Dickins <hugh@veritas.com>
Cc: Andrew Morton <akpm@osdl.org>, "E. Gryaznova" <grev@namesys.com>,
linux-kernel@vger.kernel.org, reiserfs-dev@namesys.com
Subject: [patch] flexible-mmap-update.patch, 2.6.7-mm5
Date: Fri, 2 Jul 2004 13:02:09 +0200 [thread overview]
Message-ID: <20040702110209.GA30813@elte.hu> (raw)
In-Reply-To: <Pine.LNX.4.44.0406302049500.21421-100000@localhost.localdomain>
[-- Attachment #1: Type: text/plain, Size: 927 bytes --]
* Hugh Dickins <hugh@veritas.com> wrote:
> I think it's wrong to interpret a large or rlim_infinite stack rlimit
> as an inviolable request to reserve that much for the stack: it makes
> much less VM available than bottom up, not what was intended. Perhaps
> top down should go bottom up (instead of belly up) when it fails - but
> I'd probably better leave that to Ingo.
Agreed. the attached flexible-mmap-update.patch (against 2.6.7-mm5)
implements the following changes:
- fall back to the bottom-up layout if the stack can grow unlimited
(if the stack ulimit has been set to RLIM_INFINITY)
- try the bottom-up allocator if the top-down allocator fails - this can
utilize the hole between the true bottom of the stack and its ulimit,
as a last-resort effort.
i've tested a number of failure scenarios with various ulimits and mmap
sizes, and we now successfully allocate a VM area in all cases i tested.
Ingo
[-- Attachment #2: flexible-mmap-update.patch --]
[-- Type: text/plain, Size: 2206 bytes --]
- fall back to the bottom-up layout if the stack can grow unlimited
(if the stack ulimit has been set to RLIM_INFINITY)
- try the bottom-up allocator if the top-down allocator fails - this can
utilize the hole between the true bottom of the stack and its ulimit,
as a last-resort effort.
Signed-off-by: Ingo Molnar <mingo@elte.hu>
--- linux/arch/i386/mm/mmap.c.orig
+++ linux/arch/i386/mm/mmap.c
@@ -55,9 +55,10 @@ void arch_pick_mmap_layout(struct mm_str
{
/*
* Fall back to the standard layout if the personality
- * bit is set:
+ * bit is set, or if the expected stack growth is unlimited:
*/
- if (current->personality & ADDR_COMPAT_LAYOUT) {
+ if ((current->personality & ADDR_COMPAT_LAYOUT) ||
+ current->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY) {
mm->mmap_base = TASK_UNMAPPED_BASE;
mm->get_unmapped_area = arch_get_unmapped_area;
mm->unmap_area = arch_unmap_area;
--- linux/mm/mmap.c.orig
+++ linux/mm/mmap.c
@@ -1074,13 +1074,13 @@ void arch_unmap_area(struct vm_area_stru
* stack's low limit (the base):
*/
unsigned long
-arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
- unsigned long len, unsigned long pgoff,
- unsigned long flags)
+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
+ const unsigned long len, const unsigned long pgoff,
+ const unsigned long flags)
{
struct vm_area_struct *vma, *prev_vma;
struct mm_struct *mm = current->mm;
- unsigned long base = mm->mmap_base;
+ unsigned long base = mm->mmap_base, addr = addr0;
int first_time = 1;
/* requested length too big for entire address space */
@@ -1142,7 +1142,20 @@ fail:
first_time = 0;
goto try_again;
}
- return -ENOMEM;
+ /*
+ * A failed mmap() very likely causes application failure,
+ * so fall back to the bottom-up function here. This scenario
+ * can happen with large stack limits and large mmap()
+ * allocations.
+ */
+ mm->free_area_cache = TASK_UNMAPPED_BASE;
+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
+ /*
+ * Restore the topdown base:
+ */
+ mm->free_area_cache = base;
+
+ return addr;
}
void arch_unmap_area_topdown(struct vm_area_struct *area)
prev parent reply other threads:[~2004-07-02 11:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-30 15:55 [2.6.7-mm4: OOPS] kernel BUG at mm/mmap.c:1793 E. Gryaznova
2004-06-30 18:41 ` Andrew Morton
2004-06-30 18:54 ` E. Gryaznova
2004-06-30 20:06 ` Hugh Dickins
2004-07-02 11:02 ` Ingo Molnar [this message]
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=20040702110209.GA30813@elte.hu \
--to=mingo@elte.hu \
--cc=akpm@osdl.org \
--cc=grev@namesys.com \
--cc=hugh@veritas.com \
--cc=linux-kernel@vger.kernel.org \
--cc=reiserfs-dev@namesys.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