Use smaller cache if it cannot allocate
This commit is contained in:
parent
0e7479e23e
commit
195f41bd9f
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…
Reference in a new issue