X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/593917ad86ce138fd4735628a3437a920130b691..e54662c069d72c7a22f89bd889370703790d2536:/sdk/python/arvados/diskcache.py diff --git a/sdk/python/arvados/diskcache.py b/sdk/python/arvados/diskcache.py index 1e885c15e2..528a7d28b5 100644 --- a/sdk/python/arvados/diskcache.py +++ b/sdk/python/arvados/diskcache.py @@ -32,7 +32,14 @@ class DiskCacheSlot(object): 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 @@ -84,7 +91,6 @@ class DiskCacheSlot(object): os.remove(tmpfile) except: pass - return False def size(self): if self.content is None: @@ -100,7 +106,7 @@ class DiskCacheSlot(object): 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 @@ -238,7 +244,7 @@ class DiskCacheSlot(object): # 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: