Re: memory fragmentation, Suse Linux 64b
- From: "Sudhanshu" <sudhanshu.chadha@xxxxxxxxx>
- Date: 2 Dec 2006 15:08:29 -0800
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
.
- Prev by Date: Re: pointer to const string
- Next by Date: Re: ques and and level order traversal
- Previous by thread: Re: ques and and level order traversal
- Next by thread: Sizeof for pointers
- Index(es):
Relevant Pages
|