line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#ifdef __cplusplus |
2
|
|
|
|
|
|
|
extern "C" { |
3
|
|
|
|
|
|
|
#endif |
4
|
|
|
|
|
|
|
#include "EXTERN.h" |
5
|
|
|
|
|
|
|
#include "perl.h" |
6
|
|
|
|
|
|
|
#include "XSUB.h" |
7
|
|
|
|
|
|
|
#include "ppport.h" |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#define _FILE_OFFSET_BITS 64 |
10
|
|
|
|
|
|
|
#include |
11
|
|
|
|
|
|
|
#include |
12
|
|
|
|
|
|
|
#include |
13
|
|
|
|
|
|
|
#ifdef __cplusplus |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
#endif |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
MODULE = Sys::PageCache PACKAGE = Sys::PageCache |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
BOOT: |
20
|
|
|
|
|
|
|
{ |
21
|
7
|
|
|
|
|
|
HV *stash = gv_stashpv ("Sys::PageCache", 0); |
22
|
7
|
|
|
|
|
|
newCONSTSUB (stash, "POSIX_FADV_NORMAL" , newSViv (POSIX_FADV_NORMAL)); |
23
|
7
|
|
|
|
|
|
newCONSTSUB (stash, "POSIX_FADV_SEQUENTIAL", newSViv (POSIX_FADV_SEQUENTIAL)); |
24
|
7
|
|
|
|
|
|
newCONSTSUB (stash, "POSIX_FADV_RANDOM" , newSViv (POSIX_FADV_RANDOM)); |
25
|
7
|
|
|
|
|
|
newCONSTSUB (stash, "POSIX_FADV_NOREUSE" , newSViv (POSIX_FADV_NOREUSE)); |
26
|
7
|
|
|
|
|
|
newCONSTSUB (stash, "POSIX_FADV_WILLNEED" , newSViv (POSIX_FADV_WILLNEED)); |
27
|
7
|
|
|
|
|
|
newCONSTSUB (stash, "POSIX_FADV_DONTNEED" , newSViv (POSIX_FADV_DONTNEED)); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
int |
31
|
|
|
|
|
|
|
page_size() |
32
|
|
|
|
|
|
|
CODE: |
33
|
16
|
|
|
|
|
|
RETVAL = sysconf(_SC_PAGESIZE); |
34
|
|
|
|
|
|
|
OUTPUT: |
35
|
|
|
|
|
|
|
RETVAL |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
HV* |
38
|
|
|
|
|
|
|
_fincore(fd, offset, length) |
39
|
|
|
|
|
|
|
int fd; |
40
|
|
|
|
|
|
|
size_t offset; |
41
|
|
|
|
|
|
|
size_t length; |
42
|
|
|
|
|
|
|
CODE: |
43
|
13
|
|
|
|
|
|
void *pa = (char *)0; |
44
|
13
|
|
|
|
|
|
unsigned char *vec = (unsigned char *)0; |
45
|
13
|
|
|
|
|
|
size_t page_size = sysconf(_SC_PAGESIZE); |
46
|
|
|
|
|
|
|
size_t page_index; |
47
|
13
|
|
|
|
|
|
size_t cached = 0; |
48
|
|
|
|
|
|
|
|
49
|
13
|
|
|
|
|
|
RETVAL = (HV *)sv_2mortal((SV *)newHV()); |
50
|
|
|
|
|
|
|
|
51
|
13
|
|
|
|
|
|
pa = mmap((void *)0, length, PROT_NONE, MAP_SHARED, fd, offset); |
52
|
13
|
50
|
|
|
|
|
if (pa == MAP_FAILED) { |
53
|
0
|
|
|
|
|
|
croak("mmap: %s", strerror(errno)); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
13
|
|
|
|
|
|
vec = calloc(1, (length + page_size - 1) / page_size); |
57
|
13
|
50
|
|
|
|
|
if (vec == NULL) { |
58
|
0
|
|
|
|
|
|
munmap(pa, length); |
59
|
0
|
|
|
|
|
|
croak("calloc: %s", strerror(errno)); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
13
|
50
|
|
|
|
|
if (mincore(pa, length, vec) != 0) { |
63
|
0
|
|
|
|
|
|
free(vec); |
64
|
0
|
|
|
|
|
|
munmap(pa, length); |
65
|
0
|
|
|
|
|
|
croak("mincore: %s", strerror(errno)); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
204
|
100
|
|
|
|
|
for (page_index = 0; page_index <= length / page_size; page_index++) { |
69
|
191
|
100
|
|
|
|
|
if (vec[page_index] & 1) { |
70
|
49
|
|
|
|
|
|
cached++; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
13
|
|
|
|
|
|
free(vec); |
75
|
13
|
|
|
|
|
|
munmap(pa, length); |
76
|
|
|
|
|
|
|
|
77
|
13
|
|
|
|
|
|
hv_store(RETVAL, "page_size", 9, newSViv(page_size), 0); |
78
|
13
|
|
|
|
|
|
hv_store(RETVAL, "cached_pages", 12, newSViv(cached), 0); |
79
|
13
|
|
|
|
|
|
hv_store(RETVAL, "cached_size", 11, newSViv((unsigned long long)cached * page_size), 0); |
80
|
|
|
|
|
|
|
OUTPUT: |
81
|
|
|
|
|
|
|
RETVAL |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
int |
84
|
|
|
|
|
|
|
_fadvise(fd, offset, length, advice) |
85
|
|
|
|
|
|
|
int fd; |
86
|
|
|
|
|
|
|
size_t offset; |
87
|
|
|
|
|
|
|
size_t length; |
88
|
|
|
|
|
|
|
int advice |
89
|
|
|
|
|
|
|
CODE: |
90
|
|
|
|
|
|
|
int r; |
91
|
|
|
|
|
|
|
#if linux |
92
|
7
|
|
|
|
|
|
r = fdatasync(fd); |
93
|
|
|
|
|
|
|
#else |
94
|
|
|
|
|
|
|
r = fsync(fd); |
95
|
|
|
|
|
|
|
#endif |
96
|
7
|
50
|
|
|
|
|
if (r != 0) { |
97
|
0
|
|
|
|
|
|
croak("fdatasync: %s", strerror(errno)); |
98
|
|
|
|
|
|
|
} |
99
|
7
|
|
|
|
|
|
r = posix_fadvise(fd, offset, length, advice); |
100
|
7
|
50
|
|
|
|
|
if (r != 0) { |
101
|
0
|
|
|
|
|
|
croak("posix_fadvise: %s", strerror(errno)); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
7
|
|
|
|
|
|
RETVAL = r; |
105
|
|
|
|
|
|
|
OUTPUT: |
106
|
|
|
|
|
|
|
RETVAL |