##// END OF EJS Templates
mmap: populate the mapping by default...
marmoute -
r52574:522b4d72 default
parent child Browse files
Show More
@@ -440,13 +440,18 b' class bufferedinputpipe:'
440 440 return data
441 441
442 442
443 def mmapread(fp, size=None):
443 def mmapread(fp, size=None, pre_populate=True):
444 444 """Read a file content using mmap
445 445
446 446 The responsability of checking the file system is mmap safe is the
447 responsability of the caller.
447 responsability of the caller (see `vfs.is_mmap_safe`).
448 448
449 449 In some case, a normal string might be returned.
450
451 If `pre_populate` is True (the default), the mmapped data will be
452 pre-populated in memory if the system support this option, this slow down
453 the initial mmaping but avoid potentially crippling page fault on later
454 access. If this is not the desired behavior, set `pre_populate` to False.
450 455 """
451 456 if size == 0:
452 457 # size of 0 to mmap.mmap() means "all data"
@@ -455,8 +460,12 b' def mmapread(fp, size=None):'
455 460 elif size is None:
456 461 size = 0
457 462 fd = getattr(fp, 'fileno', lambda: fp)()
463 flags = mmap.MAP_PRIVATE
464 if pre_populate:
465 flags |= getattr(mmap, 'MAP_POPULATE', 0)
458 466 try:
459 return mmap.mmap(fd, size, access=mmap.ACCESS_READ)
467 m = mmap.mmap(fd, size, flags=flags, prot=mmap.PROT_READ)
468 return m
460 469 except ValueError:
461 470 # Empty files cannot be mmapped, but mmapread should still work. Check
462 471 # if the file is empty, and if so, return an empty buffer.
General Comments 0
You need to be logged in to leave comments. Login now