<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Virtual Memory Paging Is The Lazy Man&#8217;s Caching Scheme</title>
	<atom:link href="http://gamesfromwithin.com/virtual-memory-paging-is-the-lazy-mans-caching-scheme/feed" rel="self" type="application/rss+xml" />
	<link>http://gamesfromwithin.com/virtual-memory-paging-is-the-lazy-mans-caching-scheme</link>
	<description>Indie iPhone game development</description>
	<lastBuildDate>Thu, 09 Sep 2010 21:03:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Noel</title>
		<link>http://gamesfromwithin.com/virtual-memory-paging-is-the-lazy-mans-caching-scheme/comment-page-1#comment-1978</link>
		<dc:creator>Noel</dc:creator>
		<pubDate>Mon, 01 Jun 2009 15:16:14 +0000</pubDate>
		<guid isPermaLink="false">http://gamesfromwithin.com/?p=483#comment-1978</guid>
		<description>Ash, I&#039;m a big fan of simple solutions. What you&#039;re advocating seems like a pretty good system for a very general resource caching system. If possible, I would rather keep it extremely simple. If you know how much memory you have available, and you know your level layout when you start, you don&#039;t need to do any of that at runtime (my rule is, always precompute everything you can).

If you&#039;re dealing with systems with unknown amounts of memory, and user-created content that you can&#039;t even pre-process before running, then you might need something as complex as that.

If you have to have something like that, you probably want to use spatial information instead of time information to decide what to evict (so again, the game having knowledge of where things are wins hands down over a plain, blind caching system). You can do much faster spatial queries than temporal usage ones (probably).</description>
		<content:encoded><![CDATA[<p>Ash, I&#8217;m a big fan of simple solutions. What you&#8217;re advocating seems like a pretty good system for a very general resource caching system. If possible, I would rather keep it extremely simple. If you know how much memory you have available, and you know your level layout when you start, you don&#8217;t need to do any of that at runtime (my rule is, always precompute everything you can).</p>
<p>If you&#8217;re dealing with systems with unknown amounts of memory, and user-created content that you can&#8217;t even pre-process before running, then you might need something as complex as that.</p>
<p>If you have to have something like that, you probably want to use spatial information instead of time information to decide what to evict (so again, the game having knowledge of where things are wins hands down over a plain, blind caching system). You can do much faster spatial queries than temporal usage ones (probably).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ash</title>
		<link>http://gamesfromwithin.com/virtual-memory-paging-is-the-lazy-mans-caching-scheme/comment-page-1#comment-1977</link>
		<dc:creator>Ash</dc:creator>
		<pubDate>Mon, 01 Jun 2009 13:21:15 +0000</pubDate>
		<guid isPermaLink="false">http://gamesfromwithin.com/?p=483#comment-1977</guid>
		<description>I also read and liked your book when it was published back in 2003, so that makes it three. :)

Back to the discussion, I&#039;m not convinced that an LRU system is not a good idea. Pardon my ignorance but the whole point of having a cache is to reduce load times by storing the resources in a faster medium (RAM) and avoiding full reloads from the slower medium (HDD, DVD, Blu-ray). If all resources in a sector are to be evicted before a new sector is reloaded, the cache would be reduced in functionality to a simple buffer. What if the resource that we have just evicted is required in the next sector?

Now before I go any further, let me say that I&#039;m an indie developer like you. The difference is that I&#039;ve never been part of a team, have never worked on a shipping title and lack your vast experience. :) So I have to learn the most in my limited encounters with people who know what they&#039;re talking about. So any help is greatly appreciated.

For the sake of discussion, consider an open-world, free-roam style game where the player is free to move around a vast terrain. The way I see it, by having an LRU cache, some amount of memory is set aside and resources are loaded as they are encountered. But resources are not evicted until the cache runs out of budget, at which point the least recently used resources are evicted. The cache can also have several layers. For instance, the HDD can be used as a second-tier cache, so least recently used resources in RAM can be manually swapped out to HDD, the rationale being that loading preprocessed and read-to-use data would take less time than parsing and extracting them from whatever format our resources are originally stored in. This is where the GPG article comes in handy. The additional level of indirection allows us to easily swap out/in resources without worrying about dangling pointers. The same system can also be designed around handles.

Now everything&#039;s great and all up to this point, the only problem is that we have to eventually unload some resources, even from the second-tier cache, to make room for newly loaded ones, right? The problem is that there is a distinction between those resources that are in cache and are not referenced by any other resources (so they&#039;re only there to boost load times if and only if the same resource is required in the near future) and those resources that are there and are actually referenced. Unloading the first type is good. Unloading the second type is not, because we have no idea how to reload them back. Consider a vertex buffer for instance. The data inside a vertex buffer is the result of lots processings and is not usually available as a single file (like a texture). It&#039;s usually stored as part of a mesh and god knows how much processing it&#039;s gone under. Maybe we have combined a couple of smaller buffers into a bigger one. Maybe we have re-arranged its content for better cache coherence. The point is that (unlike a texture) it&#039;s not easy to retrieve a single vertex buffer when it&#039;s unloaded. The moral of the story is that being able to make the said distinction is important. To do so we need some sort of reference counting. This is also where that article in GPG shines.

So to sum it up, not only does the design in the GPG article allow us to swap the resources in and out of memory, but it also enables us to make the distinction between the resources that are in cache but are not referenced and those that are there and are actually used. This is great.

But all of this system revolves around this fact: we need to be able to associate a time-stamp with those resources so we can evict them when they are old. This is where my previous post kicks in. Reading that time-stamp on every single de-reference is too expensive. So is moving the resources in an LRU list.

So what do you think?

I&#039;d be looking forward to hearing from you.</description>
		<content:encoded><![CDATA[<p>I also read and liked your book when it was published back in 2003, so that makes it three. <img src='http://gamesfromwithin.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Back to the discussion, I&#8217;m not convinced that an LRU system is not a good idea. Pardon my ignorance but the whole point of having a cache is to reduce load times by storing the resources in a faster medium (RAM) and avoiding full reloads from the slower medium (HDD, DVD, Blu-ray). If all resources in a sector are to be evicted before a new sector is reloaded, the cache would be reduced in functionality to a simple buffer. What if the resource that we have just evicted is required in the next sector?</p>
<p>Now before I go any further, let me say that I&#8217;m an indie developer like you. The difference is that I&#8217;ve never been part of a team, have never worked on a shipping title and lack your vast experience. <img src='http://gamesfromwithin.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  So I have to learn the most in my limited encounters with people who know what they&#8217;re talking about. So any help is greatly appreciated.</p>
<p>For the sake of discussion, consider an open-world, free-roam style game where the player is free to move around a vast terrain. The way I see it, by having an LRU cache, some amount of memory is set aside and resources are loaded as they are encountered. But resources are not evicted until the cache runs out of budget, at which point the least recently used resources are evicted. The cache can also have several layers. For instance, the HDD can be used as a second-tier cache, so least recently used resources in RAM can be manually swapped out to HDD, the rationale being that loading preprocessed and read-to-use data would take less time than parsing and extracting them from whatever format our resources are originally stored in. This is where the GPG article comes in handy. The additional level of indirection allows us to easily swap out/in resources without worrying about dangling pointers. The same system can also be designed around handles.</p>
<p>Now everything&#8217;s great and all up to this point, the only problem is that we have to eventually unload some resources, even from the second-tier cache, to make room for newly loaded ones, right? The problem is that there is a distinction between those resources that are in cache and are not referenced by any other resources (so they&#8217;re only there to boost load times if and only if the same resource is required in the near future) and those resources that are there and are actually referenced. Unloading the first type is good. Unloading the second type is not, because we have no idea how to reload them back. Consider a vertex buffer for instance. The data inside a vertex buffer is the result of lots processings and is not usually available as a single file (like a texture). It&#8217;s usually stored as part of a mesh and god knows how much processing it&#8217;s gone under. Maybe we have combined a couple of smaller buffers into a bigger one. Maybe we have re-arranged its content for better cache coherence. The point is that (unlike a texture) it&#8217;s not easy to retrieve a single vertex buffer when it&#8217;s unloaded. The moral of the story is that being able to make the said distinction is important. To do so we need some sort of reference counting. This is also where that article in GPG shines.</p>
<p>So to sum it up, not only does the design in the GPG article allow us to swap the resources in and out of memory, but it also enables us to make the distinction between the resources that are in cache but are not referenced and those that are there and are actually used. This is great.</p>
<p>But all of this system revolves around this fact: we need to be able to associate a time-stamp with those resources so we can evict them when they are old. This is where my previous post kicks in. Reading that time-stamp on every single de-reference is too expensive. So is moving the resources in an LRU list.</p>
<p>So what do you think?</p>
<p>I&#8217;d be looking forward to hearing from you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Noel</title>
		<link>http://gamesfromwithin.com/virtual-memory-paging-is-the-lazy-mans-caching-scheme/comment-page-1#comment-1976</link>
		<dc:creator>Noel</dc:creator>
		<pubDate>Mon, 01 Jun 2009 00:46:52 +0000</pubDate>
		<guid isPermaLink="false">http://gamesfromwithin.com/?p=483#comment-1976</guid>
		<description>Ash,

Glad that you liked this article and the GPG one :-)

Since the game knows all about its contents, it can usually do much better than LRU. Levels can be partitioned into sections that make sense (maybe automatically or by a designer). That can be as simple as full load areas, or different, smaller areas, each one loaded at a different LOD level. 

But the point is that, having full knowledge of the data and what the player can do/see, you can make smart, high-level decisions about what data to keep and what data to evict. If you don&#039;t, maybe you need to build a bit more structure into your level creation to allow for those type of optimizations.</description>
		<content:encoded><![CDATA[<p>Ash,</p>
<p>Glad that you liked this article and the GPG one <img src='http://gamesfromwithin.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Since the game knows all about its contents, it can usually do much better than LRU. Levels can be partitioned into sections that make sense (maybe automatically or by a designer). That can be as simple as full load areas, or different, smaller areas, each one loaded at a different LOD level. </p>
<p>But the point is that, having full knowledge of the data and what the player can do/see, you can make smart, high-level decisions about what data to keep and what data to evict. If you don&#8217;t, maybe you need to build a bit more structure into your level creation to allow for those type of optimizations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ash</title>
		<link>http://gamesfromwithin.com/virtual-memory-paging-is-the-lazy-mans-caching-scheme/comment-page-1#comment-1974</link>
		<dc:creator>Ash</dc:creator>
		<pubDate>Mon, 01 Jun 2009 00:32:21 +0000</pubDate>
		<guid isPermaLink="false">http://gamesfromwithin.com/?p=483#comment-1974</guid>
		<description>Hi Noel,

Nice post. That somehow reminded me of your article in Game Programming Gems 4 &quot;The Beauty of Weak References and Null Objects&quot;. Although that article is not directly about caching schemes, it can be thought of as a precursor, on top of which a caching scheme can be built. Ever since I read that article, I was always wondering how it can be *efficiently* used as part of a caching system. Now that I&#039;ve come across this post, I want to use it as an excuse to ask your opinion on the subject and clear things up.

You see, a cache requires a replacement policy using which resources are discarded. Now by definition, an LRU policy discards the least recently used items first and as a result it needs to keep track of what was used when. Given the design that&#039;s discussed in that article, I assume (and assumptions are wrong at times) that this step is implemented by either 1)time-stamping resources or 2)moving them around in an LRU list both on each and every single de-reference and the latter bit is exactly where I&#039;m starting to question the efficiency of this system. None of said approaches is free and they&#039;re certainly not something you want to do on each single de-reference. All in all, I seriously hope that my assumptions are incorrect and there is somehow some obvious solution that I&#039;ve been neglecting so far, but in case it&#039;s not I&#039;m wondering how this issue should be tackled? What approaches do you use to lower the cost? Do we really need to time-stamp the resources or move them around in an LRU list on each single de-reference? Am I missing something?

Any help is greatly appreciated. :)</description>
		<content:encoded><![CDATA[<p>Hi Noel,</p>
<p>Nice post. That somehow reminded me of your article in Game Programming Gems 4 &#8220;The Beauty of Weak References and Null Objects&#8221;. Although that article is not directly about caching schemes, it can be thought of as a precursor, on top of which a caching scheme can be built. Ever since I read that article, I was always wondering how it can be *efficiently* used as part of a caching system. Now that I&#8217;ve come across this post, I want to use it as an excuse to ask your opinion on the subject and clear things up.</p>
<p>You see, a cache requires a replacement policy using which resources are discarded. Now by definition, an LRU policy discards the least recently used items first and as a result it needs to keep track of what was used when. Given the design that&#8217;s discussed in that article, I assume (and assumptions are wrong at times) that this step is implemented by either 1)time-stamping resources or 2)moving them around in an LRU list both on each and every single de-reference and the latter bit is exactly where I&#8217;m starting to question the efficiency of this system. None of said approaches is free and they&#8217;re certainly not something you want to do on each single de-reference. All in all, I seriously hope that my assumptions are incorrect and there is somehow some obvious solution that I&#8217;ve been neglecting so far, but in case it&#8217;s not I&#8217;m wondering how this issue should be tackled? What approaches do you use to lower the cost? Do we really need to time-stamp the resources or move them around in an LRU list on each single de-reference? Am I missing something?</p>
<p>Any help is greatly appreciated. <img src='http://gamesfromwithin.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jalf</title>
		<link>http://gamesfromwithin.com/virtual-memory-paging-is-the-lazy-mans-caching-scheme/comment-page-1#comment-1956</link>
		<dc:creator>jalf</dc:creator>
		<pubDate>Sun, 24 May 2009 14:29:29 +0000</pubDate>
		<guid isPermaLink="false">http://gamesfromwithin.com/?p=483#comment-1956</guid>
		<description>I disagree (a little bit). Your game doesn&#039;t know everything that can be swapped out. You most likely can&#039;t determine whether a page containing code can be swapped out or not. There&#039;s plenty of code in any application that is only ever executed once. Can you swap that out as well as the OS can? :)
The OS can make a pretty good guess based on how long it&#039;s been since it was last used. Any game has quite a few pages that could be swapped out safely by the OS, and the developers have virtually no chance of identifying and exploiting this.

Apart from that, I don&#039;t see the problem in using it as a fallback. Of course you should do everything to make your game run in the amount of available memory (and if it starts paging more than a page or two, the game will probably be pretty much unplayable). But you seem to assume that the OS will swap out basically random data, and do it all the time. As long as there&#039;s enough memory for everyone, why would it? I&#039;d expect it to just not use the backing file most of the time. But having the backing file available might allow you to shut down more gracefully at least, if you start getting low memory warnings.</description>
		<content:encoded><![CDATA[<p>I disagree (a little bit). Your game doesn&#8217;t know everything that can be swapped out. You most likely can&#8217;t determine whether a page containing code can be swapped out or not. There&#8217;s plenty of code in any application that is only ever executed once. Can you swap that out as well as the OS can? <img src='http://gamesfromwithin.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
The OS can make a pretty good guess based on how long it&#8217;s been since it was last used. Any game has quite a few pages that could be swapped out safely by the OS, and the developers have virtually no chance of identifying and exploiting this.</p>
<p>Apart from that, I don&#8217;t see the problem in using it as a fallback. Of course you should do everything to make your game run in the amount of available memory (and if it starts paging more than a page or two, the game will probably be pretty much unplayable). But you seem to assume that the OS will swap out basically random data, and do it all the time. As long as there&#8217;s enough memory for everyone, why would it? I&#8217;d expect it to just not use the backing file most of the time. But having the backing file available might allow you to shut down more gracefully at least, if you start getting low memory warnings.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Noel</title>
		<link>http://gamesfromwithin.com/virtual-memory-paging-is-the-lazy-mans-caching-scheme/comment-page-1#comment-1955</link>
		<dc:creator>Noel</dc:creator>
		<pubDate>Sat, 23 May 2009 15:31:04 +0000</pubDate>
		<guid isPermaLink="false">http://gamesfromwithin.com/?p=483#comment-1955</guid>
		<description>Hi Hendrik,
This post wasn&#039;t intended to bash your suggestion, or to imply you had put it forward as the perfect solution. It was more that other people saw your comment and they ran away with it and thought it was the best thing ever. And I just couldn&#039;t hold back :-) Personally, I didn&#039;t know you could add the disk backend like you suggested, and I think it&#039;s very cool from a tech point of view. Just a horrible solution to a bad situation :-) So, really, thanks for bringing that up and sharing it in the first place.</description>
		<content:encoded><![CDATA[<p>Hi Hendrik,<br />
This post wasn&#8217;t intended to bash your suggestion, or to imply you had put it forward as the perfect solution. It was more that other people saw your comment and they ran away with it and thought it was the best thing ever. And I just couldn&#8217;t hold back <img src='http://gamesfromwithin.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Personally, I didn&#8217;t know you could add the disk backend like you suggested, and I think it&#8217;s very cool from a tech point of view. Just a horrible solution to a bad situation <img src='http://gamesfromwithin.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  So, really, thanks for bringing that up and sharing it in the first place.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hendrik</title>
		<link>http://gamesfromwithin.com/virtual-memory-paging-is-the-lazy-mans-caching-scheme/comment-page-1#comment-1954</link>
		<dc:creator>Hendrik</dc:creator>
		<pubDate>Sat, 23 May 2009 09:10:22 +0000</pubDate>
		<guid isPermaLink="false">http://gamesfromwithin.com/?p=483#comment-1954</guid>
		<description>Since it was me pointing this out, I feel like I should comment. I didn&#039;t suggest at all that the virtual memory pager was the solution for making responsive games. 
I mentioned it purely because in your previous post you stated &quot;Because it has a fixed amount of RAM, the iPhone doesn’t provide virtual memory swapping.&quot; So I thought I&#039;d point out that it does in fact provide this. And for some applications it can actually be extremely useful.</description>
		<content:encoded><![CDATA[<p>Since it was me pointing this out, I feel like I should comment. I didn&#8217;t suggest at all that the virtual memory pager was the solution for making responsive games.<br />
I mentioned it purely because in your previous post you stated &#8220;Because it has a fixed amount of RAM, the iPhone doesn’t provide virtual memory swapping.&#8221; So I thought I&#8217;d point out that it does in fact provide this. And for some applications it can actually be extremely useful.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
