Gentoo Archives: gentoo-amd64

From: Duncan <1i5t5.duncan@×××.net>
To: gentoo-amd64@l.g.o
Subject: [gentoo-amd64] Re: upgrade an old system
Date: Wed, 06 May 2009 17:09:28
Message-Id: pan.2009.05.06.16.39.01@cox.net
In Reply to: Re: [gentoo-amd64] Re: upgrade an old system by "Sami Näätänen"
1 Sami Näätänen <sn.ml@××××××××××××.fi> posted
2 200905061637.59424.sn.ml@××××××××××××.fi, excerpted below, on Wed, 06 May
3 2009 16:37:59 +0300:
4
5 > On Wednesday 06 May 2009 15:43:22 Mark Haney wrote:
6 >> Volker Armin Hemmann wrote:
7 >> > On Mittwoch 06 Mai 2009, Mark Haney wrote:
8 >> >> Duncan wrote:
9 >> >>> Consider pointing PORTAGE_TMPDIR at a tmpfs.
10 >> >>>
11 >> >>> The idea is based on the fact that everything portage does in its
12 >> >>> tmpdir (/var/tmp by default) is temporary, erased as soon as it's
13 >> >>> done emerging that package. Since tmpfs uses swap backed memory,
14 >> >>> worst-case, it has to write to swap -- that is, to disk, which is
15 >> >>> where it would otherwise be writing ALL the temporary files. With
16 >> >>> memory access so much faster than disk access, every file that's
17 >> >>> erased before it hits disk saves time, and it can make a BIG
18 >> >>> difference in emerge times.
19 >> >>
20 >> >> Duncan, you talk about tmpfs and I'm suddenly interested in trying
21 >> >> this out. My question is, how much space do you allocate for the
22 >> >> tmpfs? I know it'll fall back to swap if I'm out of space there,
23 >> >> but what works well for you? I have (currently) 1GB RAM on this
24 >> >> system, but I'm getting ready to order more to get me to 4GB.
25 >> >
26 >> > 2gb. That is enough for almost everything. Not enough for openoffice.
27 >> > tmpfs 2,0G 3,2M 2,0G 1% /var/tmp/portage tmpfs
28 >> > 1,0G 116K 1,0G 1% /tmp
29 >>
30 >> Now how is that going to play out when I only have 1GB of RAM?
31 >
32 > IMHO You shouldn't use tmpfs for the PM temp dir, until you can give
33 > that around 2GB, which shouldn't be more than half of your total memory.
34 >
35 > In your case there still could be some speed improvement if you have
36 > enough swap space. This because smaller packages wouldn't use disks at
37 > all, but still allowing bigger compiles to be carried out as the tmpfs
38 > would use swap when the memory starts to run low.
39 >
40 >
41 > When I had only 2GB of memory I used a dedicated RAID 0 (striped) ext2fs
42 > partition for the PM temp dir. As in this use case the raw speed of the
43 > used FS is more important than the reliability.
44 >
45 > Now I have 8GB of memory and I use 5GB and 2GB limits for the PM temp
46 > and the sys temp.
47
48 Sami posted pretty much what I would have posted.
49
50 As I said in my earlier post, at a gig of RAM, I'm honestly not sure if a
51 tmpfs based PORTAGE_TMPDIR is worth it or not, as I've not personally
52 tested it and have read no reports from others who have. You will very
53 likely still get faster compiles as some of the files won't be written to
54 disk at all, but the tradeoff in terms of what gets swapped out and
55 resulting system (lack of) responsiveness may or may not be worth it.
56 There's some chance you could improve responsiveness by tweaking
57 swappiness, but at a gig of memory, I expect it's still going to be very
58 much a personal preference as to whether you consider the sacrificed
59 system responsiveness worth the faster compiles, or not. I suspect those
60 that setup their emerges for overnight or otherwise set them up and then
61 do something other than work on that computer will find the faster
62 compiles useful, while those that try to do something else on the
63 computer while it's compiling are more likely to find the decreased
64 system responsiveness not worth it.
65
66 As for tmpfs size, there's a couple basics to keep in mind.
67
68 First, unlike some ramfs implementations (I'm not sure about the
69 kernel's) tmpfs doesn't actually use memory unless there's files actually
70 stored in it. Thus, the size of the tmpfs is really its maximum size --
71 the size you as sysadmin are prepared to let it grow to. Restating
72 directly just to make it clear, an empty tmpfs uses very little memory at
73 all (possibly a couple kB for the base memory structures), so unless it's
74 actually used, the (max) size of the tmpfs doesn't matter.
75
76 Second, it's worth keeping in mind the kernel tmpfs default (max) side as
77 a guideline, if nothing else. It defaults to half of physical memory.
78 Thus, create a tmpfs without setting its size, and if you have a gig of
79 RAM, it'll default to a half gig; if you have 8 gigs, it'll default to 4
80 gigs. Again, for practical purposes that's max size, as if it remains
81 unused, it takes virtually no memory at all. (See the mount (1) manpage
82 under tmpfs for this and other details. Wow! Somewhat OT, but I just
83 checked the mount manpage to double-check my half-of-memory assertion,
84 and discovered the new mpol= NUMA node allocation policy. Interesting!)
85
86 Third, tmpfs is useful in that it isn't restricted to physical memory,
87 and can use swap as well, if there's memory pressure and something in
88 tmpfs to swap out. Thus the "worst case" as mentioned earlier, that
89 there's not enough memory and the system has to write the files to disk
90 (swap, now) after all. But another implication, then, is that swap size
91 matters too. It can't use swap you don't have configured and mounted!
92 The old rule of thumb was to have swap of twice the size of regular
93 memory. While that no longer really applies as it used to, because if
94 someone has memory of say four gigs, it's unlikely they're going to be
95 prepared to wait for 8 gigs of swap to fill up even if they have it
96 configured (at least if they're running a single disk, RAID-0/striped
97 swap is faster and thus not as bad), for those with a gig of RAM or more,
98 I'd say 2 gigs swap minimum is reasonable. Those using tmpfs for
99 anything major, however, as we're talking about here, will probably want
100 more, say 4-6 gigs swap, just in case.
101
102 (As it happens, I have 8 gigs RAM and 16 gigs swap, consisting of 4,
103 4-gig swap partitions, one each on four separate drives, configured as
104 RAID-0/striped, for speed. 16 gigs swap is a bit excessive, but as I use
105 one of those 4-gig stripes as a suspend image, with a suspend image up to
106 half RAM size or four gigs, and the kernel doesn't like striped suspend
107 images very well, it works out quite well.)
108
109 With those basics in mind, we can now discuss tmpfs size policy. For PM
110 temp dir, tmpfs or not, that filesystem needs to be big enough to handle
111 your biggest package, possibly more if you compile multiple packages in
112 parallel. The biggest actually compiled package is, I believe, open-
113 office. Depending on options, I've seen it said (I don't have it
114 installed, here) that open-office takes 4-5 gigabytes of filesystem space
115 to succcessfully compile. Thus, that's what I used as my baseline here,
116 even tho I don't expect to install it. (FWIW, I do have parts of koffice
117 installed, tho.) It's also worth noting that I saw one of the games
118 developers remark that there's one games data package that's some 25 gigs
119 (!!) in size. However, it's always possible to point PORTAGE_TMPDIR (or
120 other PM tmpdir, if you're using pkgcore or paludis) at some other
121 location for huge packages, if necessary. Thus, the tmpfs doesn't
122 actually HAVE to be a full 5 gigs. If it's too small, you'll get an
123 error during the build and can either increase it temporarily (if you
124 have the memory and swap available to do so), or can point the PM tmpdir
125 elsewhere for that package from that point on. Of course, it gets old
126 VERY fast doing that for more than a handful of packages, so you'll want
127 a tmpfs of at LEAST 2-3 gigs, if not the 5 gigs I used as a baseline for
128 mine, to point PORTAGE_TMPDIR at.
129
130 But this is another reason it gets iffy running this way with only a gig
131 of RAM. If you're compiling a package needing 3 gigs filespace while
132 compiling, with only a gig of RAM and assuming a half-gig RAM of system
133 usage, you'll be into swap by two and a half gigs just for the tmpfs
134 usage while compiling that package! Yes, it's still likely to be a bit
135 faster than building to a disk based filesystem, but probably not so
136 much, and meanwhile, running that far into swap is likely to make system
137 responsiveness rather bad. Is it worth the build-time speedup for the
138 loss of responsiveness? How bad will it actually be? Can tweaking
139 swappiness help enough to make it usable? These are questions I don't
140 have the answer to, as I've yet to see a good report from anyone who
141 actually tried it.
142
143 OK, so we've established a 5 GB reasonable tmpfs size for the PM tmpdir.
144 FWIW, here, with as mentioned 8 gig RAM and 16 gig swap (enough I
145 basically never have to worry about running out of swap), and with that 5
146 GB open-office baseline, I decided a 6 GB (max size) tmpfs was
147 reasonable. Worst-case, full-maxed-out, that'd leave the system a
148 minimum of 2 gigs of RAM to play with, before it has to decide whether to
149 start swapping stuff out. That seemed reasonable to me. If I'd not had
150 8 gigs RAM to play with, I'd have probably made it 5 gigs tmpfs, or
151 possibly tried 4 and upped it if I needed to.
152
153 For a 4-gig physical RAM system or lower, people obviously aren't going
154 to have the luxury of using the same reasoning I did. At 2 and 4 gigs,
155 the kernel should be somewhat reasonable at managing things by default,
156 tho the lower physical RAM, the more likely people are to find fiddling
157 swappiness necessary for optimum results. If anyone wants to try it with
158 a gig RAM, I'd honestly like to see your results, both default and after
159 fiddling with swappiness. It'd make writing the next one of these MUCH
160 easier! =:^) For that matter, altho with two gigs RAM it should still be
161 worth it, it'd be nice confirming that, and I'd be quite interested in
162 seeing how much fiddling with swappiness was able to improve the results
163 there, as well.
164
165 Two more things to wrap up.
166
167 First, I mentioned striped swap. It can make a big difference. If
168 anyone has multiple disks and is interested in further details on that,
169 just ask.
170
171 Second, and really the only place I sort of disagree with Sami, when I
172 considered tmpfs here, I decided to go with only one tmpfs, 6 gigs as I
173 mentioned, while he chose two, separating his 5 gig PM tmp from his 2 gig
174 system tmp. Perhaps he'll post his reasoning for going separate, but
175 here's why I decided on the combined. Thinking about my usage, I decided
176 it wasn't likely that I'd do more than one thing needing substantial
177 amounts of temp filespace at once. Most of the time, that "one thing" is
178 portage, but it's occasionally handy to have a tmpfs big enough to say
179 copy a DVD image into, to burn it from memory instead of disk, for
180 instance. Standard DVDs run up to 4.7 GB single-sided, and I didn't find
181 the idea of ensuring portage wasn't hogging space while I worked with a
182 DVD or anything else I might want to store on tmpfs restrictive, so the 5
183 gig limit was convenient for that as well.
184
185 At the same time, I wanted to limit worst-case maximum tmpfs usage.
186 Since I have 8 gigs RAM and it was convenient to do so, I wanted to keep
187 total tmpfs usage to some reasonable fraction of RAM, so I'd never be
188 forced into swap on account of tmpfs usage alone. It was thus useful to
189 me to create a single tmpfs a reasonable fraction of my memory size, such
190 that if something should for some reason start unrestricted writing to
191 the tmpfs either due to a buggy program or due to some attempt at a DOS,
192 I'd be limiting it to a reasonable fraction of RAM and it could never DOS
193 me due to running me out of memory. (This, BTW, is one reason for the
194 "half of physical RAM" tmpfs max size default, as well.) So I did the 5
195 gig thing, added another gig for flexibility while still limiting it to a
196 reasonable 3/4 total physical RAM, and called that good.
197
198 If I had created two separate tmpfs, the PORTAGE_TMPDIR one and another
199 one for use with DVD images or whatever, each five gigs, that would have
200 implied a total worst-case tmpfs usage of 10 gigs altho it would have
201 allowed me to be stricter on what users/groups I allowed to write to
202 each. I decided the single 6-gig main tmpfs was better for me than two
203 smaller ones, maximizing flexibility while more strictly controlling
204 maximum system memory usage.
205
206 FWIW, I do have a much smaller tmpfs located at the FHS/LSB standard /dev/
207 shm mountpoint. However, it is just that, MUCH smaller, limited to 2 MB,
208 as standard usage is for quick 0-byte lockfiles, sockets, and other
209 similar small files. If something's abusing that standard and trying to
210 store anything of significant size there, I want to know about it right
211 away, and a 2 MB size limit should ensure that. udev is also tmpfs, size
212 2 MB, and openrc (with baselayout-2) has its rc-svcdir tmpfs mounted at /
213 lib64/rc/init.d, size 1 MB, as well. The total (max) size of these
214 "system" tmpfs mounts is thus 5 MB, rather lost in the noise on a multi-
215 gig memory system.
216
217 Again, users with 2 or 4 gigs, let alone a single gig of RAM, will by
218 necessity have a somewhat different strategy here than I did, as the 5
219 gig baseline for a PORTAGE_TMPDIR tmpfs will by definition be larger than
220 their total physical memory size. However, the idea of restricting worst-
221 case tmpfs usage remains valid, really even more so, since it WILL be
222 running in swap if full.
223
224 OTOH, while multiple tmpfs mounts increases overall resource exposure,
225 it /does/ allow one to better restrict access to individual tmpfs
226 mounts. Perhaps that's Sami's strategy. If he limits writing (and
227 perhaps reading too) on his PM temp to the portage user (and root, of
228 course), then by separating them, he's limiting exposure on his (assumed
229 world writable) 2-gig system tmpfs to its 2-gigs, while I'm exposing that
230 whole 6-gig tmpfs to writes by any user. As I said, perhaps he'll post
231 his reasoning and we'll see.
232
233 --
234 Duncan - List replies preferred. No HTML msgs.
235 "Every nonfree program has a lord, a master --
236 and if you use the program, he is your master." Richard Stallman

Replies

Subject Author
Re: [gentoo-amd64] Re: upgrade an old system "Sami Näätänen" <sn.ml@××××××××××××.fi>