檔案時間戳精度 - ext3 為奈秒,ext4 為毫秒

檔案時間戳精度 - ext3 為奈秒,ext4 為毫秒

人們說 ext3 支援高達秒的檔案時間戳精度,而 ext4 支援高達奈秒的檔案時間戳精度。

發生的情況是,我運行 Ubuntu 12.04 和 ext3 檔案系統的舊 VPS 總是(據我記得)很好地支援納秒,如下所示:

  File: `auth.log'
  Size: 147744      Blocks: 304        IO Block: 4096   regular file
Device: 800h/2048d  Inode: 32019       Links: 1
Access: (0640/-rw-r-----)  Uid: (  101/  syslog)   Gid: (    4/     adm)
Access: 2020-03-20 00:18:33.634687690 -0300
Modify: 2020-03-24 05:12:48.777610222 -0300
Change: 2020-03-24 05:12:48.777610222 -0300
 Birth: -

mount摘抄:

/dev/sda on / type ext3 (rw,noatime,errors=remount-ro)

stat -f

  File: "auth.log"
    ID: 5483af2794a91010 Namelen: 255     Type: ext2/ext3
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 3870084    Free: 272230     Available: 75643
Inodes: Total: 923520     Free: 829980
root@mail:~# df -mT
Filesystem     Type     1M-blocks  Used Available Use% Mounted on
/dev/sda       ext3         15118 14055       296  98% /
devtmpfs       devtmpfs      1973     1      1973   1% /dev
none           tmpfs          395     1       395   1% /run
none           tmpfs            5     0         5   0% /run/lock
none           tmpfs         1973     0      1973   0% /run/shm

現在,我購買了一個新的 VPS,將其更新到 Ubuntu 20.04(預測試版),它的檔案系統安裝為 ext4。

  File: auth.log
  Size: 723967      Blocks: 1424       IO Block: 4096   regular file
Device: ca03h/51715d    Inode: 398412      Links: 1
Access: (0640/-rw-r-----)  Uid: (  104/  syslog)   Gid: (    4/     adm)
Access: 2020-03-24 00:00:05.676000000 -0300
Modify: 2020-03-24 05:14:56.644000000 -0300
Change: 2020-03-24 05:14:56.644000000 -0300
 Birth: -

mount摘抄:

/dev/xvda3 on / type ext4 (rw,noatime,nobarrier,errors=remount-ro,stripe=32564)

但奇怪的stat -f是它是ext3:

  File: "auth.log"
    ID: 7e8a03105e52b018 Namelen: 255     Type: ext2/ext3
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 9857995    Free: 7434726    Available: 7007355
Inodes: Total: 2505120    Free: 2403794
root@mailnew:~# df -mT
Filesystem     Type     1M-blocks  Used Available Use% Mounted on
udev           devtmpfs       430     0       430   0% /dev
tmpfs          tmpfs           95     2        94   2% /run
/dev/xvda3     ext4         38508  9466     27373  26% /
tmpfs          tmpfs          473     0       473   0% /dev/shm
tmpfs          tmpfs            5     0         5   0% /run/lock
tmpfs          tmpfs          473     0       473   0% /sys/fs/cgroup
/dev/loop0     squashfs        54    54         0 100% /snap/lxd/11348
/dev/loop1     squashfs        92    92         0 100% /snap/core/8689
/dev/xvda1     ext4           727   183       502  27% /boot
tmpfs          tmpfs           95     0        95   0% /run/user/0

我的問題是:

  1. 為什麼我的舊 ext3 系統支援奈秒精度?

  2. 為什麼新的 ext4 限制為毫秒?它實際上是格式化為 ext3 的嗎?

  3. 我怎麼能找出問題所在並在新的問題中啟用納秒?

答案1

對奈秒與秒解析度的實際支援取決於格式化時選擇的索引節點的大小。 128位元組inode僅支援秒分辨率,256位元組inode支援奈秒分辨率。核心中的 ext3 檔案系統驅動程式實際上運行了 ext4 模組很多年,因此它支援奈秒時間戳記。

至於毫秒解析度的時間戳,這可能是虛擬化僅為檔案系統提供毫秒解析度時脈的結果。

相關內容