Skip to content

Commit 226f428

Browse files
committed
First bit of MappedMemoryManager started. Much more to come - got lost in git++ and improved it in the meanwhile
1 parent 9fe8f93 commit 226f428

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

smmap/exc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""Module with system exceptions"""
2+
3+
class MemoryManagerError(Exception):
4+
"""Base class for all exceptions thrown by the memory manager"""
5+
6+
class RegionCollectionError(MemoryManagerError):
7+
"""Thrown if a memory region could not be collected, or if no region for collection was found"""

smmap/mman.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
MappedRegionList,
66
)
77

8+
from exc import RegionCollectionError
89
from weakref import proxy
910

1011
__all__ = ["MappedMemoryManager"]
@@ -45,7 +46,7 @@ def _destroy(self):
4546
num_clients = self._rlist.client_count() - 2
4647
if num_clients == 0 and len(self._rlist) == 0:
4748
# Free all resources associated with the mapped file
48-
self._manager._files.pop(self._rlist.path())
49+
self._manager._fdict.pop(self._rlist.path())
4950
#END remove regions list from manager
5051
#END handle regions
5152

@@ -82,6 +83,7 @@ def use_region(self, offset, size):
8283
This is not the case if the mapping failed becaues we reached the end of the file
8384
:note: The size actually mapped may be smaller than the given size. If that is the case,
8485
either the file has reached its end, or the map was created between two existing regions"""
86+
8587

8688
def unuse_region(self):
8789
"""Unuse the ucrrent region. Does nothing if we have no current region
@@ -146,5 +148,19 @@ class MappedMemoryManager(object):
146148
a safe amount of memory already, which would possibly cause memory allocations to fail as our address
147149
space is full."""
148150

149-
__slots__ = tuple()
150-
151+
__slots__ = [
152+
'_fdict', # mapping of path -> MappedRegionList
153+
'_max_window_size', # maximum size of a window
154+
'_max_memory_size', # maximum amount ofmemory we may allocate
155+
'_max_handles', # maximum amount of handles to keep open
156+
'_memory_size', # currently allocated memory size
157+
'_handle_count', # amount of currently allocated file handles
158+
]
159+
160+
def _collect_one_lru_region(self, size):
161+
"""Unmap the region which was least-recently used and has no client
162+
:param size: size of the region we want to map next (assuming its not already mapped partially or full
163+
if 0, we try to free any available region
164+
:raise RegionCollectionError:
165+
:todo: implement a case where all unusued regions are discarded efficiently. Currently its only brute force"""
166+

0 commit comments

Comments
 (0)