# Samsung F4 HD204UI 2TB & best parted alignment

## user

Hi,

i want to use this disk (P/N: HD204UI no /Z4 or /UZ4) without loosing space and performance (regarding 4k sector alignment)

```
# parted --script /dev/sda print

Model: ATA SAMSUNG HD204UI (scsi)

Disk /dev/sda: 2000GB

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Number  Start  End  Size  File system  Name  Flag

# (hdparm -t /dev/sda && hdparm -t /dev/sda && hdparm -t /dev/sda) | grep Timing

 Timing buffered disk reads:  370 MB in  3.01 seconds = 123.10 MB/sec

 Timing buffered disk reads:  368 MB in  3.01 seconds = 122.30 MB/sec

 Timing buffered disk reads:  370 MB in  3.00 seconds = 123.26 MB/sec

```

Finding lowest start sector

```
# parted --align=min --script /dev/sda mkpart primary ext2 33s 100%

Error: You requested a partition from 16.9kB to 2000GB.

The closest location we can manage is 17.4kB to 2000GB.

# parted --align=min --script -- /dev/sda mkpart primary ext2 34s 100%

# parted --script /dev/sda unit s print

Model: ATA SAMSUNG HD204UI (scsi)

Disk /dev/sda: 3907029168s

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Number  Start  End          Size         File system  Name  Flags

 1      34s    3907029134s  3907029101s

```

Ok, lowest gpt start sector is 34. Quick performance test.

```

# (hdparm -t /dev/sda1 && hdparm -t /dev/sda1 && hdparm -t /dev/sda1) | grep Timing

 Timing buffered disk reads:  312 MB in  3.01 seconds = 103.56 MB/sec

 Timing buffered disk reads:  310 MB in  3.02 seconds = 102.75 MB/sec

 Timing buffered disk reads:  312 MB in  3.01 seconds = 103.49 MB/sec

```

mhh, good but not best. Trying next start sector.

```
# parted --align=min --script -- /dev/sda mkpart primary ext2 35s 100% 

# parted --script /dev/sda unit s print | tail -3

Number  Start  End          Size         File system  Name  Flags

 1      35s    3907029134s  3907029100s

# (hdparm -t /dev/sda1 && hdparm -t /dev/sda1 && hdparm -t /dev/sda1) | grep Timing

 Timing buffered disk reads:  364 MB in  3.02 seconds = 120.69 MB/sec

 Timing buffered disk reads:  364 MB in  3.02 seconds = 120.68 MB/sec

 Timing buffered disk reads:  364 MB in  3.01 seconds = 120.97 MB/sec

```

Interesting, performance with start sector 35 is better. Trying next start sectors.

```
# parted --align=min --script /dev/sda mkpart primary ext2 36s 100%

# parted --script /dev/sda unit s print | tail -3

Number  Start  End          Size         File system  Name  Flags

 1      36s    3907029134s  3907029099s

# (hdparm -t /dev/sda1 && hdparm -t /dev/sda1 && hdparm -t /dev/sda1) | grep Timing

 Timing buffered disk reads:  312 MB in  3.02 seconds = 103.43 MB/sec

 Timing buffered disk reads:  312 MB in  3.01 seconds = 103.62 MB/sec

 Timing buffered disk reads:  310 MB in  3.01 seconds = 103.03 MB/sec

# parted --align=min --script /dev/sda mkpart primary ext2 37s 100%

# parted --script /dev/sda unit s print | tail -3

Number  Start  End          Size         File system  Name  Flags

 1      37s    3907029134s  3907029098s

# (hdparm -t /dev/sda1 && hdparm -t /dev/sda1 && hdparm -t /dev/sda1) | grep Timing

 Timing buffered disk reads:  350 MB in  3.01 seconds = 116.19 MB/sec

 Timing buffered disk reads:  352 MB in  3.01 seconds = 117.03 MB/sec

 Timing buffered disk reads:  352 MB in  3.01 seconds = 116.89 MB/sec

# parted --align=min --script /dev/sda mkpart primary ext2 38s 100%

# parted --script /dev/sda unit s print | tail -3

Number  Start  End          Size         File system  Name  Flags

 1      38s    3907029134s  3907029097s

# (hdparm -t /dev/sda1 && hdparm -t /dev/sda1 && hdparm -t /dev/sda1) | grep Timing

 Timing buffered disk reads:  310 MB in  3.01 seconds = 102.88 MB/sec

 Timing buffered disk reads:  312 MB in  3.02 seconds = 103.35 MB/sec

 Timing buffered disk reads:  310 MB in  3.00 seconds = 103.30 MB/sec

# parted --align=min --script /dev/sda mkpart primary ext2 39s 100%

# parted --script /dev/sda unit s print | tail -3

Number  Start  End          Size         File system  Name  Flags

 1      39s    3907029134s  3907029096s

# (hdparm -t /dev/sda1 && hdparm -t /dev/sda1 && hdparm -t /dev/sda1) | grep Timing

 Timing buffered disk reads:  366 MB in  3.01 seconds = 121.43 MB/sec

 Timing buffered disk reads:  370 MB in  3.01 seconds = 122.86 MB/sec

 Timing buffered disk reads:  370 MB in  3.00 seconds = 123.32 MB/sec

# parted --align=min --script /dev/sda mkpart primary ext2 40s 100%

# parted --script /dev/sda unit s print | tail -3

Number  Start  End          Size         File system  Name  Flags

 1      40s    3907029134s  3907029095s

# (hdparm -t /dev/sda1 && hdparm -t /dev/sda1 && hdparm -t /dev/sda1) | grep Timing

 Timing buffered disk reads:  312 MB in  3.01 seconds = 103.49 MB/sec

 Timing buffered disk reads:  312 MB in  3.01 seconds = 103.58 MB/sec

 Timing buffered disk reads:  310 MB in  3.01 seconds = 103.11 MB/sec

# parted --align=min --script /dev/sda mkpart primary ext2 41s 100%

# parted --script /dev/sda unit s print | tail -3

Number  Start  End          Size         File system  Name  Flags

 1      41s    3907029134s  3907029094s

# (hdparm -t /dev/sda1 && hdparm -t /dev/sda1 && hdparm -t /dev/sda1) | grep Timing

 Timing buffered disk reads:  350 MB in  3.01 seconds = 116.30 MB/sec

 Timing buffered disk reads:  352 MB in  3.01 seconds = 116.85 MB/sec

 Timing buffered disk reads:  350 MB in  3.01 seconds = 116.09 MB/sec

# parted --align=min --script /dev/sda mkpart primary ext2 43s 100%

# parted --script /dev/sda unit s print | tail -3

Number  Start  End          Size         File system  Name  Flags

 1      43s    3907029134s  3907029092s

# (hdparm -t /dev/sda1 && hdparm -t /dev/sda1 && hdparm -t /dev/sda1) | grep Timing

 Timing buffered disk reads:  362 MB in  3.01 seconds = 120.37 MB/sec

 Timing buffered disk reads:  362 MB in  3.00 seconds = 120.66 MB/sec

 Timing buffered disk reads:  364 MB in  3.02 seconds = 120.68 MB/sec

# parted --align=min --script /dev/sda mkpart primary ext2 47s 100%

# parted --script /dev/sda unit s print | tail -3

Number  Start  End          Size         File system  Name  Flags

 1      47s    3907029134s  3907029088s

# (hdparm -t /dev/sda1 && hdparm -t /dev/sda1 && hdparm -t /dev/sda1) | grep Timing

 Timing buffered disk reads:  368 MB in  3.01 seconds = 122.39 MB/sec

 Timing buffered disk reads:  370 MB in  3.02 seconds = 122.67 MB/sec

 Timing buffered disk reads:  370 MB in  3.01 seconds = 123.09 MB/sec

```

Maybe a hdparm benchmark problem, testing read&write performance with dd

```
# dd if=/dev/zero of=/dev/sda bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 35.8146 s, 120 MB/s

# dd if=/dev/sda of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 33.2359 s, 129 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 34s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 49.4958 s, 86.8 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 40.6853 s, 106 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 35s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 42.3886 s, 101 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 34.7849 s, 123 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 36s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 49.0768 s, 87.5 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 41.128 s, 104 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 37s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 43.5144 s, 98.7 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 36.2233 s, 119 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 38s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 49.187 s, 87.3 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 40.9883 s, 105 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 39s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 39.5074 s, 109 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 34.0449 s, 126 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 40s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 49.1165 s, 87.4 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 41.4756 s, 104 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 41s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 43.6485 s, 98.4 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 36.2339 s, 119 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 42s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 49.1751 s, 87.3 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 41.1154 s, 104 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 43s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 41.3903 s, 104 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 34.5641 s, 124 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 44s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 49.1019 s, 87.5 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 41.9371 s, 102 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 45s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 44.1831 s, 97.2 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 36.2507 s, 118 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 46s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 48.8957 s, 87.8 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 41.0463 s, 105 MB/s

# parted --align=min --script /dev/sda mkpart primary ext2 47s 100%

# dd if=/dev/zero of=/dev/sda1 bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 39.5114 s, 109 MB/s

# dd if=/dev/sda1 of=/dev/null bs=4k count=1M 2>&1 | tail -1

4294967296 bytes (4.3 GB) copied, 33.8825 s, 127 MB/s

```

