Skip to contentSkip to conversation

Subtle MM bug

DISCUSSION Zlatko Calusic 3 participants 8 messages Jan 7, 2001 – Apr 17, 2001 Memory management

lore
Share & tools
lore
#0 lore raw

I'm trying to get more familiar with the MM code in 2.4.0, as can be seen from lots of questions I have on the subject. I discovered nasty mm behaviour under even moderate load (2.2 didn't have troubles).

Things go berzerk if you have one big process whose working set is around your physical memory size. Typical memory hoggers are good enough to trigger the bad behaviour. Final effect is that physical memory gets extremely flooded with the swap cache pages and at the same time the system absorbs ridiculous amount of the swap space. xmem is as usual very good at detecting this and you just need to press Alt-SysReq-M to see that most of the memory (e.g. 90%) is populated with the swap cache pages.

For instance on my 192MB configuration, firing up the hogmem program which allocates let's say 170MB of memory and dirties it leads to 215MB of swap used. vmstat 1 shows that the pagecache size is constantly growing - that is swapcache enlarging in fact - during the second pass of the hogmem program.

...

   procs                      memory    swap          io     system         cpu
 r  b  w   swpd  free buff  cache   si   so    bi    bo   in    cs  us  sy  id
 0  1  1 131488  1592  400  62384 4172 5188  1092  1298  353  1447   2   4  94
 0  1  1 136584  1592  400  67428 5860 4104  1465  1034  322  1327   3   3  93
 0  1  1 141668  1592  388  72536 5504 4420  1376  1106  323  1423   1   3  95
 0  1  1 146724  1592  380  77592 5996 4236  1499  1060  335  1096   2   3  94
 0  1  1 151876  1600  320  82764 6264 3712  1566   936  327  1226   3   4  93
 0  1  1 157016  1600  320  87908 5284 4268  1321  1068  315  1248   1   2  96
 1  0  0 157016  1600  308  87792 1836 5168   459  1293  281  1324   3   3  94
 0  1  0 162204  1600  304  92892 7784 5236  1946  1315  385  1353   3   5  92
 0  1  0 167216  1600  304  97780 3496 5016   874  1256  301  1222   0   2  97
 0  1  1 177904  1608  284 108276 5160 5168  1290  1300  330  1453   1   4  94
 0  1  2 182008  1588  288 112264 4936 3344  1268   838  293   801   2   3  95
 0  2  1 183620  1588  260 114012 3064 1756   830   445  290   846   0  15  85
 0  2  2 185384  1596  180 115864 2320 2620   635   658  285   722   1  29  70
 0  3  2 187528  1592  220 117892 2488 2224   657   557  273   754   3  30  67
 0  4  1 190512  1592  236 120772 2524 3012   725   760  343  1080   1  14  85
 0  4  1 195780  1592  240 125868 2336 5316   613  1331  381  1624   2   2  96
 1  0  1 200992  1592  248 131052 2080 2176   623   552  234  1044   3  23  74
 0  1  0 200996  1592  252 130948 2208 3048   580   762  256  1065  10  10  80
 0  1  1 206240  1592  252 136076 2988 5252   760  1314  309  1406   7   4  8
 0  2  1 211408  1592  256 141080 5424 5180  1389  1303  395  1885   3   5  91
 0  2  0 214744  1592  264 144280 4756 3328  1223   834  327  1211   1   5  95
 1  0  0 214868  1592  244 144468 4344 5148  1087  1295  303  1189  11   2  86
 0  1  1 214900  1592  248 144496 4360 3244  1098   812  318  1467   7   4  89
 0  1  1 214916  1592  248 144520 4280 3452  1070   865  336  1602   3   3  94
 0  1  1 214964  1592  248 144580 4972 4184  1243  1054  368  1620   3   5  92
 0  2  2 214956  1592  272 144548 3700 4544  1081  1142  665  2952   1   1  98
 0  1  0 214992  1592  272 144588 1220 5088   305  1274  282  1363   1   4  95
 0  1  1 215012  1592  272 144600 3640 4420   910  1106  325  1579   3   2  9

Any thoughts on this?

Signature · 5 lines
Zlatko
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
#1 lore raw
Quoted 2 lines · Zlatko Calusic

Things go berzerk if you have one big process whose working set is around your physical memory size.

"go berzerk" in what way? Does the system cause lots of extra swap IO and does it make the system thrash where 2.2 didn't even touch the disk ?

Quoted 3 lines

Final effect is that physical memory gets extremely flooded with the swap cache pages and at the same time the system absorbs ridiculous amount of the swap space.

This is mostly because Linux 2.4 keeps dirty pages in the swap cache. Under Linux 2.2 a page would be deleted from the swap cache when a program writes to it, but in Linux 2.4 it can stay in the swap cache.

Oh, and don't forget that pages in the swap cache can also be resident in the process, so it's not like the swap cache is "eating into" the process' RSS ;)

Quoted 3 lines

For instance on my 192MB configuration, firing up the hogmem program which allocates let's say 170MB of memory and dirties it leads to 215MB of swap used.

So that's 170MB of swap space for hogmem and 45MB for the other things in the system (daemons, X, ...).

Sounds pretty ok, except maybe for the fact that now Linux allocates (not uses!) a lot more swap space then before and some people may need to add some swap space to their system ...

Now if 2.4 has worse _performance_ than 2.2 due to one reason or another, that I'd like to hear about ;)

regards,

Rik
--
Virtual memory is like a game you can't win; However, without VM there's truly nothing to lose...

		http://www.surriel.com/

http://www.conectiva.com/ http://distro.conectiva.com.br/

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

#2 lore raw
Quoted 9 lines · Rik van Riel
Quoted 2 lines · Zlatko Calusic

Things go berzerk if you have one big process whose working set is around your physical memory size.

"go berzerk" in what way? Does the system cause lots of extra swap IO and does it make the system thrash where 2.2 didn't even touch the disk ?

Well, I think yes. I'll do some testing on the 2.2 before I can tell you for sure, but definitely the system is behaving badly where I think it should not.

Quoted 9 lines
Quoted 3 lines

Final effect is that physical memory gets extremely flooded with the swap cache pages and at the same time the system absorbs ridiculous amount of the swap space.

This is mostly because Linux 2.4 keeps dirty pages in the swap cache. Under Linux 2.2 a page would be deleted from the swap cache when a program writes to it, but in Linux 2.4 it can stay in the swap cache.

OK, I can buy that.

Quoted 4 lines

Oh, and don't forget that pages in the swap cache can also be resident in the process, so it's not like the swap cache is "eating into" the process' RSS ;)

So far so good... A little bit weird but not alarming per se.

Quoted 7 lines
Quoted 3 lines

For instance on my 192MB configuration, firing up the hogmem program which allocates let's say 170MB of memory and dirties it leads to 215MB of swap used.

So that's 170MB of swap space for hogmem and 45MB for the other things in the system (daemons, X, ...).

Yes, that's it. So it looks like all of my processes are on the swap. That can't be good. I mean, even Solaris (known to eat swap space like there's no tomorrow :)) would probably be more polite.

Quoted 5 lines

Sounds pretty ok, except maybe for the fact that now Linux allocates (not uses!) a lot more swap space then before and some people may need to add some swap space to their system ...

Yes, I would say really a lot more. Big diffeence.

Also, I don't see a diference between allocated and used swap space on the Linux. Could you elaborate on that?

Quoted 4 lines

Now if 2.4 has worse _performance_ than 2.2 due to one reason or another, that I'd like to hear about ;)

I'll get back to you later with more data. Time to boot 2.2. :)

Signature · 5 lines
Zlatko
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
#3 lore raw
In reply to Rik van Riel
Quoted 3 lines · Rik van Riel

Now if 2.4 has worse _performance_ than 2.2 due to one reason or another, that I'd like to hear about ;)

Oh, well, it seems that I was wrong. :)

First test: hogmem 180 5 = allocate 180MB and dirty it 5 times (on a 192MB machine)

kernel | swap usage | speed
-------------------------------
2.2.17 | 48 MB | 11.8 MB/s
-------------------------------
2.4.0 | 206 MB | 11.1 MB/s
-------------------------------

So 2.2 is only marginally faster. Also it can be seen that 2.4 uses 4 times more swap space. If Linus says it's ok... :)

Second test: kernel compile make -j32 (empirically this puts the VM under load, but not excessively!)

2.2.17 -> make -j32 392.49s user 47.87s system 168% cpu 4:21.13 total 2.4.0 -> make -j32 389.59s user 31.29s system 182% cpu 3:50.24 total

Now, is this great news or what, 2.4.0 is definitely faster.

Signature · 5 lines
Zlatko
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
#4 lore raw
Quoted 18 lines · Zlatko Calusic
Quoted 3 lines · Rik van Riel

