Changeset 182124 in webkit


Ignore:
Timestamp:
Mar 29, 2015 4:43:32 PM (9 years ago)
Author:
Antti Koivisto
Message:

Use st_mtime instead of st_atime to track file access time
https://bugs.webkit.org/show_bug.cgi?id=143200

Reviewed by Darin Adler.

On OS X atime updates automatically on read so calling Storage::traverse() would always ends up updating access times
for all cache entries to the current time. This would make entry worth computation produce unexpected results.
We update mtime manually on successful cache retrieve only so switching to it fixes the problem.

  • NetworkProcess/cache/NetworkCacheFileSystemPosix.h:

(WebKit::NetworkCache::fileTimes):
(WebKit::NetworkCache::updateFileModificationTimeIfNeeded):
(WebKit::NetworkCache::updateFileAccessTimeIfNeeded): Deleted.

  • NetworkProcess/cache/NetworkCacheStorage.cpp:

(WebKit::NetworkCache::Storage::updateFileModificationTime):
(WebKit::NetworkCache::Storage::dispatchReadOperation):
(WebKit::NetworkCache::deletionProbability):
(WebKit::NetworkCache::Storage::updateFileAccessTime): Deleted.

  • NetworkProcess/cache/NetworkCacheStorage.h:
Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r182101 r182124  
     12015-03-29  Antti Koivisto  <antti@apple.com>
     2
     3        Use st_mtime instead of st_atime to track file access time
     4        https://bugs.webkit.org/show_bug.cgi?id=143200
     5
     6        Reviewed by Darin Adler.
     7
     8        On OS X atime updates automatically on read so calling Storage::traverse() would always ends up updating access times
     9        for all cache entries to the current time. This would make entry worth computation produce unexpected results.
     10        We update mtime manually on successful cache retrieve only so switching to it fixes the problem.
     11
     12        * NetworkProcess/cache/NetworkCacheFileSystemPosix.h:
     13        (WebKit::NetworkCache::fileTimes):
     14        (WebKit::NetworkCache::updateFileModificationTimeIfNeeded):
     15        (WebKit::NetworkCache::updateFileAccessTimeIfNeeded): Deleted.
     16        * NetworkProcess/cache/NetworkCacheStorage.cpp:
     17        (WebKit::NetworkCache::Storage::updateFileModificationTime):
     18        (WebKit::NetworkCache::Storage::dispatchReadOperation):
     19        (WebKit::NetworkCache::deletionProbability):
     20        (WebKit::NetworkCache::Storage::updateFileAccessTime): Deleted.
     21        * NetworkProcess/cache/NetworkCacheStorage.h:
     22
    1232015-03-27  Gwang Yoon Hwang  <yoon@igalia.com>
    224
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystemPosix.h

    r181700 r182124  
    7272struct FileTimes {
    7373    std::chrono::system_clock::time_point creation;
    74     std::chrono::system_clock::time_point access;
     74    std::chrono::system_clock::time_point modification;
    7575};
    7676
     
    8080    if (stat(WebCore::fileSystemRepresentation(path).data(), &fileInfo))
    8181        return { };
    82     return { std::chrono::system_clock::from_time_t(fileInfo.st_birthtime), std::chrono::system_clock::from_time_t(fileInfo.st_atime) };
     82    return { std::chrono::system_clock::from_time_t(fileInfo.st_birthtime), std::chrono::system_clock::from_time_t(fileInfo.st_mtime) };
    8383}
    8484
    85 inline void updateFileAccessTimeIfNeeded(const String& path)
     85inline void updateFileModificationTimeIfNeeded(const String& path)
    8686{
    8787    auto times = fileTimes(path);
    88     if (times.creation != times.access) {
    89         // Don't update more than once per hour;
    90         if (std::chrono::system_clock::now() - times.access < std::chrono::hours(1))
     88    if (times.creation != times.modification) {
     89        // Don't update more than once per hour.
     90        if (std::chrono::system_clock::now() - times.modification < std::chrono::hours(1))
    9191            return;
    9292    }
    93     // This really updates both access time and modification time.
     93    // This really updates both the access time and the modification time.
    9494    utimes(WebCore::fileSystemRepresentation(path).data(), 0);
    9595}
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp

    r182019 r182124  
    293293}
    294294
    295 void Storage::updateFileAccessTime(IOChannel& channel)
     295void Storage::updateFileModificationTime(IOChannel& channel)
    296296{
    297297    StringCapture filePathCapture(channel.path());
    298298    serialBackgroundIOQueue().dispatch([filePathCapture] {
    299         updateFileAccessTimeIfNeeded(filePathCapture.string());
     299        updateFileModificationTimeIfNeeded(filePathCapture.string());
    300300    });
    301301}
     
    317317                bool success = read.completionHandler(WTF::move(record));
    318318                if (success)
    319                     updateFileAccessTime(*channel);
     319                    updateFileModificationTime(*channel);
    320320                else
    321321                    remove(read.key);
     
    590590    using namespace std::chrono;
    591591    auto age = system_clock::now() - times.creation;
    592     auto accessAge = times.access - times.creation;
     592    // File modification time is updated manually on cache read. We don't use access time since OS may update it automatically.
     593    auto accessAge = times.modification - times.creation;
    593594
    594595    // For sanity.
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h

    r182019 r182124  
    9898    void dispatchPendingWriteOperations();
    9999
    100     void updateFileAccessTime(IOChannel&);
     100    void updateFileModificationTime(IOChannel&);
    101101
    102102    WorkQueue& ioQueue() { return m_ioQueue.get(); }
Note: See TracChangeset for help on using the changeset viewer.