Gentoo Archives: gentoo-user

From: Kai Krakow <hurikhan77@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: tmp on tmpfs
Date: Thu, 25 May 2017 03:37:08
Message-Id: 20170525053646.42aba17f@jupiter.sol.kaishome.de
In Reply to: [gentoo-user] Re: tmp on tmpfs by Ian Zimmerman
1 Am Wed, 24 May 2017 11:34:20 -0700
2 schrieb Ian Zimmerman <itz@×××××××.net>:
3
4 > On 2017-05-24 08:00, Kai Krakow wrote:
5 >
6 > > While I have no benchmarks and use the systemd default of tmpfs for
7 > > /tmp, I also put /var/tmp/portage on tmpfs, automounted through
8 > > systemd so it is cleaned up when no longer used (by unmounting).
9 > >
10 > > What can I say? It works so much faster: Building packages is a lot
11 > > faster most of the time, even if you'd expect gcc uses a lot of
12 > > memory.
13 > >
14 > > Well, why might that be? First, tmpfs is backed by swap space, that
15 > > means, you need a swap partition of course. Swap is a lot simpler
16 > > than file systems, so swapping out unused temporary files is fast
17 > > and is a good thing. Also, unused memory sitting around may be
18 > > swapped out early. Why would you want inactive memory resident? So
19 > > this is also a good thing. Portage can use memory much more
20 > > efficient by this.
21 > >
22 > > Applying this reasoning over to /tmp should no explain why it works
23 > > so well and why you may want it.
24 > >
25 > > BTW: I also use zswap, so tmpfs sits in front of a compressed
26 > > write-back cache before being written out to swap compressed. This
27 > > should generally be much more efficient (performance-wise) than
28 > > putting /tmp on zram.
29 > >
30 > > I configured tmpfs for portage to use up to 30GB of space, which is
31 > > almost twice the RAM I have. And it works because tmpfs is not
32 > > required to be resident all the time: Inactive parts will be swapped
33 > > out. The kernel handles this much similar to the page cache, with
34 > > the difference that your files aren't backed by your normal file
35 > > system but by swap. And swap has a lot lower IO overhead.
36 > >
37 > > Overall, having less IO overhead (and less head movement for portage
38 > > builds) is a very very efficient thing to do. GCC constantly needs
39 > > all sorts of files from your installation (libs for linking, header
40 > > files, etc), and writes a lot of transient files which are needed
41 > > once later and then discarded. There's no point in putting it on a
42 > > non-transient file system.
43 > >
44 > > I use the following measures to get more performance out of this
45 > > setup:
46 > >
47 > > * I have three swap partitions spread across three HDDs
48 > > * I have a lot of swap space (60 GB) to have space for tmpfs
49 > > * I have bcache in front of my HDD filesystem
50 > > * I have a relatively big SSD dedicated to bcache
51 > >
52 > > My best recommendation is to separate swap and filesystem devices.
53 > > While I didn't do it that way, I still separate them through bcache
54 > > and thus decouple fs access and swap access although they are on the
55 > > same physical devices. My bcache is big enough that most accesses
56 > > would go to the SSD only. I enabled write-back to have that effect
57 > > also for write access.
58 > >
59 > > If you cannot physically split swap from fs, a tmpfs setup for
60 > > portage may not be recommended (except you have a lot of memory,
61 > > like 16GB or above). But YMMV.
62 > >
63 > > Still, I recommend it for /tmp, especially if your system is on
64 > > SSD.
65 >
66 > All interesting points, and you convinced me to at least give tmpfs a
67 > try on the desktop.
68 >
69 > My laptop is different, though. It doesn't have that much RAM by
70 > comparison (4G) and it _only_ has a SSD. Builds have been slow :( I
71 > am afraid to mess with it lest I increase the wear on the SSD.
72
73 You still may want to test /var/tmp/portage as tmpfs for small
74 packages... Or manually call:
75
76 # sudo PORTAGE_TMPDIR=/path/to/tmpfs emerge -1a small-package
77
78 For big packages, I suggest to nfs mount some storage from your desktop.
79 It probably will still be slow (maybe a little bit slower) but should
80 be much better for your SSD lifetime.
81
82
83 > > Unix semantics suggest that /tmp is not expected to survive reboots
84 > > anyways (in contrast, /var/tmp is expected to survive reboots), so
85 > > tmpfs is a logical consequence to use for /tmp.
86 >
87 > /tmp is wiped by the bootmisc init job anyway.
88
89 That's why such jobs exist, and why usually /tmp is wiped completely
90 while /var/tmp is wiped based on atime/mtime...
91
92
93 --
94 Regards,
95 Kai
96
97 Replies to list-only preferred.