When working with SSDs as raw LVM physical volumes, proper alignment with erase block boundaries becomes crucial for both performance and longevity. Unlike traditional partitioning where alignment can be handled during partition creation, raw device usage requires explicit configuration.
For an SSD with 1024k erase blocks, your proposed approach is fundamentally correct:
# Create PV with erase block alignment
pvcreate --dataalignment 1024k /dev/nvme0n1
# Create VG with PE size as erase block multiple
vgcreate --physicalextentsize 4096k vg_ssd /dev/nvme0n1
The 4MB PE size (4× erase block) is a practical choice that balances alignment with manageable allocation granularity.
For ext4 on top of LVM:
# Create LV with stripe-aware sizing
lvcreate -L 100G -i 1 -I 4096k -n lv_data vg_ssd
# Format with matching stripe parameters
mkfs.ext4 -E stride=1024,stripe-width=1024 /dev/vg_ssd/lv_data
The stride value (1024 blocks = 4MB with default 4k blocks) matches our PE size, while stripe-width maintains this alignment for RAID-0 style allocations.
To confirm proper alignment throughout the stack:
# Check PV alignment
pvdisplay --units k --columns /dev/nvme0n1
# Verify PE to erase block ratio
vgdisplay vg_ssd | grep "PE Size"
# Confirm filesystem alignment
tune2fs -l /dev/vg_ssd/lv_data | grep -i stride
Proper alignment achieves:
- Reduced write amplification through aligned I/O operations
- Optimal flash page programming (typically 16k-32k)
- Efficient garbage collection by matching erase units
Modern SSDs with native 4k sectors often handle misalignment better than older models, but explicit alignment remains best practice.
For advanced configurations like:
- SSDs with variable erase block sizes (check manufacturer specs)
- Mixed HDD/SSD volume groups
- Thin-provisioned LVs
Consider additional testing with fio
or vendor-specific tools to validate performance characteristics.
When configuring SSDs with LVM on raw devices (without partitions), proper alignment becomes crucial for performance optimization. Modern SSDs have specific erase block sizes (typically 512KB-2MB) that directly impact write performance and wear leveling.
Your approach using pvcreate --dataalignment
and vgcreate --physicalextentsize
is fundamentally correct. Here's the technical breakdown:
# For a 1024K erase block SSD: pvcreate --dataalignment 1024k /dev/nvme0n1 vgcreate --physicalextentsize 4096k vg_ssd /dev/nvme0n1
The physical extent (PE) size should ideally be:
- A multiple of the erase block size (e.g., 4x for 1024k blocks)
- Aligned with your anticipated I/O patterns (larger for sequential workloads)
- Compatible with your filesystem allocation strategies
For ext4 on LVM:
# Create LV with aligned size lvcreate -L 100G -n lv_data vg_ssd # Format with stripe-aware options mkfs.ext4 -E stride=16,stripe_width=32 /dev/vg_ssd/lv_data # Mount with discard option for TRIM mount -o discard /dev/vg_ssd/lv_data /mnt/ssd
To confirm your alignment is correct:
# Check PV alignment pvdisplay -m /dev/nvme0n1 | grep "PE Start" # Verify filesystem alignment tune2fs -l /dev/vg_ssd/lv_data | grep "Block size" filefrag -v /mnt/ssd/largefile | grep "extent"
A proper alignment configuration can yield:
- 20-30% improvement in random write performance
- Reduced write amplification (extending SSD lifespan)
- More efficient TRIM operations
For NVMe SSDs, also consider:
# Check namespace optimal I/O size nvme id-ns /dev/nvme0n1 -H | grep "LBA Format" # Align with controller's preferred unit size pvcreate --dataalignment 8192k /dev/nvme0n1