LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 12-05-2006, 03:40 PM   #1
TheLinuxer
LQ Newbie
 
Registered: Dec 2006
Posts: 2

Rep: Reputation: 0
FC2.6.14: memory management


Hi,

How good is Linux's memory management (MM) in this version? would it be a good idea to develop a thin, simple and robust layer of memory management in my application on top of Linux MM, since my app allocs and deallocs a bunch (a high number) of pieces of memory of similar size (not exact the same size but close)? Performance is critical in my app.

Thanks!

Linuxer
 
Old 12-05-2006, 09:03 PM   #2
studioj
Member
 
Registered: Oct 2006
Posts: 460

Rep: Reputation: 31
well the kernel has to and is going to do it on its own anyway no matter what your user space sugestions so i think more code is a waste of resources.
i think linux MM is very good now but it kind of depends on the hardware setup.
if you have something exotic like NUMA setup it's not going to be as good but like i said the kernel has to do it so the only option to improve it is kernel hacking.
i think one of the experimental branches of the kernel is the MM branch if you feel like experimenting. I bet they like feedback as well.

Last edited by studioj; 12-05-2006 at 09:05 PM.
 
Old 12-07-2006, 06:27 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
Quote:
Originally Posted by TheLinuxer
How good is Linux's memory management (MM) in this version? would it be a good idea to develop a thin, simple and robust layer of memory management in my application on top of Linux MM, since my app allocs and deallocs a bunch (a high number) of pieces of memory of similar size (not exact the same size but close)? Performance is critical in my app.
The memory-management code that your application invokes are actually provided by the runtime libraries used by your application, such as glibc. These libraries handle the complexities of malloc() and free(), et al, calling upon the kernel only to obtain additional (large) chunks of memory as-needed. The kernel is not bothered with trifles.

If you have a high-performance memory requirement like this, consider implementing your own layer of code within your appliation. Handle all memory-allocation requirements by calling this layer.

Consider implementing a "free list," one for each chunk-size. When you release a memory block, just fill it with garbage bytes and chain it to the appropriate free-list. The next request for the same-sized block can check to see if the free-list has anything on it. If so, the first block is dequeued, set to binary zeroes, and returned. A LIFO (last-in first-out) strategy is used to increase the probability that the necessary memory-pages will not have been swapped out yet; the address is "recently used."

If you have many memory allocation requests of a similar size, round them up to a convenient larger size. In the long run, a few extra bytes won't matter. Then use the free-list strategy outlined above.

In the free-list strategy, you never check any other list when satisfying memory requests. You don't "clean up" the lists, or get excited about how many entries they might contain.

I find it very helpful to "fill released blocks with garbage," so that if I accidentally refer to it later the problem is very noticeable. (Finding garbage-bytes in a released block is also an indication of the dreaded "double free.") I also find it very helpful to set the newly allocated (or re-used) blocks explicitly to binary zeroes. Adding a few extra (known-zero) bytes to every memory allocation is also a useful idea.

Last edited by sundialsvcs; 12-07-2006 at 06:32 PM.
 
Old 12-09-2006, 09:35 PM   #4
studioj
Member
 
Registered: Oct 2006
Posts: 460

Rep: Reputation: 31
yes in a way what sundialsvcs says makes sense but just keep in mind
*all user space memory programming is virtual only*
it ain't got one single thing to do with actual management of physical memory
which is what i thought you were talking about kernel level MM and performance of your application.

so yes you can manage your programs use of virtual memory you cannot manage your programs use of actual memory from user space.
 
Old 12-12-2006, 01:26 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
High-performance applications definitely need to consider the vagaries of a virtual-memory environment. Here are a few ways in which you can do that...

Try to re-use "recently used" things. A memory block that has been recently used probably hasn't been paged-out yet. Hence, the free-lists that I spoke of should use a LIFO (last-in first-out, "pushdown") discipline. The most recently disposed-of element is the one that's popped back off first.

Use hash tables and trees, instead of singly-linked lists, so that you can locate information with a minimum number of memory references. Each memory-reference has the potential of causing a page fault.

Use large "in-memory" buffers instead of disk-files, because your program's memory is, in fact, "a disk file." It's the system paging file, and it's going to be managed as efficiently as it possibly can be by the operating-system kernel itself. Nonetheless, view "memory" as you would a file, considering (as I said before) that each new reference to a "not-nearby" address could result in a page fault.

Don't stare fixedly at the "amount of" memory being used. As long as the working-set size (the number of "recently used" pages) is not excessive, in a system that is actually undergoing some amount of virtual-memory stress, the total size of the memory-allocation is little more than "the current size of that great-big file." Don't abuse or waste the memory resource, but also don't fixate on the particular numbers even when they become large.
 
Old 12-15-2006, 09:12 AM   #6
rajesh_b_2k
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Rep: Reputation: 0
This is really nice post sundialsvcs. I have a similar requirement. To be precise, we use free list approach you mentioned earlier with 512 byte chunk size.

However, we do see heavy memory contentions when lots of threads are doing work. what happens is that, when all the threads wake up and try to get memory from the memory layer, it severely contends for lock and sometimes it takes even 100ms to acquire the lock (1% of the total requests).

We do see heavy context switches. Do you have any suggestions on this?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
KDE / Power Management in FC2 jeopardyracing Linux - Newbie 0 09-20-2004 09:22 PM
FC2 window management. TheRealDeal Fedora 3 05-31-2004 05:53 PM
Memory management Mojojo Linux - Hardware 11 08-31-2003 10:29 AM
memory management exigent Linux - General 1 08-17-2003 08:28 PM
Memory Management mrsolo Linux - General 7 06-26-2002 12:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 08:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration