linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
To: Michel Lespinasse <walken@google.com>
Cc: kosaki.motohiro@jp.fujitsu.com, linux-mm <linux-mm@kvack.org>
Subject: Re: RFC: reviving mlock isolation dead code
Date: Tue,  9 Nov 2010 13:34:16 +0900 (JST)	[thread overview]
Message-ID: <20101109115540.BC3F.A69D9226@jp.fujitsu.com> (raw)
In-Reply-To: <20101101015311.6062.A69D9226@jp.fujitsu.com>

Hi Michel,

> Hello,
> 
> > I would like to resurect this, as I am seeing problems during a large
> > mlock (many GB). The mlock takes a long time to complete
> > (__mlock_vma_pages_range() is loading pages from disk), there is
> > memory pressure as some pages have to be evicted to make room for the
> > large mlock, and the LRU algorithm performs badly with the high amount
> > of pages still on LRU list - PageMlocked has not been set yet - while
> > their VMA is already VM_LOCKED.
> > 
> > One approach I am considering would be to modify
> > __mlock_vma_pages_range() and it call sites so the mmap sem is only
> > read-owned while __mlock_vma_pages_range() runs. The mlock handling
> > code in try_to_unmap_one() would then be able to acquire the
> > mmap_sem() and help, as it is designed to do.
> 
> I would like to talk historical story a bit. Originally, Lee designed it as you proposed. 
> but Linus refused it. He thought ro-rwsem is bandaid fix. That is one of reason that
> some developers seeks proper mmap_sem dividing way.

While in airplane to come back from KS and LPC, I was thinking this issue. now I think
we can solve this issue. can you please hear my idea?

Now, mlock has following call flow

sys_mlock
	down_write(mmap_sem)
	do_mlock()
		for-each-vma
			mlock_fixup()
				__mlock_vma_pages_range()
					__get_user_pages()
	up_write(mmap_sem)


And, someone tried following change and Linus refuse it because releasing mmap_sem
while mlock() syscall can makes nasty race issue. He storongly requested we don't release
mmap_sem while processing mlock().


sys_mlock
	down_write(mmap_sem)
	do_mlock()
		for-each-vma
			downgrade_write(mmap_sem)
			mlock_fixup()
				__mlock_vma_pages_range()
					__get_user_pages()
			up_read(mmap_sem)
			// race here
			down_write(mmap_sem)
	up_write(mmap_sem)


Then, I'd propose two phase mlock. that said,

sys_mlock
	down_write(mmap_sem)
	do_mlock()
		for-each-vma
			turn on VM_LOCKED and merge/split vma
	downgrade_write(mmap_sem)
		for-each-vma
			mlock_fixup()
				__mlock_vma_pages_range()
	up_read(mmap_sem)


Usually, kernel developers strongly dislike two phase thing beucase it's slow. but at least
_I_ think it's ok in this case. because mlock is really really slow syscall, it often take a few
*miniture*. then, A few microsecond slower is not big matter.

What do you think?


--
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 policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2010-11-09  4:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-30 10:16 Michel Lespinasse
2010-10-30 12:48 ` Michel Lespinasse
2010-11-01  7:05 ` KOSAKI Motohiro
2010-11-09  4:34   ` KOSAKI Motohiro [this message]
2010-11-10 12:21     ` Michel Lespinasse
2010-11-14  5:07       ` KOSAKI Motohiro
2010-11-16  1:44         ` Hugh Dickins
2010-11-16  6:50           ` Michel Lespinasse
2010-11-16 23:28             ` Hugh Dickins
2010-11-18 11:16               ` Michel Lespinasse

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=20101109115540.BC3F.A69D9226@jp.fujitsu.com \
    --to=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-mm@kvack.org \
    --cc=walken@google.com \
    /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