This is not funny. Best lowest start sector is 39.

This means HD204UI working with 4k sectors internal?

Any explanations?

edit: add dd benchmarkLast edited by user on Sun Oct 17, 2010 3:14 pm; edited 4 times in total

----------

## frostschutz

HD204UI/Z4 uses 4k sectors

Out of curiosity, what do you get on sda without partition?

I have a 4k sector disk by WD and I get the same value for the disk directly as for the (literally) 4k aligned partitions so I suppose it's correct.

```

# hdparm -t /dev/sdb1

/dev/sdb1:

 Timing buffered disk reads: 296 MB in  3.02 seconds =  98.16 MB/sec

# hdparm -t /dev/sdb

/dev/sdb:

 Timing buffered disk reads: 296 MB in  3.02 seconds =  98.10 MB/sec

```

My disk also has a sector offset jumper that moves sector addressing somehow so a windows XP full disk install would turn out aligned or something... naturally that would mess with alignment in any other system so I'm not using it...

----------

## no.op

 *user wrote:*   

> 
> 
> i want to use this disk (P/N: HD204UI no /Z4 or /UZ4) without loosing space and performance (regarding 4k sector alignment)
> 
> <...snip...>
> ...

 

hmm, I just bought the same disk, i.e. "Model: HD204UI; HDD P/N: HD204UI; rev.A", hdparm -i /dev/sda returns "Model=SAMSUNG HD204UI, FwRev=1AQ10001, ...".

I've verified your findings about the benchmarks with dd and hdparm, but I cannot agree with the conclusion, that the 4k sector alignment starts at sector 39!

Please note, even though my speeds are significantly lower, they are closely corresponding to your measurements.

The reason for speed difference is weak system (VIA Epia CL6000 board integrated with VIA C3 Eden 600Mhz cpu, added PCI SATA one card for the HD).

See following results - they suggest 39 sector as the first sector for 4k aligned partition similarly as your findings - but it's a false assumption, see even further...

The benchmark methods with dd and hdparm are not too good in my opinion:

```

=== partition start at sect 38

Number  Start  End          Size         File system  Name  Flags

 1      38s    3907029134s  3907029097s

dd RAW write: 536870912 bytes (537 MB) copied, 15.8362 s, 33.9 MB/s

dd RAW read : 536870912 bytes (537 MB) copied, 17.1584 s, 31.3 MB/s

 Timing buffered disk reads:  100 MB in  3.01 seconds =  33.20 MB/sec

 Timing buffered disk reads:  100 MB in  3.01 seconds =  33.26 MB/sec

 Timing buffered disk reads:  100 MB in  3.00 seconds =  33.30 MB/sec

=== partition start at sect 39

Number  Start  End          Size         File system  Name  Flags

 1      39s    3907029134s  3907029096s

dd RAW write: 536870912 bytes (537 MB) copied, 8.7617 s, 61.3 MB/s

dd RAW read : 536870912 bytes (537 MB) copied, 9.85733 s, 54.5 MB/s

 Timing buffered disk reads:  154 MB in  3.04 seconds =  50.67 MB/sec

 Timing buffered disk reads:  152 MB in  3.00 seconds =  50.62 MB/sec

 Timing buffered disk reads:  150 MB in  3.03 seconds =  49.47 MB/sec

=== partition start at sect 40

Number  Start  End          Size         File system  Name  Flags

 1      40s    3907029134s  3907029095s

dd RAW write: 536870912 bytes (537 MB) copied, 15.825 s, 33.9 MB/s

dd RAW read : 536870912 bytes (537 MB) copied, 17.0971 s, 31.4 MB/s

 Timing buffered disk reads:  102 MB in  3.06 seconds =  33.34 MB/sec

 Timing buffered disk reads:  100 MB in  3.00 seconds =  33.33 MB/sec

 Timing buffered disk reads:  100 MB in  3.01 seconds =  33.25 MB/sec

```

Please note that parted counts the sectors from sector number 0 as the very first sector (I've verified where partition really start with dd after it was created onto zeroed beginning of disk).

I tend to believe that 4k alignment on this drive is simply starting at sector 0, sector 8, ..., sector 32, sector 40, ...

So the best beginning of the first partition is in my opinion sector 40 as the lowest 4k aligned sector for GPT.

I've created another benchmark that helps to prove this:

```

#define _FILE_OFFSET_BITS 64

#include <unistd.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <stdio.h>

unsigned char buffer[4096];

int main(int argc, char **argv)

{

   int fd;

   int opt;

   off_t off;

   off_t base = 0;

   off_t stride = sizeof buffer;

   size_t size = 512 * 1024 * 1024;

   const char *device = NULL;

   int do_sync = 0;

   while ((opt = getopt(argc, argv, "d:b:i:s:S")) != -1) {

      switch (opt) {

      case 'd':

         device = optarg;

         break;

      case 'b':

         base = atoll(optarg) * 512;

         break;

      case 'i':

         stride = atoll(optarg);

         break;

      case 's':

         size = atoll(optarg);

         break;

      case 'S':

         do_sync = 1;

         break;

      default:

         fprintf(stderr, "Usage: part-align-bench "

            "[-b <base sector>] [-i <stride>] "

            "[-s <size>] [-S] -d <block device>\n");

         return 1;

      }

   }

   if (device == NULL) {

      fprintf(stderr, "missing device name argument\n");

      return 1;

   }

   fd = open(device, O_RDWR);

   if (fd < 0) {

      perror("open");

      return 1;

   }

   off = base;

   printf("part-align-bench: %s base sector=%lld "

      "stride=%lld size=%lld %s\n",

      device, base / 512ll, (long long)stride, (long long)size,

      do_sync ? "do_sync" : "no_sync");

   while (size > 0) {

      if (lseek(fd, off, SEEK_SET) == (off_t)-1) {

         perror("lseek");

         close(fd);

         return 1;

      }

      if (write(fd, buffer, sizeof buffer) != sizeof buffer) {

         perror("write");

         close(fd);

         return 1;

      }

      if (do_sync)

         if (fdatasync(fd) < 0) {

            perror("fdatasync");

            close(fd);

            return 1;

         }

      off += stride;

      size -= sizeof buffer;

   }

   close(fd);

   return 0;

}

```

And here are following results:

```

epia # time ./part-align-bench -d /dev/sda -b 46

part-align-bench: /dev/sda base sector=46 stride=4096 size=536870912 no_sync

real    0m36.414s

user    0m0.000s

sys     0m0.500s

epia # time ./part-align-bench -d /dev/sda -b 47

part-align-bench: /dev/sda base sector=47 stride=4096 size=536870912 no_sync

real    0m36.497s

user    0m0.000s

sys     0m0.520s

epia # time ./part-align-bench -d /dev/sda -b 48

part-align-bench: /dev/sda base sector=48 stride=4096 size=536870912 no_sync

real    0m8.814s

user    0m0.090s

sys     0m6.550s

epia # time ./part-align-bench -d /dev/sda -b 49

part-align-bench: /dev/sda base sector=49 stride=4096 size=536870912 no_sync

real    0m36.472s

user    0m0.000s

sys     0m0.530s

epia # time ./part-align-bench -d /dev/sda -b 0 

part-align-bench: /dev/sda base sector=0 stride=4096 size=536870912 no_sync

real    0m8.822s

user    0m0.070s

sys     0m6.480s

epia # time ./part-align-bench -d /dev/sda -b 8

part-align-bench: /dev/sda base sector=8 stride=4096 size=536870912 no_sync

real    0m8.822s

user    0m0.020s

sys     0m6.610s

```

You can see that writing 512MB consequent data starting at sectors 46, 47 and 49 takes much longer than the same with starting sector 48 or 0 or 8, right?

And it gets even worse, see following:

```

epia # time ./part-align-bench -d /dev/sda -b 0 -i $((32 * 1024 * 1024)) -s $((128 * 1024 * 1024))

part-align-bench: /dev/sda base sector=0 stride=33554432 size=134217728 no_sync

real    2m59.729s

user    0m0.010s

sys     0m1.920s

epia # time ./part-align-bench -d /dev/sda -b 1 -i $((32 * 1024 * 1024)) -s $((128 * 1024 * 1024))

part-align-bench: /dev/sda base sector=1 stride=33554432 size=134217728 no_sync

real    7m24.263s

user    0m0.000s

sys     0m0.660s

```

In this benchmark we have written 128MB of data consisting of 4k blocks that have 32MB of skipped space between any of two following blocks written.

I believe that this would make the disk internal cache ineffective - if there were cached consecutive blocks from single track (or 32MB part of it that fits into the cache during a spin with not moving head) we deliberately write the next 4k block with next offset of 32MB after the previous one.

This type of benchmark really prolongs the time spent in it, in order to write even 4 time less data (128MB) than in the first part of tests where consecutive 512MB were written!

The important is that in this case the difference between 4k aligned and unaligned writes is even more visible:

starting at sector 0: around 3 minutes to write 128MB of 4k aligned blocks avoiding use of internal chache

starting at sector 1: 7 minutes 24 secs to write 128MB of 4k blocks avoiding use of internal chache

More than two times slower for not aligned blocks - the test shows the same result if started on any sector that is not a multiply of 8!

So I am aligning partitions so that the first one starts at sector 40 (the lowest sector with multiply of 8 after GPT which occupies first 34 sectors) and all sizes and starts of partitions are multiply of 8 to hopefully get the best performance possible.

----------

## user

Thanks no.op for your research.

Sadly I can not test anymore. Disc is in production now.

Its odd that simple dd and hdparm test demonstrates other "best" first sector.

Are we really ensure that parted sector is equal to benchmark base/off value?

Can you crosscheck part-align-bench with parted created partition sda1 for sector 36 to 42?

----------

## kernelOfTruth

just a heads up folks:

 *http://sourceforge.net/apps/trac/smartmontools/wiki/SamsungF4EGBadBlocks wrote:*   

>  WARNING: Do not use smartmontools with Samsung HD155UI and HD204UI drives unless the firmware patch is already installed.
> 
> Samsung provides separate patches for HD155UI and HD204UI and for HD204UI/JP.
> 
> This warning also applies to other tools which use IDENTIFY DEVICE to obtain drive information. The problem is not SMART related.
> ...

 

----------

## no.op

 *user wrote:*   

> 
> 
> Its odd that simple dd and hdparm test demonstrates other "best" first sector.
> 
> 

 

I would guess that at least dd is a lot influenced by disk internal cache - you can imagine that the first block that dd writes may be 4k unaligned causing internally read of overlapping sectors, but all following blocks that are then cached in the drive are just written in background when the cache gets emptied. Maybe the moment when the cache gets flushed shifts the real alignment and shows best result for different base sector than it is physically. Who knows...

 *user wrote:*   

> 
> 
> Are we really ensure that parted sector is equal to benchmark base/off value?
> 
> 

 

I am 100% sure that parted sector is equal to those used in the benchmark - I really wanted to be sure about this, so I've verified that with searching on sda for the first sector of sda1 that had been written with random data - see following script:

```

dd if=/dev/urandom of=mark.bin bs=512 count=1

findsect() {

   FILE="$1"

   [ -n "$2" ] && FROM=$2 || FROM=0

   SECT=$FROM

   COUNT=`stat -c "%s" $FILE`

   COUNT=$(($COUNT / 512))

   while dd if=/dev/sda of=sect.bin bs=512 skip=$SECT count=$COUNT >/dev/null 2>&1

   do

      diff -q sect.bin $FILE >/dev/null 2>&1 && break

      SECT=$(($SECT + 1))

      #[ $(($SECT % 16)) -eq 0 ] && echo $SECT >&2

      [ $(($SECT - $FROM)) -gt 8192 ] && return 1

   done

   echo "$SECT"

}

for i in `seq ${LOWEST} $((${LOWEST} + 17))`

do

   umount /dev/sda1 >/dev/null 2>&1

   parted --script /dev/sda rm 1 >/dev/null 2>&1

   dd if=/dev/zero of=/dev/sda bs=4096 count=1024 >/dev/null 2>&1

   dd if=/dev/zero of=/dev/sda bs=512 skip=$(($i - 34)) count=8226 >/dev/null 2>&1

   echo "=== partition start at sect ${i}"

   parted --script /dev/sda mklabel gpt

   parted --align=min --script /dev/sda mkpart primary ${i}s 100%

   parted --script /dev/sda unit s print | tail -n 4

   DCNT=0

   while [ ! -e /dev/sda1 ]

   do

      sleep .500

      DCNT=$(($DCNT + 1))

      [ $DCNT -gt 10 ] && {

         echo "partition /dev/sda1 does not exist!"

         exit 1

      }

   done

   DCNT=0

   while ! dd if=/dev/sda1 bs=512 count=1 >/dev/null 2>&1

   do

      sleep .500

      DCNT=$(($DCNT + 1))

      [ $DCNT -gt 10 ] && {

         echo "partition /dev/sda1 is not readable!"

         exit 1

      }

   done

   dd if=mark.bin of=/dev/sda1 bs=512 count=1 >/dev/null 2>&1

   echo "- sda1 starts at sector number `findsect mark.bin $(($i - 34))`"

   time ./part-align-bench -d /dev/sda1 -b 0 -i $((32 * 1024 * 1024)) -s $((128 * 1024 * 1024))

done

```

So the parted sectors start with sector number 0 and are equal to sector base/offsets used with the part-align-bench.

 *user wrote:*   

> 
> 
> Can you crosscheck part-align-bench with parted created partition sda1 for sector 36 to 42?
> 
> 

 

```

=== partition start at sect 36

Number  Start  End          Size         File system  Name  Flags

 1      36s    3907029134s  3907029099s

- sda1 starts at sector number 36

part-align-bench: /dev/sda1 base sector=0 stride=33554432 size=134217728 no_sync

real   5m31.967s

user   0m0.010s

sys   0m2.370s

=== partition start at sect 37

Number  Start  End          Size         File system  Name  Flags

 1      37s    3907029134s  3907029098s

- sda1 starts at sector number 37

part-align-bench: /dev/sda1 base sector=0 stride=33554432 size=134217728 no_sync

real   5m31.339s

user   0m0.010s

sys   0m2.150s

=== partition start at sect 38

Number  Start  End          Size         File system  Name  Flags

 1      38s    3907029134s  3907029097s

- sda1 starts at sector number 38

part-align-bench: /dev/sda1 base sector=0 stride=33554432 size=134217728 no_sync

real   5m31.727s

user   0m0.000s

sys   0m2.380s

=== partition start at sect 39

Number  Start  End          Size         File system  Name  Flags

 1      39s    3907029134s  3907029096s

- sda1 starts at sector number 39

part-align-bench: /dev/sda1 base sector=0 stride=33554432 size=134217728 no_sync

real   5m30.384s

user   0m0.020s

sys   0m1.790s

=== partition start at sect 40

Number  Start  End          Size         File system  Name  Flags

 1      40s    3907029134s  3907029095s

- sda1 starts at sector number 40

part-align-bench: /dev/sda1 base sector=0 stride=33554432 size=134217728 no_sync

real   2m59.344s

user   0m0.020s

sys   0m2.490s

=== partition start at sect 41

Number  Start  End          Size         File system  Name  Flags

 1      41s    3907029134s  3907029094s

- sda1 starts at sector number 41

part-align-bench: /dev/sda1 base sector=0 stride=33554432 size=134217728 no_sync

real   5m33.458s

user   0m0.010s

sys   0m2.140s

=== partition start at sect 42

Number  Start  End          Size         File system  Name  Flags

 1      42s    3907029134s  3907029093s

- sda1 starts at sector number 42

part-align-bench: /dev/sda1 base sector=0 stride=33554432 size=134217728 no_sync

real   5m31.910s

user   0m0.020s

sys   0m2.340s

```

So we get the best results as expected for the sector number 40.

And I've verified the same behavior also for the middle of the disk - the best results are for partition starting with sector number that is a multiply of 8, i.e. 4kB block aligned since beginning of the disk.

If you think about that, it might not have been wise by Sumsung to shift unconditionally the alignment to sector 39 with reporting 512 bytes sector's size - if they had a jumper for  that, ok, but without a jumper, it is more logical to have 4k blocks since beginning of the disk, in my opinion.

kernelOfTruth: thanks for warning, this does not look too good, even worse, that the firmware version does not increase - I guess I will need to update to be sure even though I don't like to...

----------

## cpu

Hi, I have two WD15EARS with 4k sectors and now I bought HD204UI.

I've had this problem just when I bought this two WD drives and for me best sector too was 40. I can say that you should start your partitions when you can divide secotor by 8 (8 sectors == 4 kB internal sector of this HDD) so 40, 48, 56 and so on.

Here you have a little disscusion about this problem from january/febuary this year -> http://thread.gmane.org/gmane.linux.utilities.util-linux-ng/2926

----------

## frostschutz

That makes a lot more sense, thanks.

----------

## weedy

using ./part-align-bench I see exactly the same results. 

but I am still amazed as to how far off hdparm is. sector 39 is the same 150MB/s as the raw disk. but sector 40 in 60MB/s. Even though I know the math is right all these years of using hdparm has me constantly second guessing this.

----------

## tomk

Moved from Gentoo Chat to Kernel & Hardware as it fits better here.

----------

## no.op

 *weedy wrote:*   

> but I am still amazed as to how far off hdparm is. sector 39 is the same 150MB/s as the raw disk. but sector 40 in 60MB/s. 

 

Well, using hdparm -t for checking sector alignment is not suitable in my opinion - hdparm -t performs reading only - so you would not get the overhead present in not-aligned write, where the disk needs to read adjacent sectors first, modify them and write them back (in case of 4kB block not-aligned write, two physical 4k sectors need to be touched - probably two spins under the disk head are needed - in the first spin the read and with second spin the write back).

But you are right, it's strange that there is so big difference for the hdparm itself, even more strange that better results are for sector 39.

Still I would take more seriously the results from benchmark that does the writing, in which the penalty of not-aligned partition must be visible...

----------

## user

Yep,

I test it with another disc.

Starting sector 40 wins, good visibly at random write benchmark (only).

----------

## ssam

```
time sudo mke2fs -t ext4 /dev/sdc1
```

gives sector 40 as the winner (5m40 vs 6m10)

i also tried mounting with

```
sudo mount /dev/sdc1 /mnt -o sync
```

and untaring a tar.gz with a ~1MB of smallish files.

get nearly a factor of 2 speed up for s40

1  MiB (sector 2048) is fast too.

----------

## drescherjm

 *frostschutz wrote:*   

> HD204UI/Z4 uses 4k sectors
> 
> Out of curiosity, what do you get on sda without partition?
> 
> I have a 4k sector disk by WD and I get the same value for the disk directly as for the (literally) 4k aligned partitions so I suppose it's correct.

 

```

jmd1 ~ # hdparm -t /dev/sdd

/dev/sdd:

 Timing buffered disk reads: 394 MB in  3.01 seconds = 130.84 MB/sec

jmd1 ~ # hdparm -t /dev/sdd1

/dev/sdd1:

 Timing buffered disk reads: 396 MB in  3.01 seconds = 131.76 MB/sec

```

```

jmd1 ~ # smartctl --all /dev/sdd

smartctl 5.40 2010-10-16 r3189 [x86_64-pc-linux-gnu] (local build)

Copyright (C) 2002-10 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF INFORMATION SECTION ===

Device Model:     SAMSUNG HD204UI

Serial Number:    S2HGJDWZ806051

Firmware Version: 1AQ10001

User Capacity:    2,000,398,934,016 bytes

Device is:        Not in smartctl database [for details use: -P showall]

ATA Version is:   8

ATA Standard is:  ATA-8-ACS revision 6

Local Time is:    Wed Jan 26 17:15:43 2011 EST

SMART support is: Available - device has SMART capability.

SMART support is: Enabled

```

```

jmd1 ~ # gdisk -l /dev/sdd

GPT fdisk (gdisk) version 0.6.13

Partition table scan:

  MBR: protective

  BSD: not present

  APM: not present

  GPT: present

Found valid GPT with protective MBR; using GPT.

Disk /dev/sdd: 3907029168 sectors, 1.8 TiB

Logical sector size: 512 bytes

Disk identifier (GUID): E79F2DD1-2510-4A99-87AD-DD0BCE00F421

Partition table holds up to 128 entries

First usable sector is 34, last usable sector is 3907029134

Partitions will be aligned on 8-sector boundaries

Total free space is 6 sectors (3.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name

   1              40      3907029134   1.8 TiB     8E00  Linux LVM

```

----------

