<?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>/dev/zero &#187; enhanced</title>
	<atom:link href="http://www.devzero.it/tag/enhanced/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devzero.it</link>
	<description>Unix power @ your service</description>
	<lastBuildDate>Sun, 10 Oct 2010 05:52:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Give me a&#8230; second chance!</title>
		<link>http://www.devzero.it/2009/10/give-me-a-second-chance/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=give-me-a-second-chance</link>
		<comments>http://www.devzero.it/2009/10/give-me-a-second-chance/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 18:18:46 +0000</pubDate>
		<dc:creator>unixo</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[University]]></category>
		<category><![CDATA[ansi c]]></category>
		<category><![CDATA[enhanced]]></category>
		<category><![CDATA[frame]]></category>
		<category><![CDATA[I/O]]></category>
		<category><![CDATA[mmu]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[second chance]]></category>
		<category><![CDATA[simulator]]></category>
		<category><![CDATA[thread]]></category>
		<category><![CDATA[virtual memory]]></category>

		<guid isPermaLink="false">http://www.devzero.it/?p=91</guid>
		<description><![CDATA[As university assignment, I wrote a small virtual memory simulator which implements pagination; the algorithm chosen to replace a target page is the enhanced second chance, also known as &#8220;clock algorithm&#8221;: this solution comes out as natural evolution of FIFO algorithm, working out the problem of removing those pages which are frequently accessed. This algorithm requires [...]]]></description>
			<content:encoded><![CDATA[<p>As university assignment, I wrote a small virtual memory simulator which implements pagination; the algorithm chosen to replace a target page is the <strong>enhanced second chance</strong>, also known as &#8220;clock algorithm&#8221;: this solution comes out as natural evolution of FIFO algorithm, working out the problem of removing those pages which are frequently accessed.<br />
<span id="more-91"></span></p>
<p style="text-align: center;"><a rel="attachment wp-att-125" href="http://www.devzero.it/2009/10/give-me-a-second-chance/img208/"><img class="aligncenter size-thumbnail wp-image-125" title="Classical second chance algorithm" src="http://www.devzero.it/wp-content/uploads/2009/10/img208-150x150.png" alt="Classical second chance algorithm" width="150" height="150" /></a></p>
<p>This algorithm requires that each page contained in the <em>page table</em>, besides the common attributes, must also contains two further bits:</p>
<ul>
<li>reference bit (R): this bit will be 1 when the system accesses the page, both for read and write operations;</li>
<li>dirty bit (D): this bit will be 1 only when the page will be written: when a page must be removed from main memory, this bit will remember the operative system to make a copy into secondary storage, before wiping it out.</li>
</ul>
<p>Searching for a virtual page to be removed will take in account of four possible combinations:</p>
<ol>
<li>R=0, D=0: this page has never been used nor modified -&gt; remove this page</li>
<li>R=0, D=1: this page has not been recently used, but has been modified -&gt; write it back to secondary storage and set D=0;</li>
<li>R=1, D=0: this page has been recently used only for read access -&gt; set R=0</li>
<li>R=1, D=1: this page has been recently used and modified -&gt; set R=0, do a write back and set D=0.</li>
</ol>
<p>Searching for the best page to replace won&#8217;t only be equivalent to select the less used page, but also those pages that weren&#8217;t modified; in this way, the more the system uses a page, the less is the probability for that page to be removed.</p>
<p>When a page present into the main memory is <em>dirty</em>, the system must issue two I/O requests: the former to access the secondary memory for paging it out, the latter to bring the requested page into memory (page in). In this scenario, by analyzing the dirty pages periodically and writing them back to the storage, the algorithm improves the overall performances as well as average access time to memory.</p>
<p>This algorithm suffers the disadvantage of partitioning the main memory in two classes: pages which are frequently accessed and pages less frequently accessed; when searching for target page ends, it&#8217;s not assured that the victim page is the oldest, but only one of the less accessed pages.</p>
<p>The best instance happens when the first frame has both R &amp; D bits equal to zero: searching stops immediately and it&#8217;s not necessary to page it out.</p>
<p>The worst case happens when all pages are both referenced and modified: in this scenario the MMU must completely scan all the entries, just like a FIFO.</p>
<p>The simulator, written in C, is made up of different entities, which are:</p>
<ul>
<li><strong>process</strong>: it simulates a user process which can access to an random memory location or issue a I/O read</li>
<li><strong>i/o device</strong>: a dedicated thread is spawn to simulate an i/o device (it comes with a FIFO queue to serve processes requests)</li>
<li><strong>mmu</strong>: the MMU simulates the Memory Management Unit, i.e. the responsible to translate virtual addresses (generated by a user process) into physical address; it&#8217;s also implements the second chance algorithm.</li>
</ul>
<p>It let the user specify how many processes run, how much physical memory is installed, the page size and so on; it requires only a C compiler (like <em>gcc</em>) and the utility <em>Makefile</em>.</p>
<p>Its output is in italian language, even if very simple terms have been used.</p>
<p>Download <a href="http://www.devzero.it/files/vmbo.tar.gz">vmbo.tar.gz</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.devzero.it/2009/10/give-me-a-second-chance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

