From: Minchan Kim <minchan@kernel.org>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Rik van Riel <riel@redhat.com>, Mel Gorman <mgorman@suse.de>,
Hugh Dickins <hughd@google.com>,
Dave Hansen <dave.hansen@intel.com>,
Johannes Weiner <hannes@cmpxchg.org>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
John Stultz <john.stultz@linaro.org>, Jason Evans <je@fb.com>
Subject: Re: [RFC 0/6] mm: support madvise(MADV_FREE)
Date: Wed, 19 Mar 2014 10:02:53 +0900 [thread overview]
Message-ID: <20140319010253.GC13475@bbox> (raw)
In-Reply-To: <CALCETrUsgVgKDRjqY=7avbvowkNSn-CWJ3L9zti1SCOYgrY3UA@mail.gmail.com>
On Tue, Mar 18, 2014 at 05:23:37PM -0700, Andy Lutomirski wrote:
> On Tue, Mar 18, 2014 at 5:18 PM, Minchan Kim <minchan@kernel.org> wrote:
> > Hello,
> >
> > On Tue, Mar 18, 2014 at 10:55:24AM -0700, Andy Lutomirski wrote:
> >> On 03/13/2014 11:37 PM, Minchan Kim wrote:
> >> > This patch is an attempt to support MADV_FREE for Linux.
> >> >
> >> > Rationale is following as.
> >> >
> >> > Allocators call munmap(2) when user call free(3) if ptr is
> >> > in mmaped area. But munmap isn't cheap because it have to clean up
> >> > all pte entries, unlinking a vma and returns free pages to buddy
> >> > so overhead would be increased linearly by mmaped area's size.
> >> > So they like madvise_dontneed rather than munmap.
> >> >
> >> > "dontneed" holds read-side lock of mmap_sem so other threads
> >> > of the process could go with concurrent page faults so it is
> >> > better than munmap if it's not lack of address space.
> >> > But the problem is that most of allocator reuses that address
> >> > space soonish so applications see page fault, page allocation,
> >> > page zeroing if allocator already called madvise_dontneed
> >> > on the address space.
> >> >
> >> > For avoidng that overheads, other OS have supported MADV_FREE.
> >> > The idea is just mark pages as lazyfree when madvise called
> >> > and purge them if memory pressure happens. Otherwise, VM doesn't
> >> > detach pages on the address space so application could use
> >> > that memory space without above overheads.
> >>
> >> I must be missing something.
> >>
> >> If the application issues MADV_FREE and then writes to the MADV_FREEd
> >> range, the kernel needs to know that the pages are no longer safe to
> >> lazily free. This would presumably happen via a page fault on write.
> >> For that to happen reliably, the kernel has to write protect the pages
> >> when MADV_FREE is called, which in turn requires flushing the TLBs.
> >
> > It could be done by pte_dirty bit check. Of course, if some architectures
> > don't support it by H/W, pte_mkdirty would make it CoW as you said.
>
> If the page already has dirty PTEs, then you need to clear the dirty
> bits and flush TLBs so that other CPUs notice that the PTEs are clean,
> I think.
True. I didn't mean we don't need TLB flush. Look at the code although
there are lots of bug in RFC v1.
>
> Also, this has very odd semantics wrt reading the page after MADV_FREE
> -- is reading the page guaranteed to un-free it?
Yeb, I thought about that oddness but didn't make conclusion because
other OS seem to work like that.
http://www.freebsd.org/cgi/man.cgi?query=madvise&sektion=2
But we could fix it easily by checking access bit instead of dirty bit.
>
> >>
> >> How does this end up being faster than munmap?
> >
> > MADV_FREE doesn't need to return back the pages into page allocator
> > compared to MADV_DONTNEED and the overhead is not small when I measured
> > that on my machine.(Roughly, MADV_FREE's cost is half of DONTNEED through
> > avoiding involving page allocator.)
> >
> > But I'd like to clarify that it's not MADV_FREE's goal that syscall
> > itself should be faster than MADV_DONTNEED but major goal is to
> > avoid unnecessary page fault + page allocation + page zeroing +
> > garbage swapout.
>
> This sounds like it might be better solved by trying to make munmap or
> MADV_DONTNEED faster. Maybe those functions should lazily give pages
> back to the buddy allocator.
About munmap, it needs write-mmap_sem and it hurts heavily of
allocator performance in multi-thread.
About MADV_DONTNEED, Rik van Riel tried to replace MADV_DONTNEED
with MADV_FREE in 2007(http://lwn.net/Articles/230799/).
But I don't know why it was dropped. One think I can imagine
is that it could make regression because user on MADV_DONTNEED
expect rss decreasing when syscall is called.
>
> --Andy
>
> --
> 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/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
--
Kind regards,
Minchan Kim
--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2014-03-19 1:02 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-14 6:37 [RFC 0/6] mm: support madvise(MADV_FREE) Minchan Kim
2014-03-14 6:37 ` Minchan Kim
2014-03-14 6:37 ` [RFC 1/6] mm: clean up PAGE_MAPPING_FLAGS Minchan Kim
2014-03-14 6:37 ` Minchan Kim
2014-03-14 6:37 ` [RFC 2/6] mm: work deactivate_page with anon pages Minchan Kim
2014-03-14 6:37 ` Minchan Kim
2014-03-14 6:37 ` [RFC 3/6] mm: support madvise(MADV_FREE) Minchan Kim
2014-03-14 6:37 ` Minchan Kim
2014-03-14 7:49 ` Minchan Kim
2014-03-14 7:49 ` Minchan Kim
2014-03-14 13:33 ` Kirill A. Shutemov
2014-03-14 13:33 ` Kirill A. Shutemov
2014-03-14 15:24 ` Minchan Kim
2014-03-14 15:24 ` Minchan Kim
2014-03-18 18:26 ` Johannes Weiner
2014-03-18 18:26 ` Johannes Weiner
2014-03-19 1:22 ` Minchan Kim
2014-03-14 6:37 ` [RFC 4/6] mm: add stat about lazyfree pages Minchan Kim
2014-03-14 6:37 ` Minchan Kim
2014-03-14 6:37 ` [RFC 5/6] mm: reclaim lazyfree pages in swapless system Minchan Kim
2014-03-14 6:37 ` Minchan Kim
2014-03-14 6:37 ` [RFC 6/6] mm: ksm: don't merge lazyfree page Minchan Kim
2014-03-14 6:37 ` Minchan Kim
2014-03-14 7:37 ` [RFC 0/6] mm: support madvise(MADV_FREE) Zhang Yanfei
2014-03-14 7:37 ` Zhang Yanfei
2014-03-14 7:56 ` Minchan Kim
2014-03-14 7:56 ` Minchan Kim
2014-03-18 17:55 ` Andy Lutomirski
2014-03-18 17:55 ` Andy Lutomirski
2014-03-19 0:18 ` Minchan Kim
2014-03-19 0:23 ` Andy Lutomirski
2014-03-19 0:23 ` Andy Lutomirski
2014-03-19 1:02 ` Minchan Kim [this message]
2014-03-19 5:15 ` Johannes Weiner
2014-03-19 5:15 ` Johannes Weiner
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=20140319010253.GC13475@bbox \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@intel.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=je@fb.com \
--cc=john.stultz@linaro.org \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@amacapital.net \
--cc=mgorman@suse.de \
--cc=riel@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.