RESOLVED FIXED 142925
[WK2] NetworkCache retrievals sometimes fail on browser startup
https://bugs.webkit.org/show_bug.cgi?id=142925
Summary [WK2] NetworkCache retrievals sometimes fail on browser startup
Chris Dumez
Reported 2015-03-20 15:33:51 PDT
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 query this bloom filter before it is completely populated and we fails to retrieve the cached entry because we think it is not there. Radar: <rdar://problem/20245368>
Attachments
Patch (3.55 KB, patch)
2015-03-20 15:40 PDT, Chris Dumez
no flags
Patch (4.74 KB, patch)
2015-03-20 16:04 PDT, Chris Dumez
no flags
Patch (4.71 KB, patch)
2015-03-20 16:08 PDT, Chris Dumez
no flags
Chris Dumez
Comment 1 2015-03-20 15:40:00 PDT
Darin Adler
Comment 2 2015-03-20 15:53:39 PDT
Comment on attachment 249138 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=249138&action=review > Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h:112 > + std::atomic<bool> m_isPopulatingContentsFilter { false }; Doesn’t seem good to have a time window where this is false at first, and then have it become true later. I think this should be: std::atomic<bool> m_hasPopulatedContentsFilter { false }; Then we could just set it to true once we are done with that.
Antti Koivisto
Comment 3 2015-03-20 15:54:49 PDT
Comment on attachment 249138 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=249138&action=review > Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp:377 > - if (!m_contentsFilter.mayContain(key.shortHash())) { > + if (!m_isPopulatingContentsFilter && !m_contentsFilter.mayContain(key.shortHash())) { There are number of other places where we check the bloom filter. Might those need this check too? In any case it would be nicer to factor this into a function.
Chris Dumez
Comment 4 2015-03-20 16:04:44 PDT
Chris Dumez
Comment 5 2015-03-20 16:05:28 PDT
(In reply to comment #2) > Comment on attachment 249138 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=249138&action=review > > > Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h:112 > > + std::atomic<bool> m_isPopulatingContentsFilter { false }; > > Doesn’t seem good to have a time window where this is false at first, and > then have it become true later. I think this should be: > > std::atomic<bool> m_hasPopulatedContentsFilter { false }; > > Then we could just set it to true once we are done with that. Oh, I have just seen your comment. Yes, this makes sense. I'll update.
Chris Dumez
Comment 6 2015-03-20 16:08:00 PDT
Chris Dumez
Comment 7 2015-03-20 16:10:33 PDT
Comment on attachment 249143 [details] Patch Clearing flags on attachment: 249143 Committed r181816: <http://trac.webkit.org/changeset/181816>
Chris Dumez
Comment 8 2015-03-20 16:10:41 PDT
All reviewed patches have been landed. Closing bug.
Alexey Proskuryakov
Comment 9 2015-03-22 18:36:53 PDT
I don't think that an atomic value is sufficient - all it does is enforce consistency when accessing itself, not when accessing the filter data. You need an actual mutex or semaphore, and there are surprisingly few opportunities for smarts.
Gavin Barraclough
Comment 10 2015-03-22 19:36:18 PDT
(In reply to comment #9) > I don't think that an atomic value is sufficient - all it does is enforce > consistency when accessing itself, not when accessing the filter data. You > need an actual mutex or semaphore, and there are surprisingly few > opportunities for smarts. I think all errors are fine in this case. False negative from the bloom filter would result in a cache miss, false positive would result in looking up in the file system index. Additional locking overhead would probably be a net loss. ('atomic' might be entirely moot, though it may usefully be preventing the compiler from coalescing bits into a bitfield.)
Alexey Proskuryakov
Comment 11 2015-03-22 22:12:37 PDT
> Additional locking overhead would probably be a net loss. Sounds good to me, as long as the filter structure wouldn't cause a crash when incompletely visible to the thread using it.
Note You need to log in before you can comment on or make changes to this bug.