linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Chuck Lever <cel@monkey.org>
To: Jamie Lokier <jamie.lokier@cern.ch>
Cc: linux-mm@kvack.org
Subject: Re: madvise (MADV_FREE)
Date: Wed, 22 Mar 2000 11:24:51 -0500 (EST)	[thread overview]
Message-ID: <Pine.BSO.4.10.10003221106150.16476-100000@funky.monkey.org> (raw)
In-Reply-To: <20000321022053.A4271@pcep-jamie.cern.ch>

hi jamie-

ok, i think i'm getting a more clear picture of what you are thinking.

On Tue, 21 Mar 2000, Jamie Lokier wrote:
> > >    The principle here is very simple: MADV_FREE marks all the pages in
> > >    the region as "discardable", and clears the accessed and dirty bits
> > >    of those pages.
> > > 
> > >    Later when the kernel needs to free some memory, it is permitted to
> > >    free "discardable" pages immediately provided they are still not
> > >    accessed or dirty.  When vmscan is clearing the accessed and dirty
> > >    bits on pages, if they were set it must clear the " discardable" bit.
> > > 
> > >    This allows malloc() and other user space allocators to free pages
> > >    back to the system.  Unlike DU's MADV_DONTNEED, or mmapping
> > >    /dev/zero, if the system does not need the page there is no
> > >    inefficient zero-copy.  If there was, malloc() would be better off
> > >    not bothering to return the pages.
> > 
> > unless i've completely misunderstood what you are proposing, this is what
> > MADV_DONTNEED does today,
> 
> No, your MADV_DONTNEED _always_ discards the data in those pages.  That
> makes it too inefficient for application memory allocators, because they
> will often want to reuse some of the pages soon after.  You don't want
> redundant page zeroing, and you don't want to give up memory which is
> still nice and warm in the CPU's cache.  Unless the kernel has a better
> use for it than you.
> 
> MADV_FREE on the other hand simply permits the kernel to reclaim those
> pages, if it is under memory pressure.
> 
> If there is no pressure, the pages are reused by the application
> unchanged.  In this way different subsystems competing for memory get to
> share it out -- essentially the fairness mechanisms in the kernel are
> extending to application page management.  And the application hardly
> knows a think about it.

ok, so you're asking for a lite(TM) version of DONTNEED that provides the
following hint to the kernel: "i may be finished with this page, but i may
also want to reuse it immediately."

memory allocation studies i've read show that dynamically allocated memory
objects are often re-used immediately after they are freed.  even if the
memory is being freed just before a process exits, it will be recycled
immediately by the kernel, so why use MADV_FREE if you are about to
munmap() it anyway?  finally, as you point out, the heap is generally too
fragmented to return page-sized chunks of it to the kernel, especially if
you consider that glibc uses *multiple* subheaps to reduce lock contention
in multithreaded applications.  it seems to me that normal page aging will
adequately identify these pages and flush them out.

if the application needs to recycle areas of a virtual address space
immediately, why should the kernel be involved at all?  i think even doing
an MADV_FREE during arbitrary free() operations would be more overhead
then you really want. in other words, i don't think free() as it exists
today harms performance in the ways you describe.

thus, either the application keeps the memory, or it is really completely
finished with it -- MADV_DONTNEED.

	- Chuck Lever
--
corporate:	<chuckl@netscape.com>
personal:	<chucklever@netscape.net> or <cel@monkey.org>

The Linux Scalability project:
	http://www.citi.umich.edu/projects/linux-scalability/

--
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.eu.org/Linux-MM/

  parent reply	other threads:[~2000-03-22 16:24 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20000320135939.A3390@pcep-jamie.cern.ch>
2000-03-20 19:09 ` MADV_SPACEAVAIL and MADV_FREE in pre2-3 Chuck Lever
2000-03-21  1:20   ` madvise (MADV_FREE) Jamie Lokier
2000-03-21  2:24     ` William J. Earl
2000-03-21 14:08       ` Jamie Lokier
2000-03-22 16:24     ` Chuck Lever [this message]
2000-03-22 18:05       ` Jamie Lokier
2000-03-22 21:39         ` Chuck Lever
2000-03-22 22:31           ` Jamie Lokier
2000-03-22 22:44             ` Stephen C. Tweedie
2000-03-23 18:53             ` Chuck Lever
2000-03-24  0:00               ` /dev/recycle Jamie Lokier
2000-03-24  9:14                 ` /dev/recycle Christoph Rohland
2000-03-24 13:10                   ` /dev/recycle Jamie Lokier
2000-03-24 13:54                     ` /dev/recycle Christoph Rohland
2000-03-24 14:17                       ` /dev/recycle Jamie Lokier
2000-03-24 17:40                         ` /dev/recycle Christoph Rohland
2000-03-24 18:13                           ` /dev/recycle Jamie Lokier
2000-03-25  8:35                             ` /dev/recycle Christoph Rohland
2000-03-28  0:48                 ` /dev/recycle Chuck Lever
2000-03-24  0:21               ` madvise (MADV_FREE) Jamie Lokier
2000-03-24  7:21                 ` lars brinkhoff
2000-03-24 17:42                   ` Jeff Dike
2000-03-24 16:49                     ` Jamie Lokier
2000-03-24 17:08                     ` Stephen C. Tweedie
2000-03-24 19:58                       ` Jeff Dike
2000-03-25  0:30                         ` Stephen C. Tweedie
2000-03-22 22:33           ` Stephen C. Tweedie
2000-03-22 22:45             ` Jamie Lokier
2000-03-22 22:48               ` Stephen C. Tweedie
2000-03-22 22:55                 ` Q. about swap-cache orphans Jamie Lokier
2000-03-22 22:58                   ` Stephen C. Tweedie
2000-03-22 18:15       ` madvise (MADV_FREE) Christoph Rohland
2000-03-22 18:30         ` Jamie Lokier
2000-03-23 16:56           ` Christoph Rohland
2000-03-21  1:29   ` MADV_DONTNEED Jamie Lokier
2000-03-22 17:04     ` MADV_DONTNEED Chuck Lever
2000-03-22 17:10       ` MADV_DONTNEED Stephen C. Tweedie
2000-03-22 17:32         ` MADV_DONTNEED Jamie Lokier
2000-03-22 17:33         ` MADV_DONTNEED Jamie Lokier
2000-03-22 17:37           ` MADV_DONTNEED Stephen C. Tweedie
2000-03-22 17:43       ` MADV_DONTNEED Jamie Lokier
2000-03-22 21:54         ` MADV_DONTNEED Chuck Lever
2000-03-22 22:41           ` MADV_DONTNEED Jamie Lokier
2000-03-23 19:13             ` MADV_DONTNEED James Antill
2000-03-21  1:47   ` Extensions to mincore Jamie Lokier
2000-03-21  9:11     ` Eric W. Biederman
2000-03-21  9:40       ` lars brinkhoff
2000-03-21 11:34       ` Stephen C. Tweedie
2000-03-21 15:15         ` Jamie Lokier
2000-03-21 15:41           ` Stephen C. Tweedie
2000-03-21 15:55             ` Jamie Lokier
2000-03-21 16:08               ` Stephen C. Tweedie
2000-03-21 16:48                 ` Jamie Lokier
2000-03-22  7:36                   ` Eric W. Biederman
2000-03-21  1:50   ` MADV flags as mmap options Jamie Lokier

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=Pine.BSO.4.10.10003221106150.16476-100000@funky.monkey.org \
    --to=cel@monkey.org \
    --cc=jamie.lokier@cern.ch \
    --cc=linux-mm@kvack.org \
    /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