Skip to content

Commit

Permalink
Use direct I/O for loop devices
Browse files Browse the repository at this point in the history
This is a huge performance improvement for two reasons:

1. It uses the filesystem’s asynchronous I/O support, rather than using
   synchronous I/O.
2. It bypasses the page cache, removing a redundant layer of caching and
   associated overhead.

I also took the opportunity to rip out some cruft related to old losetup
versions, which Qubes OS doesn't need to support anymore.

Fixes QubesOS/qubes-issues#7332.
  • Loading branch information
DemiMarie committed Mar 11, 2022
1 parent f41b02e commit e879ec2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
55 changes: 55 additions & 0 deletions patch-use-direct-io.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--- xen-4.14.4/tools/hotplug/Linux/block 2022-01-31 04:44:39.000000000 -0500
+++ xen-4.14.4/tools/hotplug/Linux/block 2022-03-11 15:17:37.410000000 -0500
@@ -16,27 +16,6 @@
echo -n $dev
}

-find_free_loopback_helper() {
- local next_devnum=0
- local busy_devnum
- while read busy_devnum; do
- if [ "$next_devnum" != "$busy_devnum" ]; then
- break
- fi
- let next_devnum=$next_devnum+1
- done
- echo "/dev/loop${next_devnum}"
-}
-
-# Not all distros have "losetup -f"
-find_free_loopback_dev() {
- local loopdev
- loopdev=$(losetup -a | sed -e 's+^/dev/loop++' -e 's/:.*//' | find_free_loopback_helper)
- if [ -n "$loopdev" ] && [ -b "$loopdev" ]; then
- echo "$loopdev"
- fi
-}
-
##
# check_sharing devtype device mode [inode]
#
@@ -317,20 +296,16 @@
check_file_sharing "$file" "$dev" "$mode" "$inode"
fi

- loopdev=$(losetup -f 2>/dev/null || find_free_loopback_dev)
+ loopdev=$(losetup -f 2>/dev/null)
if [ "$loopdev" = '' ]
then
release_lock "block"
fatal 'Failed to find an unused loop device'
fi

- if LANG=C losetup -h 2>&1 | grep read-only >/dev/null
- then
- roflag="-$mode"; roflag="${roflag#-w}"; roflag="${roflag#-!}"
- else
- roflag=''
- fi
- do_or_die losetup $roflag "$loopdev" "$file"
+ roflag="-$mode"
+ roflag="${roflag#-w}"
+ do_or_die losetup --direct-io=on ${roflag#-!} "$loopdev" "$file"
xenstore_write "$XENBUS_PATH/node" "$loopdev"
write_dev "$loopdev"
release_lock "block"
1 change: 1 addition & 0 deletions series-debian-vm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ patch-Define-build-dates-time-based-on-SOURCE_DATE_EPOCH.patch
patch-docs-rename-DATE-to-PANDOC_REL_DATE-and-allow-to-spe.patch
patch-docs-xen-headers-use-alphabetical-sorting-for-incont.patch
patch-Strip-build-path-directories-in-tools-xen-and-xen-ar.patch
patch-use-direct-io.patch
1 change: 1 addition & 0 deletions series-vm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ patch-Define-build-dates-time-based-on-SOURCE_DATE_EPOCH.patch
patch-docs-rename-DATE-to-PANDOC_REL_DATE-and-allow-to-spe.patch
patch-docs-xen-headers-use-alphabetical-sorting-for-incont.patch
patch-Strip-build-path-directories-in-tools-xen-and-xen-ar.patch
patch-use-direct-io.patch
1 change: 1 addition & 0 deletions xen.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ Patch636: patch-autoconf-fix-handling-absolute-PYTHON-path.patch
Patch638: patch-libxl-do-not-require-filling-backend_domid-to-remove.patch
Patch639: patch-libxl-add-pcidevs-to-stubdomain-earlier.patch
Patch640: patch-xen-efi-align.patch
Patch641: patch-use-direct-io.patch

# GCC8 fixes
Patch714: patch-tools-kdd-mute-spurious-gcc-warning.patch
Expand Down

0 comments on commit e879ec2

Please sign in to comment.