* Re: 63 sectors
2008-09-03 8:12 63 sectors Avi Kivity
@ 2008-09-03 8:35 ` David Mair
2008-09-03 9:32 ` Avi Kivity
2008-09-03 11:26 ` Gerd Hoffmann
` (3 subsequent siblings)
4 siblings, 1 reply; 17+ messages in thread
From: David Mair @ 2008-09-03 8:35 UTC (permalink / raw)
To: KVM list; +Cc: H. Peter Anvin
Avi Kivity wrote:
> Qemu sets the sectors-per-track setting of virtual disks to 63. This
> seems to be in accordance with the specs; drivers/ide/ide-disk.c says:
>
>> /*
>> * The ATA spec tells large drives to return
>> * C/H/S = 16383/16/63 independent of their size.
>> * Some drives can be jumpered to use 15 heads instead of 16.
>> * Some drives can be jumpered to use 4092 cyls instead of 16383.
>> */
>> if ((id->cyls == 16383
>> || (id->cyls == 4092 && id->cur_cyls == 16383)) &&
>> id->sectors == 63 &&
>> (id->heads == 15 || id->heads == 16) &&
>> (id->lba_capacity >= 16383*63*id->heads))
>> return 1;
>
> That setting has some unfortunate side effects. Partitioning tools will
> locate the first partition at the second cylinder, which is at the 63rd
> sector. This means that if the guest uses a 4K block filesystem on the
> first partition (an incredibly common occurance), then every single
> access will not be 4K aligned with respect to the virtual block device.
> This will cause fragmentation and read/modify/write cycles with:
Oh, the tales I could tell of big disk hardware vendors that cache their storage
platforms on 4k aligned blocks and have horrible performance for reads across a
block boundary and only provide drivers for Windows to format LUNs with 4k
alignment.
AFAIK, this is actually a relic limitation of the IBM PC-BIOS hard disk geometry
functions and the MS-DOS partitioning scheme. The BIOS provides only five bits
for sector number in a track and zero is invalid. And, sectors have to claim to
be aligned on a cylinder boundary except for the first partition which is
permitted to begin on the second head of the first cylinder (so sectors/track
reserved sectors and the mis-alignment).
> - qcow2 (which uses aligned 4K blocks)
> - any host filesystem which uses 4K blocks
> - any host disk which uses 4K blocks (not yet common)
>
> I can think of a few workarounds, all bad:
> - add a partitioning tool (or option to qemu-img) to format the disk,
> placing the first partition on the fourth cylinder, aligning it. tell
> the users not to wipe the disks out but instead install to one of the
> existing parititions
> - add a tool to optimize an existing disk by extending it and moving the
> partitions around so they are aligned. may break boot loaders.
> - make qcow4 use 512 byte sectors. will increase overhead and doesn't
> solve problems on the host filesystem and disk.
> - have qcow51 detect misaligned accesses and adjust itself somehow.
> doesn't help raw and other formats. likely very difficult.
A solution used on another platform I'm familiar with is for the platform's
storage drivers to report disk geometry as having have 32 sectors per track. The
native partitioning tool will then always create partitions with 32 sector
alignment. It's possible a BIOS change could be made to achieve that.
> Does anybody know if scsi will have the same problems? Can anyone
> suggest other workarounds?
If you are using a guest platform like linux and don't need multiple file
systems on the same [virtual] disk then just format the whole disk rather than
partition it:
# mkfs -t ext3 /dev/sdb
(instead of /dev/sdb1, 2, 3, etc)
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: 63 sectors
2008-09-03 8:35 ` David Mair
@ 2008-09-03 9:32 ` Avi Kivity
0 siblings, 0 replies; 17+ messages in thread
From: Avi Kivity @ 2008-09-03 9:32 UTC (permalink / raw)
To: David Mair; +Cc: KVM list, H. Peter Anvin
David Mair wrote:
> A solution used on another platform I'm familiar with is for the
> platform's storage drivers to report disk geometry as having have 32
> sectors per track. The native partitioning tool will then always
> create partitions with 32 sector alignment. It's possible a BIOS
> change could be made to achieve that.
>
I tried 60 sectors per track, but Windows saw the disk as an 8GB disk
and refused to format. Linux had similar problems.
>> Does anybody know if scsi will have the same problems? Can anyone
>> suggest other workarounds?
>
> If you are using a guest platform like linux and don't need multiple
> file systems on the same [virtual] disk then just format the whole
> disk rather than partition it:
>
> # mkfs -t ext3 /dev/sdb
>
> (instead of /dev/sdb1, 2, 3, etc)
That won't work with the installers (at least not simply), and doesn't
allow for a swap partition.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: 63 sectors
2008-09-03 8:12 63 sectors Avi Kivity
2008-09-03 8:35 ` David Mair
@ 2008-09-03 11:26 ` Gerd Hoffmann
2008-09-04 8:49 ` Gerd Hoffmann
2008-09-03 16:15 ` H. Peter Anvin
` (2 subsequent siblings)
4 siblings, 1 reply; 17+ messages in thread
From: Gerd Hoffmann @ 2008-09-03 11:26 UTC (permalink / raw)
To: Avi Kivity; +Cc: KVM list, H. Peter Anvin
> I can think of a few workarounds, all bad:
> - add a partitioning tool (or option to qemu-img) to format the disk,
> placing the first partition on the fourth cylinder, aligning it. tell
> the users not to wipe the disks out but instead install to one of the
> existing parititions
Well, that one slightly modified could work out quite well, at least for
linux.
As far I know the linux kernel uses the geometry provided by the storage
adapter only in case the disk is blank. If there is a partition table
present on the disk, the linux kernel will calculate the geometry based
on that.
Background for this is that scsi disks have no disk geometry, they just
have a bunch of sectors. The scsi hostadapter bioses have to pull out
some geometry out of thin air to satisfy ms-dos and real os boot
loaders, and there was no standard on how to do that. Thus moving disks
from one scsi adapter to another may result in hba-reported and on-disk
geometry being different, and the only sane way to deal with that is
using the on-disk geometry. With LBA this is much less an issue these
days though.
So qemu-img could create a partition table, containing one partition,
hinting 32 sectors/cylinder. Linux should keep that geometry then, even
when distro installers are deleting the partition and creating their own
scheme.
Dunno how what *BSD or Windows guests will deal with that though.
cheers,
Gerd
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: 63 sectors
2008-09-03 8:12 63 sectors Avi Kivity
2008-09-03 8:35 ` David Mair
2008-09-03 11:26 ` Gerd Hoffmann
@ 2008-09-03 16:15 ` H. Peter Anvin
2008-09-04 3:20 ` Liu Yu-B13201
2008-09-04 8:58 ` Ian Kirk
4 siblings, 0 replies; 17+ messages in thread
From: H. Peter Anvin @ 2008-09-03 16:15 UTC (permalink / raw)
To: Avi Kivity; +Cc: KVM list
Avi Kivity wrote:
>
> That setting has some unfortunate side effects. Partitioning tools will
> locate the first partition at the second cylinder, which is at the 63rd
> sector. This means that if the guest uses a 4K block filesystem on the
> first partition (an incredibly common occurance), then every single
> access will not be 4K aligned with respect to the virtual block device.
> This will cause fragmentation and read/modify/write cycles with:
>
> - qcow2 (which uses aligned 4K blocks)
> - any host filesystem which uses 4K blocks
> - any host disk which uses 4K blocks (not yet common)
>
> I can think of a few workarounds, all bad:
> - add a partitioning tool (or option to qemu-img) to format the disk,
> placing the first partition on the fourth cylinder, aligning it. tell
> the users not to wipe the disks out but instead install to one of the
> existing parititions
> - add a tool to optimize an existing disk by extending it and moving the
> partitions around so they are aligned. may break boot loaders.
> - make qcow4 use 512 byte sectors. will increase overhead and doesn't
> solve problems on the host filesystem and disk.
> - have qcow51 detect misaligned accesses and adjust itself somehow.
> doesn't help raw and other formats. likely very difficult.
>
> Does anybody know if scsi will have the same problems? Can anyone
> suggest other workarounds?
>
This is not just limited to KVM. The right thing is for partitioning
tools to realize that this isn't 1981 and actually align partitions to
block boundaries. Windows Vista aligns partitions to megabyte
boundaries; I personally think that is somewhat excessive, but aligning
partitions to 128K (or possibly 64K) would be better.
This idiotic default damages virtualizers, flash drives, hardware RAID,
and pretty soon spinning media as well.
-hpa
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: 63 sectors
2008-09-03 8:12 63 sectors Avi Kivity
` (2 preceding siblings ...)
2008-09-03 16:15 ` H. Peter Anvin
@ 2008-09-04 3:20 ` Liu Yu-B13201
2008-09-04 3:33 ` H. Peter Anvin
2008-09-04 8:58 ` Ian Kirk
4 siblings, 1 reply; 17+ messages in thread
From: Liu Yu-B13201 @ 2008-09-04 3:20 UTC (permalink / raw)
To: Avi Kivity, KVM list; +Cc: H. Peter Anvin
> -----Original Message-----
> From: kvm-owner@vger.kernel.org
> [mailto:kvm-owner@vger.kernel.org] On Behalf Of Avi Kivity
> Sent: Wednesday, September 03, 2008 4:12 PM
> To: KVM list
> Cc: H. Peter Anvin
> Subject: 63 sectors
>
> Qemu sets the sectors-per-track setting of virtual disks to 63. This
> seems to be in accordance with the specs; drivers/ide/ide-disk.c says:
>
> > /*
> > * The ATA spec tells large drives to return
> > * C/H/S = 16383/16/63 independent of their size.
> > * Some drives can be jumpered to use 15 heads
> instead of 16.
> > * Some drives can be jumpered to use 4092 cyls
> instead of 16383.
> > */
> > if ((id->cyls == 16383
> > || (id->cyls == 4092 && id->cur_cyls == 16383)) &&
> > id->sectors == 63 &&
> > (id->heads == 15 || id->heads == 16) &&
> > (id->lba_capacity >= 16383*63*id->heads))
> > return 1;
>
> That setting has some unfortunate side effects. Partitioning
> tools will
> locate the first partition at the second cylinder, which is
> at the 63rd
> sector. This means that if the guest uses a 4K block
> filesystem on the
> first partition (an incredibly common occurance), then every single
> access will not be 4K aligned with respect to the virtual
> block device.
> This will cause fragmentation and read/modify/write cycles with:
>
> - qcow2 (which uses aligned 4K blocks)
> - any host filesystem which uses 4K blocks
> - any host disk which uses 4K blocks (not yet common)
>
> I can think of a few workarounds, all bad:
> - add a partitioning tool (or option to qemu-img) to format the disk,
> placing the first partition on the fourth cylinder, aligning
> it. tell
> the users not to wipe the disks out but instead install to one of the
> existing parititions
> - add a tool to optimize an existing disk by extending it and
> moving the
> partitions around so they are aligned. may break boot loaders.
> - make qcow4 use 512 byte sectors. will increase overhead
> and doesn't
> solve problems on the host filesystem and disk.
> - have qcow51 detect misaligned accesses and adjust itself somehow.
> doesn't help raw and other formats. likely very difficult.
>
> Does anybody know if scsi will have the same problems? Can anyone
> suggest other workarounds?
>
How about adding 1 sector offset when access disk image.
So that it looks like the 63rd sector, but it's indeed the 64th.
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: 63 sectors
2008-09-04 3:20 ` Liu Yu-B13201
@ 2008-09-04 3:33 ` H. Peter Anvin
2008-09-04 3:39 ` Liu Yu-B13201
0 siblings, 1 reply; 17+ messages in thread
From: H. Peter Anvin @ 2008-09-04 3:33 UTC (permalink / raw)
To: Liu Yu-B13201; +Cc: Avi Kivity, KVM list
Liu Yu-B13201 wrote:
> How about adding 1 sector offset when access disk image.
> So that it looks like the 63rd sector, but it's indeed the 64th.
The problem with that is you make it suck on OSes which actually
partition sanely.
-hpa
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: 63 sectors
2008-09-04 3:33 ` H. Peter Anvin
@ 2008-09-04 3:39 ` Liu Yu-B13201
2008-09-04 3:56 ` H. Peter Anvin
0 siblings, 1 reply; 17+ messages in thread
From: Liu Yu-B13201 @ 2008-09-04 3:39 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: Avi Kivity, KVM list
> -----Original Message-----
> From: H. Peter Anvin [mailto:hpa@zytor.com]
> Sent: Thursday, September 04, 2008 11:33 AM
> To: Liu Yu-B13201
> Cc: Avi Kivity; KVM list
> Subject: Re: 63 sectors
>
> Liu Yu-B13201 wrote:
> > How about adding 1 sector offset when access disk image.
> > So that it looks like the 63rd sector, but it's indeed the 64th.
>
> The problem with that is you make it suck on OSes which actually
> partition sanely.
>
You mean guest OSes?
Guest OSes never know this offset, adding one sector offset is in qemu and transparent to them.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: 63 sectors
2008-09-04 3:39 ` Liu Yu-B13201
@ 2008-09-04 3:56 ` H. Peter Anvin
2008-09-04 7:47 ` Itamar Heim
0 siblings, 1 reply; 17+ messages in thread
From: H. Peter Anvin @ 2008-09-04 3:56 UTC (permalink / raw)
To: Liu Yu-B13201; +Cc: Avi Kivity, KVM list
Liu Yu-B13201 wrote:
>>
>> Liu Yu-B13201 wrote:
>>> How about adding 1 sector offset when access disk image.
>>> So that it looks like the 63rd sector, but it's indeed the 64th.
>> The problem with that is you make it suck on OSes which actually
>> partition sanely.
>
> You mean guest OSes?
> Guest OSes never know this offset, adding one sector offset is in qemu and transparent to them.
I mean guest OSes.
And no, they won't know the difference, but you are suggesting
optimizing for guest OSes who are legacy/broken *AT THE EXPENSE* of
guest OSes who do things sanely.
As partition and install utilities get a clue, there are going to be
less of the former and more of the latter.
-hpa
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: 63 sectors
2008-09-04 3:56 ` H. Peter Anvin
@ 2008-09-04 7:47 ` Itamar Heim
2008-09-07 8:20 ` Avi Kivity
0 siblings, 1 reply; 17+ messages in thread
From: Itamar Heim @ 2008-09-04 7:47 UTC (permalink / raw)
To: H. Peter Anvin, Liu Yu-B13201; +Cc: Avi Kivity, KVM list
This can be left to the userspace to pass as an option, to optimize for relevant guests, since the one running the userspace probably knows which OS he will run on it, so he can pass "-sector64" as an optimization.
-----Original Message-----
From: kvm-owner@vger.kernel.org [mailto:kvm-owner@vger.kernel.org] On Behalf Of H. Peter Anvin
Sent: Thursday, September 04, 2008 6:57 AM
To: Liu Yu-B13201
Cc: Avi Kivity; KVM list
Subject: Re: 63 sectors
Liu Yu-B13201 wrote:
>>
>> Liu Yu-B13201 wrote:
>>> How about adding 1 sector offset when access disk image.
>>> So that it looks like the 63rd sector, but it's indeed the 64th.
>> The problem with that is you make it suck on OSes which actually
>> partition sanely.
>
> You mean guest OSes?
> Guest OSes never know this offset, adding one sector offset is in qemu and transparent to them.
I mean guest OSes.
And no, they won't know the difference, but you are suggesting
optimizing for guest OSes who are legacy/broken *AT THE EXPENSE* of
guest OSes who do things sanely.
As partition and install utilities get a clue, there are going to be
less of the former and more of the latter.
-hpa
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: 63 sectors
2008-09-04 7:47 ` Itamar Heim
@ 2008-09-07 8:20 ` Avi Kivity
0 siblings, 0 replies; 17+ messages in thread
From: Avi Kivity @ 2008-09-07 8:20 UTC (permalink / raw)
To: Itamar Heim; +Cc: H. Peter Anvin, Liu Yu-B13201, KVM list
Itamar Heim wrote:
> This can be left to the userspace to pass as an option, to optimize for relevant guests, since the one running the userspace probably knows which OS he will run on it, so he can pass "-sector64" as an optimization.
>
Or rather -drive ...,offset=512
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: 63 sectors
2008-09-03 8:12 63 sectors Avi Kivity
` (3 preceding siblings ...)
2008-09-04 3:20 ` Liu Yu-B13201
@ 2008-09-04 8:58 ` Ian Kirk
2008-09-04 11:15 ` Laurent Vivier
` (2 more replies)
4 siblings, 3 replies; 17+ messages in thread
From: Ian Kirk @ 2008-09-04 8:58 UTC (permalink / raw)
To: Avi Kivity; +Cc: KVM list, H. Peter Anvin
Avi Kivity wrote:
> - add a partitioning tool (or option to qemu-img) to format the disk, placing
> the first partition on the fourth cylinder, aligning it. tell the users not
> to wipe the disks out but instead install to one of the existing parititions
I thought that updating qemu-img to have quasi-fdisk functionality was a
good idea myself. Is there a respected libfdisk.so thing that could be
used to abstract most of the work ?
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: 63 sectors
2008-09-04 8:58 ` Ian Kirk
@ 2008-09-04 11:15 ` Laurent Vivier
2008-09-04 12:18 ` H. Peter Anvin
2008-09-04 17:56 ` Charles Duffy
2 siblings, 0 replies; 17+ messages in thread
From: Laurent Vivier @ 2008-09-04 11:15 UTC (permalink / raw)
To: Ian Kirk; +Cc: Avi Kivity, KVM list, H. Peter Anvin
Le jeudi 04 septembre 2008 à 09:58 +0100, Ian Kirk a écrit :
> Avi Kivity wrote:
>
> > - add a partitioning tool (or option to qemu-img) to format the disk, placing
> > the first partition on the fourth cylinder, aligning it. tell the users not
> > to wipe the disks out but instead install to one of the existing parititions
>
> I thought that updating qemu-img to have quasi-fdisk functionality was a
> good idea myself. Is there a respected libfdisk.so thing that could be
> used to abstract most of the work ?
libparted ?
Laurent
--
----------------- Laurent.Vivier@bull.net ------------------
"La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever." Saint Exupéry
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: 63 sectors
2008-09-04 8:58 ` Ian Kirk
2008-09-04 11:15 ` Laurent Vivier
@ 2008-09-04 12:18 ` H. Peter Anvin
2008-09-04 13:56 ` H. Peter Anvin
2008-09-04 17:56 ` Charles Duffy
2 siblings, 1 reply; 17+ messages in thread
From: H. Peter Anvin @ 2008-09-04 12:18 UTC (permalink / raw)
To: Ian Kirk; +Cc: Avi Kivity, KVM list
Ian Kirk wrote:
> Avi Kivity wrote:
>
>> - add a partitioning tool (or option to qemu-img) to format the disk, placing
>> the first partition on the fourth cylinder, aligning it. tell the users not
>> to wipe the disks out but instead install to one of the existing parititions
>
> I thought that updating qemu-img to have quasi-fdisk functionality was a
> good idea myself. Is there a respected libfdisk.so thing that could be
> used to abstract most of the work ?
libparted, although I wouldn't call it "respectable".
Writing a partition table to an otherwise empty disk is actually dirt
simple.
-hpa
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: 63 sectors
2008-09-04 8:58 ` Ian Kirk
2008-09-04 11:15 ` Laurent Vivier
2008-09-04 12:18 ` H. Peter Anvin
@ 2008-09-04 17:56 ` Charles Duffy
2 siblings, 0 replies; 17+ messages in thread
From: Charles Duffy @ 2008-09-04 17:56 UTC (permalink / raw)
To: kvm
Ian Kirk wrote:
> I thought that updating qemu-img to have quasi-fdisk functionality was a
> good idea myself. Is there a respected libfdisk.so thing that could be
> used to abstract most of the work ?
Exporting textual output and piping that to sfdisk is one approach.
^ permalink raw reply [flat|nested] 17+ messages in thread