Gentoo Archives: gentoo-user

From: Kai Krakow <hurikhan77@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: tmp on tmpfs
Date: Wed, 24 May 2017 17:06:03
Message-Id: 20170524190546.1de43d7f@jupiter.sol.kaishome.de
In Reply to: [gentoo-user] Re: tmp on tmpfs by Kai Krakow
1 Am Wed, 24 May 2017 08:00:33 +0200
2 schrieb Kai Krakow <hurikhan77@×××××.com>:
3
4 > Am Wed, 24 May 2017 07:34:34 +0200
5 > schrieb gentoo-user@××××.de:
6 >
7 > > On 17-05-23 at 22:16, Ian Zimmerman wrote:
8 > > > So what are gentoo users' opinions on this matter of faith?
9 > > I use an ext4 partition backed by zram. Gives me ~3x compression on
10 > > the things I normally have lying around there (plain text files) and
11 > > ensures that anything I throw there (or programs throw there) gets
12 > > cleaned up on reboot.
13 > >
14 > > > I have long been in the camp that thinks tmpfs for /tmp has no
15 > > > advantages (and may have disadvantages) over a normal filesystem
16 > > > like ext3, because the files there are normally so small that they
17 > > > will stay in the page cache 100% of the time.
18 > > I've never actually benchmarked this. Most of the things I notice
19 > > that tend to end up there are temporary build files generated during
20 > > configure stages or temporary log files used by various programs
21 > > (clang static analyzer). Even if the entire file stays in the page
22 > > cache, it'll still generate IO overhead and extra seeks that might
23 > > slow down the rest of your system (unless your /tmp is on a
24 > > different hard drive) which on spinning rust will cause slowdowns
25 > > while on an ssd it'll eat away at your writes (which you may or may
26 > > not have to worry about).
27 > >
28 > > > But I see that tmpfs is the default with systemd. Surely they
29 > > > have a good reason for this? :)
30 > > Or someone decided they liked the idea and made it the default and
31 > > nobody ever complained (or if they did were told to just change it
32 > > on their system).
33 > >
34 > > Either way, it'd be nice if someone actually benchmarked this.
35 >
36 > While I have no benchmarks and use the systemd default of tmpfs
37 > for /tmp, I also put /var/tmp/portage on tmpfs, automounted through
38 > systemd so it is cleaned up when no longer used (by unmounting).
39 >
40 > What can I say? It works so much faster: Building packages is a lot
41 > faster most of the time, even if you'd expect gcc uses a lot of
42 > memory.
43 >
44 > Well, why might that be? First, tmpfs is backed by swap space, that
45 > means, you need a swap partition of course.
46
47 To get in line with Rich Freeman: I didn't want to imply that zswap
48 only works with swap, neither that tmpfs only works with swap. Both
49 work without. But if you want to put some serious amount of data into
50 tmpfs, you need swap as a backing device sooner or later.
51
52 > Swap is a lot simpler than
53 > file systems, so swapping out unused temporary files is fast and is a
54 > good thing. Also, unused memory sitting around may be swapped out
55 > early. Why would you want inactive memory resident? So this is also a
56 > good thing. Portage can use memory much more efficient by this.
57 >
58 > Applying this reasoning over to /tmp should no explain why it works so
59 > well and why you may want it.
60 >
61 > BTW: I also use zswap, so tmpfs sits in front of a compressed
62 > write-back cache before being written out to swap compressed. This
63 > should generally be much more efficient (performance-wise) than
64 > putting /tmp on zram.
65 >
66 > I configured tmpfs for portage to use up to 30GB of space, which is
67 > almost twice the RAM I have. And it works because tmpfs is not
68 > required to be resident all the time: Inactive parts will be swapped
69 > out. The kernel handles this much similar to the page cache, with the
70 > difference that your files aren't backed by your normal file system
71 > but by swap. And swap has a lot lower IO overhead.
72 >
73 > Overall, having less IO overhead (and less head movement for portage
74 > builds) is a very very efficient thing to do. GCC constantly needs all
75 > sorts of files from your installation (libs for linking, header files,
76 > etc), and writes a lot of transient files which are needed once later
77 > and then discarded. There's no point in putting it on a non-transient
78 > file system.
79 >
80 > I use the following measures to get more performance out of this
81 > setup:
82 >
83 > * I have three swap partitions spread across three HDDs
84 > * I have a lot of swap space (60 GB) to have space for tmpfs
85 > * I have bcache in front of my HDD filesystem
86 > * I have a relatively big SSD dedicated to bcache
87 >
88 > My best recommendation is to separate swap and filesystem devices.
89 > While I didn't do it that way, I still separate them through bcache
90 > and thus decouple fs access and swap access although they are on the
91 > same physical devices. My bcache is big enough that most accesses
92 > would go to the SSD only. I enabled write-back to have that effect
93 > also for write access.
94 >
95 > If you cannot physically split swap from fs, a tmpfs setup for portage
96 > may not be recommended (except you have a lot of memory, like 16GB or
97 > above). But YMMV.
98 >
99 > Still, I recommend it for /tmp, especially if your system is on SSD.
100 > Unix semantics suggest that /tmp is not expected to survive reboots
101 > anyways (in contrast, /var/tmp is expected to survive reboots), so
102 > tmpfs is a logical consequence to use for /tmp.
103
104
105 --
106 Regards,
107 Kai
108
109 Replies to list-only preferred.

Replies

Subject Author
[gentoo-user] Puzzled by zswap [Was: tmp on tmpfs] Ian Zimmerman <itz@×××××××.net>