Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F6454209
raw.txt
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
kib
May 3 2020, 10:04 PM
2020-05-03 22:04:03 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
raw.txt
View Options
/* $Id: hugetlb2.c,v 1.4 2020/05/03 16:58:27 kostik Exp kostik $ */
#include <sys/param.h>
#include <sys/fcntl.h>
#include <sys/filio.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <err.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static int pn;
static size_t pagesize[10];
static const u_int cnt = 5;
static void
test_sp(int idx)
{
char *addr;
struct shm_largepage_conf slc;
size_t i, sz;
int error, fd;
printf("Mapping %#zx x %d (idx %d) superpages\n", pagesize[idx],
cnt, idx);
sz = pagesize[idx] * cnt;
fd = syscall(SYS_shm_open2, SHM_ANON, O_CREAT | O_RDWR, 0666,
SHM_LARGEPAGE, (void *)NULL);
if (fd == -1)
err(1, "shm_open2");
memset(&slc, 0, sizeof(slc));
slc.domain = -1;
slc.psind = idx;
slc.alloc_policy = SHM_LARGEPAGE_ALLOC_DEFAULT;
error = ioctl(fd, FIOSHMLPGCNF, &slc);
if (error == -1)
err(1, "FIOSHMLPGCNF");
error = ftruncate(fd, sz);
if (error == -1)
err(1, "ftruncate");
addr = mmap(NULL, sz, PROT_READ | PROT_WRITE,
MAP_LARGEPAGE | MAP_SHARED, fd, 0);
if (addr == MAP_FAILED)
err(1, "mmap MAP_LARGEPAGE");
printf("Mapped at %p\n", addr);
for (i = 0; i < sz; addr++, i++)
*addr = 0x13;
printf("Done\n");
error = munmap(addr, sz);
if (error == -1)
err(1, "munmap");
}
int
main(void)
{
int i;
pn = getpagesizes(pagesize, nitems(pagesize));
printf("Supported page sizes:");
for (i = 0; i < pn; i++)
printf(" %#zx", pagesize[i]);
printf("\n");
for (i = 0; i < pn; i++) {
if (pagesize[i] == (size_t)getpagesize())
continue;
test_sp(i);
}
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2568691
Default Alt Text
raw.txt (1 KB)
Attached To
Mode
P384 largepage shm API example
Attached
Detach File
Event Timeline
Log In to Comment