Re: How to use hugetlb for the text of a program ?

dada1
2003-08-13T12:43:18Z

From: "Andrew Morton" <akpm@osdl.org>
> "dada1" <dada1@cosmosbay.com> wrote:
> >
> > The msync() call produces this kernel message (linux-2.6.0-test3)
> > mm/msync.c:52: bad pmd 108000e7.
>
> please post the whole test application, and the command line which was
used
> to demonstrate this failure.

My problem came from the choice of _end : it was not the last byte of the
text segment.

I changed the ldscript to define _last_byte (after .rodata, .rodata1,
.gcc_except_table) and now it's ok.

However the msync() problem stays. And a 4M mem leak happens.

Here is a sample program.

# cat msync.c
/* start of msync.c */
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>

#define HUGESZ 4*1024*1024 /* size of one 4M page*/

int main(int argc, char *argv[])
{
int fd ;
char *ptr ;
const char *filename ;

if (argc < 2) {
fprintf(stderr, "Usage : msync filename\n") ;
exit(1) ;
}
filename = argv[1] ;
fd = open(filename, O_RDWR | O_CREAT, 0644) ;
if (fd == -1) {perror("filename") ; return 1; }
ftruncate(fd, 0) ;
ftruncate(fd, HUGESZ) ;
ptr = mmap((char *)0x10000000, HUGESZ, PROT_READ|PROT_WRITE, MAP_SHARED, fd,
0) ;
if (ptr == (char *)-1) { perror("mmap") ; close(fd);return 2;}
msync(ptr, HUGESZ, MS_SYNC) ;
close(fd) ;
munmap(ptr, HUGESZ) ;
return 0 ;
}
/* end of msync.c */
# gcc -o msync msync.c
# ./msync /huge/testfile
mm/msync.c:52: bad pmd 114000e7
# ./msync /huge/testfile
mm/msync.c:52: bad pmd 118000e7
# ./msync /huge/testfile
mm/msync.c:52: bad pmd 11c000e7
# ./msync /huge/testfile
mmap: Cannot allocate memory

# grep HugePages /proc/meminfo
HugePages_Total: 16
HugePages_Free: 0

Thanks

Eric Dumazet