Skip to contentSkip to conversation

Memory management in Kernel 2.4.x

DISCUSSION Andreas Hartmann 8 participants 19 messages May 27, 2002 – Jun 5, 2002 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 9 lines · Zwane Mwaikambo
Quoted 5 lines · Andreas Hartmann

rsync allocates all of the memory the machine has (256 MB RAM, 128 MB swap). When this occures, processes get killed like described in the posting before. The machine doesn't respond as long as the rsync - process isn't killed, because it fetches all the memory which gets free after a process has been killed.

And the rsync process never gets singled out? nice!

Until it's killed by the kernel (if overcommitment isn't deactivated). If overcommitment is deactivated, the services of the machine are dead forever. There will be nothing, which kills such a process. Or am I wrong?

Regards,
Andreas Hartmann

#2 lore raw
In reply to a message not in the archive
Quoted 12 lines · Andreas Hartmann
Quoted 9 lines · Zwane Mwaikambo
Quoted 6 lines · Andreas Hartmann

rsync allocates all of the memory the machine has (256 MB RAM, 128 MB swap). When this occures, processes get killed like described in the posting before. The machine doesn't respond as long as the rsync - process isn't killed, because it fetches all the memory which gets free after a process has been killed.

Quoted 5 lines
Quoted 2 lines

And the rsync process never gets singled out? nice!

Until it's killed by the kernel (if overcommitment isn't deactivated). If overcommitment is deactivated, the services of the machine are dead forever. There will be nothing, which kills such a process. Or am I wrong?

There is still the oom killer (Out Of Memory).
But it doesn't trigger and the machine pages "forever". Usually kswapd eats the CPU then, discarding and reloading pages, searching lists for pages to evict and so on.

#3 lore raw
Quoted 4 lines · Peter Wächtler

There is still the oom killer (Out Of Memory).
But it doesn't trigger and the machine pages "forever". Usually kswapd eats the CPU then, discarding and reloading pages, searching lists for pages to evict and so on.

On a -ac kernel with mode 2 or 3 set for overcommit you have to run out of kernel resources to hang the box. It won't go OOM because it can't. That wouldn't be a VM bug but a leak or poor handling of kernel allocations somewhere. Sadly the changes needed to do that (beancounter patch) were things Linus never accepted for 2.4

#4 lore raw
In reply to a message not in the archive
Quoted 8 lines · Alan Cox
Quoted 5 lines · Peter Wächtler

There is still the oom killer (Out Of Memory).
But it doesn't trigger and the machine pages "forever". Usually kswapd eats the CPU then, discarding and reloading pages, searching lists for pages to evict and so on.

Quoted 6 lines

On a -ac kernel with mode 2 or 3 set for overcommit you have to run out of kernel resources to hang the box. It won't go OOM because it can't. That wouldn't be a VM bug but a leak or poor handling of kernel allocations somewhere. Sadly the changes needed to do that (beancounter patch) were things Linus never accepted for 2.4

I heard of the "beancounter patch" several times now.
Where is it - that beancounter patch? What does it besides bean counting ;-) ah, googled it:

ftp://ftp.sw.com.sg/pub/Linux/people/saw/kernel/user_beancounter/UserBeancounter.html

I think we will get another candidate for beancounting: the futexes are locking user pages.. and I already thought about accounting with setrlimit/ulimit and "max locked memory (kbytes)"

#5 lore raw
In reply to a message not in the archive
Followup to:  <[email protected]>
By author:    Alan Cox <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 7 lines

On a -ac kernel with mode 2 or 3 set for overcommit you have to run out of kernel resources to hang the box. It won't go OOM because it can't. That wouldn't be a VM bug but a leak or poor handling of kernel allocations somewhere. Sadly the changes needed to do that (beancounter patch) were things Linus never accepted for 2.4

Well, if you can't fork a new process because that would push you into overcommit, then you usually can't actually do anything useful on the machine.

-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	<[email protected]>
#6 lore raw
Quoted 11 lines · H. Peter Anvin
Followup to:  <[email protected]>
By author:    Alan Cox <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 7 lines

On a -ac kernel with mode 2 or 3 set for overcommit you have to run out of kernel resources to hang the box. It won't go OOM because it can't. That wouldn't be a VM bug but a leak or poor handling of kernel allocations somewhere. Sadly the changes needed to do that (beancounter patch) were things Linus never accepted for 2.4

Quoted 3 lines

Well, if you can't fork a new process because that would push you into overcommit, then you usually can't actually do anything useful on the machine.

Thats actually easy to deal with and on my list for modes 4 and 5 (2 and 3 with root granted a reserved fraction)

#7 lore raw
Quoted 1 line · Alan Cox

On Mon, 2002-05-27 at 22:22, H. Peter Anvin wrote:

    <_snip_>
Quoted 6 lines
Quoted 3 lines

Well, if you can't fork a new process because that would push you into overcommit, then you usually can't actually do anything useful on the machine.

Thats actually easy to deal with and on my list for modes 4 and 5 (2 and 3 with root granted a reserved fraction)

It seems to me that selectively limiting the number of processes in a pgroup, or selectively killing large RSS programs in a large pgroup (non-root) would be one way to identify the processes which were either clone/fork looping, or have children begetting children. After than perhaps killing or restricting from the high numerical uid down. That might tend to spare system and/or well-behaved processes.

Comment?

Signature · 3 lines
bill davidsen <[email protected]>
  CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.
#8 lore raw
In reply to a message not in the archive
Quoted 3 lines · H. Peter Anvin

Well, if you can't fork a new process because that would push you into overcommit, then you usually can't actually do anything useful on the machine.

Just use vfork or clone + exec. It's faster and uses less memory.

-ben

Signature · 1 line
"You will be reincarnated as a toad; and you will be much happier."
#9 lore raw
Quoted 6 lines · Benjamin LaHaise
Quoted 3 lines · H. Peter Anvin

Well, if you can't fork a new process because that would push you into overcommit, then you usually can't actually do anything useful on the machine.

Just use vfork or clone + exec. It's faster and uses less memory.

In the general case a fork doesn't cause too much overcommit. Most of the binary is mapped read-only as is a lot of the library space. Since its read only and backed by a file it has zero cost. If you mprotect it then you pay at mprotect time

#10 lore raw
In reply to a message not in the archive
Quoted 9 lines · Benjamin LaHaise
Quoted 3 lines · H. Peter Anvin

Well, if you can't fork a new process because that would push you into overcommit, then you usually can't actually do anything useful on the machine.

Just use vfork or clone + exec. It's faster and uses less memory.

Doesn't help. exec() should fail.

-hpa

#11 lore raw
In reply to a message not in the archive
Quoted 1 line · H. Peter Anvin

Doesn't help. exec() should fail.

Only if you're out of memory (any sane app nowadays does not allocate memory from data/bss).

-ben

Signature · 1 line
"You will be reincarnated as a toad; and you will be much happier."
#12 lore raw
In reply to a message not in the archive
Quoted 7 lines · Benjamin LaHaise
Quoted 1 line · H. Peter Anvin

Doesn't help. exec() should fail.

Only if you're out of memory (any sane app nowadays does not allocate memory from data/bss).

.data/.bss is writable, and will need to be allocated to avoid overcommitment, so the exec() will fail.

-hpa

#13 lore raw
In reply to a message not in the archive
Quoted 3 lines · H. Peter Anvin
Quoted 3 lines
Quoted 3 lines

Well, if you can't fork a new process because that would push you into overcommit, then you usually can't actually do anything useful on the machine.

Quoted 1 line · Benjamin LaHaise
Quoted 1 line

Just use vfork or clone + exec. It's faster and uses less memory.

Quoted 4 lines · Alan Cox

In the general case a fork doesn't cause too much overcommit. Most of the binary is mapped read-only as is a lot of the library space. Since its read only and backed by a file it has zero cost. If you mprotect it then you pay at mprotect time

If you're willing to take a feature request, I'd be much obliged if the pagetable memory were also accounted.

Thanks,
Bill

#14 lore raw
Quoted 2 lines · William Lee Irwin III

If you're willing to take a feature request, I'd be much obliged if the pagetable memory were also accounted.

I suspect that is doable providing you are willing to handwave a few assumptions and be a fraction conservative. However I'm accounting against ram+swap. You need to account against ram only.

#15 lore raw
In reply to a message not in the archive
Quoted 21 lines · Peter Wächtler
Quoted 12 lines · Andreas Hartmann
Quoted 9 lines · Zwane Mwaikambo
Quoted 6 lines · Andreas Hartmann

rsync allocates all of the memory the machine has (256 MB RAM, 128 MB swap). When this occures, processes get killed like described in the posting before. The machine doesn't respond as long as the rsync - process isn't killed, because it fetches all the memory which gets free after a process has been killed.

Quoted 7 lines
Quoted 2 lines

And the rsync process never gets singled out? nice!

Until it's killed by the kernel (if overcommitment isn't deactivated). If overcommitment is deactivated, the services of the machine are dead forever. There will be nothing, which kills such a process. Or am I wrong?

Quoted 4 lines

There is still the oom killer (Out Of Memory).
But it doesn't trigger and the machine pages "forever". Usually kswapd eats the CPU then, discarding and reloading pages, searching lists for pages to evict and so on.

can you reproduce with 2.4.19pre9aa2? I expect at least the deadlock (if it's a deadlock and not a livelock) should go away.

Also I read in another email that somebody grown the per-socket buffer to hundred mbytes, if you do that on a 32bit arch with highmem you'll run into troubles, too much ZONE_NORMAL ram will be constantly pinned for the tcp pipeline and the machine can enter livelocks.

Andrea

#16 lore raw
In reply to a message not in the archive

Hello Andrea,

Quoted 31 lines · Andrea Arcangeli
Quoted 20 lines · Peter Wächtler
Quoted 18 lines · Andreas Hartmann
Quoted 13 lines · Zwane Mwaikambo
Quoted 6 lines · Andreas Hartmann

rsync allocates all of the memory the machine has (256 MB RAM, 128 MB swap). When this occures, processes get killed like described in the posting before. The machine doesn't respond as long as the rsync - process isn't killed, because it fetches all the memory which gets free after a process has been killed.

And the rsync process never gets singled out? nice!

Quoted 7 lines
Quoted 2 lines

Until it's killed by the kernel (if overcommitment isn't deactivated). If overcommitment is deactivated, the services of the machine are dead forever. There will be nothing, which kills such a process. Or am I wrong?

There is still the oom killer (Out Of Memory).
But it doesn't trigger and the machine pages "forever". Usually kswapd eats the CPU then, discarding and reloading pages, searching lists for pages to evict and so on.

Quoted 7 lines

can you reproduce with 2.4.19pre9aa2? I expect at least the deadlock (if it's a deadlock and not a livelock) should go away.

Also I read in another email that somebody grown the per-socket buffer to hundred mbytes, if you do that on a 32bit arch with highmem you'll run into troubles, too much ZONE_NORMAL ram will be constantly pinned for the tcp pipeline and the machine can enter livelocks.

I tested it and the error-situation occured again (thanks to rsync :-)).

How did the kernel react?
Well, I waited some seconds until all the memory was in use (256 MB RAM and 128 MB swap). I have to say, nearly all the memory, because there was allways some MB's free in RAM. So I was able to login via ssh as root. As I wanted to do something, the machine didn't react. Until this point, the machine seemed to work fine - xosview through ssh showed the activity very well. But then it crashed, because it couldn't open /proc/stat:
Can not open file : /proc/stat
Some seconds later, the machine was working normal again. What happened?
/var/log/messages says:

Jun  1 14:03:46 susi squid[271]: Squid Parent: child process 273 exited due to signal 9
Jun  1 14:03:48 susi kernel: __alloc_pages: 0-order allocation failed (gfp=0x1d2/0)
Jun  1 14:03:48 susi kernel: __alloc_pages: 0-order allocation failed (gfp=0x1d2/0)
Jun  1 14:03:48 susi kernel: VM: killing process squid
Jun  1 14:04:05 susi kernel: __alloc_pages: 0-order allocation failed (gfp=0x1f0/0)
Jun  1 14:04:07 susi kernel: __alloc_pages: 0-order allocation failed (gfp=0xf0/0)
Jun  1 14:04:11 susi kernel: __alloc_pages: 0-order allocation failed (gfp=0x1f0/0)
Jun  1 14:04:25 susi kernel: __alloc_pages: 0-order allocation failed (gfp=0x1d2/0)
Jun  1 14:04:25 susi kernel: VM: killing process rsync

The kernel killed the maliciuos rsync-process.
Not nice was, that the kernel killed squid, too. If it didn't kill squid it would have been a very good result. On the other hand, squid had already problems - so it was probably a good idea to kill it completely to make room for other running programs.

I would like to know, if the killing of rsync was pure chance or if it was systematically. I will try it again :-).

Regards,
Andreas Hartmann

#17 lore raw
In reply to a message not in the archive

Hello Andrea,

Quoted 2 lines
Quoted 1 line

Andreas Hartmann wrote:

Andrea Arcangeli wrote:

[...]

Quoted 27 lines
Quoted 8 lines

can you reproduce with 2.4.19pre9aa2? I expect at least the deadlock (if it's a deadlock and not a livelock) should go away.

Also I read in another email that somebody grown the per-socket buffer
to hundred mbytes, if you do that on a 32bit arch with highmem you'll run into troubles, too much ZONE_NORMAL ram will be constantly pinned for the tcp pipeline and the machine can enter livelocks.

I tested it and the error-situation occured again (thanks to rsync :-)).

How did the kernel react?
Well, I waited some seconds until all the memory was in use (256 MB RAM
and 128 MB swap). I have to say, nearly all the memory, because there was allways some MB's free in RAM. So I was able to login via ssh as root. As I wanted to do something, the machine didn't react. Until this
point, the machine seemed to work fine - xosview through ssh showed the
activity very well. But then it crashed, because it couldn't open /proc/stat:
Can not open file : /proc/stat
Some seconds later, the machine was working normal again. What happened?
/var/log/messages says:

[...]

Quoted 2 lines

I would like to know, if the killing of rsync was pure chance or if it was systematically. I will try it again :-).

I did now two more tests. The kernel reacted nearly as described above. The malicious process was killed but one time unfortunately xosview, too. I always tried to open a new ssh session, wich always worked. Even
innd was able to server some news-postings :-).

If the kernel always only would kill the malicious process, it would be really great and probably the solution of a really big problem of 2.4.-kernels!

1. try

Jun  1 14:40:58 susi PAM_unix[2650]: (sshd) session closed for user root
Jun  1 14:42:08 susi sshd[2660]: Accepted publickey for root from 192.168.1.3 port 32987 ssh2
Jun  1 14:42:20 susi PAM_unix[2660]: (sshd) session opened for user root by (uid=0)
Jun  1 14:44:36 susi kernel: __alloc_pages: 0-order allocation failed (gfp=0x1d2/0)
Jun  1 14:44:36 susi kernel: VM: killing process rsync

2. try

Jun  1 14:49:00 susi PAM_unix[2804]: (sshd) session closed for user root
Jun  1 14:50:21 susi sshd[2813]: Accepted publickey for andreas from 192.168.1.3 port 32991 ssh2
Jun  1 14:50:27 susi PAM_unix[2813]: (sshd) session opened for user andreas by (uid=0)
Jun  1 14:51:37 susi kernel: __alloc_pages: 0-order allocation failed (gfp=0x1f0/0)
Jun  1 14:51:46 susi last message repeated 2 times
Jun  1 14:51:50 susi kernel: __alloc_pages: 0-order allocation failed (gfp=0x1d2/0)
Jun  1 14:51:50 susi kernel: VM: killing process xosview
Jun  1 14:52:03 susi kernel: __alloc_pages: 0-order allocation failed (gfp=0x1d2/0)
Jun  1 14:52:03 susi kernel: VM: killing process rsync

The problems of resync always occure if the rsync-process on the other side is stoped with CTRL-C e.g. At this moment, the ssh-connection to the host susi is closed, which rsync obviously can't handle correctly. That's why it's very easy for me to reproduce the situation and how the kernel is acting.

Regards,
Andreas Hartmann

#18 lore raw
In reply to a message not in the archive
Quoted 77 lines · Andreas Hartmann

Hello Andrea,

Quoted 34 lines · Andrea Arcangeli
Quoted 26 lines · Peter Wächtler
Quoted 15 lines · Andreas Hartmann
Quoted 11 lines · Zwane Mwaikambo
Quoted 6 lines · Andreas Hartmann

rsync allocates all of the memory the machine has (256 MB RAM, 128 MB swap). When this occures, processes get killed like described in the posting before. The machine doesn't respond as long as the rsync - process isn't killed, because it fetches all the memory which gets free after a process has been killed.

Quoted 8 lines
Quoted 2 lines

And the rsync process never gets singled out? nice!

Until it's killed by the kernel (if overcommitment isn't deactivated). If overcommitment is deactivated, the services of the machine are dead forever. There will be nothing, which kills such a process. Or am I wrong?

Quoted 4 lines

There is still the oom killer (Out Of Memory).
But it doesn't trigger and the machine pages "forever". Usually kswapd eats the CPU then, discarding and reloading pages, searching lists for pages to evict and so on.

Quoted 7 lines

can you reproduce with 2.4.19pre9aa2? I expect at least the deadlock (if it's a deadlock and not a livelock) should go away.

Also I read in another email that somebody grown the per-socket buffer to hundred mbytes, if you do that on a 32bit arch with highmem you'll run into troubles, too much ZONE_NORMAL ram will be constantly pinned for the tcp pipeline and the machine can enter livelocks.

I tested it and the error-situation occured again (thanks to rsync :-)).

How did the kernel react?
Well, I waited some seconds until all the memory was in use (256 MB RAM and 128 MB swap). I have to say, nearly all the memory, because there was allways some MB's free in RAM. So I was able to login via ssh as root. As I wanted to do something, the machine didn't react. Until this point, the machine seemed to work fine - xosview through ssh showed the activity very well. But then it crashed, because it couldn't open /proc/stat:
Can not open file : /proc/stat
Some seconds later, the machine was working normal again. What happened?
/var/log/messages says:

Jun  1 14:03:46 susi squid[271]: Squid Parent: child process 273 exited 
due to signal 9
Jun  1 14:03:48 susi kernel: __alloc_pages: 0-order allocation failed 
(gfp=0x1d2/0)
Jun  1 14:03:48 susi kernel: __alloc_pages: 0-order allocation failed 
(gfp=0x1d2/0)
Jun  1 14:03:48 susi kernel: VM: killing process squid
Jun  1 14:04:05 susi kernel: __alloc_pages: 0-order allocation failed 
(gfp=0x1f0/0)
Jun  1 14:04:07 susi kernel: __alloc_pages: 0-order allocation failed 
(gfp=0xf0/0)
Jun  1 14:04:11 susi kernel: __alloc_pages: 0-order allocation failed 
(gfp=0x1f0/0)
Jun  1 14:04:25 susi kernel: __alloc_pages: 0-order allocation failed 
(gfp=0x1d2/0)
Jun  1 14:04:25 susi kernel: VM: killing process rsync
Quoted 3 lines

The kernel killed the maliciuos rsync-process.
Not nice was, that the kernel killed squid, too. If it didn't kill squid it would have been a very good result. On the other hand, squid had

squid or any other task could as well have more memory allocated than rsync, so the oom killer heuristic could get wrong it too. There's simply no way that the kernel will be able to do the right choice always without user intervention, no-way. Adding the allocation rate of tasks would be a good start, much better than the current oom killer heuristic that will fail on any real non-desktop server usage with 90% of virtual memory always allocated in non malicious tasks.

Quoted 5 lines

already problems - so it was probably a good idea to kill it completely to make room for other running programs.

I would like to know, if the killing of rsync was pure chance or if it was systematically. I will try it again :-).

it was systemaltically. If will eventually be killed as you expect. The only problem is that something else may be killed too in the meantime, but the kernel can always do the wrong choice anyways, and being guaranteed of no-deadlock is much better than the current status of mainline.

we had some discussion with Andrew on l-k last month on how to be safe and to still allow an heuristic to make a first-choice based on some statistic, but that's low prio for me. no matter what we do the kernel can always do the wrong thing and have to kill task without the userspace being aware of the error condition.

Andrea

#19 lore raw
In reply to a message not in the archive
Quoted 31 lines · Andrea Arcangeli
Quoted 20 lines · Peter Wächtler
Quoted 18 lines · Andreas Hartmann
Quoted 14 lines · Zwane Mwaikambo
Quoted 7 lines · Andreas Hartmann

rsync allocates all of the memory the machine has (256 MB RAM, 128 MB swap). When this occures, processes get killed like described in the posting before. The machine doesn't respond as long as the rsync - process isn't killed, because it fetches all the memory which gets free after a process has been killed.

And the rsync process never gets singled out? nice!

Quoted 8 lines
Quoted 3 lines

Until it's killed by the kernel (if overcommitment isn't deactivated). If overcommitment is deactivated, the services of the machine are dead forever. There will be nothing, which kills such a process. Or am I wrong?

There is still the oom killer (Out Of Memory).
But it doesn't trigger and the machine pages "forever". Usually kswapd eats the CPU then, discarding and reloading pages, searching lists for pages to evict and so on.

Quoted 8 lines

can you reproduce with 2.4.19pre9aa2? I expect at least the deadlock (if it's a deadlock and not a livelock) should go away.

Also I read in another email that somebody grown the per-socket buffer to hundred mbytes, if you do that on a 32bit arch with highmem you'll run into troubles, too much ZONE_NORMAL ram will be constantly pinned for the tcp pipeline and the machine can enter livelocks.

Sorry for the confusion.
I was just trying to explain that without overcommitment there would be the "normal" OOM handling. But I don't know this feature from the -ac kernels. Am I wrong?

It's Andreas who has the problem with rsync being killed and the machine seems to hang.
But I still think that the buffer cache has to be better restricted. The vm is caching far too aggressively (but I never tried with -aa)