|
From: Itay D. <Ita...@ex...> - 2005-12-12 07:47:15
|
Hello,
First of all thank you for creating such a great tool,=20
I used it in the past on various occasions and it saved me a lot of time
and effort.
We are trying to use valgrind on our system to check if we have
allocation problems, our memory management is done using our own
allocation system.
Our allocation system draws its memory from a hugetlbfs file, apparently
valgrind refuses to mmap the memory file.
The problem raises from the fact that when using mmap with no hint on
the address of the map file, valgrind chooses the page address,=20
but the page address is aligned to 4k boundaries which causes the call
to fail (the hugetlbfs page alignment is 2mb).
If we set the hint in the mmap call, valgrind doesn't change the hint
given and the call succeed.
Good call :=20
void* m1 =3D mmap((void*) 0x200000, 4194304, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, fd, 0);
Strace output taken from valgrind :
map2(0x200000, 4194304, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, 3,
0) =3D 0x200000
Bad call=20
m3 =3D mmap(0, mem_size,PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0)) =3D=3D
MAP_FAILED) =20
Strace output taken from valgrind :
mmap2(0x4101000, 4194304, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, 3,
0) =3D -1 EINVAL (Invalid argument)
this is what needs to be done to create the hugetlbfs file
su
mkdir /var/memory
echo 129 > /proc/sys/vm/hugetlb_pool; =20
mount -t hugetlbfs none /var/memory;
dd if=3D/dev/zero of=3D/var/memory/0 bs=3D1M count=3D0 seek=3D128
And this is the test program,=20
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdlib.h>
int
main()
{
int fd=3D open("/var/memory/0", O_RDWR);
if (fd =3D=3D -1){
perror("file open failed");
exit(1);
}
int mem_size =3D 4096*1024;
unsigned long offset =3D 0;
void* m1 =3D mmap((void*) 0x200000, 4194304, =
PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, fd, 0);
if(m1 =3D=3D MAP_FAILED){
perror("error in mmap");
printf("1 no sugar, come back tommorow\n");
exit(1);
}
void* m2 =3D mmap((void*) 0x400000, 4194304,
PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, 4194304);
if(m2 =3D=3D MAP_FAILED){
perror("error in mmap");
printf("2 no sugar, come back tommorow\n");
exit(1);
}
void* m3;
if((m3 =3D mmap(0, mem_size,PROT_READ|PROT_WRITE,MAP_SHARED, fd,
0)) =3D=3D MAP_FAILED) {
perror("error in mmap");
printf("3 no sugar, come back tommorow\n");
exit(1);
}
close(fd);
printf("all sugar\n");
return 0;
}
Thank you in adavance=20
Itay dar
|