"J. Lewis Muir" <jlmuir%imca-cat.org@localhost> writes: > This came up when I read > > https://mail-index.netbsd.org/netbsd-users/2018/08/15/msg021269.html > > in which Michael van Elst wrote: > > Can you verify partition alignment? Modern disks require an alignment > of 4kbyte (8 sectors), otherwise all write operations are executed as > slow read-modify-write cycles. The effect is also somewhat true for > reading but usually hidden by the read cache. > > Which partitions does this apply to: the MBR partitions (i.e., > partitions that can be manipulated with fdisk(8)), the NetBSD disklabel > partitions (i.e., partitions that can be manipulated with disklabel(8)), > both, others? If the underlying actual disk(s) has 512-byte sectors, so that operations are the same speed whether aligned or not then it doesn't amtter. If the underlying actual disk(s) has 4K sectors (typical on > 2T disks, and maybe newer disks even if smaller), then you need to set things up so that actual write operations (that are bigger than 512 bytes) are lined up so they don't span 4K sectors. Filesystems typically have 8K or some other block size, and generally do 8K (or 4K or 16K) writes, aligned naturally relative to the beginning of the filesystem. But, there's the within-filesystem alignment, and then the fs within the disklabel, and then the disklabel within the mbr partition. All that really matters in the end is that the writes hit the disk controller aligned. So yes, if you use MBR, make the NetBSD partition start at a mulitple of 64. Then, within disklabel, make every partition start at a multiple of 64. > I couldn't find this in the NetBSD guide nor the NetBSD tutorials; did I > miss it? Hard to say. It really depends on your actual disk. > Does this apply for a VPS (e.g., Vltr's Cloud Compute (VC2))? Yes, it applies. VPS is basically the same thing, execpt there is the added step of your apparent physical disk, which is somehow mapped into a file or a partition. So you need to be aligned when hitting the logical disk, and hope that the VPS provider is not breaking alignment. Probably a fairly safe hope these days. > Does this apply for a VMware guest where the disk is a sparse virtual > disk file (.vmdk) or a sparse virtual disk file split into multiple > virtual disk files? The disk is detected by NetBSD 8 as follows (from > dmesg): Yes. Same as VPS. Sparse and separate are almost certainly in chunks that are big enough to preserve 4K alignment. All systems have the same issues. > wd0 at atabus0 drive 0 > wd0: <VMware Virtual IDE Hard Drive> > wd0: drive supports 64-sector PIO transfers, LBA addressing > wd0: 20480 MB, 44384 cyl, 15 head, 63 sec, 512 bytes/sect x 41943040 sectors > wd0: 32-bit data port > wd0: drive supports PIO mode 4, DMA mode 2, Ultra-DMA mode 2 (Ultra/33) > wd0(piixide0:0:0): using PIO mode 4, Ultra-DMA mode 2 (Ultra/33) (using DMA) All that geometry is fictitious. It's really just an interface for 512 byte sectors, so it will work. But if you do a write that isn't a whole group of 8 such sectors, it has to read-modify-write. So you can't tell about the underlying disk from the vmware side, other than measuring writes of varying alignments and benchmarking. > However, Andy Ball's output looked like > > === > Model: HGST HTS545025A7E380, Rev: GGEOAC90 > Capacity 250 Gbytes, 488397168 sectors, 512 bytes/sector > Physical sector size: 4096 bytes > === > > What program displays that kind of information? Good question. And if correct, that's a smallish disk with 4K secqtors. > Does the NetBSD installer take this into account when it creates the > default MBR partitions and BSD disklabel partitions, or do I need to > watch out and correct it? For example, I ran > > fdisk > > in an amd64 NetBSD 8 VM, and it displayed "bytes/sector: 512" and the > following partition table: > > === > 0: NetBSD (sysid 169) > start 63, size 41942977 (20480 MB, Cyls 0-2610/212/34), Active > 1: <UNUSED> > 2: <UNUSED> > 3: <UNUSED> > === Arguably we should change all of these to default to 4K-safe alignment maybe even just all the time. Are there systems were 64 alignment is trouble? > And I ran > > disklabel wd0 > > and it displayed "bytes/sector: 512" and the following partition table: > > === > 16 partitions: > # size offset fstype [fsize bsize cpg/sgs] > a: 40893930 63 4.2BSD 2048 16384 0 # (Cyl. 0*- 43274*) > b: 1049047 40893993 swap # (Cyl. 43274*- 44384*) > c: 41942977 63 unused 0 0 # (Cyl. 0*- 44384*) > d: 41943040 0 unused 0 0 # (Cyl. 0 - 44384*) > === disklabel partitions are apparently relative to start-of-disk. > So, it looks like my root file system starts at sector 63, not 64, and > my swap partition starts at sector 40893993, not 40894000, so neither > are 4K-aligned? I haven't determined that this VM disk is 4K-aligned, > and maybe the NetBSD installer is smart enough to know when it matters, > and perhaps it doesn't matter for this VM disk detected by NetBSD? It depends on how the VM disk is implemented in terms of physical disks. But, these days, just always align to 64, absent retrocomputing with early 90s or earlier pc hardware, when I'm not sure.
Attachment:
signature.asc
Description: PGP signature