Browse Source

Use smaller cache if it cannot allocate

master
Geoffrey Frogeye 3 years ago
parent
commit
195f41bd9f
Signed by: geoffrey GPG Key ID: D8A7ECA00A8CD3DD
  1. 13
      database.py

13
database.py

@ -227,10 +227,19 @@ class Database(Profiler):
self.log.warning("Allocating more than 512 MiB of RAM for "
"the Ip4 cache is not necessary.")
max_cache_width = int(math.log2(max(1, max_size*8)))
allocated = False
cache_width = min(2**32, max_cache_width)
while not allocated:
cache_size = 2**cache_width
try:
self.ip4cache = numpy.zeros(cache_size, dtype=numpy.bool)
except MemoryError:
self.log.exception(
"Could not allocate cache. Retrying a smaller one.")
cache_width -= 1
continue
allocated = True
self.ip4cache_shift = 32-cache_width
cache_size = 2**cache_width
self.ip4cache = numpy.zeros(cache_size, dtype=numpy.bool)
for _ in self.exec_each_ip4(self._set_ip4cache):
pass

Loading…
Cancel
Save