Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Paste
P384
largepage shm API example
Active
Public
Actions
Authored by
kib
on May 3 2020, 10:04 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Flag For Later
Award Token
Tags
None
Referenced Files
F6454209: raw.txt
May 3 2020, 10:04 PM
2020-05-03 22:04:03 (UTC+0)
Subscribers
None
/* $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
);
}
}
Event Timeline
kib
created this paste.
May 3 2020, 10:04 PM
2020-05-03 22:04:03 (UTC+0)
kib
created this object in space
S1 Global
.
kib
mentioned this in
D24652: Non-transparent superpages support.
.
Santhosh Raju <fox@FreeBSD.org>
mentioned this in
R11:677f4c2bf26a: security/wolfssl: Update to v5.1.0
.
Dec 30 2021, 1:27 AM
2021-12-30 01:27:42 (UTC+0)
Santhosh Raju <fox@FreeBSD.org>
mentioned this in
R11:d915d5a47915: security/wolfssl: Update to v5.5.0
.
Sep 4 2022, 8:46 AM
2022-09-04 08:46:39 (UTC+0)
Log In to Comment