⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181816 in webkit


Ignore:
Timestamp:
Mar 20, 2015, 4:09:56 PM (11 years ago)
Author:
Chris Dumez
Message:

[WK2] NetworkCache retrievals sometimes fail on browser startup
https://bugs.webkit.org/show_bug.cgi?id=142925
<rdar://problem/20245368>

Reviewed by Antti Koivisto.

NetworkCache retrievals sometimes fail on browser startup for resources
that are actually cached. The reason is that we are using a bloom filter
for performance reasons to avoid unnecessary disk I/O and this bloom
filter is populated on start up in a background thread by traversing the
cache files on disk. However, when restoring the tabs on start-up we
sometimes query this bloom filter before it is completely populated and
we thus fail to retrieve cached entries because we think they don't
exist and don't check the disk.

This patch adds an "isPopulatingContentsFilter" flag that is turned ON
on start up while we are populating the bloon filter. We then bypass
the bloom filter and send queries directly to disk on start up if this
flag is ON.

  • NetworkProcess/cache/NetworkCacheStorage.cpp:

(WebKit::NetworkCache::Storage::initialize):
(WebKit::NetworkCache::Storage::retrieve):
(WebKit::NetworkCache::Storage::dispatchPendingWriteOperations):
(WebKit::NetworkCache::Storage::dispatchHeaderWriteOperation):

  • NetworkProcess/cache/NetworkCacheStorage.h:

(WebKit::NetworkCache::Storage::cacheMayContain):

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r181815 r181816  
     12015-03-20  Chris Dumez  <cdumez@apple.com>
     2
     3        [WK2] NetworkCache retrievals sometimes fail on browser startup
     4        https://bugs.webkit.org/show_bug.cgi?id=142925
     5        <rdar://problem/20245368>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        NetworkCache retrievals sometimes fail on browser startup for resources
     10        that are actually cached. The reason is that we are using a bloom filter
     11        for performance reasons to avoid unnecessary disk I/O and this bloom
     12        filter is populated on start up in a background thread by traversing the
     13        cache files on disk. However, when restoring the tabs on start-up we
     14        sometimes query this bloom filter before it is completely populated and
     15        we thus fail to retrieve cached entries because we think they don't
     16        exist and don't check the disk.
     17
     18        This patch adds an "isPopulatingContentsFilter" flag that is turned ON
     19        on start up while we are populating the bloon filter. We then bypass
     20        the bloom filter and send queries directly to disk on start up if this
     21        flag is ON.
     22
     23        * NetworkProcess/cache/NetworkCacheStorage.cpp:
     24        (WebKit::NetworkCache::Storage::initialize):
     25        (WebKit::NetworkCache::Storage::retrieve):
     26        (WebKit::NetworkCache::Storage::dispatchPendingWriteOperations):
     27        (WebKit::NetworkCache::Storage::dispatchHeaderWriteOperation):
     28        * NetworkProcess/cache/NetworkCacheStorage.h:
     29        (WebKit::NetworkCache::Storage::cacheMayContain):
     30
    1312015-03-20  Chris Dumez  <cdumez@apple.com>
    232
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp

    r181700 r181816  
    9393            m_approximateSize += fileSize;
    9494        });
     95        m_hasPopulatedContentsFilter = true;
    9596    });
    9697}
     
    373374    }
    374375
    375     if (!m_contentsFilter.mayContain(key.shortHash())) {
     376    if (!cacheMayContain(key.shortHash())) {
    376377        completionHandler(nullptr);
    377378        return;
     
    461462        m_activeWriteOperations.add(WTF::move(writeOperation));
    462463
    463         if (write.existingEntry && m_contentsFilter.mayContain(write.entry.key.shortHash())) {
     464        if (write.existingEntry && cacheMayContain(write.entry.key.shortHash())) {
    464465            dispatchHeaderWriteOperation(write);
    465466            continue;
     
    516517    ASSERT(write.existingEntry);
    517518    ASSERT(m_activeWriteOperations.contains(&write));
    518     ASSERT(m_contentsFilter.mayContain(write.entry.key.shortHash()));
     519    ASSERT(cacheMayContain(write.entry.key.shortHash()));
    519520
    520521    // Try to update the header of an existing entry.
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h

    r181700 r181816  
    104104    WorkQueue& serialBackgroundIOQueue() { return m_serialBackgroundIOQueue.get(); }
    105105
     106    bool cacheMayContain(unsigned shortHash) { return !m_hasPopulatedContentsFilter || m_contentsFilter.mayContain(shortHash); }
     107
    106108    const String m_baseDirectoryPath;
    107109    const String m_directoryPath;
     
    110112
    111113    BloomFilter<20> m_contentsFilter;
     114    std::atomic<bool> m_hasPopulatedContentsFilter { false };
     115
    112116    std::atomic<size_t> m_approximateSize { 0 };
    113117    std::atomic<bool> m_shrinkInProgress { false };
Note: See TracChangeset for help on using the changeset viewer.