更新:原來我很笨。我正在檢查修改時間,當我應該檢查訪問時間。不可重複的原因是測試文件是用dd if=/dev/urandom of="$target" bs='1K' count=1 || exit 1
製作的,其大部分時間對於新文件的修改時間(dd
的末尾)來說太快而不同於訪問時間(開始時間爲dd
) 。另一件需要注意的事情。EXT4上的觸摸時間戳準確性
我正在處理一個腳本,將一個文件加兩年的訪問時間應用到另一個文件。這使用stat -c %x
,date --rfc-3339=ns
和touch -a --date="$result"
。 stat
和date
兩個輸出日期字符串與納秒,像
2012-11-17 10:22:15.390351800+01:00
,並info coreutils 'touch invocation'
表示支持納秒。但是有時在應用觸摸時,應用的時間戳與統計之後返回的時間戳之間存在細微的差異。這裏的數據從實際運行:
$ for i in {1..100}; do ./t_timecopy.sh 2>/dev/null| grep ASSERT; done
ASSERT:Expecting same access time expected:<2012-11-17 10:58:40.719320935+01:00> but was:<2012-11-17 10:58:40.723322203+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:00:04.342346275+01:00> but was:<2012-11-17 11:00:04.346358718+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:00:39.343348183+01:00> but was:<2012-11-17 11:00:39.347351686+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:01:08.655348312+01:00> but was:<2012-11-17 11:01:08.659347625+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:01:37.930346876+01:00> but was:<2012-11-17 11:01:37.934347311+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:02:16.939319832+01:00> but was:<2012-11-17 11:02:16.943323061+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:02:46.456443149+01:00> but was:<2012-11-17 11:02:46.458379114+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:03:15.487339595+01:00> but was:<2012-11-17 11:03:15.491341426+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:04:04.646335863+01:00> but was:<2012-11-17 11:04:04.650346634+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:04:14.410326608+01:00> but was:<2012-11-17 11:04:14.414331233+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:04:24.159367348+01:00> but was:<2012-11-17 11:04:24.163352418+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:04:33.931387953+01:00> but was:<2012-11-17 11:04:33.935350115+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:05:03.394361030+01:00> but was:<2012-11-17 11:05:03.398320957+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:05:42.054317430+01:00> but was:<2012-11-17 11:05:42.059106497+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:06:40.346320820+01:00> but was:<2012-11-17 11:06:40.350346956+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:08:17.194346778+01:00> but was:<2012-11-17 11:08:17.198338832+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:08:27.102347603+01:00> but was:<2012-11-17 11:08:27.106320380+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:09:16.247322948+01:00> but was:<2012-11-17 11:09:16.251347966+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:09:55.191325266+01:00> but was:<2012-11-17 11:09:55.195320672+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:12:09.915318301+01:00> but was:<2012-11-17 11:12:09.919334099+01:00>
ASSERT:Expecting same access time expected:<2012-11-17 11:12:28.906346914+01:00> but was:<2012-11-17 11:12:28.910348186+01:00>
所以21出的100次測試失敗,以3.938ms的平均值和4.001 ms的中位數。任何想法可能導致這種情況?
$ uname -a
Linux user 2.6.32-22-generiC#33-Ubuntu SMP Wed Apr 28 13:27:30 UTC 2010 i686 GNU/Linux
如果您提供了您正在使用的測試腳本的代碼,它將對我們有所幫助。另外,你是否完全確定在你這樣做的時候什麼都沒有讀(注意:atime)這些文件? – thkala 2010-11-17 17:11:45
這可以解釋它:-)。您還應該記住兩件事:1.僅僅因爲FS支持納秒級分辨率,並不意味着內核實際上使用這種分辨率來計算任何事情。 2.有時是敏感的事情。你需要用strictatime mount選項明確地打開它們,這會顯着降低FS(通常默認爲relatime)的性能。他們也容易受到任何隨機應用程序訪問您正在觀看的文件。 – thkala 2010-11-18 17:19:18