Re: memory fragmentation, Suse Linux 64b



Barry Schwarz wrote:
On Fri, 24 Nov 2006 11:23:59 +0100, "Gennady Maly"
<gemal@xxxxxxxxxxxxxx> wrote:

I have an understanding problem with memory management on 64-bit SUSE LINUX.
Maybe somebody of you has some ideas

1)
Consider this small program, allocating a number of 100,000 Bytes memory
blocks and than freeing every second of them. The freeing doesn't have any
influence on the memory consumption of the process. Is it really the desired
behaviour? I see that it may be changed by mallopt(M_MMAP_THRESHOLD,...), is
it recommended?

#include <stdio.h>
#include <string.h>
int main()
{
const int N = 10000; //number ob blocks
const int n = 100000; //block-size
printf("n=%d\n", n);
char* arr[N];
int i=0;
for(i=0; i < N; ++i){
arr[i] = new char[n];

This is not C. You might try a C++ newsgroup but I don't think it is
topical there either since it is really a linux question

memset(arr[i], 'a', n);
}
for(i=0; i < N; ){
delete[] arr[i]; //process' virt memory doesn't shrink if block-size
< 128KB (??)
i += 2;
}
printf ("deallocated... press key\n");
scanf("%d", &i);
}


2)
Out Of Memory Killer takes 15-20 minutes to kill processes if there are no
free virtual memory more on the system. Why does it take so long? Would it
be possible to accelerate it?

3)
Is mallinfo() supported on 64 Bit LINUX?


Remove del for email

I will try to explain withe help of a example for a typical free/alloc
example for the most popular algo that is used . first fit for
fragmentation and compaction

if we have 4 blcks in a linked list of free blocks - 4 4 4 4 at 0x0
0x9 0x17 and 0x33
the free blocks that needs to be merged are of size 4 4 at position
0x5 0x25

then before the next alloc the list of free blocks will look like this

4 8 4 4 4 at 0x0 0x5 0x17 0x25 and 0x33

So if you want 8 bytes it will be available

if we have 4 blcks in a linked list of free blocks - 4 4 4 4 at 0x0
0x9 0x17 and 0x33
the free blocks that needs to be merged are of size 4 4 at position
0x25 0x41

then before the next alloc the list of free blocks will look like this

4 4 4 4 4 4 at 0x0 0x5 0x9 0x17 0x25 and 0x33 and 0x41
So if you want 8 bytes it won't be available and the free will not have
any effect

Hope this helps ..Else give a shout again

Best Regards
Sudhanshu

.



Relevant Pages

  • Re: the different between aaa m1[100] and aaa *p = new [100]
    ... it has to find an appropriate block of memory. ... know what the glibc version of malloc uses, ... This means that it looks through a list of free blocks ... it of free blocks, and allocates memory. ...
    (comp.lang.cpp)
  • Re: How to demand swap memory on an Apple II
    ... stock Apple II is capable of. ... Memory is allocated using a simple best fit. ... simple linked list of free blocks. ... minimum memory allocation size is 8 bytes, 4 for header and 4 for ...
    (comp.sys.apple2.programmer)
  • Re: Memory management terminology
    ... a range of pages is a larger chunk of memory than a single ... For a page that does not have physical backing before the ... always immediately coalesce these two free blocks into one free ... You are confusing OS memory manager and CRT heap manager. ...
    (microsoft.public.vc.language)
  • Re: Memory management terminology
    ... a range of pages is a larger chunk of memory than a single ... For a page that does not have physical backing before the ... always immediately coalesce these two free blocks into one free ... You are confusing OS memory manager and CRT heap manager. ...
    (microsoft.public.vc.language)
  • Re: DNS Server Stops Responding to Requests
    ... DNS Server Time Statistics ... Security Packet Contexts: ... Alloc Count = 177557 ... FreeList Memory = 49384 ...
    (microsoft.public.windows.server.sbs)