def get(self):
self.ready.wait()
- if isinstance(self.content, mmap.mmap):
+ # 'content' can None, an empty byte string, or a nonempty mmap
+ # region. If it is an mmap region, we want to advise the
+ # kernel we're going to use it. This nudges the kernel to
+ # re-read most or all of the block if necessary (instead of
+ # just a few pages at a time), reducing the number of page
+ # faults and improving performance by 4x compared to not
+ # calling madvise.
+ if self.content:
self.content.madvise(mmap.MADV_WILLNEED)
return self.content
os.remove(tmpfile)
except:
pass
- return False
def size(self):
if self.content is None:
return len(self.content)
def evict(self):
- if self.content is None or len(self.content) == 0:
+ if not self.content:
return
# The mmap region might be in use when we decided to evict
# Map in all the files we found, up to maxslots, if we exceed
# maxslots, start throwing things out.
- cachelist = collections.OrderedDict()
+ cachelist: collections.OrderedDict = collections.OrderedDict()
for b in blocks:
got = DiskCacheSlot.get_from_disk(b[0], cachedir)
if got is None: