Commit 4952bf86 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8287b988
# 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)
......@@ -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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment