On Fri, Dec 14, 2012 at 6:17 PM, Andy Lutomirski <luto@xxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxx> 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 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>