{"id":185036,"date":"2025-01-22T04:48:04","date_gmt":"2025-01-22T04:48:04","guid":{"rendered":"https:\/\/learnexams.com\/blog\/?p=185036"},"modified":"2025-01-22T04:48:06","modified_gmt":"2025-01-22T04:48:06","slug":"cache-inclusion-assume-you-have-an-l2-cache-that-is-direct-mapped-with-4-sets","status":"publish","type":"post","link":"https:\/\/www.learnexams.com\/blog\/2025\/01\/22\/cache-inclusion-assume-you-have-an-l2-cache-that-is-direct-mapped-with-4-sets\/","title":{"rendered":"Cache Inclusion Assume you have an L2 cache that is direct-mapped with 4 sets"},"content":{"rendered":"\n<p>Cache Inclusion Assume you have an L2 cache that is direct-mapped with 4 sets. Assume L1 cache is fully-associate with capacity of 2 blocks and it uses LRU policy If you know that blocks A, B, C and D map to sets 0, 1, 2 and 3 in L2 Cache. If you know the current state of both L1 and L2 cache is as following: Set 0 LRU t 1 Set 2 DIC Set 3 L1 Cache L2 Cache .If our next access is for block E that maps to set 3 in L2 cache, fill\/describe the state of the caches after the access, if we use: Inclusive L2 Cache Non-Inclusive L2 Cache<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-6-color\"><strong>The Correct Answer and Explanation is :<\/strong><\/mark><\/p>\n\n\n\n<p>Here\u2019s the step-by-step explanation for the given scenario:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Assumptions:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>L2 Cache<\/strong>: Direct-mapped with 4 sets (Set 0 to Set 3).<\/li>\n\n\n\n<li><strong>L1 Cache<\/strong>: Fully associative with a capacity of 2 blocks and uses <strong>LRU replacement<\/strong>.<\/li>\n\n\n\n<li><strong>Current State<\/strong>:<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>L1 Cache: Contains <code>A<\/code> and <code>B<\/code> (most recently used first order assumed as <code>A, B<\/code>).<\/li>\n\n\n\n<li>L2 Cache:\n<ul class=\"wp-block-list\">\n<li>Set 0: Contains <code>A<\/code>.<\/li>\n\n\n\n<li>Set 1: Contains <code>B<\/code>.<\/li>\n\n\n\n<li>Set 2: Contains <code>C<\/code>.<\/li>\n\n\n\n<li>Set 3: Contains <code>D<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Block <code>E<\/code> maps to <strong>Set 3<\/strong> in L2 Cache.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Access: Block <code>E<\/code> (maps to Set 3 in L2)<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Case 1: <strong>Inclusive L2 Cache<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Rule<\/strong>: L1 cache must contain only blocks also present in L2 cache.<\/li>\n\n\n\n<li><strong>Access flow<\/strong>:<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Block <code>E<\/code> replaces <code>D<\/code> in <strong>Set 3 of L2<\/strong> (due to direct mapping).<\/li>\n\n\n\n<li>Since <code>D<\/code> is removed from L2, it must also be invalidated in L1 (inclusive property).<\/li>\n\n\n\n<li>Block <code>E<\/code> is loaded into L1.<\/li>\n\n\n\n<li>L1 now updates based on <strong>LRU replacement<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Since <code>A<\/code> and <code>B<\/code> are in L1 and the capacity is 2, the least recently used block (<code>B<\/code>) is evicted to accommodate <code>E<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Final State<\/strong>:<\/li>\n\n\n\n<li><strong>L1 Cache<\/strong>: <code>A, E<\/code> (most recent first).<\/li>\n\n\n\n<li><strong>L2 Cache<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Set 0: <code>A<\/code>.<\/li>\n\n\n\n<li>Set 1: <code>B<\/code>.<\/li>\n\n\n\n<li>Set 2: <code>C<\/code>.<\/li>\n\n\n\n<li>Set 3: <code>E<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Case 2: <strong>Non-Inclusive L2 Cache<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Rule<\/strong>: L1 and L2 are independent; L1 may contain blocks not present in L2.<\/li>\n\n\n\n<li><strong>Access flow<\/strong>:<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Block <code>E<\/code> replaces <code>D<\/code> in <strong>Set 3 of L2<\/strong> (due to direct mapping).<\/li>\n\n\n\n<li>No invalidation occurs in L1 (non-inclusive property allows <code>D<\/code> to remain in L1).<\/li>\n\n\n\n<li>Block <code>E<\/code> is loaded into L1. Based on <strong>LRU<\/strong>, <code>B<\/code> (least recently used in L1) is evicted.<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Final State<\/strong>:<\/li>\n\n\n\n<li><strong>L1 Cache<\/strong>: <code>A, E<\/code> (most recent first).<\/li>\n\n\n\n<li><strong>L2 Cache<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Set 0: <code>A<\/code>.<\/li>\n\n\n\n<li>Set 1: <code>B<\/code>.<\/li>\n\n\n\n<li>Set 2: <code>C<\/code>.<\/li>\n\n\n\n<li>Set 3: <code>E<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Key Difference:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Inclusive L2 Cache<\/strong>: Blocks evicted from L2 are invalidated in L1.<\/li>\n\n\n\n<li><strong>Non-Inclusive L2 Cache<\/strong>: No invalidation in L1 occurs when blocks are evicted from L2.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Cache Inclusion Assume you have an L2 cache that is direct-mapped with 4 sets. Assume L1 cache is fully-associate with capacity of 2 blocks and it uses LRU policy If you know that blocks A, B, C and D map to sets 0, 1, 2 and 3 in L2 Cache. If you know the current [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25],"tags":[],"class_list":["post-185036","post","type-post","status-publish","format-standard","hentry","category-exams-certification"],"_links":{"self":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/185036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/comments?post=185036"}],"version-history":[{"count":0,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/185036\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/media?parent=185036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/categories?post=185036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/tags?post=185036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}