lkml.org 
[lkml]   [2012]   [Dec]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v2] mm: Downgrade mmap_sem before locking or populating on mmap
On Fri, Dec 14, 2012 at 6:17 PM, Andy Lutomirski <luto@amacapital.net> wrote:
> This is a serious cause of mmap_sem contention. MAP_POPULATE
> and MCL_FUTURE, in particular, are disastrous in multithreaded programs.
>
> Signed-off-by: Andy Lutomirski <luto@amacapital.net>

Ugh. This patch is just too ugly.

Conditional locking like this is just too disgusting for words. And
this v2 is worse, with that whole disgusting 'downgraded' pointer
thing.

I'm not applying disgusting hacks like this. I suspect you can clean
it up by moving the mlock/populate logic into the (few) callers
instead (first as a separate patch that doesn't do the downgrading)
and then a separate patch that does the downgrade in the callers,
possibly using a "finish_mmap" helper function that releases the lock.

No "if (write) up_write() else up_read()" crap. Instead, make the
finish_mmap helper do something like

if (!populate_r_mlock) {
up_write(mmap_sem);
return;
}
downgrade(mmap_sem);
.. populate and mlock ..
up_read(mmap_sem);

and you never have any odd "now I'm holding it for writing" state
variable with conditional locking rules etc.

Linus


\
 
 \ /
  Last update: 2012-12-16 21:21    [W:0.131 / U:0.476 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site