<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bread &#38; Cup &#187; cache</title>
	<atom:link href="http://blog.breadncup.com/tag/cache/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.breadncup.com</link>
	<description></description>
	<lastBuildDate>Sat, 28 Jan 2012 11:25:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Way not to use Cache in Linux</title>
		<link>http://blog.breadncup.com/2009/12/04/way-not-to-use-cache-in-linux/</link>
		<comments>http://blog.breadncup.com/2009/12/04/way-not-to-use-cache-in-linux/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 17:21:17 +0000</pubDate>
		<dc:creator>Breadncup</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://blog.breadncup.com/?p=217</guid>
		<description><![CDATA[Introducing the way not to use cache in linux programming.]]></description>
			<content:encoded><![CDATA[<p>Here is an information not to use cache in linux while reading the kernel newbie mailing list.</p>
<blockquote><p>Hi!<br />
On 19:29 Fri 04 Dec     , Lal wrote:<br />
&gt; Dear list members,<br />
&gt;<br />
&gt; I have a question about Linux page cache. I create a 10MB file using<br />
&gt; following application code:<br />
&gt;<br />
&gt; int fd=open(&#8220;foo.txt&#8221;, O_CREAT|O_RDWR|O_SYNC);<br />
&gt; char* content=(char *)malloc(1024*1024*10);<br />
&gt; write(fd, content, 1024*1024*10);<br />
&gt; free(content); close(fd);<br />
&gt;<br />
&gt; Immediately before and after this code execution, command &#8220;free -m&#8221;<br />
&gt; shows free memory decreased by 10M and cache incresed by 10M.<br />
&gt;<br />
&gt; If I delete foo.txt, then free memory increases by 10M and cache<br />
&gt; decreases by 10M.<br />
&gt;<br />
&gt; My question is why the cache is growing even after O_SYNC flag? Even<br />
&gt; fsync does not help. But deleting file freeing the cache.</p>
<p><span style="color: #ff0000;">O_SYNC</span> does not mean &#8220;do not cache&#8221;. It means &#8220;make sure the data is written<br />
to disk. The data is kept in memory even after writing to speed up subsequent<br />
reads. If you do not want this, you can pass the <span style="color: #ff0000;">O_DICECT</span> flag. But be aware<br />
that using this can easily slow you down.<br />
Either way, if you want to write zeros to the file, make sure the buffer is<br />
initialised after malloc, e.g. via memset or bzero. If you only want to<br />
allocate a file with zeros, you can also consider using fallocate or sparse<br />
files.</p>
<p>-Michi</p></blockquote>
 <img src="http://blog.breadncup.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=217" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.breadncup.com/2009/12/04/way-not-to-use-cache-in-linux/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

