# open it initially and hold the flock(), and a second
# hidden one used by mmap().
#
- # Set max slots to 3/8 of maximum file handles. This
- # means we'll use at most 3/4 of total file handles.
+ # Set max slots to 1/8 of maximum file handles. This
+ # means we'll use at most 1/4 of total file handles.
#
# NOFILE typically defaults to 1024 on Linux so this
- # is 384 slots (768 file handles), which means we can
- # cache up to 24 GiB of 64 MiB blocks. This leaves
- # 256 file handles for sockets and other stuff.
- self._max_slots = int((resource.getrlimit(resource.RLIMIT_NOFILE)[0] * 3) / 8)
+ # is 128 slots (256 file handles), which means we can
+ # cache up to 8 GiB of 64 MiB blocks. This leaves
+ # 768 file handles for sockets and other stuff.
+ #
+ # When we want the ability to have more cache (e.g. in
+ # arv-mount) we'll increase rlimit before calling
+ # this.
+ self._max_slots = int(resource.getrlimit(resource.RLIMIT_NOFILE)[0] / 8)
else:
# RAM cache slots
self._max_slots = 512
self._resize_cache(self.cache_max, self._max_slots-1)
while len(self._cache) >= self._max_slots:
# If there isn't a slot available, need to wait
- # until some other cache action happens.
- self._cache_updating.wait()
+ # for something to happen that releases one of the
+ # cache slots. Idle for 200 ms or woken up by
+ # another thread
+ self._cache_updating.wait(timeout=0.2)
self._resize_cache(self.cache_max, self._max_slots-1)
if self._disk_cache: