mirror of https://github.com/borgbackup/borg.git
repo writes: call posix_fadvise between fsync and close
less calls to posix_fadvise (which seem to force a write-cache sync-to-disk and wait for that to complete) - if we call it after we synced anyway, we don't lose time. also: fixed a bug in the os.fsync call, it needs the fileno.
This commit is contained in:
parent
874f5c491b
commit
57071ce6fd
|
@ -555,10 +555,6 @@ class LoggedIO(object):
|
|||
header = self.header_no_crc_fmt.pack(size, TAG_PUT)
|
||||
crc = self.crc_fmt.pack(crc32(data, crc32(id, crc32(header))) & 0xffffffff)
|
||||
fd.write(b''.join((crc, header, id, data)))
|
||||
if hasattr(os, 'posix_fadvise'): # python >= 3.3, only on UNIX
|
||||
# tell the OS that it does not need to cache what we just wrote,
|
||||
# avoids spoiling the cache for the OS and other processes.
|
||||
os.posix_fadvise(fd.fileno(), 0, 0, os.POSIX_FADV_DONTNEED)
|
||||
self.offset += size
|
||||
return self.segment, offset
|
||||
|
||||
|
@ -581,6 +577,10 @@ class LoggedIO(object):
|
|||
if self._write_fd:
|
||||
self.segment += 1
|
||||
self.offset = 0
|
||||
os.fsync(self._write_fd)
|
||||
os.fsync(self._write_fd.fileno())
|
||||
if hasattr(os, 'posix_fadvise'): # python >= 3.3, only on UNIX
|
||||
# tell the OS that it does not need to cache what we just wrote,
|
||||
# avoids spoiling the cache for the OS and other processes.
|
||||
os.posix_fadvise(self._write_fd.fileno(), 0, 0, os.POSIX_FADV_DONTNEED)
|
||||
self._write_fd.close()
|
||||
self._write_fd = None
|
||||
|
|
Loading…
Reference in New Issue