From: denc716@gmail.com
To: linux-mm@kvack.org, "Kirill A. Shutemov" <kirill@shutemov.name>,
David Rientjes <rientjes@google.com>
Cc: Derek Che <crquan@ymail.com>
Subject: [PATCH 1/2] mremap should return -ENOMEM when __vm_enough_memory fail
Date: Tue, 17 Mar 2015 01:25:12 -0700 [thread overview]
Message-ID: <1426580713-21151-1-git-send-email-denc716@gmail.com> (raw)
Recently I straced bash behavior in this dd zero pipe to read test,
in part of testing under vm.overcommit_memory=2 (OVERCOMMIT_NEVER mode):
# dd if=/dev/zero | read x
The bash sub shell is calling mremap to reallocate more and more memory
untill it finally failed -ENOMEM (I expect), or to be killed by system
OOM killer (which should not happen under OVERCOMMIT_NEVER mode);
But the mremap system call actually failed of -EFAULT, which is a
surprise to me, I think it's supposed to be -ENOMEM? then I wrote this
piece of C code testing confirmed it:
https://gist.github.com/crquan/326bde37e1ddda8effe5
$ ./remap
allocated one page @0x7f686bf71000, (PAGE_SIZE: 4096)
grabbed 7680512000 bytes of memory (1875125 pages) @ 00007f6690993000.
mremap failed Bad address (14).
The -EFAULT comes from the branch of security_vm_enough_memory_mm
failure, underlyingly it calls __vm_enough_memory which returns only
0 for success or -ENOMEM; So why vma_to_resize needs to return
-EFAULT in this case? this sounds like a mistake to me.
Some more digging into git history:
1) Before commit 119f657c7 in May 1 2005 (pre 2.6.12 days) it was
returning -ENOMEM for this failure;
2) but commit 119f657c7 changed it accidentally, to what ever is
preserved in local ret, which happened to be -EFAULT, in a previous assignment;
3) then in commit 54f5de709 code refactoring, it's explicitly returning
-EFAULT, should be wrong.
Signed-off-by: Derek Che <crquan@ymail.com>
Acked-by: "Kirill A. Shutemov" <kirill@shutemov.name>
Acked-by: David Rientjes <rientjes@google.com>
---
mm/mremap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/mremap.c b/mm/mremap.c
index 57dadc0..5da81cb 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -375,7 +375,7 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
if (vma->vm_flags & VM_ACCOUNT) {
unsigned long charged = (new_len - old_len) >> PAGE_SHIFT;
if (security_vm_enough_memory_mm(mm, charged))
- goto Efault;
+ goto Enomem;
*p = charged;
}
--
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 reply other threads:[~2015-03-17 8:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-17 8:25 denc716 [this message]
2015-03-17 8:25 ` [PATCH 2/2] clean up to just return ERR_PTR denc716
2015-03-17 22:57 ` David Rientjes
2015-03-17 22:52 ` [PATCH 1/2] mremap should return -ENOMEM when __vm_enough_memory fail David Rientjes
-- strict thread matches above, loose matches on Subject: below --
2015-03-17 23:35 Derek
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=1426580713-21151-1-git-send-email-denc716@gmail.com \
--to=denc716@gmail.com \
--cc=crquan@ymail.com \
--cc=kirill@shutemov.name \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.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;
as well as URLs for NNTP newsgroup(s).