noatime和nodiratime的設定問題

來源:互聯網
上載者:User

noatime和nodiratime的設定問題 相信對效能、最佳化這些關鍵字有興趣的朋友都知道在 Linux 下面掛載檔案系統的時候設定 noatime 可以顯著提高檔案系統的效能。預設情況下,Linux ext2/ext3 檔案系統在檔案被訪問、建立、修改等的時候記錄下了檔案的一些時間戳記,比如:檔案建立時間、最近一次修改時間和最近一次訪問時間。因為系統啟動並執行時候要訪問大量檔案,如果能減少一些動作(比如減少時間戳記的記錄次數等)將會顯著提高磁碟 IO 的效率、提升檔案系統的效能。Linux 提供了 noatime 這個參數來禁止記錄最近一次訪問時間戳記。  www.2cto.com  給檔案系統掛載的時候加上 noatime 參數能大幅提高檔案系統效能: # vi /etc/fstab /dev/sda1        /             ext3     defaults,noatime,errors=remount-ro 0 0devpts           /dev/pts      devpts   gid=5,mode=620             0 0proc             /proc         proc     defaults                   0 0/dev/sda2        swap          swap     defaults,noatime           0 0修改設定後只需要重新掛載檔案系統、不需要重啟就可以應用新設定: # mount -o remount / # mount/dev/sda1 on / type ext3 (rw,noatime,errors=remount-ro)proc on /proc type proc (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)網上很多資料都提到要同時設定 noatime 和 nodiratime,不知道這個結論來自哪裡,其實不需要像設定 noatime 那樣設定 nodiratime,最可靠的資料應該是原始碼,VPSee 查了一下原始碼,發現在核心原始碼 linux-2.6.33/fs/inode.c 檔案裡有一個 touch_atime 函數,可以看出如果 inode 的標記位是 NOATIME 的話就直接返回了,根本就走不到 NODIRATIME 那裡去,所以只設定 noatime 就可以了,不必再設定 nodiratime.  www.2cto.com   void touch_atime(struct vfsmount *mnt, struct dentry *dentry)1405{1406        struct inode *inode = dentry->d_inode;1407        struct timespec now;14081409        if (inode->i_flags & S_NOATIME)1410                return;1411        if (IS_NOATIME(inode))1412                return;1413        if ((inode->i_sb->s_flags & MS_NODIRATIME) && S_ISDIR(inode->i_mode))1414                return;14151416        if (mnt->mnt_flags & MNT_NOATIME)1417                return;1418        if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))1419                return;...1435} 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.