From: Arun Sharma <asharma@fb.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Arun Sharma <asharma@fb.com>,
linux-mm@kvack.org, Davide Libenzi <davidel@xmailserver.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Balbir Singh <bsingharora@gmail.com>
Subject: MAP_UNINITIALIZED (Was Re: MAP_NOZERO revisited)
Date: Wed, 11 Jan 2012 10:50:09 -0800 [thread overview]
Message-ID: <20120111185009.GA26693@dev3310.snc6.facebook.com> (raw)
In-Reply-To: <20120105162311.09dac4b7.kamezawa.hiroyu@jp.fujitsu.com>
On Thu, Jan 05, 2012 at 04:23:11PM +0900, KAMEZAWA Hiroyuki wrote:
> When pages are freed, it goes back to global page allocator.
> memcg has no page allocator hooks for alloc/free.
I missed this part. Thanks for reminding me.
> We, memcg guys, tries to reduce size of page_cgroup remove page_cgroup->flags.
> And finally want to integrate it to struct 'page'.
> So, I don't like your idea very much.
> please find another way.
Thinking a bit more, it may be possible to implement this without
page_cgroup->flags using mm_match_cgroup(current->mm, page->mem_cgroup).
>
> > Security implications: this is not as good as the UID based checks in
> > Davide's implementation, so should probably be an opt-in instead of
> > being enabled by default.
> >
>
> I think you need an another page allocator as hugetlb.c does and need to
> maintain 'page pool'.
That sounds like a bigger change. All I need is a way of computing
"was this page previously mapped into the current cgroup?"
without affecting allocator performance. I'm thinking this more relaxed
check is sufficient for many real world use cases.
I also realized that I could use MAP_UNINITIALIZED for this purpose.
Attached is a completely insecure patch, which may be interesting for
embedded use cases on CPUs with MMU.
Yeah, the VM_SAO hack is ugly. Any better suggestions?
-Arun
commit 37b83f3fb77a177a2f81ebb8aeaec28c2a46e503
Author: Arun Sharma <asharma@fb.com>
Date: Tue Jan 10 17:02:46 2012 -0800
mm: Enable MAP_UNINITIALIZED for archs with mmu
This enables malloc optimizations where we might
madvise(..,MADV_DONTNEED) a page only to fault it
back at a different virtual address.
Signed-off-by: Arun Sharma <asharma@fb.com>
diff --git a/include/asm-generic/mman-common.h b/include/asm-generic/mman-common.h
index 787abbb..71e079f 100644
--- a/include/asm-generic/mman-common.h
+++ b/include/asm-generic/mman-common.h
@@ -19,11 +19,7 @@
#define MAP_TYPE 0x0f /* Mask for type of mapping */
#define MAP_FIXED 0x10 /* Interpret addr exactly */
#define MAP_ANONYMOUS 0x20 /* don't use a file */
-#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
-# define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory could be uninitialized */
-#else
-# define MAP_UNINITIALIZED 0x0 /* Don't support this flag */
-#endif
+#define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory could be uninitialized */
#define MS_ASYNC 1 /* sync memory asynchronously */
#define MS_INVALIDATE 2 /* invalidate the caches */
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 3a93f73..04d838e 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -156,6 +156,11 @@ __alloc_zeroed_user_highpage(gfp_t movableflags,
struct page *page = alloc_page_vma(GFP_HIGHUSER | movableflags,
vma, vaddr);
+#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
+ if (!vma->vm_file && vma->vm_flags & VM_UNINITIALIZED)
+ return page;
+#endif
+
if (page)
clear_user_highpage(page, vaddr);
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 4baadd1..6345c57 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -118,6 +118,8 @@ extern unsigned int kobjsize(const void *objp);
#define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
#define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
#define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
+#define VM_UNINITIALIZED VM_SAO /* Steal a powerpc bit for now, since we're out
+ bits for 32 bit archs */
/* Bits set in the VMA until the stack is in its final location */
#define VM_STACK_INCOMPLETE_SETUP (VM_RAND_READ | VM_SEQ_READ)
diff --git a/include/linux/mman.h b/include/linux/mman.h
index 51647b4..f7d4f60 100644
--- a/include/linux/mman.h
+++ b/include/linux/mman.h
@@ -88,6 +88,7 @@ calc_vm_flag_bits(unsigned long flags)
return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) |
_calc_vm_trans(flags, MAP_DENYWRITE, VM_DENYWRITE ) |
_calc_vm_trans(flags, MAP_EXECUTABLE, VM_EXECUTABLE) |
+ _calc_vm_trans(flags, MAP_UNINITIALIZED, VM_UNINITIALIZED) |
_calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED );
}
#endif /* __KERNEL__ */
diff --git a/init/Kconfig b/init/Kconfig
index 43298f9..428e047 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1259,7 +1259,7 @@ endchoice
config MMAP_ALLOW_UNINITIALIZED
bool "Allow mmapped anonymous memory to be uninitialized"
- depends on EXPERT && !MMU
+ depends on EXPERT
default n
help
Normally, and according to the Linux spec, anonymous memory obtained
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index c3fdbcb..e6dd642 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1868,6 +1868,12 @@ alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma,
put_mems_allowed();
return page;
}
+
+#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
+ if (!vma->vm_file && vma->vm_flags & VM_UNINITIALIZED)
+ gfp &= ~__GFP_ZERO;
+#endif
+
/*
* fast path: default or task policy
*/
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-01-11 18:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-05 0:37 MAP_NOZERO revisited Arun Sharma
2012-01-05 7:23 ` KAMEZAWA Hiroyuki
2012-01-11 18:50 ` Arun Sharma [this message]
2012-01-12 5:10 ` MAP_UNINITIALIZED (Was Re: MAP_NOZERO revisited) Balbir Singh
2012-01-12 18:16 ` Arun Sharma
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=20120111185009.GA26693@dev3310.snc6.facebook.com \
--to=asharma@fb.com \
--cc=bsingharora@gmail.com \
--cc=davidel@xmailserver.org \
--cc=hannes@cmpxchg.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--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