LWN.net Logo

KS2007: Memory management & application notification of low memory

KS2007: Memory management & application notification of low memory

Posted Sep 10, 2007 22:53 UTC (Mon) by vomlehn (subscriber, #45588)
Parent article: KS2007: Memory management

The claim is that application developers will tend to avoid application notification of low memory conditions as it would be a Linux-specific extension. This is only an issue in situations where an application is targeted to multiple operating systems. In the embedded world, user-mode software tends to be more closely tied to the operating system. In addition, many embedded applications need the benefit of keeping around cached data as their network connections tend to be slower. As a result, I've already been toying with the notion of designing a framework for user mode software to return memory to the kernel on demand. I doubt I'm alone in this...and I certainly don't want to support it all myself...


(Log in to post comments)

KS2007: Memory management & application notification of low memory

Posted Sep 13, 2007 22:07 UTC (Thu) by oak (guest, #2786) [Link]

I think in Nokia internet tablets there's a notification about low memory
situations to applications through system D-BUS broadcasts[1]. Delivering
information with D-BUS messages has obviously a latency issue if
application is gobbling memory very fast, but I guess it works acceptably.

[1]
https://stage.maemo.org/svn/maemo/projects/haf/trunk/libo...

Btw. I think for applications which keep large freeable memory caches i.e.
have a very active and complex memory allocation schemes, (Glibc) heap
fragmentation is at least as large problem as getting rid of their caches.
The caches should at least be large enough that their allocations have
been memory mapped (>= 128KB is the Glibc default) instead of coming from
heap and therefore they are returned back to system immediately when they
are freed, but with heap fragmentation you can only hope that allocation
re-ordering helps (after you've analyzed which allocations are the
problem).

KS2007: Memory management & application notification of low memory

Posted Sep 13, 2007 22:30 UTC (Thu) by nix (subscriber, #2304) [Link]

The glibc mmap threshold *minimum* is 128Kb. In recent versions of glibc
the threshold is dynamically adjusted between 128Kb and 512Kb (on 32-bit
boxes) and 64Mb (on 64-bit). (The mmap threshold starts at 128Kb and rises
whenever the application frees mmap()ed memory, so that transient
allocations tend to use brk() instead.)

(This is new behaviour in glibc 2.5.)

KS2007: Memory management & application notification of low memory

Posted Sep 16, 2007 19:43 UTC (Sun) by oak (guest, #2786) [Link]

> The glibc mmap threshold *minimum* is 128Kb. In recent versions of glibc
the threshold is dynamically adjusted [...] (This is new behaviour in
glibc 2.5.)

Can you still limit that to be smaller with MALLOC_MMAP_THRESHOLD_
environment variable? This would indicate that the limit just increases
and never decreases, regardless of the environment variable:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/malloc/...

However, in some environments and with some applications, the memory
fragmentation is actually worse problem than some performance decrease. If
a device (e.g. an embedded one where you cannot just add more RAM) runs
out of memory because of heap fragmentation, that's going to have much
more drastic effect on performance than e.g. threading scalability
mentioned here:
http://sourceware.org/bugzilla/show_bug.cgi?id=1541

KS2007: Memory management & application notification of low memory

Posted Sep 16, 2007 23:11 UTC (Sun) by nix (subscriber, #2304) [Link]

MALLOC_MMAP_THRESHOLD_ still works: it's precisely equivalent to calling
mallopt (M_MMAP_THRESHOLD, ...); setting any of these mmap parameters
disables dynamic adjustment completely.

KS2007: Memory management & application notification of low memory

Posted Sep 20, 2007 11:20 UTC (Thu) by renox (guest, #23785) [Link]

>>The claim is that application developers will tend to avoid application notification of low memory conditions as it would be a Linux-specific extension.<<

Note that a low memory condition doesn't have to be handled by the application developer to be useful:
http://lambda-the-ultimate.org/node/2391 points to an article where a researcher patched a JVM GC, and a Linux kernel(2.4) VM so that they discuss, with the result that they have a GC which works well even under memory pressure, all this without application developer lifting one finger :-)

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds