xfs 的一些工具使用


[root@localhost caq]# xfs_db -c frag -r /dev/sdaw
actual 20316, ideal 3544, fragmentation factor 82.56%
Note, this number is largely meaningless.
Files on this filesystem average 5.73 extents per file
[root@localhost caq]# xfs_fsr /dev/sdaw
/mnt/K4HUWARB start inode=0

[root@localhost caq]#
[root@localhost caq]#
[root@localhost caq]# xfs_db -c frag -r /dev/sdaw
actual 4159, ideal 3544, fragmentation factor 14.79%
Note, this number is largely meaningless.
Files on this filesystem average 1.17 extents per file

在碎片化整理之前,碎片化率為82.56%,一般來說,碎片化率高於45%,則建議整理,一來連續的塊可以提高讀的性能,二來可以省出很多block。

除了xfs_fsr,還有很多有用的工具。

xfs_admin      xfs_db         xfs_freeze     xfs_info       xfs_logprint   xfs_mkfile     xfs_repair
xfs_bmap       xfsdump        xfs_fsr        xfsinvutil     xfs_mdrestore  xfs_ncheck     xfsrestore
xfs_copy       xfs_estimate   xfs_growfs     xfs_io         xfs_metadump   xfs_quota      xfs_rtcp

用的最多的是xfs_repair,xfs_check,xfs_db.

xfs_info的使用:

[root@localhost caq]# xfs_info /dev/sdaw
meta-data=/dev/sdaw              isize=256    agcount=4, agsize=122094720 blks
         =                       sectsz=512   attr=2
data     =                       bsize=4096   blocks=488378646, imaxpct=5
         =                       sunit=128    swidth=512 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal               bsize=4096   blocks=238472, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

可以看出,sdaw有4個AG,block個數為 488378646,每個AG管理的block數量為總數量/4, 扇區大小為512,

swidth=0  條帶參數,raid使用。

該掛載點的xfs的日志記錄在內部,有些設備上面既有慢速的機械盤,又有快速的ssd甚至nvme盤,則可以把慢速設備的xfs日志放在nvme上,可以提高性能。

[root@localhost caq]# xfs_info -V 
xfs_info version 3.1.1

xfs_admin 的使用:

該工具能修改xfs文件系統參數

設置uuid      xfs_admin –U uuid /dev/sdc

設置label    xfsadmin –L label /dev/sdc

xfs_db工具能打印和修改未mount的,xfs元數據結構體:

xfs_db /dev/sdc

xfs_db> sb

xfs_db> p

magicnum = 0x58465342

blocksize = 4096

dblocks = 524288

 

修改:xfs_db -x -c 'sb 0' -c 'write dblocks 0' /dev/sdc

查看文件inode xfs_db> inode 131

xfs_db> p

core.magic = 0x494e

core.mode = 0100644

core.version = 2

 

打印文件系統剩余空間:

xfs_db> freesp
   from      to extents  blocks    pct
      1       1     129     129   0.00
      8      15       3      24   0.00
     64     127     131   14682   0.00
    128     255      35    5613   0.00
    256     511       3     892   0.00
    512    1023       1     981   0.00
   1024    2047       7   10178   0.00
   2048    4095       3    8192   0.00
   4096    8191       4   24022   0.00
   8192   16383      14  176636   0.02
  16384   32767      62 1223755   0.13
  32768   65535      63 2769390   0.29
  65536  131071      67 6069834   0.63
 131072  262143      41 7339741   0.76
 262144  524287      25 9600697   0.99
 524288 1048575      21 14054653   1.46
1048576 2097151       2 2121340   0.22
16777216 30523648      32 922117670  95.50

打印原始16進制數據:

xfs_db> type text

xfs_db> p

00:  49 4e 81 ed 02 02 00 00 00 00 00 00 00 00 00 00  IN..............

10:  00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 01  ................

20:  54 a2 14 e5 01 bb 2a 29 54 a2 14 e5 02 72 45 2a  T.......T....rE.

30:  54 a2 14 e5 02 72 45 2a 00 00 00 00 00 00 22 4c  T....rE........L

40:  00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 01  ................

…..

xfs對block的管理是通過分級來管理數據的,扇區,塊,et,ag。

其中:sector<block<extent<ag

typedef struct xfs_agf {
    /*
     * Common allocation group header information
     */
    __be32        agf_magicnum;    /* magic number == XFS_AGF_MAGIC */
    __be32        agf_versionnum;    /* header version == XFS_AGF_VERSION */
    __be32        agf_seqno;    /* sequence # starting from 0 */
    __be32        agf_length;    /* size in blocks of a.g. */
    /*
     * Freespace information
     */
    __be32        agf_roots[XFS_BTNUM_AGF];    /* root blocks */
    __be32        agf_spare0;    /* spare field */
    __be32        agf_levels[XFS_BTNUM_AGF];    /* btree levels */
    __be32        agf_spare1;    /* spare field */

    __be32        agf_flfirst;    /* first freelist block's index */
    __be32        agf_fllast;    /* last freelist block's index */
    __be32        agf_flcount;    /* count of blocks in freelist */
    __be32        agf_freeblks;    /* total free blocks */

    __be32        agf_longest;    /* longest free space */
    __be32        agf_btreeblks;    /* # of blocks held in AGF btrees */
    uuid_t        agf_uuid;    /* uuid of filesystem */------------------------------以下字段在2.6.32版本中沒看到,3.10對應的xfs模塊有,中間版本沒對比過

    /*
     * reserve some contiguous space for future logged fields before we add
     * the unlogged fields. This makes the range logging via flags and
     * structure offsets much simpler.
     */
    __be64        agf_spare64[16];

    /* unlogged fields, written during buffer writeback. */
    __be64        agf_lsn;    /* last write sequence */
    __be32        agf_crc;    /* crc of agf sector */
    __be32        agf_spare2;

    /* structure must be padded to 64 bit alignment */
} xfs_agf_t;

可以查看一個agf對比下:

[root@localhost caq]# xfs_db /dev/sdaw
xfs_db> agf 0
xfs_db> p
magicnum = 0x58414746--------------對比agf_magicnum字段
versionnum = 1---------------------對比agf_versionnum字段
seqno = 0--------------------------對比agf_seqno
length = 30523648------------------對比agf_length
bnoroot = 144----------------------agf_roots
cntroot = 145
bnolevel = 1
cntlevel = 1
flfirst = 0
fllast = 3
flcount = 4
freeblks = 29067437----------------空閑的block數
longest = 28900480-----------------最大的空閑段長度
btreeblks = 0
uuid = 6c46ba7a-03b6-46bc-912c-7bac04aafe92
lsn = 0xd000484b0
crc = 0x37a41d5b (correct)----------crc字段

查看144這個block的信息:

xfs_db> fsblock 144
xfs_db> p
000: 41423342 00000028 ffffffff ffffffff 00000000 00000480 0000000d 000484b0
020: 6c46ba7a 03b646bc 912c7bac 04aafe92 00000000 8e0f24fb 00000004 00000077
040: 00000096 0000006a 000006a4 0000005c 00004107 000002f9 000049a4 0000005c
060: 00006a24 0000005c 00006f24 00001cdc 00008d00 00000100 00015400 00000500
080: 00015b00 00000f00 00016a01 0000007f 0001aa80 00002d00 00021880 00000100
0a0: 00031f80 00003380 00039300 00000500 00041800 00002380 00043b88 00000078
0c0: 0004b704 0000007c 0004f780 00002080 00059800 00000200 00079504 0000037c
0e0: 00081880 00000400 00096180 00000500 0009a680 00000400 000a6a80 00000100
100: 000aab80 00000c00 000ab880 00003400 000b6c80 00000200 000c6e80 00000300
120: 000d7480 00000200 000df088 000000f8 000e3184 0000007c 000f7200 00000f80
140: 00100180 00000200 00118580 00003f80 00164700 00000080 00164880 00003c00
160: 0016c480 00008000 00184480 00004000 0018c480 01b8fc80 0018c480 01b8fc80
180: 0018c480 01b8fc80 0018c480 01b8fc80 0018c480 01b8fc80 001a1e00 01b7a300
1a0: 001a2500 01b79c00 001a2b00 01b79600 001a3100 01b79000 001a3100 01b79000
1c0: 001a3900 01b78800 001a3900 01b78800 001a3b00 01b78600 001a4100 01b78000

這樣打印不明顯,可以跟printf一樣,格式化,

xfs_db> fsblock 144
xfs_db> type bnobt-----------------指定打印的type類型
xfs_db> p
magic = 0x41423342-----------------這個可以看到,和上圖直接打印的magic是一樣的,就是‘ABTB’
level = 0--------------------------表示葉子節點,1表示中間節點
numrecs = 40-----------------------本葉子節點管理的空閑block塊,就是recs的數組中有效的元素個數
leftsib = null
rightsib = null
bno = 1152
lsn = 0xd000484b0
uuid = 6c46ba7a-03b6-46bc-912c-7bac04aafe92
owner = 0
crc = 0x8e0f24fb (correct)
recs[1-40] = [startblock,blockcount] 1:[4,119] 2:[150,106] 3:[1700,92] 4:[16647,761] 5:[18852,92] 6:[27172,92] 7:[28452,7388] 8:[36096,256] 9:[87040,1280] 10:[88832,3840] 11:[92673,127] 12:[109184,11520] 13:[137344,256] 14:[204672,13184] 15:[234240,1280] 16:[268288,9088] 17:[277384,120] 18:[308996,124] 19:[325504,8320] 20:[366592,512] 21:[496900,892] 22:[530560,1024] 23:[614784,1280] 24:[632448,1024] 25:[682624,256] 26:[699264,3072] 27:[702592,13312] 28:[748672,512] 29:[814720,768] 30:[881792,512] 31:[913544,248] 32:[930180,124] 33:[1012224,3968] 34:[1048960,512] 35:[1148288,16256] 36:[1459968,128] 37:[1460352,15360] 38:[1492096,32768] 39:[1590400,16384] 40:[1623168,28900480]

 

 查看xfs超級塊的一些信息:

[root@localhost /]# xfs_db  /dev/sdaw
xfs_db> sb 0-----------------超級塊
xfs_db> p
magicnum = 0x58465342--------這個就是XFSB的acsii碼
blocksize = 4096-------------邏輯塊大小
dblocks = 976754646----------磁盤總塊數,塊數*塊大小就是磁盤的空間了
rblocks = 0
rextents = 0
uuid = 6c46ba7a-03b6-46bc-912c-7bac04aafe92
logstart = 536870919
rootino = 1024---------------根節點inode號
rbmino = 1025
rsumino = 1026
rextsize = 1
agblocks = 30523648----------每個AG的塊數量,
agcount = 32-----------------32個AG,和AG塊數乘起來就是塊總數
rbmblocks = 0
logblocks = 476930-----------日志塊數
versionnum = 0xbda5
sectsize = 4096
inodesize = 512
inopblock = 8----------------每個block可以存儲的inode的個數,4096/512=8
fname = "\000\000\000\000\000\000\000\000\000\000\000\000"--------------文件系統的名稱
blocklog = 12----------------2的12次方,這個可以和page的shift類比,
sectlog = 12-----------------sector大小的log表示,
inodelog = 9-----------------inode大小的log表示
inopblog = 3-----------------每個block可以存儲的inode的log表示,
agblklog = 25----------------每個ag可以管理的blcok個數的log表示,這個存在向上取整
rextslog = 0
inprogress = 0
imax_pct = 5
icount = 4480
ifree = 929
fdblocks = 931125411
frextents = 0
uquotino = null
gquotino = null
qflags = 0
flags = 0
shared_vn = 0
inoalignmt = 4
unit = 128
width = 512
dirblklog = 0
logsectlog = 12
logsectsize = 4096
logsunit = 4096
features2 = 0x18a
bad_features2 = 0x18a
features_compat = 0
features_ro_compat = 0
features_incompat = 0x1
features_log_incompat = 0
crc = 0xd0deb599 (correct)
spino_align = 0
pquotino = null
lsn = 0xd00048528
meta_uuid = 00000000-0000-0000-0000-000000000000

 xfs的加載過程及常見維護的隊列:

Xfs加載ko入口函數在init_xfs_fs,主要申請xfs內核模塊使用的內存資源,注冊xfs文件系統。
常駐內存工作隊列說明:
[xfsalloc] 模塊加載產生,用於文件申請extent的時候,調用__xfs_bmapi_allocate,分配extent。
[xfs_mru_cache] 模塊加載產生,用於訪問MRU (Most Recently Used) Cache的時候使用。
[xfslogd]模塊加載產生,xfs_buf的IO結束調用 b_iodone_work的隊列。

產生階段為mount階段,此時會有指定的實例,掛載點,設備號等。
[xfs-data/sdc]mount產生,數據IO的異步操作隊列,directIO結束的時候調用io_work。
[xfs-conv/sdc] mount產生,數據IO的異步操作隊列,bufIO結束時候調用io_work。
[xfs-cil/sdc] mount產生,push日志的工作隊列,用於xfs_trans_commit將事務提交到日志里。
[xfsaild/sdc] mount產生, xfs_log_worker觸發,將臟節點push到buf,再將buf下盤,umount的時候也經常調用類似流程,如 xfs_ail_push_all_sync 函數。

 

參考資料:

http://oss.sgi.com

http://xfs.org/

https://access.redhat.com/

中興OS團隊的相關GPL文檔。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM