public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* vma_merge issue
@ 2009-08-10 20:47 Bill Speirs
  2009-08-12 18:26 ` Hugh Dickins
  0 siblings, 1 reply; 7+ messages in thread
From: Bill Speirs @ 2009-08-10 20:47 UTC (permalink / raw)
  To: linux-kernel

Hello-

I came across an issue where adjacent pages are not properly coalesced
together when changing protections on them. This can be shown by doing
the following:

1) Map 3 pages with PROT_NONE and MAP_PRIVATE | MAP_ANONYMOUS
2) Set the middle page's protection to PROT_READ | PROT_WRITE
3) Set the middle page's protection back to PROT_NONE

You are left with 3 entries in /proc/self/map where you should only
have 1. If you only change the protection to PROT_READ in step 2, then
it is properly merged together. I noticed in mprotect.c the following
comment in the function mprotect_fixup; I'm not sure if it applies or
not:
        /*
         * If we make a private mapping writable we increase our commit;
         * but (without finer accounting) cannot reduce our commit if we
         * make it unwritable again.
         *
         * FIXME? We haven't defined a VM_NORESERVE flag, so mprotecting
         * a MAP_NORESERVE private mapping to writable will now reserve.
         */

I think this only applies to setting charged = nrpages; however,
VM_ACCOUNT is also added to newflags. Could it be that the adjacent
blocks don't have VM_ACCOUNT and so the call to vma_merge cannot merge
because the flags for the adjacent vma are not the same?

Can anyone shed some light on this? While it isn't an issue for 3
pages, I'm mmaping 200K+ pages and changing the perms on random pages
throughout and then back but I quickly run into the max_map_count when
I don't actually need that many mappings.

Thanks...

Bill-

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-08-13 17:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-10 20:47 vma_merge issue Bill Speirs
2009-08-12 18:26 ` Hugh Dickins
2009-08-12 19:04   ` Bill Speirs
2009-08-12 20:23     ` Hugh Dickins
2009-08-12 20:53       ` Hugh Dickins
2009-08-13  1:15       ` William R Speirs
2009-08-13 17:33         ` Hugh Dickins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox