From: "dada1" <dada1@cosmosbay.com>
To: <linux-kernel@vger.kernel.org>
Subject: How to use hugetlb for the text of a program ?
Date: Wed, 13 Aug 2003 11:11:54 +0200 [thread overview]
Message-ID: <020c01c3617a$f1b7ba00$4600a8c0@edumazet> (raw)
In-Reply-To: 20030813013156.49200358.akpm@osdl.org
Hi all
I'm trying to use a 4Mo page on a i686 to map the text portion of a
statically linked program.
I used a link script to make the text mapped to 0x00400000
The datas start at next 4M boundary (0x00800000)
architecture: i386, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x00400100
Program Header:
LOAD off 0x00000000 vaddr 0x00400000 paddr 0x00400000 align 2**12
filesz 0x00080ebc memsz 0x00080ebc flags r-x
LOAD off 0x00081000 vaddr 0x00800000 paddr 0x00800000 align 2**12
filesz 0x00005994 memsz 0x00047870 flags rw-
NOTE off 0x00000094 vaddr 0x00400094 paddr 0x00400094 align 2**2
filesz 0x00000020 memsz 0x00000020 flags r--
Next, I tried to use the following function in a hope to copy the text into
a single 4Mo page :
#include <sys/mman.h>
#include <fcntl.h>
#define HUGESZ 0x400000 /* size of one 4M page*/
#define TEXTSTART (char*)0x00400000 /* see ldscript */
void hugerelocate()
{
int fd = open("/huge/textfile", O_RDWR | O_CREAT, 0644) ;
char *ptr ;
extern int _etext ;
if (fd == -1) return ;
ftruncate(fd, 0) ;
ftruncate(fd, HUGESZ) ;
ptr = mmap((char *)0x10000000, HUGESZ, PROT_READ|PROT_WRITE, MAP_SHARED, fd,
0) ;
if (ptr == (char *)1) { close(fd);return;}
memcpy(ptr, TEXTSTART, (char *)&_etext - TEXTSTART) ;
msync(ptr, HUGESZ, MS_SYNC) ;
mmap(TEXTSTART, HUGESZ, PROT_READ|PROT_EXEC,
MAP_SHARED|MAP_FIXED|MAP_POPULATE, fd, 0) ;
close(fd) ;
munmap(ptr, HUGESZ) ;
}
The msync() call produces this kernel message (linux-2.6.0-test3)
mm/msync.c:52: bad pmd 108000e7.
The problem I have is the last mmap(), trying to replace the program text by
the 4M page, just kills the program.
If I try to use a regular file (not on a hugetlbfs), the program is killed
to.
I tried other MAP_??? flags without success.
Do you know if what I'm trying to do is possible ? ie is a hugetlb page OK
with PROT_EXEC ?
Alternatives :
- I was thinking to write a special loader to load the program, but I dont
know how to cope with the brk()
- A combination of a linker/kernel new feature :
ELF tagged program to ask the kernel to use 4Mo pages if possible to
load the text of a program from the executable file, instead of mapping it
(only for superuser users)
Thanks
Eric Dumazet
next prev parent reply other threads:[~2003-08-13 9:12 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-13 8:31 2.6.0-test3-mm2 Andrew Morton
2003-08-13 8:31 ` 2.6.0-test3-mm2 Andrew Morton
2003-08-13 9:11 ` dada1 [this message]
2003-08-13 9:26 ` How to use hugetlb for the text of a program ? Andrew Morton
2003-08-13 12:42 ` dada1
2003-08-13 9:22 ` 2.6.0-test3-mm2 hugang
2003-08-13 10:48 ` 2.6.0-test3-mm2 Andrew Morton
2003-08-13 13:02 ` 2.6.0-test3-mm2 Con Kolivas
2003-08-13 13:02 ` 2.6.0-test3-mm2 Con Kolivas
2003-08-13 13:35 ` 2.6.0-test3-mm2 Luiz Capitulino
2003-08-13 13:35 ` 2.6.0-test3-mm2 Luiz Capitulino
2003-08-13 13:36 ` 2.6.0-test3-mm2 Luiz Capitulino
2003-08-13 13:36 ` 2.6.0-test3-mm2 Luiz Capitulino
2003-08-13 14:32 ` 2.6.0-test3-mm2 Hugh Dickins
2003-08-13 14:32 ` 2.6.0-test3-mm2 Hugh Dickins
2003-08-13 16:16 ` 2.6.0-test3-mm2 Martin J. Bligh
2003-08-13 16:16 ` 2.6.0-test3-mm2 Martin J. Bligh
2003-08-13 16:18 ` 2.6.0-test3-mm2 Luiz Capitulino
2003-08-13 16:18 ` 2.6.0-test3-mm2 Luiz Capitulino
2003-08-15 19:38 ` Compile problem with CONFIG_X86_CYCLONE_TIMER 2.6.0-test3-mm2 Mike Fedyk
2003-08-15 19:38 ` Mike Fedyk
2003-08-15 20:23 ` Mike Fedyk
2003-08-15 20:23 ` Mike Fedyk
2003-08-15 20:36 ` Mike Fedyk
2003-08-15 20:36 ` Mike Fedyk
2003-08-16 20:32 ` Dave Hansen
2003-08-27 1:08 ` Compile problem with CONFIG_X86_CYCLONE_TIMER Re: 2.6.0-test4-mm1 Mike Fedyk
2003-08-27 1:08 ` Mike Fedyk
2003-08-27 4:41 ` Dave Hansen
2003-08-27 4:41 ` Dave Hansen
2003-08-27 16:00 ` Mike Fedyk
2003-08-27 16:00 ` Mike Fedyk
2003-08-27 16:15 ` Dave Hansen
2003-08-27 16:15 ` Dave Hansen
2003-08-17 20:37 ` 2.6.0-test3-mm2 Peter Osterlund
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='020c01c3617a$f1b7ba00$4600a8c0@edumazet' \
--to=dada1@cosmosbay.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.