Red Hat Training
A Red Hat training course is available for Red Hat Enterprise Linux
3.8. 資料記錄
Ordinarily, GFS2 writes only metadata to its journal. File contents are subsequently written to disk by the kernel's periodic sync that flushes file system buffers. An
fsync()
call on a file causes the file's data to be written to disk immediately. The call returns when the disk reports that all data is safely written.
資料日誌會導致
fsync()
時間降低,尤其是小檔案;這是因為除了 metadata 之外,檔案資料也會被紀錄到日誌中。資料安全地紀錄到日誌後, fsync()
會回傳,這樣會比把檔案資料寫入主檔案系統要來得快。
依賴
fsync()
來同步檔案資料的應用程式,會因為使用資料日誌功能,而改善效能。資料日誌可以在任何已標示旗標的目錄(及其子目錄)中,自動啟用。長度為零的現有檔案,也可以啟用或停用資料日誌功能。
Enabling data journaling on a directory sets the directory to "inherit jdata", which indicates that all files and directories subsequently created in that directory are journaled. You can enable and disable data journaling on a file or a directory with either of the following methods:
- 對檔案或目錄執行
chattr +j
或chattr -j
指令。 - 用
gfs2_tool setflag
或gfs2_tool clearflag
指令,設定或清除檔案或目錄的jdata
旗標。
使用
chattr
指令來啟用或停用檔案或目錄的資料日誌功能,是比較建議的作法。
3.8.1. 使用 chattr
指令來啟用或停用資料日誌
您可以使用
chattr
指令來啟用或停用一個檔案的資料日誌功能。以下指令啟用 /mnt/gfs2/gfs2_dir/newfile
檔案的資料日誌,並檢查旗標是否已經正確設定。
[root@roth-01 ~]#chattr +j /mnt/gfs2/gfs2_dir/newfile
[root@roth-01 ~]#lsattr /mnt/gfs2/gfs2_dir
---------j--- /mnt/gfs2/gfs2_dir/newfile
以下指令停用
/mnt/gfs2/gfs2_dir/newfile
檔案的資料日誌,並檢查旗標是否已經正確設定。
[root@roth-01 ~]#chattr -j /mnt/gfs2/gfs2_dir/newfile
[root@roth-01 ~]#lsattr /mnt/gfs2/gfs2_dir
------------- /mnt/gfs2/gfs2_dir/newfile
您也可以使用
chattr
指令來設定目錄的 j
旗標。當您為目錄設定這個旗標時,所有在這目錄中建立的檔案與目錄都會啟用日誌功能。以下指令集會設定 gfs2_dir
目錄的 j
旗標,然後檢查該旗標是否設定正確。之後,這指令會在 /mnt/gfs2/gfs2_dir
目錄建立一個新檔案,稱為 newfile
,然後檢查該檔案的 j
旗標是否設定正確。因為該目錄已經設定了 j
旗標,所以 newfile
的日誌功能也會被啟用。
[root@roth-01 ~]#chattr -j /mnt/gfs2/gfs2_dir
[root@roth-01 ~]#lsattr /mnt/gfs2
---------j--- /mnt/gfs2/gfs2_dir [root@roth-01 ~]#touch /mnt/gfs2/gfs2_dir/newfile
[root@roth-01 ~]#lsattr /mnt/gfs2/gfs2_dir
---------j--- /mnt/gfs2/gfs2_dir/newfile