Subject: Re: Getting block size for swap devices and files
To: None <tech-kern@netbsd.org>
From: Emmanuel Dreyfus <manu@netbsd.org>
List: tech-kern
Date: 03/28/2002 17:52:18
Since I finnally found, I'm replying to myself. Who knows, it could be
usefull for someone else one day.

> On my system, the value seems to always be 512, but I don't beleive this
> is really constant. Is it?

It is. 

The value for block size hold in struct swapdev (sys/uvm/uvm_swap.c) is
only used for I/O for swap on regular files. It is initialized as the
block size of the underlying block device, which is not necessarily 512.
It's unused, useless, and uninitialized for block devices swap objects.
This value is not used for anything else than I/O for swap on regular
files. This block size is never exposed to userland.

The swap block size as seen in userland is used to fill the se_nblks
field of struct swapent (it's the size of the swap object in blocks).
Still in uvm_swap.c, at the beginning of swap_on, we get nblocks, then
we fill se_nblks of struct swapent with it. nblocks is obtained by a
stat call, using the size in bytes and applying btodb() on it.

btodb is MD, for mips it's defined in <arch/mips/include/mips_param.h>
as:

#define btodb(x) ((x) >> DEV_BSHIFT)

DEV_BSHIFT is defined in <arch/sgimips/include/param.h> as:

#define DEV_BSHIFT 9

Conslusion: the swap block size is constant for a given arch,
it's value is  (1 << DEV_BSHIFT). And, by a quick grep in the MD
headers, it seems to be 512 for all archs...

-- 
Emmanuel Dreyfus.
Si la reponse est NT, c'est probablement 
que vous n'avez pas compris la question.
manu@netbsd.org