Supporting efficient operations on drives with 4K physical sectors

Matthew Dillon dillon at apollo.backplane.com
Mon Dec 28 10:44:15 PST 2009


    It looks like a number of newer drives are going to a 4K physical
    sector size (but retaining the 512 byte logical sector size for
    the interface).  Properly aligned operations wind up being more
    efficient.

    So here's the issue for us.  The fdisk program initializes slice 1
    starting at (512 byte) sector #63 instead of 64 in order to align
    to the system's idea of a cylinder boundary.  This is due to
    the 63 sectors/track value:

cylinders=242251 heads=256 sectors/track=63 (16128 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 165,(DragonFly/FreeBSD/NetBSD/386BSD)
    start 63, size 3907024065 (1907726 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 1023/ head 255/ sector 63
The data for partition 2 is:

     The question is, can we safely modify fdisk to start the
     slice in the second sector of the cylinder instead of the
     first (cyl 0 head 1 sector 2) in order to align it to
     logical sector #64?

     It's a one-line fix in the fdisk program.  The question is
     whether doing that retains compatibility for booting PCs.
     Presuming that PCs support LBA or LARGE mode it should work,
     theoretically.  I haven't tried booting from such a disk yet.

					-Matt
					Matthew Dillon 
					<dillon at backplane.com>

diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c
index fbdad7d..38b970f 100644
--- a/sbin/fdisk/fdisk.c
+++ b/sbin/fdisk/fdisk.c
@@ -373,7 +373,7 @@ main(int argc, char *argv[])
 		partp = (struct dos_partition *) (&mboot.parts[0]);
 		partp->dp_typ = DOSPTYP_386BSD;
 		partp->dp_flag = ACTIVE;
-		partp->dp_start = dos_sectors;
+		partp->dp_start = (dos_sectors + 63) & ~63;
 		if (disksecs - dos_sectors > 0xFFFFFFFFU) {
 			printf("Warning: Ending logical block > 2TB, using max value\n");
 			partp->dp_size = 0xFFFFFFFFU;





More information about the Kernel mailing list