Gentoo Archives: gentoo-user

From: Uwe Thiem <uwix@××××.na>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Memory Usage
Date: Fri, 15 Dec 2006 11:41:24
Message-Id: 200612151332.04021.uwix@iway.na
In Reply to: Re: [gentoo-user] Memory Usage by Redouane Boumghar
1 On 15 December 2006 13:53, Redouane Boumghar wrote:
2 > Hello all,
3 >
4 > Grant wrote:
5 > > Also, I've noticed in top that when my server's 2GB of memory is
6 > > filled, it uses a small amount of swap (~24k) before it frees some up.
7 > > The "Swap: 24k" then remains. Is that normal?
8 >
9 > Yes I have also notice that after a heavy ram use I get this tiny
10 > space used on my swap. And it remains even after my ram has been half
11 > freed. My box has 1GB of ram and the small amount I sometime get on swap is
12 > 164KB and it can stay like that for 2 weeks, until i reboot.
13 > But I assume rebooting is not a great solution for a server :=)
14 >
15 > Writing to disk is too expensive as Pablo Antonio suggested, so once swap
16 > has been used it won't be cleaned until next use, but how to be sure
17 > it is cleaned at next use ?
18
19 That is *not* the reason. Your memory is organised in pages. How much memory a
20 page is, 4KB, 8Kb,..., depends on your memory model and the architecture of
21 your box. Let's assume your systems needs more memory than you have ram
22 installed. So your memory manager searches for pages that haven't been used
23 for a while. Let's assume further that you are running cupsd but haven't
24 printed after booting yet. So it's highly likely that those memory pages
25 occupied by cupsd are swapped out (or actually paged out because linux
26 doesn't do swapping but paging).
27
28 After a while, your memory usage decreases. Why would cupsd be paged in again
29 unless you start printing? Since cupsd isn't used it stays where it is - in
30 your swap partition.
31
32 I used cupsd here just as an example. It's the same for many other daemons
33 that are there to provide a service. If you don't use that service the daemon
34 is a very good candidate for being paged out. It isn't a candidate for being
35 paged in again at all as long as you don't use the service.
36
37 Other good candidates are code parts in applications that are executed exactly
38 once, at start time. Say, you keep your browser open all the time. The
39 initialisation code has been executed when you open the browser first, never
40 thereafter. So it's a very good candidate for being paged out if it fills at
41 least one memory page. It will never be paged in again because it isn't used
42 any more. When you close your browser that code isn't paged in either but
43 simply deleted from swap space.
44
45 So once your system has started to use swap space, some memory pages will
46 always stay in your swap space because things are paged in again only if they
47 are used.
48
49 Uwe
50
51 --
52 Mark Twain: I rather decline two drinks than a German adjective.
53 http://www.SysEx.com.na
54 --
55 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Memory Usage Redouane Boumghar <redouane.boumghar@×××××××××.fr>