Skip to content

Commit 5bde4ca

Browse files
committed
Show how to move mkosi WorkspaceDirectory to /tmp(fs)
I've been selfishly enjoying this major optimization for a while; time to share it. mkosi-workspace is located on /var/tmp/ by default, which usually does not run out of RAM but is persistent and slow storage which wears out. On success, mkosi-workspace is deleted at the end of the build so it really does not need to be located on persistent storage. So, show how to move it to /tmp which is usually tmpfs. Also document some of the pitfalls discovered so far. On one of my systems, moving to tmpfs lowers the build time from 4 min to 1 min! If you ever wondered how I could git bisect mkosi faster than reading its release notes: that's how. Signed-off-by: Marc Herbert <[email protected]>
1 parent 6529b48 commit 5bde4ca

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

.github/workflows/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ jobs:
166166
set -x
167167
mkosi --version
168168
ccache --show-stats
169+
cp run_qemu/contrib/tmpfs_workspace.tmpl run_qemu/mkosi_tmpl_portable/
169170
cd kernel
170171
PATH=/usr/lib/ccache:"$PATH" \
171172
distro=${{ matrix.cfg.img_distro }} rev=${{ matrix.cfg.img_rel }} \

contrib/tmpfs_workspace.tmpl

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# mkosi never locates its workspace in "/tmp/" by default because many Linux
2+
# distributions use tmpfs for /tmp and mkosi does not want to risk running out
3+
# of RAM with very large images. But on success, mkosi-workspace is deleted at
4+
# the end of the build so it really does not need to be located on persistent
5+
# storage. Also, we tend to build relatively small images: only a few
6+
# gigabytes.
7+
#
8+
# => to use /tmp for mkosi workspaces, simply copy this file to your
9+
# run_qemu.git/mkosi_tmpl_portable/ directory. This will save several minutes
10+
# of build time when you have fast CPUs and slow storage
11+
#
12+
# Pro-tip: symlink kernel/qbuild/ to /tmp/qbuild.real too. A few more gigabytes
13+
# required. (some old mkosi versions nest their WorkspaceDir inside qbuild/ by
14+
# default)
15+
16+
# If you run out of /tmp space you can make it bigger without rebooting
17+
# with: "mount -o remount,size=newsize"
18+
19+
# Warning: mkosi version v15 and v16 cannot use /tmp/... here because it's not
20+
# bind-mounted in bubblewrap (cpio error). Point WorkspaceDirectory= at another
21+
# tmpfs with a different name or cherry-pick mkosi fix 28ccb67a92e (v17)
22+
23+
# We don't use "/tmp/" itself but a _subdirectory_ of it because:
24+
# - This keeps /tmp/ "cleaner"
25+
# - `WorkspaceDirectory=/tmp` is not compatible with mkosi v24 commit
26+
# f4eba02dd3ca and the bwrap-sandboxed "rm -rf
27+
# WorkspaceDirectory/mkosi-workspace-12345", see
28+
# https://github.com/pmem/run_qemu/pull/116 for the obscure details. (v25
29+
# drops bwrap entirely)
30+
31+
[Output]
32+
# WorkspaceDirectory= (and others) were moved to the brand new [Build]
33+
# section in mkosi v25 commit ef5a79993e2. Fortunately, no version
34+
# before or after that mkosi commit seems to mind the duplicate (mkosi
35+
# versions < v15 don't seem to care about sections at all). So just
36+
# duplicate [Output] and [Build] and forget about it. This may print
37+
# a warning.
38+
WorkspaceDirectory=/tmp/rq_mkosi_wspaces/
39+
40+
[Build]
41+
WorkspaceDirectory=/tmp/rq_mkosi_wspaces/

run_qemu.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,8 @@ post_script()
16571657
main()
16581658
{
16591659
mkdir -p "$builddir"
1660+
# Optional
1661+
mkdir -p /tmp/rq_mkosi_wspaces/
16601662
process_options_logic
16611663

16621664
case "$_arg_rebuild" in

0 commit comments

Comments
 (0)