public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Interesting VM feature?
@ 2003-08-15  2:17 mouschi
  2003-08-15 12:37 ` jlnance
  2003-08-15 12:57 ` Jamie Lokier
  0 siblings, 2 replies; 8+ messages in thread
From: mouschi @ 2003-08-15  2:17 UTC (permalink / raw)
  To: linux-kernel

(Please CC: me,)

Hi,

I've recently come across someone porting some code
from windows that trys to implement an efficient
memory pool using some VM tricks. I have no idea if
linux has an equivalent to this feature (described
below), and wouldn't know what to even search for to
find out.

What this mempool wants to do is to be able to
allocate a block of memory and tell the kernel which
pages from it can be outright discarded, instead of
swapped out when memory starts to get crowded. 

Now, from looking at mel's docs, it looks to me like
this would mean letting the application directly
mark pages clean. But it would also mean finding any
swapped out versions of this page and deallocating
them, otherwise if the page is discarded and then
used again, time would be wasted swapping in garbage.

I'm going to keep reading. If this is already
implemented, or if the efficiency gains would be
nil, somebody yell at me before I start crashing my
kernel with attempts at doing this myself. :-) It
seems so trivial after all...

Thanks,
Ted Kaminski


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interesting VM feature?
  2003-08-15  2:17 mouschi
@ 2003-08-15 12:37 ` jlnance
  2003-08-15 12:57 ` Jamie Lokier
  1 sibling, 0 replies; 8+ messages in thread
From: jlnance @ 2003-08-15 12:37 UTC (permalink / raw)
  To: mouschi, linux-kernel

On Thu, Aug 14, 2003 at 09:17:07PM -0500, mouschi@wi.rr.com wrote:

> What this mempool wants to do is to be able to
> allocate a block of memory and tell the kernel which
> pages from it can be outright discarded, instead of
> swapped out when memory starts to get crowded. 

I think you might be able to get what you want with madvise() or perhaps
by mmap()ing new clean pages on top of the pages you want to throw away.

> I'm going to keep reading. If this is already
> implemented, or if the efficiency gains would be
> nil, somebody yell at me before I start crashing my

I would not implement this unless you either know you have a problem
with your mempool swap speed or you are bored.  I doubt it is going
to help a lot, and it will certainly simplify your code to leave it
out.  If you later find that you have performance problems you can
look into this again.

Thanks,

Jim

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interesting VM feature?
  2003-08-15  2:17 mouschi
  2003-08-15 12:37 ` jlnance
@ 2003-08-15 12:57 ` Jamie Lokier
  1 sibling, 0 replies; 8+ messages in thread
From: Jamie Lokier @ 2003-08-15 12:57 UTC (permalink / raw)
  To: mouschi; +Cc: linux-kernel

mouschi@wi.rr.com wrote:
> What this mempool wants to do is to be able to
> allocate a block of memory and tell the kernel which
> pages from it can be outright discarded, instead of
> swapped out when memory starts to get crowded. 

You can call madvise(start, length, MADV_DONTNEED),
or you can mmap() fresh empty pages into the region.

I have no idea if either of these methods is efficient enough to be
useful.  Also, I don't know whether mmap() would create multiple VMAs,
or if it is clever enough to merge adjacent vmas of anonymous private
mappings regardles of offset.

The ideal implementation would give the kernel the _option_ of
discarding pages until they are next touched, so that they are
discarded when there is memory pressure but retained if not, avoiding
the unnecessary zero-fill and cache flush.

Unfortunately, though much discussed a long time ago, the kernel
offers no service like this.

-- Jamie

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interesting VM feature?
@ 2003-08-15 19:56 mouschi
  2003-08-15 20:00 ` Mike Fedyk
  0 siblings, 1 reply; 8+ messages in thread
From: mouschi @ 2003-08-15 19:56 UTC (permalink / raw)
  To: Jamie Lokier; +Cc: linux-kernel

Jamie Lokier wrote:
> You can call madvise(start, length, MADV_DONTNEED),
> or you can mmap() fresh empty pages into the region.

madvise appears to be exactly what I'm looking for.
(almost...)

> I have no idea if either of these methods is
efficient enough to be
> useful.  Also, I don't know whether mmap() would
create multiple VMAs,
> or if it is clever enough to merge adjacent vmas
of anonymous private
> mappings regardles of offset.

Enough possible pitfalls that madvise becomes the
better solution.

> The ideal implementation would give the kernel the
_option_ of
> discarding pages until they are next touched, so
that they are
> discarded when there is memory pressure but
retained if not, avoiding
> the unnecessary zero-fill and cache flush.

Is madvise required to result in zero filled pages
by a standard, or is this just the commonly accepted
behavior?

> -- Jamie

Thanks a bunch,
Ted


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interesting VM feature?
  2003-08-15 19:56 Interesting VM feature? mouschi
@ 2003-08-15 20:00 ` Mike Fedyk
  2003-08-15 21:19   ` Jamie Lokier
  0 siblings, 1 reply; 8+ messages in thread
From: Mike Fedyk @ 2003-08-15 20:00 UTC (permalink / raw)
  To: mouschi; +Cc: Jamie Lokier, linux-kernel

On Fri, Aug 15, 2003 at 02:56:02PM -0500, mouschi@wi.rr.com wrote:
> Is madvise required to result in zero filled pages
> by a standard, or is this just the commonly accepted
> behavior?

I believe it is the standard for clean pages, though someone else will have
to point out where...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interesting VM feature?
  2003-08-15 20:00 ` Mike Fedyk
