lkml.org 
[lkml]   [2000]   [Mar]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: Avoiding OOM on overcommit...?
In <87r9czjty5.fsf@infovore.xs4all.nl> Olaf Weber (olaf@infovore.xs4all.nl) wrote:
> Sandy Harris writes:

>> Earlier in this thread, though, someone suggested replacing malloc()
>> with calloc() to ensure that space actually gets allocated. That should
>> not be necessary.

> Nor should it work, because the implementation of calloc relies on the
> kernel zeroing new pages, and therefore won't touch new pages.

It WORKS. Not perfectly but works. If calloc returned something it's your
memory but it can just kill program... For buffer prealloction in deamons
it should be enough though.

Take a look:
-- cut --
[khim@localhost khim]$ for i in 0 1 2 3 4 ; do { ./test c & ./test m & } ; done
[1] 896
[2] 897
[3] 898
[4] 899
[5] 900
[6] 901
[7] 902
[8] 903
[9] 904
[10] 905

[2]+ Stopped ./test m

[4] Stopped ./test m

[6]- Stopped ./test m
[khim@localhost khim]$ VM: killing process test
VM: killing process test
VM: killing process test
ps l
FLAGS UID PID PPID PRI NI SIZE RSS WCHAN STA TTY TIME COMMAND
100 503 863 862 10 0 2156 568 wait4 S 3 0:00 -bash
0 503 897 863 0 0 52204 48 do_signal T 3 0:00 ./test m
0 503 898 863 6 0 52204 51376 do_signal T 3 0:04 ./test c
0 503 899 863 0 0 52204 48 do_signal T 3 0:00 ./test m
0 503 901 863 0 0 52204 48 do_signal T 3 0:00 ./test m
0 503 903 863 0 0 52204 48 do_signal T 3 0:00 ./test m
0 503 904 863 12 0 52204 51376 do_signal T 3 0:04 ./test c
0 503 905 863 0 0 52204 48 do_signal T 3 0:00 ./test m
0 503 908 863 11 0 1444 560 R 3 0:00 ps l
[1] Killed ./test c

[3]- Stopped ./test c
[5] Killed ./test c
[7] Killed ./test c

[8] Stopped ./test m

[9]+ Stopped ./test c

[10] Stopped ./test m
[khim@localhost khim]$ cat test.c
#include <string.h>
#include <stdio.h>

int main(int argc,char *argv[]) {
/* Allocate 50MiB of memory */
if (strcmp(argv[1],"c"))
malloc(50*1024*1024);
else
calloc(1,50*1024*1024);
getchar();
}
[khim@localhost khim]$
-- cut --





-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:57    [W:0.098 / U:1.656 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site