From 79b2f37cbc02d23a3bd20951f957e7ebb92f0dbc Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Mon, 22 Jul 2019 14:55:51 +0200 Subject: [PATCH] loop: add direct-io support Support the LOOP_SET_DIRECT_IO ioctl, which alows us to control whether or not a loopback device should perform its own buffering or rely on the one done by the underlying backing file. Enabling this should improve both throughput and memory consumption, it is not currently hooked up as more testing would be required. --- osbuild/loop.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/osbuild/loop.py b/osbuild/loop.py index 04dac67b..1967b1d3 100644 --- a/osbuild/loop.py +++ b/osbuild/loop.py @@ -207,6 +207,20 @@ class Loop: info.lo_flags &= ~self.LO_FLAGS_PARTSCAN fcntl.ioctl(self.fd, self.LOOP_SET_STATUS64, info) + def set_direct_io(self, dio=True): + """Set the direct-IO property on the loopback device + + Enabling direct IO allows one to avoid double caching, which + should improve performance and memory usage. + + Parameters + ---------- + dio : bool, optional + Whether or not to enable direct IO (default is True) + """ + + fcntl.ioctl(self.fd, self.LOOP_SET_DIRECT_IO, dio) + def mknod(self, dir_fd=None, mode=0o600): """Create a secondary device node