Re: ~500 megs cached yet 2.6.5 goes into swap hell

Jeff Garzik
2004-04-29T00:13:59Z

[-- Attachment #1: Type: text/plain, Size: 695 bytes --]

Brett E. wrote:
> exits, freeing up the malloc'ed memory. This brings free memory up by
> 400 megs and brings the cache down to close to 0, of course the cache

Yeah, I have something similar (attached). Run it like

fillmem <number-of-megabytes>

> grows right afterwards. It would be nice to cap the cache datastructures
> in the kernel but I've been posting about this since September to no
> avail so my expectations are pretty low.

This is a frequent request... although I disagree with a hard cap on
the cache, I think the request (and similar ones) should hopefully
indicate to the VM gurus that the kernel likes cache better than anon
VMAs that must be swapped out.

Jeff

[-- Attachment #2: fillmem.c --]
[-- Type: text/plain, Size: 707 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#define MEGS 140
#define MEG (1024 * 1024)

int main (int argc, char *argv[])
{
void **data;
int i, r;
size_t megs = MEGS;

if ((argc >= 2) && (atoi(argv[1]) > 0))
megs = atoi(argv[1]);

data = malloc (megs * sizeof (void*));
if (!data) abort();

memset (data, 0, megs * sizeof (void*));

srand(time(NULL));

for (i = 0; i < megs; i++) {
data[i] = malloc(MEG);
memset (data[i], i, MEG);
printf("malloc/memset %03d/%03lu\n", i+1, megs);
}
for (i = megs - 1; i >= 0; i--) {
r = rand() % 200;
memset (data[i], r, MEG);
printf("memset #2 %03d/%03lu = %d\n", i+1, megs, r);
}
printf("done\n");
return 0;
}