mercurial/util.py
changeset 51738 b619ba39d10a
parent 51727 92845af308b4
child 51796 62806be5cbda
--- a/mercurial/util.py	Thu Jul 25 14:40:38 2024 -0400
+++ b/mercurial/util.py	Tue Jul 09 20:08:48 2024 +0200
@@ -451,7 +451,9 @@
 
 
 def has_mmap_populate():
-    return hasattr(mmap, 'MAP_POPULATE')
+    return hasattr(osutil, "background_mmap_populate") or hasattr(
+        mmap, 'MAP_POPULATE'
+    )
 
 
 def mmapread(fp, size=None, pre_populate=True):
@@ -475,10 +477,13 @@
         size = 0
     fd = getattr(fp, 'fileno', lambda: fp)()
     flags = mmap.MAP_PRIVATE
-    if pre_populate:
+    bg_populate = hasattr(osutil, "background_mmap_populate")
+    if pre_populate and not bg_populate:
         flags |= getattr(mmap, 'MAP_POPULATE', 0)
     try:
         m = mmap.mmap(fd, size, flags=flags, prot=mmap.PROT_READ)
+        if pre_populate and bg_populate:
+            osutil.background_mmap_populate(m)
         return m
     except ValueError:
         # Empty files cannot be mmapped, but mmapread should still work.  Check