/* 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. */ #include #include #include #include #include extern int errno; #define SHM_HUGETLB 04000 #define LPAGE_SIZE (4UL*1024UL*1024UL) #define dprintf(x) printf(x) #define ADDR (0x8000000000000000UL) main() { int shmid; int i, j, k; volatile char *shmaddr; if ((shmid =shmget(IPC_PRIVATE, 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