Now if 2.4 has worse _performance_ than 2.2 due to one reason or another, that I'd like to hear about ;)

Oh, well, it seems that I was wrong. :)

First test: hogmem 180 5 = allocate 180MB and dirty it 5 times (on a 192MB machine)

kernel | swap usage | speed
-------------------------------
2.2.17 | 48 MB | 11.8 MB/s
-------------------------------
2.4.0 | 206 MB | 11.1 MB/s
-------------------------------

Quoted 2 lines

So 2.2 is only marginally faster. Also it can be seen that 2.4 uses 4 times more swap space. If Linus says it's ok... :)

I have been working on some changes to page_launder() which might just fix this problem. Quick and dirty patches are on my home page and I'll try to clean things up and make something correct & clean later today or tomorrow ;)

Quoted 7 lines

Second test: kernel compile make -j32 (empirically this puts the VM under load, but not excessively!)

2.2.17 -> make -j32 392.49s user 47.87s system 168% cpu 4:21.13 total 2.4.0 -> make -j32 389.59s user 31.29s system 182% cpu 3:50.24 total

Now, is this great news or what, 2.4.0 is definitely faster.

One problem is that these tasks may be waiting on kswapd when kswapd might not get scheduled in on time. On the one hand this will mean lower load and less thrashing, on the other hand it means more IO wait.

This is another area where we may be able to improve some things.

(btw, according to Alan the 2.4 kernel is the first one to break the 1.2 kernel compiling speed record on an 8MB machine he has ;))

cheers,

Rik (stuck in australia on a conference)
--
Virtual memory is like a game you can't win; However, without VM there's truly nothing to lose...

		http://www.surriel.com/

http://www.conectiva.com/ http://distro.conectiva.com.br/

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

#5 lore raw
Quoted 6 lines · Rik van Riel
Quoted 6 lines

Second test: kernel compile make -j32 (empirically this puts the VM under load, but not excessively!)

2.2.17 -> make -j32 392.49s user 47.87s system 168% cpu 4:21.13 total 2.4.0 -> make -j32 389.59s user 31.29s system 182% cpu 3:50.24 total

Quoted 7 lines
Quoted 1 line

Now, is this great news or what, 2.4.0 is definitely faster.

One problem is that these tasks may be waiting on kswapd when kswapd might not get scheduled in on time. On the one hand this will mean lower load and less thrashing, on the other hand it means more IO wait.

Hm, if all tasks are waiting for memory, what is stopping kswapd to run? :)

Signature · 5 lines
Zlatko
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
#6 lore raw
Quoted 10 lines · Zlatko Calusic
Quoted 8 lines · Rik van Riel
Quoted 7 lines

Second test: kernel compile make -j32 (empirically this puts the VM under load, but not excessively!)

2.2.17 -> make -j32 392.49s user 47.87s system 168% cpu 4:21.13 total 2.4.0 -> make -j32 389.59s user 31.29s system 182% cpu 3:50.24 total

Now, is this great news or what, 2.4.0 is definitely faster.

Quoted 7 lines
Quoted 4 lines

One problem is that these tasks may be waiting on kswapd when kswapd might not get scheduled in on time. On the one hand this will mean lower load and less thrashing, on the other hand it means more IO wait.

Hm, if all tasks are waiting for memory, what is stopping kswapd to run? :)

Suppose you have 8 high-priority tasks waiting on kswapd and one lower-priority (but still higher than kswapd) process running and preventing kswapd from doing its work. Oh .. and also preventing the higher-priority tasks from being woken up and continuing...

Rik
--
Virtual memory is like a game you can't win; However, without VM there's truly nothing to lose...

		http://www.surriel.com/

http://www.conectiva.com/ http://distro.conectiva.com.br/

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

#7 lore raw
In reply to Zlatko Calusic
Followup to:  <[email protected]>
By author:    Rik van Riel <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 7 lines

Suppose you have 8 high-priority tasks waiting on kswapd and one lower-priority (but still higher than kswapd) process running and preventing kswapd from doing its work. Oh .. and also preventing the higher-priority tasks from being woken up and continuing...

Classic priority inversion. In this particular case it seems like it should be unusually simple to apply priority inheritance, though (the general case is complicated by the fact that the dependency matrix usually isn't readily available.)

-hpa

Signature · 3 lines
<[email protected]> at work, <[email protected]> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt