X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=Documentation%2Fvm%2Fhugetlbpage.txt;h=687104bfd09a79eef794b8dbe1357c33864d028c;hb=a2f44b27303a5353859d77a3e96a1d3f33f56ab7;hp=61ae09f49abc716188c01c7b09ce4c4388eb1aee;hpb=ed54dc1279543caf10ba95fb0a1e9fa47ab6c4b4;p=linux-2.6.git diff --git a/Documentation/vm/hugetlbpage.txt b/Documentation/vm/hugetlbpage.txt index 61ae09f49..687104bfd 100644 --- a/Documentation/vm/hugetlbpage.txt +++ b/Documentation/vm/hugetlbpage.txt @@ -1,24 +1,25 @@ The intent of this file is to give a brief summary of hugetlbpage support in the Linux kernel. This support is built on top of multiple page size support -that is provided by most of modern architectures. For example, IA-32 -architecture supports 4K and 4M (2M in PAE mode) page sizes, IA-64 +that is provided by most modern architectures. For example, i386 +architecture supports 4K and 4M (2M in PAE mode) page sizes, ia64 architecture supports multiple page sizes 4K, 8K, 64K, 256K, 1M, 4M, 16M, -256M. A TLB is a cache of virtual-to-physical translations. Typically this -is a very scarce resource on processor. Operating systems try to make best -use of limited number of TLB resources. This optimization is more critical -now as bigger and bigger physical memories (several GBs) are more readily -available. +256M and ppc64 supports 4K and 16M. A TLB is a cache of virtual-to-physical +translations. Typically this is a very scarce resource on processor. +Operating systems try to make best use of limited number of TLB resources. +This optimization is more critical now as bigger and bigger physical memories +(several GBs) are more readily available. Users can use the huge page support in Linux kernel by either using the mmap system call or standard SYSv shared memory system calls (shmget, shmat). -First the Linux kernel needs to be built with CONFIG_HUGETLB_PAGE (present -under Processor types and feature) and CONFIG_HUGETLBFS (present under file -system option on config menu) config options. +First the Linux kernel needs to be built with the CONFIG_HUGETLBFS +(present under "File systems") and CONFIG_HUGETLB_PAGE (selected +automatically when CONFIG_HUGETLBFS is selected) configuration +options. The kernel built with hugepage support should show the number of configured -hugepages in the system by running the "cat /proc/meminfo" command. +hugepages in the system by running the "cat /proc/meminfo" command. /proc/meminfo also provides information about the total number of hugetlb pages configured in the kernel. It also displays information about the @@ -26,31 +27,40 @@ number of free hugetlb pages at any time. It also displays information about the configured hugepage size - this is needed for generating the proper alignment and size of the arguments to the above system calls. -The output of "cat /proc/meminfo" will have output like: +The output of "cat /proc/meminfo" will have lines like: ..... HugePages_Total: xxx HugePages_Free: yyy -Hugepagesize: zzz KB +HugePages_Rsvd: www +Hugepagesize: zzz kB + +where: +HugePages_Total is the size of the pool of hugepages. +HugePages_Free is the number of hugepages in the pool that are not yet +allocated. +HugePages_Rsvd is short for "reserved," and is the number of hugepages +for which a commitment to allocate from the pool has been made, but no +allocation has yet been made. It's vaguely analogous to overcommit. /proc/filesystems should also show a filesystem of type "hugetlbfs" configured in the kernel. /proc/sys/vm/nr_hugepages indicates the current number of configured hugetlb pages in the kernel. Super user can dynamically request more (or free some -pre-configured) hugepages. -The allocation( or deallocation) of hugetlb pages is posible only if there are +pre-configured) hugepages. +The allocation (or deallocation) of hugetlb pages is possible only if there are enough physically contiguous free pages in system (freeing of hugepages is -possible only if there are enough hugetlb pages free that can be transfered +possible only if there are enough hugetlb pages free that can be transferred back to regular memory pool). -Pages that are used as hugetlb pages are reserved inside the kernel and can -not be used for other purposes. +Pages that are used as hugetlb pages are reserved inside the kernel and cannot +be used for other purposes. Once the kernel with Hugetlb page support is built and running, a user can use either the mmap system call or shared memory system calls to start using the huge pages. It is required that the system administrator preallocate -enough memory for huge page purposes. +enough memory for huge page purposes. Use the following command to dynamically allocate/deallocate hugepages: @@ -59,7 +69,7 @@ Use the following command to dynamically allocate/deallocate hugepages: This command will try to configure 20 hugepages in the system. The success or failure of allocation depends on the amount of physically contiguous memory that is preset in system at this time. System administrators may want -to put this command in one of the local rc init file. This will enable the +to put this command in one of the local rc init files. This will enable the kernel to request huge pages early in the boot process (when the possibility of getting physical contiguous pages is still very high). @@ -77,143 +87,208 @@ the uid and gid of the current process are taken. The mode option sets the mode of root of file system to value & 0777. This value is given in octal. By default the value 0755 is picked. The size option sets the maximum value of memory (huge pages) allowed for that filesystem (/mnt/huge). The size is -rounded down to HPAGE_SIZE. The option nr_inode sets the maximum number of -inodes that /mnt/huge can use. If the size or nr_inode options are not +rounded down to HPAGE_SIZE. The option nr_inodes sets the maximum number of +inodes that /mnt/huge can use. If the size or nr_inodes options are not provided on command line then no limits are set. For size and nr_inodes -options, you can use [G|g]/[M|m]/[K|k] to represent giga/mega/kilo. For -example, size=2K has the same meaning as size=2048. An example is given at -the end of this document. +options, you can use [G|g]/[M|m]/[K|k] to represent giga/mega/kilo. For +example, size=2K has the same meaning as size=2048. An example is given at +the end of this document. read and write system calls are not supported on files that reside on hugetlb file systems. -A regular chown, chgrp and chmod commands (with right permissions) could be +Regular chown, chgrp, and chmod commands (with right permissions) could be used to change the file attributes on hugetlbfs. Also, it is important to note that no such mount command is required if the -applications are going to use only shmat/shmget system calls. It is possible -for same or different applications to use any combination of mmaps and shm* -calls. Though the mount of filesystem will be required for using mmaps. - -/* Example of using hugepage in user application using Sys V shared memory - * system calls. In this example, app is requesting memory of size 256MB that - * is backed by huge pages. Application uses the flag SHM_HUGETLB in shmget - * system call to informt the kernel that it is requesting hugepages. For - * IA-64 architecture, Linux kernel reserves Region number 4 for hugepages. - * That means the addresses starting with 0x800000....will need to be - * specified. +applications are going to use only shmat/shmget system calls. Users who +wish to use hugetlb page via shared memory segment should be a member of +a supplementary group and system admin needs to configure that gid into +/proc/sys/vm/hugetlb_shm_group. It is possible for same or different +applications to use any combination of mmaps and shm* calls, though the +mount of filesystem will be required for using mmap calls. + +******************************************************************* + +/* + * Example of using hugepage memory in a user application using Sys V shared + * memory system calls. In this example the app is requesting 256MB of + * memory that is backed by huge pages. The application uses the flag + * SHM_HUGETLB in the shmget system call to inform the kernel that it is + * requesting hugepages. + * + * For the ia64 architecture, the Linux kernel reserves Region number 4 for + * hugepages. That means the addresses starting with 0x800000... will need + * to be specified. Specifying a fixed address is not required on ppc64, + * i386 or x86_64. + * + * Note: The default shared memory limit is quite low on many kernels, + * you may need to increase it via: + * + * echo 268435456 > /proc/sys/kernel/shmmax + * + * This will increase the maximum size per shared memory segment to 256MB. + * The other limit that you will hit eventually is shmall which is the + * total amount of shared memory in pages. To set it to 16GB on a system + * with a 4kB pagesize do: + * + * echo 4194304 > /proc/sys/kernel/shmall */ +#include +#include #include +#include #include -#include #include -#include -extern int errno; +#ifndef SHM_HUGETLB #define SHM_HUGETLB 04000 -#define LPAGE_SIZE (256UL*1024UL*1024UL) -#define dprintf(x) printf(x) -#define ADDR (0x8000000000000000UL) -main() +#endif + +#define LENGTH (256UL*1024*1024) + +#define dprintf(x) printf(x) + +/* Only ia64 requires this */ +#ifdef __ia64__ +#define ADDR (void *)(0x8000000000000000UL) +#define SHMAT_FLAGS (SHM_RND) +#else +#define ADDR (void *)(0x0UL) +#define SHMAT_FLAGS (0) +#endif + +int main(void) { - int shmid; - int i, j, k; - volatile char *shmaddr; - - if ((shmid =shmget(2, LPAGE_SIZE, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W )) -< 0) { - perror("Failure:"); - exit(1); - } - printf("shmid: 0x%x\n", shmid); - shmaddr = shmat(shmid, (void *)ADDR, SHM_RND) ; - if (errno != 0) { - perror("Shared Memory Attach Failure:"); - exit(2); - } - printf("shmaddr: %p\n", shmaddr); - - dprintf("Starting the writes:\n"); - for (i=0;i +#include #include +#include #include #include -#include #define FILE_NAME "/mnt/hugepagefile" -#define LENGTH (256*1024*1024) +#define LENGTH (256UL*1024*1024) #define PROTECTION (PROT_READ | PROT_WRITE) -#define FLAGS MAP_SHARED |MAP_FIXED -#define ADDRESS (char *)(0x60000000UL + 0x8000000000000000UL) -extern errno; +/* Only ia64 requires this */ +#ifdef __ia64__ +#define ADDR (void *)(0x8000000000000000UL) +#define FLAGS (MAP_SHARED | MAP_FIXED) +#else +#define ADDR (void *)(0x0UL) +#define FLAGS (MAP_SHARED) +#endif -check_bytes(char *addr) +void check_bytes(char *addr) { - printf("First hex is %x\n", *((unsigned int *)addr)); + printf("First hex is %x\n", *((unsigned int *)addr)); } -write_bytes(char *addr) +void write_bytes(char *addr) { - int i; - for (i=0;i