@ 2003-08-15 21:19   ` Jamie Lokier
  2003-08-21  2:24     ` H. Peter Anvin
  0 siblings, 1 reply; 8+ messages in thread
From: Jamie Lokier @ 2003-08-15 21:19 UTC (permalink / raw)
  To: mouschi, linux-kernel

Mike Fedyk wrote:
> On Fri, Aug 15, 2003 at 02:56:02PM -0500, mouschi@wi.rr.com wrote:
> > Is madvise required to result in zero filled pages
> > by a standard, or is this just the commonly accepted
> > behavior?
> 
> I believe it is the standard for clean pages, though someone else will have
> to point out where...

That's the answer to a different question.

The unanswered question is: what should madvise(MADV_DONTNEED) do,
given dirty pages?

man madvise(*) says that it zero-fills anonymous private mappings, and
restores private file-backed mappings to the original file pages.

That is not surprising, as the CPU-friendly semantic is more
complicated to implement, needing an extra flag in the page table
(or rmap structure).

-- Jamie

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interesting VM feature?
  2003-08-15 21:19   ` Jamie Lokier
@ 2003-08-21  2:24     ` H. Peter Anvin
  2003-08-21 11:59       ` Jeff Dike
  0 siblings, 1 reply; 8+ messages in thread
From: H. Peter Anvin @ 2003-08-21  2:24 UTC (permalink / raw)
  To: linux-kernel

Followup to:  <20030815211937.GA20208@mail.jlokier.co.uk>
By author:    Jamie Lokier <jamie@shareable.org>
In newsgroup: linux.dev.kernel
>
> Mike Fedyk wrote:
> > On Fri, Aug 15, 2003 at 02:56:02PM -0500, mouschi@wi.rr.com wrote:
> > > Is madvise required to result in zero filled pages
> > > by a standard, or is this just the commonly accepted
> > > behavior?
> > 
> > I believe it is the standard for clean pages, though someone else will have
> > to point out where...
> 
> That's the answer to a different question.
> 
> The unanswered question is: what should madvise(MADV_DONTNEED) do,
> given dirty pages?
> 
> man madvise(*) says that it zero-fills anonymous private mappings, and
> restores private file-backed mappings to the original file pages.
> 
> That is not surprising, as the CPU-friendly semantic is more
> complicated to implement, needing an extra flag in the page table
> (or rmap structure).
> 

Sounds entirely reasonable.

It *would* be nice with a way to be able to say to the kernel "you may
discard this but if so I want SIGSEGV", for things like LPSM and the
like.

	-hpa
-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
If you send me mail in HTML format I will assume it's spam.
"Unix gives you enough rope to shoot yourself in the foot."
Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interesting VM feature?
  2003-08-21  2:24     ` H. Peter Anvin
@ 2003-08-21 11:59       ` Jeff Dike
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff Dike @ 2003-08-21 11:59 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: linux-kernel

hpa@zytor.com said:
> It *would* be nice with a way to be able to say to the kernel "you may
> discard this but if so I want SIGSEGV", for things like LPSM and the
> like. 

Yeah, UML could put this to good use, as well...

				Jeff


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-08-21 11:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-15 19:56 Interesting VM feature? mouschi
2003-08-15 20:00 ` Mike Fedyk
2003-08-15 21:19   ` Jamie Lokier
2003-08-21  2:24     ` H. Peter Anvin
2003-08-21 11:59       ` Jeff Dike
  -- strict thread matches above, loose matches on Subject: below --
2003-08-15  2:17 mouschi
2003-08-15 12:37 ` jlnance
2003-08-15 12:57 ` Jamie Lokier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox