mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Navin P <navinp1912@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Why is SECTOR_SIZE = 512 inside kernel ?
Date: Mon, 17 Aug 2015 09:54:50 -0400	[thread overview]
Message-ID: <20150817135450.GB27202@thunk.org> (raw)
In-Reply-To: <CAA=4086O2qJT53wh9Qq8K5-8aRxtHrf5Ybnjrw39Vp8L3PrVqQ@mail.gmail.com>

On Mon, Aug 17, 2015 at 06:23:04PM +0530, Navin P wrote:
> 
>  Why is SECTOR_SIZE 512 ?
> 
> http://lxr.free-electrons.com/source/include/linux/ide.h#L118
> 
> http://lxr.free-electrons.com/source/include/linux/device-mapper.h#L548
> 
> 548 #define SECTOR_SHIFT 9
> 
> I was looking at disks with hw_sector_size . Most of them i looked at
> had 512 bytes except for one which had 4096 (virtual disk). The one
> with AF format ie has logical sector size as 512 and hw_sector_size as
> 512 . So it is fine for my calculation from /proc/diskstats.
> 
> But the one with 4096 logical and 4096 physical i multiply
> hw_sector_size with the sectors read and written but that is wrong
> since the kernel always defines sectors in terms of 512.
> 
> Is it going to change or is it  cast in stone ?

It's cast in stone.  There are too many places all over the kernel,
especially in a huge number of file systems, which assume that the
sector size is 512 bytes.  So above the block layer, the sector size
is always going to be 512.

This is actually *better* for user space programs using
/proc/diskstats, since they don't need to know whether a particular
underlying hardware is using 512, 4k, (or if the HDD manufacturers
fantasies become true 32k or 64k) sector sizes.

For similar reason, st_blocks in struct size is always in units of 512
bytes.  We don't want to force userspace to have to figure out whether
the underlying file system is using 1k, 2k, or 4k.  For that reason
the units of st_blocks is always going to be 512 bytes, and this is
hard-coded in the POSIX standard.

					- Ted

  reply	other threads:[~2015-08-17 13:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-17 12:53 Navin P
2015-08-17 13:54 ` Theodore Ts'o [this message]
2015-08-18 21:06   ` Brice Goglin
2015-08-18 21:38     ` tytso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150817135450.GB27202@thunk.org \
    --to=tytso@mit.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=navinp1912@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®