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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joshua
wendelin.core
Commits
4952bf86
Commit
4952bf86
authored
Mar 14, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
8287b988
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
0 deletions
+85
-0
wcfs/mman.pyx
wcfs/mman.pyx
+81
-0
wcfs/wcfs_test.py
wcfs/wcfs_test.py
+4
-0
No files found.
wcfs/mman.pyx
0 → 100644
View file @
4952bf86
# Copyright (C) 2019 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
# cython: language_level=2
"""Module mman provides memory management utilities like mlock and mincore."""
from
posix
cimport
mman
from
cpython.exc
cimport
PyErr_SetFromErrno
#from libc.stdio cimport printf
cdef
extern
from
"<sys/user.h>"
:
cpdef
enum
:
PAGE_SIZE
cdef
extern
from
"<sys/mman.h>"
:
cpdef
enum
:
MLOCK_ONFAULT
# XXX not in posix.mman
int
mlock2
(
const
void
*
addr
,
size_t
len
,
int
flags
)
# mincore returns bytearray vector indicating whether page of mem is in core or not.
#
# mem start must be page-aligned.
def
mincore
(
const
unsigned
char
[::
1
]
mem
not
None
)
->
bytearray
:
cdef
const
void
*
addr
=
&
mem
[
0
]
cdef
size_t
size
=
mem
.
shape
[
0
]
# size in pages; rounded up
cdef
size_t
pgsize
=
(
size
+
(
PAGE_SIZE
-
1
))
//
PAGE_SIZE
#printf("\n\n%p %ld\n", addr, size)
incore
=
bytearray
(
pgsize
)
cdef
unsigned
char
[::
1
]
incorev
=
incore
cdef
err
=
mman
.
mincore
(
<
void
*>
addr
,
size
,
&
incorev
[
0
])
if
err
:
PyErr_SetFromErrno
(
OSError
)
return
incore
# mlock locks mem pages to be resident in RAM.
#
# see mlock2(2) for description of flags.
def
mlock
(
const
unsigned
char
[::
1
]
mem
not
None
,
int
flags
):
cdef
const
void
*
addr
=
&
mem
[
0
]
cdef
size_t
size
=
mem
.
shape
[
0
]
cdef
err
=
mlock2
(
addr
,
size
,
flags
)
if
err
:
PyErr_SetFromErrno
(
OSError
)
# munlock unlocks mem pages from being pinned in RAM.
def
munlock
(
const
unsigned
char
[::
1
]
mem
not
None
):
cdef
const
void
*
addr
=
&
mem
[
0
]
cdef
size_t
size
=
mem
.
shape
[
0
]
cdef
err
=
mman
.
munlock
(
addr
,
size
)
if
err
:
PyErr_SetFromErrno
(
OSError
)
wcfs/wcfs_test.py
View file @
4952bf86
...
...
@@ -38,6 +38,10 @@ from golang import func, defer
from
zodbtools.util
import
ashex
as
h
,
fromhex
from
pytest
import
raises
from
.
import
mman
#print(mman.PAGE_SIZE)
#mman.mincore(bytearray(b'hello world'))
# setup:
# - create test database, compute zurl and mountpoint for wcfs
# - at every test: make sure wcfs is not running before & after the test.
...
...
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