Fwd: swapon and swapoff testcases on busybox
Luciano Miguel Ferreira Rocha
strange at nsk.no-ip.org
Tue Mar 13 03:54:51 PDT 2007
On Tue, Mar 13, 2007 at 01:09:30PM +0530, Riaz Rahaman wrote:
> / # dd if=/dev/zero of=swappyfile bs=1 count=1 seek=500000
> 1+0 records in
> 1+0 records out
That creates a file with holes, and the kernel *doesn't* support that.
Swap files are already chaotic enough without supporting filesystem
block allocation on critically low memory cases.
> / # ./stat_riaz --> a small binary that does a stat on swappyfile and
Don't forget mkswap.
Just tested here, a file with holes and one without, and swapon using
the simple program:
#include <unistd.h>
#include <asm/page.h>
#include <sys/swap.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
while (*++argv) {
if (swapon(*argv, 0))
perror(*argv);
}
}
return 0;
}
# dd if=/dev/zero of=swp bs=1 count=1 seek=128000000 # with holes
# mkswap swp
Setting up swapspace version 1, size = 127995 kB
# ./swpo swp
swp: Invalid argument
# dd if=/dev/zero of=swp2 bs=100000 count=1280 # w/o holes
# mkswap swp2
Setting up swapspace version 1, size = 127995 kB
# ./swpo swp2
# grep swp /proc/swaps
/root/swp2 file 124992 0 -3
> prints the below values
> stat_buf.st_blocks: 506
> stat_buf.st_size: 500001
> stat_buf.st_blksize: 512
# stat swp swp2 | grep Block
Size: 128000001 Blocks: 32 IO Block: 4096 regular file
Size: 128000000 Blocks: 250256 IO Block: 4096 regular file
Note that IO Block is *IO* Block, not block size:
$ man 2 stat
...
The st_blocks field indicates the number of blocks allocated to the
file, 512-byte units. (This may be smaller than st_size/512, for exam-
ple, when the file has holes.)
The st_blksize field gives the "preferred" blocksize for efficient file
system I/O. (Writing to a file in smaller chunks may cause an ineffi-
cient read-modify-rewrite.)
...
--
lfr
0/0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://busybox.net/lists/busybox/attachments/20070313/bb29d256/attachment.pgp
More information about the busybox
mailing list