Gentoo Archives: gentoo-amd64

From: Volker Armin Hemmann <volker.armin.hemmann@××××××××××××.de>
To: gentoo-amd64@l.g.o
Subject: Re: [gentoo-amd64] Re: System becomes almost unusable when compling c++ code
Date: Fri, 03 Aug 2007 22:10:58
Message-Id: 200708040007.39114.volker.armin.hemmann@tu-clausthal.de
In Reply to: Re: [gentoo-amd64] Re: System becomes almost unusable when compling c++ code by Richard Freeman
1 On Freitag, 3. August 2007, Richard Freeman wrote:
2 > Volker Armin Hemmann wrote:
3 > > where is the difference between 'app syncs its files to disk' and 'kernel
4 > > swaps app to disk, than decides to swap it in, so app can decides which
5 > > files it wants to sync to disk, then swap it out again'?
6 > >
7 > > oh, more disk access...
8 >
9 > Actually, you're not quite looking at it the right way. Suppose during
10 > the course of an emerge I need 150MB of temp files. I have two choices
11 > - write to disk, or write to tmpfs.
12 >
13 > In the former case every write goes to disk buffer (ram), and then is
14 > synced to disk within about 5 seconds. In the latter case every write
15 > goes to tmpfs (ram), and if necessary gets written to swap at an
16 > opportune time (when the system needs more ram, the page is idle for a
17 > long time, the system is otherwise idle, etc) - and if this need doesn't
18 > come up before the file is deleted it never gets written to disk at all.
19 >
20 > In the worst case both get synced to disk, but in the former case the
21 > kernel does not get to choose when outside the forced setting of about 5
22 > seconds. In the latter case the kernel can schedule disk access more
23 > opportunistically - because the kernel knows the data isn't that
24 > important and doesn't need to be written to disk quickly.
25 >
26 > Generally well-written apps don't decide what files it wants syned to
27 > disk - the kernel does that. If a file is written to a normal
28 > filesystem it gets synced according to the rules of the filesystem, and
29 > if it is written to tmpfs it gets written to disk if the system needs
30 > more ram and the file is more idle than most of the rest of RAM.
31 >
32 > I think you'd be surprised at how similarly files on disk and memory in
33 > ram get handled. Both get "swapped" in and out of memory (if the file
34 > is mmapped - which is often the case), and writes to files get stored in
35 > buffers/cache just like files in tmpfs. The big difference is that
36 > tmpfs files are not guaranteed to ever get written to disk, which means
37 > the kernel can handle them more flexibly. Normal files are ALWAYS
38 > written to disk (unless they're deleted in the few seconds before they
39 > are synced), and the kernel isn't allowed to just keep them in buffers
40 > for 30 minutes if the disk is busy.
41 >
42 > In the extreme of excessive RAM the tmpfs is going to be many orders of
43 > magnitude faster than writing to disk. In the extreme of a very
44 > ram-starved system it will probably be comparable.
45 >
46 > > And honestly? From my 'feelings' swap is way slower than normal disk
47 > > accesses.
48 >
49 > What kinds of access are you comparing? If you're talking about
50 > swapping in and out a 50MB binary vs a 50kb text file then you're
51 > comparing apples to oranges.
52
53 I am comparing an open konqueror window that was minimized, had a webpage open
54 and was swapped out with the rest of X and the KDE session compared with log
55 in, start konqueror and loading that page.
56
57 You see, both give me a usable window in the same timeframe (+/- 1 or 2
58 seconds) but the second choice does not make the mouse jerking around.
59
60 The worst: as soon as say 100mb are in swap, everything is slow for the rest
61 of the evening. Best solution?
62 swapoff -a && swapon -a. And have some popcorn when the disk is accessed like
63 mad.
64
65 >even if you have no swap partition. Linux just mmaps the
66 > executable into memory and starts running it (with little to nothing in
67 > RAM) - any time the program accesses its own code it triggers a swap-in.
68 >
69 I know that - and it is faster to read that executable from fs than to swap it
70 in....
71 --
72 gentoo-amd64@g.o mailing list