[Warning: The resulting partition is not properly aligned for best performance
在使用parted
創建分區時產生告警信息, "Warning: The resulting partition is not properly aligned for best performance."
這個問題Redhat官網有解析:https://access.redhat.com/mt/zh-hans/solutions/184143
問題
在使用parted
分區工具時,告警顯示新的分區沒有正確對齊以達到最佳性能。
(parted) mkpart primary 128 1048575
Warning: You requested a partition from 128s to 1048575s.
The closest location we can manage is 128s to 1048542s.
Is this still acceptable to you?
Yes/No? Yes
Warning: The resulting partition is not properly aligned for best performance. <-----
Ignore/Cancel? C
忽略這個告警分區可以正常創建,只不過會影響磁盤性能。那么該如何創建一個正確對齊的分區呢?
解決方案
1、百分比
一般來說只要正確的選擇分區開始的位置就可以解決這個問題,但需要查詢和計算一下相應的參數。通常相較於使用明確的開始和結束位置使用百分比可以更容易使分區對齊。
mkpart primary 0% 100%
or mkpart primary 0% 320GB
創建單個分區, 或
mkpart primary 0% 50%
and mkpart primary 50% 100%
創建兩個大小相等的分區。
2、1MiB偏移量
一般情況下,很大一部分磁盤的默認對齊粒度為1MiB,因此在大多數情況下,使用MiB作為mkpart
中的單元就可以創建一個對齊的分區。由於磁盤空間上的第一個MiB包括0扇區中的遺留主引導記錄(MBR)和緊隨其后的gpt主表(如果是gpt類型),因此需要跳過磁盤上的第一個MiB,並從1MiB開始分區:
mkpart primary 1MiB 100%
例如,創建單個分區。
3、計算偏移量
如果使用百分比或1MiB偏移量不起作用,可以通過查詢設備相應的sysfs條目來直接計算所需的對齊
獲取如下值:
# cat /sys/block/sdb/queue/optimal_io_size
# cat /sys/block/sdb/alignment_offset
# cat /sys/block/sdb/queue/physical_block_size
獲取正確的偏移扇區數是將 optimal_io_size
和 alignment_offset
相加然后除以 physical_block_size
.
For example:
optimal_io_size = 1310720
alignment_offset = 0
physical_block_size = 512
i.e 1310720+0/512 = 2560
現在創建分區的命令可以是:
(parted) mkpart primary 2560 100% OR
(parted) mkpart primary 2560 1000G