Skip to content

Commit c90cfef

Browse files
committed
Fixed a few little issues, the random access test/perftest now work perfectly. Its not too slow either, 160MB/s compared to the 320MB/s that the c++ implementation gets in release mode. Its odd that for some reason, the Debug version of the c++ implementation is at 940MB/s, which is more like the performance i would have expected
1 parent 997a580 commit c90cfef

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

smmap/mman.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def includes_ofs(self, ofs):
244244
:note: always False if the cursor does not point to a valid region"""
245245
if self._region is None:
246246
return False
247-
return (self.ofs_begin() <= ofs) and (ofs < self.ofs_end())
247+
return self.ofs_begin() <= ofs < self.ofs_end()
248248

249249
def file_size(self):
250250
""":return: size of the underlying file"""
@@ -326,7 +326,7 @@ def _collect_lru_region(self, size):
326326
for regions in self._fdict.itervalues():
327327
for region in regions:
328328
# check client count - consider that we keep one reference ourselves !
329-
if (region.client_count()-1 == 0 and
329+
if (region.client_count()-2 == 0 and
330330
(lru_region is None or region.usage_count() < lru_region.usage_count())):
331331
lru_region = region
332332
lru_list = regions

smmap/test/test_mman.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,14 @@ def test_memman_operation(self):
138138
st = time()
139139

140140
while num_random_accesses:
141-
num_random_accesses += 1
141+
num_random_accesses -= 1
142142
base_offset = randint(0, fc.size - 1)
143143

144144
# precondition
145145
assert man.max_mapped_memory_size() >= man.mapped_memory_size()
146146
assert man.max_file_handles() >= man.num_file_handles()
147-
148147
assert c.use_region(base_offset, size).is_valid()
149-
assert c.buffer()[:] == data[base_offset:base_offset+size]
148+
assert c.buffer()[:] == data[base_offset:base_offset+c.size()]
150149
memory_read += c.size()
151150

152151
assert c.includes_ofs(base_offset)

smmap/util.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def __init__(self, path, ofs, size):
116116
# have to correct size, otherwise (instead of the c version) it will
117117
# bark that the size is too large ... many extra file accesses because
118118
# if this ... argh !
119-
self._mf = mmap.mmap(fd, min(os.fstat(fd).st_size - sizeofs, corrected_size - sizeofs), **kwargs)
119+
self._mf = mmap.mmap(fd, min(os.fstat(fd).st_size - sizeofs, corrected_size), **kwargs)
120120

121121
if self._need_compat_layer:
122122
self._mfb = buffer(self._mf, ofs, size)
@@ -125,6 +125,11 @@ def __init__(self, path, ofs, size):
125125
os.close(fd)
126126
#END close file handle
127127

128+
def __repr__(self):
129+
return "MappedRegion<%i, %i>" % (self._b, self.size())
130+
131+
#{ Interface
132+
128133
def buffer(self):
129134
""":return: a sliceable buffer which can be used to access the mapped memory"""
130135
return self._mf
@@ -143,7 +148,7 @@ def ofs_end(self):
143148

144149
def includes_ofs(self, ofs):
145150
""":return: True if the given offset can be read in our mapped region"""
146-
return (ofs >= self.ofs_begin()) and (ofs <= self.ofs_end())
151+
return self.ofs_begin() <= ofs < self.ofs_end()
147152

148153
def client_count(self):
149154
""":return: number of clients currently using this region"""
@@ -170,6 +175,8 @@ def buffer(self):
170175
return self._mfb
171176
#END handle compat layer
172177

178+
#} END interface
179+
173180

174181
class MappedRegionList(list):
175182
"""List of MappedRegion instances associating a path with a list of regions."""

0 commit comments

Comments
 (0)