swap partition seems faster than a swap file (Re: [SHR-Unstable] swapon: swapfile has holes)
Timo Juhani Lindfors
timo.lindfors at iki.fi
Sun Sep 6 10:25:33 CEST 2009
Matthias Huber <matthias.huber at wollishausen.de> writes:
> afaik, it is much faster than file.
On a computer with 256M ram and compact flash as storage I ran
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define BUFSIZE (400*1024*1024)
int main(int argc, char *argv[]) {
char *p;
int i;
int ret;
puts("allocating memory");
p = malloc(BUFSIZE);
assert(p);
puts("writing to memory");
for (i = 0; i < BUFSIZE; i++) {
p[i] ^= 3;
}
puts("reading from memory");
for (i = 0; i < BUFSIZE; i++) {
ret ^= p[i];
}
return ret;
}
with both cases. It seems that partition is somewhat faster indeed:
256M swap partition:
$ for i in 1 2 3 4; do time ./a.out ; done
allocating memory
writing to memory
reading from memory
real 3m47.793s
user 0m27.282s
sys 0m5.592s
allocating memory
writing to memory
reading from memory
real 3m16.614s
user 0m27.114s
sys 0m5.624s
allocating memory
writing to memory
reading from memory
real 3m10.966s
user 0m27.010s
sys 0m5.456s
allocating memory
writing to memory
reading from memory
real 3m14.328s
user 0m27.106s
sys 0m5.160s
256M swap file:
allocating memory
writing to memory
reading from memory
real 6m19.494s
user 0m27.630s
sys 0m6.956s
allocating memory
writing to memory
reading from memory
real 3m49.047s
user 0m27.698s
sys 0m5.028s
allocating memory
writing to memory
reading from memory
real 4m18.462s
user 0m27.442s
sys 0m5.296s
allocating memory
writing to memory
reading from memory
real 4m1.905s
user 0m27.858s
sys 0m4.928s
More information about the community
mailing list