Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
89a69226
Commit
89a69226
authored
Jun 24, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
ea6a66e4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
8 deletions
+47
-8
wcfs/internal/mm.pyx
wcfs/internal/mm.pyx
+25
-5
wcfs/internal/wcfs_test.pyx
wcfs/internal/wcfs_test.pyx
+13
-0
wcfs/wcfs_test.py
wcfs/wcfs_test.py
+9
-3
No files found.
wcfs/internal/mm.pyx
View file @
89a69226
...
...
@@ -40,6 +40,12 @@ cpdef enum:
MADV_SEQUENTIAL
=
mman
.
MADV_SEQUENTIAL
MADV_WILLNEED
=
mman
.
MADV_WILLNEED
MADV_DONTNEED
=
mman
.
MADV_DONTNEED
MADV_FREE
=
mman
.
MADV_FREE
MADV_REMOVE
=
mman
.
MADV_REMOVE
MS_ASYNC
=
mman
.
MS_ASYNC
MS_SYNC
=
mman
.
MS_SYNC
MS_INVALIDATE
=
mman
.
MS_INVALIDATE
# incore returns bytearray vector indicating whether page of mem is in core or not.
#
...
...
@@ -78,7 +84,7 @@ def lock(const unsigned char[::1] mem not None, int flags):
if
err
:
PyErr_SetFromErrno
(
OSError
)
return
# ok
return
# unlock unlocks mem pages from being pinned in RAM.
...
...
@@ -90,7 +96,7 @@ def unlock(const unsigned char[::1] mem not None):
if
err
:
PyErr_SetFromErrno
(
OSError
)
return
# ok
return
from
posix.types
cimport
off_t
...
...
@@ -114,7 +120,7 @@ def map_into_ro(unsigned char[::1] mem not None, int fd, off_t offset):
if
addr
==
mman
.
MAP_FAILED
:
PyErr_SetFromErrno
(
OSError
)
return
# ok
return
# unmap unmaps memory covered by mem.
def
unmap
(
const
unsigned
char
[::
1
]
mem
not
None
):
...
...
@@ -125,7 +131,7 @@ def unmap(const unsigned char[::1] mem not None):
if
err
:
PyErr_SetFromErrno
(
OSError
)
return
# ok
return
# advise advises kernel about use of mem's memory.
...
...
@@ -139,4 +145,18 @@ def advise(const unsigned char[::1] mem not None, int advice):
if
err
:
PyErr_SetFromErrno
(
OSError
)
return
# ok
return
# sync asks the kernel to synchronize the file with a memory map.
#
# see msync(2) for details.
def
sync
(
const
unsigned
char
[::
1
]
mem
not
None
,
int
flags
):
cdef
const
void
*
addr
=
&
mem
[
0
]
cdef
size_t
size
=
mem
.
shape
[
0
]
cdef
err
=
mman
.
msync
(
<
void
*>
addr
,
size
,
flags
)
if
err
:
PyErr_SetFromErrno
(
OSError
)
return
wcfs/internal/wcfs_test.pyx
View file @
89a69226
...
...
@@ -26,6 +26,7 @@ from libc.signal cimport SIGBUS
from
libc.stdlib
cimport
abort
from
libc.string
cimport
strlen
from
posix.unistd
cimport
write
,
sleep
from
posix.types
cimport
off_t
from
cpython.exc
cimport
PyErr_SetFromErrno
from
cpython.pystate
cimport
PyGILState_Ensure
,
PyGILState_Release
,
PyGILState_STATE
...
...
@@ -43,6 +44,18 @@ def read_nogil(const unsigned char[::1] mem not None) -> bytes:
return
bytes
(
bytearray
([
b
]))
cdef
extern
from
"<fcntl.h>"
nogil
:
int
posix_fadvise
(
int
fd
,
off_t
offset
,
off_t
len
,
int
advice
);
enum
:
POSIX_FADV_DONTNEED
# fadvise_dontneed teels the kernel that file<fd>[offset +len) is not needed.
#
# see fadvise(2) for details.
def
fadvise_dontneed
(
int
fd
,
off_t
offset
,
off_t
len
):
cdef
int
err
=
posix_fadvise
(
fd
,
offset
,
len
,
POSIX_FADV_DONTNEED
)
if
err
:
PyErr_SetFromErrno
(
OSError
)
# ---- signal handling ----
# XXX -> golang.signal ?
...
...
wcfs/wcfs_test.py
View file @
89a69226
...
...
@@ -42,7 +42,7 @@ from zodbtools.util import ashex as h, fromhex
from
pytest
import
raises
from
six
import
reraise
from
.internal
import
mm
from
.internal.wcfs_test
import
read_nogil
,
install_sigbus_trap
from
.internal.wcfs_test
import
read_nogil
,
install_sigbus_trap
,
fadvise_dontneed
# setup:
# - create test database, compute zurl and mountpoint for wcfs
...
...
@@ -1553,11 +1553,17 @@ def test_wcfs_no_pin_twice():
assert
w
.
pinned
==
{
2
:
at1
}
# drop file[blk] from cache, access again -> no pin message sent the second time
print
(
'
\
n
\
n
\
n
\
n
\
n
ABCDEF
\
n
\
n
\
n
'
)
#
# ( we need both madvise(DONTNEED) and fadvise(DONTNEED) - given only one of
# those the kernel won't release the page from pagecache; madvise does
# not work without munlock. )
mm
.
unlock
(
f
.
_blk
(
2
))
mm
.
advise
(
f
.
_blk
(
2
),
mm
.
MADV_DONTNEED
)
fadvise_dontneed
(
f
.
f
.
fileno
(),
2
*
blksize
,
1
*
blksize
)
f
.
assertCache
([
0
,
0
,
0
])
# XXX
f
.
assertBlk
(
2
,
'c2'
,
{
wl
:
{}})
f
.
assertCache
([
0
,
0
,
1
])
# verify watching for 2 files over single watch link.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment