On Wed, Aug 21, 2013 at 11:49 PM, Simon Paillard <spaill...@debian.org> wrote:
> Control: tag -1 +upstream
>
> On Mon, Apr 02, 2012 at 08:43:17PM -0400, A. Costa wrote:
>> Package: manpages
>> Version: 3.35-0.1
>> Severity: normal
>>
>> Dear Maintainer,
>>
>>     % man proc | grep -A 2 -n '/proc/partition'
>>     988:       /proc/partitions
>>     989-              Contains major and minor numbers of each partition as 
>> well as number of
>>     990-              blocks and partition name.
>>
>> There's no mention of how many bytes are in a block, and no description of 
>> how
>> block numbers are counted.
>
> A full definition of fields is available in the kernel tree:
> http://lxr.linux.no/#linux+v3.5/Documentation/iostats.txt
>
> We can either just point to that doc in the manpage, or document all the 
> fields
> of /proc/partition.

It would I think be best to have this information in the man page.
But, I cannot see where you are finding the info in
Documentation/iostats.txt, Simon.

A. Costa: From scanning the source code (where the count of blocks is
"part_nr_sects_read(part) >> 1" in block/genhd.c::show_partition() --
I assume a sector is 512 B), I'm reasonably sure that /proc/partitions
is giving us 1024-byte blocks. Here's my experiment:

$ cat /proc/partitions | grep sdc1
   8       33 1465136128 sdc1
$ df -B 1024 | grep sdc1
/dev/sdc1      1464421040 447518960 1016902080  31% /run/media/mtk/CNM1500
$ bc -q
1465136128 * 1000000 / 1464421040
1000488

In other words, the difference between the two values is just under
0.05%. Looking at the source code of 'df', it gets it's information
using the statvfs() function which in turn calls statfs(2). I
confirmed that direct statfs(2) calls return information precisely
consistent with the output of df.

The question is still why there is a difference between blocks as
reported by statfs() and /proc/partitions, with the latter always a
little bigger than the former. Well, looking at the statfs()
implementation (fs/statfs.c), the relevant field pulled from kernel
data structures is 'f_blocks', and looking in (for example),
fs/ext4/super.c::ext4_statfs(),, I find:

        buf->f_blocks = ext4_blocks_count(es) - EXT4_C2B(sbi, overhead);

"sbi" is super block info.

That looks to me to mean that stafs() is deducting a small amount from
the number of blocks, for the overhead of the super block info, and
without digging too much further, I'm going to guess that that might
explain the difference from /proc/partitions. However, that's all
fairly speculative, so I'm not confident enough to put too much detail
into the page. However, I did apply the small patch below:

Cheers,

Michael

diff --git a/man5/proc.5 b/man5/proc.5
index e40dd4d..95eb743 100644
--- a/man5/proc.5
+++ b/man5/proc.5
@@ -2160,7 +2160,7 @@ socket and Path is the bound path (if any) of the socket.
 .TP
 .I /proc/partitions
 Contains major and minor numbers of each partition as well as number
-of blocks and partition name.
+of 1024-byte blocks and partition name.
 .TP
 .I /proc/pci
 This is a listing of all PCI devices found during kernel initialization


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to