Bug 142925 - [WK2] NetworkCache retrievals sometimes fail on browser startup
Summary: [WK2] NetworkCache retrievals sometimes fail on browser startup
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-03-20 15:33 PDT by Chris Dumez
Modified: 2015-03-22 22:12 PDT (History)
3 users (show)

See Also:


Attachments
Patch (3.55 KB, patch)
2015-03-20 15:40 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (4.74 KB, patch)
2015-03-20 16:04 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (4.71 KB, patch)
2015-03-20 16:08 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 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>
Comment 1 Chris Dumez 2015-03-20 15:40:00 PDT
Created attachment 249138 [details]
Patch
Comment 2 Darin Adler 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.
Comment 3 Antti Koivisto 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.
Comment 4 Chris Dumez 2015-03-20 16:04:44 PDT
Created attachment 249142 [details]
Patch
Comment 5 Chris Dumez 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.
Comment 6 Chris Dumez 2015-03-20 16:08:00 PDT
Created attachment 249143 [details]
Patch
Comment 7 Chris Dumez 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>
Comment 8 Chris Dumez 2015-03-20 16:10:41 PDT
All reviewed patches have been landed.  Closing bug.
Comment 9 Alexey Proskuryakov 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.
Comment 10 Gavin Barraclough 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.)
Comment 11 Alexey Proskuryakov 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.