#666972 proc(5): /proc/partition block size and count method undocumented

#666972#5
Date:
2012-04-03 00:43:17 UTC
From:
To:
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.

The counting method seems relevant since 'df' returns different numbers; numbers
which must have been counted using a different method:

    % D=/proc/partitions
    % cat $D | grep -w $D
       8       37   58348048 sdc5

    # show 'df /dev/sdc5' output, 1000 bytes per block
    % df -B 1KB $D
    Filesystem     1kB-blocks     Used Available Use% Mounted on
    /dev/sdc5        58765693 47037772   9337988  84% /tmp

    # Again, with 1024 byte blocks:
    % df -B 1K  $D
    Filesystem     1K-blocks     Used Available Use% Mounted on
    /dev/sdc5       57388372 45935324   9119128  84% /tmp

Summary:

    1024b	57388372
    1000b	58765693
    proc	58348048

Neither 'df' block size matches 'proc'.

HTH...

#666972#10
Date:
2013-08-21 21:49:16 UTC
From:
To:
Control: tag -1 +upstream
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.

#666972#17
Date:
2013-09-04 14:28:32 UTC
From:
To:
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