<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-10341375</id><updated>2023-10-09T09:55:46.230-07:00</updated><title type='text'>Gautam&#39;s Tech World</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://techgautam.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10341375/posts/default?alt=atom'/><link rel='alternate' type='text/html' href='http://techgautam.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Gautam Borah</name><uri>http://www.blogger.com/profile/16013859180069667396</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-10341375.post-110682372879147366</id><published>2005-01-27T03:00:00.001-08:00</published><updated>2005-01-29T20:51:27.536-08:00</updated><title type='text'>Set Associative Cache</title><content type='html'>&lt;p style=&quot;MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;&quot;&gt;Whenever we talk about cache design an interview question always comes to my mind.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family:verdana;&quot;&gt;There is a parking lot for 100 cars. How do you arrange these slots efficiently so that you could park 1000 cars. Assuming only 100 cars needs to be parked at a time.&lt;br /&gt;To make things simpler lets say, the car number plates starts from 1 to 1000, and their car keys also has that number printed on them, just to help the valets, assume the parking lot has valet parking.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;FONT-WEIGHT: bold; MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;&quot;&gt;Solution 1 :&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;&quot;&gt;Lets start with a direct approach, there are 1000 cars and 100 slots. Each slot could take 10 cars. So we divide cars by there number plate number.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-family:verdana;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;From 1 to 10 will be parked at slot 1&lt;br /&gt;From 11 to 20 will be parked at slot 2&lt;br /&gt;From 21 to 30 will be parked at slot 3&lt;br /&gt;..&lt;br /&gt;...&lt;br /&gt;.....&lt;br /&gt;From 991 to 1000 will be parked at slot 100&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;&quot;&gt;This is a pretty simple scheme, when the car 22 arrives, it will be parked at slot 3. Whenever the owner wants to take out his car the valet will take his car key, find out his car number and go to that particular slot and take out the car.&lt;br /&gt;In this scheme searching for a car in the slots is pretty fast, each car is indexed.&lt;br /&gt;Now there will be problem if car 22 and 23 both arrive at the same time, or car 35 arrived while car number 37 already occupying the 4&lt;sup&gt;th&lt;/sup&gt; slot.&lt;br /&gt;The flaw in the first design is visible now, if all the cars arrive belong to the same slot we have a real problem.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;font-family:verdana;&quot;&gt;&lt;span style=&quot;FONT-WEIGHT: bold&quot;&gt;Solution 2 :&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;&quot;&gt;To overcome design flaws discussed above, we make the design simpler on the other extreme. Lets say we allow all the slots to all the cars, as they arrive. Now we do not have any problem as at a time, the need is to park only 100 cars and there are 100 slots. Then why did we think about the first design in the first place ? Well lets say car no 55&#39;s owner wants to take out his car. The valet person has no clue where this car is parked, it could be in the 1&lt;sup&gt;st&lt;/sup&gt; slot or may be in the 30&lt;sup&gt;th&lt;/sup&gt; slot. The valet person has to search through the entire slots in the worst case scenario. &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;&quot;&gt;The advantage of the second scheme is we could store all the cars at any point of time. But to find out where we have parked the car is a real problem. Here the problem is searching for a particular car number.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;FONT-WEIGHT: bold; MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;&quot;&gt;Solution 3:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-family:verdana;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;A more efficient design would be a compromise of the above two extreme designs. Here lets say we divide the slots in to separate sets. Lets say,&lt;br /&gt;From 1 to 50 will be parked in slots [1, 2, 3, 4, 5]&lt;br /&gt;From 51 to 100 will be parked in slots [6, 7, 8, 9, 10]&lt;br /&gt;.....&lt;br /&gt;........&lt;br /&gt;From 951 to 1000 will be parked in slots [96, 97, 98, 99, 100]&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;&quot;&gt;Now in this design we have some flexibility in terms of parking cars belonging to the same set. If car 25 and 45 arrives at the same time we could park them at slot 1 and 2, still we will have empty slots to park 3 more cars belonging to that set.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-family:verdana;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;Search a particular car number say 77, we know it belongs to the 2&lt;sup&gt;nd&lt;/sup&gt; set and we go and search slots [6, 7, 8, 9, 10]. Each car is in a broader sense indexed to a particular set. So we have better search results.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family:verdana;font-size:85%;&quot;&gt;This is again not the ultimate &lt;span lang=&quot;en-US&quot;&gt;Utopian&lt;/span&gt; design. Imagine 6 cars arrived at the same time which belongs to the first set. The limitation here is at a time we could park only 5 cars in any slot. Same way, search is also not fully indexed, there is a minimum search of iterating 5 slots for a particular car. If we increase the slot sizes, we at a time could park more cars, but search would be expensive. On the other hand if we reduce the set size we could store less cars belonging to the same set, but the search would be faster. In a way we could say, this 3&lt;sup&gt;rd&lt;/sup&gt; design is a hybrid of the above two designs and above two designs are the extreme cases of the 3&lt;sup&gt;rd&lt;/sup&gt; design.&lt;br /&gt;Now some theory, the first design we discussed is called, &lt;b&gt;Direct Mapped Cache&lt;/b&gt;&lt;span style=&quot;font-size:0;&quot;&gt;, the second design is called &lt;/span&gt;&lt;b&gt;Fully Associative Cache &lt;/b&gt;&lt;span style=&quot;font-size:0;&quot;&gt;and the third design we discussed &lt;/span&gt;&lt;b&gt;N-Way Set Associative Cache&lt;/b&gt;&lt;span style=&quot;font-size:0;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;There is a critical trade-off in cache performance that has led to the creation of the various cache mapping techniques described in the previous section. In order for the cache to have good performance you want to maximize both of the following: &lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p style=&quot;MARGIN-BOTTOM: 0in&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;font-family:verdana;&quot;&gt;&lt;b&gt;Hit Ratio:&lt;/b&gt; You want to increase as much as possible the likelihood of the cache containing the memory addresses that the processor wants. Otherwise, you lose much of the benefit of caching because there will be too many misses. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;font-family:verdana;&quot;&gt;&lt;b&gt;Search Speed:&lt;/b&gt; You want to be able to determine as quickly as possible if you have scored a hit in the cache. Otherwise, you lose a small amount of time on every access, hit &lt;i&gt;or&lt;/i&gt; miss, while you search the cache. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style=&quot;font-family:verdana;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;The performance of the above 3 designs could be best &lt;span lang=&quot;en-US&quot;&gt;summarized&lt;/span&gt; by the diagram below.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://us.f3.yahoofs.com/users/41ee6961z45ef0919/6f0c/__sr_/4497.jpg?phpsG_BBCrErgXyx&quot; /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the &quot;real world&quot;, the direct mapped and set associative caches are by far the most common. Direct mapping is used more for level 2 caches on motherboards, while the higher-performance set-associative cache is found more commonly on the smaller primary caches contained within processors. &lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://techgautam.blogspot.com/feeds/110682372879147366/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10341375&amp;postID=110682372879147366' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10341375/posts/default/110682372879147366'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10341375/posts/default/110682372879147366'/><link rel='alternate' type='text/html' href='http://techgautam.blogspot.com/2005/01/set-associative-cache.html' title='Set Associative Cache'/><author><name>Anonymous</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/blank.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10341375.post-110647469891498909</id><published>2005-01-23T02:04:00.000-08:00</published><updated>2005-01-23T02:13:16.150-08:00</updated><title type='text'>Introduction to technologies</title><content type='html'>This is a blog on my tech interests. I have mostly worked on server side java technologies, with a avid interest in network technologies. Also I have worked on peer to peer technologies recently. I would like to share some of my experiesnces and designs I have worked on, with my friends through this blog. I hope I could post regularly to this blog.&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://techgautam.blogspot.com/feeds/110647469891498909/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10341375&amp;postID=110647469891498909' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10341375/posts/default/110647469891498909'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10341375/posts/default/110647469891498909'/><link rel='alternate' type='text/html' href='http://techgautam.blogspot.com/2005/01/introduction-to-technologies.html' title='Introduction to technologies'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16013859180069667396</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>