21639: Code cleanup
[arvados.git] / sdk / python / arvados / diskcache.py
index 1e885c15e2146ea9a0c2cf67a1fb333617729138..22bf73894b8fd8d9d1a1270de1973481a937dc51 100644 (file)
@@ -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: