Re: Memory management

Harald Koenig (koenig@tat.physik.uni-tuebingen.de)
Thu, 28 Nov 1996 13:48:46 +0100 (MET)


> I'm not sure what Maple's memory access patterns are (pretty chaotic,
> probably), but Linux memory management sure isn't suited for them...

even sequential access to one large array isn't any different

> 8:52pm up 7 days, 9:49, 1 user, load average: 1.05, 1.03, 0.70
> 30 processes: 27 sleeping, 3 running, 0 zombie, 0 stopped
> CPU states: 12.4% user, 1.7% system, 0.0% nice, 95.0% idle
> Mem: 63300K av, 62532K used, 768K free, 1528K shrd, 68K buff
> Swap: 130624K av, 27376K used, 103248K free 1212K cached
>
> PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND
> 18038 ig25 10 0 64356 56756 228 R 48 4.1 89.6 44:59 mapleV
> 18037 ig25 0 0 15732 516 396 S 204 0.0 0.8 2:39 irisVxm
> 18377 ig25 0 0 568 368 344 S 0 0.0 0.5 0:00 bash

here is the "top" output when running "eatmem" (source below) which is
just trashing 30MB memory (32MB DRAM installed). note that the RSSs of
alll processes sum up to 26456K vs. 30304K "used memory".

1:41pm up 1 day, 12:20, 4 users, load average: 0.98, 0.43, 0.15
41 processes: 36 sleeping, 2 running, 0 zombie, 3 stopped
CPU states: 3.9% user, 7.1% system, 0.0% nice, 89.4% idle
Mem: 30688K av, 30304K used, 384K free, 1716K shrd, 376K buff
Swap: 32752K av, 14608K used, 18144K free 680K cached

PID USER PRI NI SIZE RES SHRD STAT %CPU %MEM TIME COMMAND
1628 root 19 0 30924 23772 0 R 3.1 77.4 0:04 eatmem 30000 loop
1627 root 19 0 952 280 164 R 2.8 0.9 0:03 top
195 root 12 0 7892 608 316 S 2.4 1.9 17:56 /soft/Xserver/XV :0
3 root -7 -12 0 0 0 SW< 0.9 0.0 0:01 kswapd
209 root 4 0 2092 256 152 S 0.7 0.8 2:11 xsysinfo -geometry 2
223 root 4 0 2632 288 188 S 0.5 0.9 0:02 xterm -ls -tn vt100
207 root 1 0 1972 184 100 S 0.1 0.5 0:02 xeyes -geometry 150x
208 root 1 0 2116 296 184 S 0.1 0.9 0:00 xload -geometry 100x
1 root 0 0 868 0 0 SW 0.0 0.0 0:14 init
2 root 0 0 0 0 0 SW 0.0 0.0 0:00 kflushd
180 root 0 0 1244 8 8 S 0.0 0.0 0:00 sh
181 root 0 0 936 0 0 SW 0.0 0.0 0:00 getty
6 root 0 0 840 32 20 S 0.0 0.1 0:04 update (bdflush)
28 root 0 0 0 0 0 SW 0.0 0.0 0:00 nfsiod
29 root 0 0 0 0 0 SW 0.0 0.0 0:00 nfsiod
30 root 0 0 0 0 0 SW 0.0 0.0 0:00 nfsiod
31 root 0 0 0 0 0 SW 0.0 0.0 0:00 nfsiod
173 root -10 -10 964 100 56 S < 0.0 0.3 0:00 dcf -j -D0 -R1 -ds -
130 root 0 0 884 0 0 SW 0.0 0.0 0:00 inetd
134 root 0 0 872 0 0 SW 0.0 0.0 0:00 portmap
143 root 0 0 864 32 32 S 0.0 0.1 0:00 syslogd
152 root 0 0 904 4 4 S 0.0 0.0 0:00 rpc.mountd
156 root 0 0 1056 0 0 SW 0.0 0.0 1:35 rpc.nfsd
161 root 0 0 884 4 4 S 0.0 0.0 0:00 cron
174 root 0 0 840 28 20 S 0.0 0.0 0:00 tee -a /usr/adm/J-DC
175 root -10 -10 848 4 4 S < 0.0 0.0 0:00 gbz1
176 root 0 0 840 0 0 SW 0.0 0.0 0:00 tee
187 root 0 0 1164 0 0 SW 0.0 0.0 0:00 startx
182 root 0 0 936 0 0 SW 0.0 0.0 0:00 getty
183 root 0 0 936 0 0 SW 0.0 0.0 0:00 getty
184 root 0 0 940 0 0 SW 0.0 0.0 0:00 getty
185 root 0 0 852 48 28 S 0.0 0.1 0:00 selection -b9600 -s1
194 root 0 0 1480 28 28 S 0.0 0.0 0:00 xinit
197 root 0 0 2772 140 140 S 0.0 0.4 0:37 xterm
206 root 0 0 2076 200 120 S 0.0 0.6 0:00 xclock -geometry 100
222 root 0 0 2304 124 124 S 0.0 0.4 0:02 twm
266 root 0 0 1248 4 4 S 0.0 0.0 0:00 sh
1424 root 0 0 1212 8 8 T 0.0 0.0 0:02 elm
1385 root 0 0 1400 0 0 TW 0.0 0.0 0:11 elm
916 root 0 0 1384 0 0 TW 0.0 0.0 0:00 bash
267 root 0 0 1272 8 8 S 0.0 0.0 0:05 sh

Harald
-------------------------------------------------------------------------------
/*
* eatmem.c -- allocate a junk of memory and make it dirty
* Copyright Harald Koenig <koenig@tat.physik.uni-tuebingen.de> 1994
*
* Permission is hereby granted to copy, modify and redistribute this code
* in terms of the GNU Library General Public License, Version 2 or later,
* at your option.
*
* to compile use
* cc -O2 -Wall -fomit-frame-pointer -N -s -o eatmem eatmem.c
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <malloc.h>

void main(int argc, char *argv[])
{
int i;
char *b=NULL,*pb;
int n=(-1);
int err=0, exit_flag=0, loop_flag=0;

if (argc >= 2) {
n = atoi(argv[1]);
if (argc == 3) {
if (!strcmp(argv[2],"pause")) exit_flag = 0;
else if (!strcmp(argv[2],"exit" )) exit_flag = 1;
else if (!strcmp(argv[2],"loop" )) loop_flag = 1;
else err=1;
}
else if (argc > 3) err=1;
}
if (n<=0 || err) {
fprintf(stderr,"usage: eatmem size_in_kb [ pause | exit | loop ]\n");
exit(1);
}

b = malloc(n*1024);
if (b == NULL) {
fprintf(stderr,"malloc failed.\n");
exit(1);
}

do {
pb = b;
for (i=0; i<n; i++) {
(*pb)++;
pb += 1024;
}
} while (loop_flag);

write(1,"\007",1);
if (!exit_flag)
kill(0,SIGSTOP);
exit(0);
}

--
All SCSI disks will from now on                     ___       _____
be required to send an email notice                0--,|    /OOOOOOO\
24 hours prior to complete hardware failure!      <_/  /  /OOOOOOOOOOO\
                                                    \  \/OOOOOOOOOOOOOOO\
                                                      \ OOOOOOOOOOOOOOOOO|//
Harald Koenig,                                         \/\/\/\/\/\/\/\/\/
Inst.f.Theoret.Astrophysik                              //  /     \\  \
koenig@tat.physik.uni-tuebingen.de                     ^^^^^       ^^^^^