Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(12060)

Issue 3674042: Review: ImageCache policy bug fix (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 4 months ago by larrygritz
Modified:
13 years, 3 months ago
Reviewers:
Chris Foster, oiio-dev
Base URL:
http://svn.openimageio.org/oiio/trunk/
Visibility:
Public.

Description

In poking around ImageCache internals, I noticed what I think is a bug: although find_tile_main_cache marks the tiles it retrieves as 'used', the main outer routine find_tile -- which wraps find_tile_main_cache but only calls it if the tile we're seeking is not in the per-thread 2-tile microcache -- does not! That means that potentially the MOST frequently accessed files -- accessed so frequently that they perpetually stay in the microcache -- may fall out of the main cache because they don't look used. Consider this 2-thread access pattern (assume a tiny main cache): thread 0 thread 1 A B A C (note: A not marked used) A D (A not marked used) A E (A has fallen out of the main cache, though still in 0's microcache) B F C C (now A is out of 0's microcache, and thus freed) A <- main cache miss! Despite being the most commonly used file! And it can even be a problem for single thread, consider the following access pattern: A, B, A, C, A, D, A, F, G, A <- main cache miss, despite A being the most commonly used tile. I don't know if this actually results in worse performance for typical scenes (we certainly see a great cache hit rate for production scenes). Today I'll try a couple benchmarks and see how it changes the stats. But either way, I still think it's a bug and can't be a good thing. Do you guys agree? The solution is to move the used() call out of find_tile_main_cache and into find_tile (the only other place that ever calls find_tile_main_cache already explicitly calls used() immediately thereafter. I believe this marks every retrieved tile as used, regardless of whether it was retrieved from the main or micro cache.

Patch Set 1 #

Patch Set 2 : Update after catching a minor bug in my original diff #

Patch Set 3 : Update: simplify, I prefer this formulation of the patch #

Patch Set 4 : Typo fix (used -> use!) and make m_used atomic #

Unified diffs Side-by-side diffs Delta from patch set Stats (+27 lines, -20 lines) Patch
src/libtexture/imagecache.cpp View 1 2 3 3 chunks +5 lines, -2 lines 0 comments Download
src/libtexture/imagecache_pvt.h View 1 2 3 4 chunks +22 lines, -18 lines 0 comments Download

Messages

Total messages: 8
larrygritz
13 years, 4 months ago (2010-12-15 16:05:34 UTC) #1
larrygritz
Update after catching a minor bug in my original diff
13 years, 4 months ago (2010-12-16 01:14:09 UTC) #2
larrygritz
I tried this on a few "real" scenes today, and it doesn't seem to make ...
13 years, 4 months ago (2010-12-16 01:16:28 UTC) #3
larrygritz
Update: simplify, I prefer this formulation of the patch
13 years, 4 months ago (2010-12-16 01:42:29 UTC) #4
larrygritz
Typo fix (used -> use!) and make m_used atomic
13 years, 4 months ago (2010-12-17 07:03:19 UTC) #5
larrygritz
On 2010/12/17 07:03:19, larrygritz wrote: > Typo fix (used -> use!) and make m_used atomic ...
13 years, 4 months ago (2010-12-17 07:06:00 UTC) #6
larrygritz
Going once... going twice...
13 years, 4 months ago (2010-12-24 19:04:47 UTC) #7
Chris Foster
13 years, 3 months ago (2011-01-08 14:52:30 UTC) #8
On Fri, Dec 17, 2010 at 5:06 PM,  <larrygritz@gmail.com> wrote:
> On 2010/12/17 07:03:19, larrygritz wrote:
>>
>> Typo fix (used -> use!) and make m_used atomic
>
> I noticed that the last patch I submitted had a typo -- I had used()
> where I meant use().  Also, I made the ImageCacheTile m_used field an
> atomic_int instead of an unprotected bool.  I'm not sure it makes a
> practical difference, but it makes me feel better.  I reran the
> benchmarks, and it doesn't increase the cost.
>
> So I stand by this patch and wish to commit it if I get a LGTM from
> somebody.

Ok, I'm reviewing on list, since the code review tool is throwing a fit
with this patch for some reason.

Anyway, LGTM.  I'm not sure whether using an atomic type for m_used is
strictly necessary, but in the absence of a performance hit it can't
hurt :)

~Chris
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b