OSDN Git Service

mmap: fix calculation of is_private_anonymous variable
authorVitaly Vul <vitaly.vul@sonymobile.com>
Thu, 24 Sep 2015 12:28:59 +0000 (14:28 +0200)
committerElliott Hughes <enh@google.com>
Fri, 20 Nov 2015 17:16:59 +0000 (09:16 -0800)
commitee67dd75e215f88e5632c05c7e7e7c7d30910359
tree90447b12715a95240614e440be8cbb7c42d191a1
parentf30170dfa514266a0bf007091aa54a866920208c
mmap: fix calculation of is_private_anonymous variable

Currently is_private_anonymous is calculated as true if _either_
MAP_PRIVATE or MAP_ANONYMOUS is set, which is a mistake.
According to Documentation/vm/ksm.txt, "KSM only merges anonymous
(private) pages, never pagecache (file) pages". MAP_PRIVATE can
still be set on file cache pages so in order to not redundantly
set MADV_MERGEABLE on pages that are not fitted for it, both
MAP_PRIVATE and MAP_ANONYMOUS should be set.

Along with this fix, add an extra check that the mapped page is
not a stack page before setting MADV_MERGEABLE for it. Stack pages
change too quickly and always end up in KSM 'page_volatile' list.

Change-Id: If4954142852f17cc61f02985ea1cb625a7f3dec6
libc/bionic/mmap.cpp