{"id":1119,"date":"2024-04-05T07:24:59","date_gmt":"2024-04-05T07:24:59","guid":{"rendered":"https:\/\/learnlearn.uk\/ibcs\/?page_id=1119"},"modified":"2025-04-05T11:21:51","modified_gmt":"2025-04-05T11:21:51","slug":"virtual-memory-paging","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/","title":{"rendered":"Virtual Memory &#038; Paging"},"content":{"rendered":"<p>&nbsp;<\/p>\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Introduction<\/h2>\n<div class=\"tabcontent\">\n\n<h2>Virtual Memory Paging<\/h2>\n<p>Memory paging is a memory management technique used to control sharing of memory resources belonging to a computer or virtual machine (VM).<\/p>\n<p>In this scheme, the operating system retrieves data from secondary storage in same-size blocks called pages.<\/p>\n<p>A computer can address memory beyond the amount physically installed on the system. This non-physical memory, or virtual memory, is actually a section of a hard disk set up to emulate the computer&#8217;s RAM.<\/p>\n\n<\/div><h2 class=\"tabtitle\"> Address Spaces<\/h2>\n<div class=\"tabcontent\">\n\n<h2>Virtual Address Spaces<\/h2>\n<p>A virtual address space is the set of ranges of virtual addresses that an operating system makes available to a process (max 64 bits on a 64 bit OS) .<\/p>\n<p>Each process has its own virtual address space that is distinct from other processes.<\/p>\n<p>This provides several benefits, one of which is security through process isolation assuming each process is given a separate address space.<\/p>\n<h2>Physical Address space<\/h2>\n<p>When a process is loaded into RAM the virtual address space is mapped to a physical address space of the same size.<\/p>\n<p>The physical address space might be non-contiguous, meaning each page could be physically located in different parts of the RAM.<\/p>\n<p>The mapping assignments are recorded in the page table.<\/p>\n\n<\/div><h2 class=\"tabtitle\">Page Table<\/h2>\n<div class=\"tabcontent\">\n\n<h2>Page Table<\/h2>\n<p>The page table is a data structure used by a virtual memory system in a computer to store mappings between virtual addresses and physical addresses.<\/p>\n<p>The page table is set up by the computer&#8217;s operating system, and may be read and written by the memory management unit (MMU) or by low-level system software or firmware during the virtual address translation process .<\/p>\n<p>Physically, the memory of each process may be dispersed across different areas of physical memory, or may have been moved (paged out) to secondary storage, typically to a hard disk drive (HDD) or solid-state drive (SSD).<\/p>\n<p>However every process is given the impression that it is working with large, contiguous sections of memory.<\/p>\n\n<\/div><h2 class=\"tabtitle\">MMU<\/h2>\n<div class=\"tabcontent\">\n\n<h2>Memory Management Unit (MMU)<\/h2>\n<p>The MMU maps the virtual addresses from each program into separate areas in physical memory, which is generally much smaller than the theoretical maximum.<\/p>\n<p>This means that programs generally have addresses that access the theoretical maximum memory of the computer architecture, 32 or 64 bits.<\/p>\n<div><\/div>\n\n<\/div><h2 class=\"tabtitle\">TLB<\/h2>\n<div class=\"tabcontent\">\n\n<h2>Translation Lookaside Buffer<\/h2>\n<p>The Translation Lookaside Buffer (TLB) is a a small, fast memory cache that stores recently used mappings between virtual addresses and their corresponding physical addresses.<\/p>\n<p>Once the translation information is retrieved, a new TLB entry is created using this information. This typically includes the virtual address, the corresponding physical address, and additional control bits such as access permissions.<\/p>\n<p>If the TLB is full and there is no space for the new entry, a replacement policy is used to select an existing entry to be evicted from the TLB to make room for the new entry.<\/p>\n<p>Common replacement policies include least recently used (LRU), random replacement, or first-in-first-out (FIFO).<\/p>\n<div><\/div>\n\n<\/div><h2 class=\"tabtitle\">Page Fault \/ Miss<\/h2>\n<div class=\"tabcontent\">\n\n<h2>Page Fault \/ Page Table Miss<\/h2>\n<p>A page fault is an exception that the memory management unit (MMU) raises when a process accesses a memory page without proper preparations .<\/p>\n<p>The MMU raises the exception and the operating system&#8217;s kernel handles the exception by loading the requested page into RAM or denying an illegal memory access.<\/p>\n\n<\/div><h2 class=\"tabtitle\">Steps<\/h2>\n<div class=\"tabcontent\">\n\n<h2>Step 1 &#8211; Search the TLB<\/h2>\n<p>When a virtual address needs to be translated into a physical address, the Translation Lookaside Buffer is searched first.<\/p>\n<p>If a match is found, which is known as a TLB hit, the physical address is returned and memory access can continue.<\/p>\n<h2>Step 2 &#8211; Walking the Page Table<\/h2>\n<p>However, if there is no match this results in a TLB miss.<\/p>\n<p>The MMU, the system firmware, or the operating system&#8217;s TLB miss handler will look up the address mapping in the page table to see whether a mapping exists.<\/p>\n<p>This is known as a page walk.<\/p>\n<h2>Step 3 &#8211; Write Back to TLB<\/h2>\n<p>If the memory mapping exists, it is written back to the TLB and the faulting instruction is restarted.<\/p>\n<p>The subsequent translation will result in a TLB hit, and the memory access will continue.<\/p>\n<h2>Step 4 &#8211; Page Fault<\/h2>\n<p>If the page is not in RAM (because it had been paged out onto secondary storage) this will result in a page table miss, triggering a page fault).<\/p>\n<h2>Step 5 &#8211; Paging In<\/h2>\n<p>The process is not currently stored in RAM and therefore the system will need to load the process back into RAM (paged in).<\/p>\n<h2>Stage 6 &#8211; Paging Out<\/h2>\n<p>Other data in the RAM may need to be paged out the Secondary Storage.<\/p>\n<h2>Step 7 &#8211; Page Table Update &amp; Process Restart<\/h2>\n<p>Finally the page table and TLB are updated the process is restarted.<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Video<\/h2>\n<div class=\"tabcontent\">\n\n<div class=\"nv-iframe-embed\">\n<div class=\"container-lazyload preview-lazyload container-youtube js-lazyload--not-loaded\"><a href=\"https:\/\/www.youtube.com\/watch?v=8yO2FBBfaB0\" class=\"lazy-load-youtube preview-lazyload preview-youtube\" data-video-title=\"16.2.2 Basics of Virtual Memory\" title=\"Play video &quot;16.2.2 Basics of Virtual Memory&quot;\">https:\/\/www.youtube.com\/watch?v=8yO2FBBfaB0<\/a><noscript>Video can&#8217;t be loaded because JavaScript is disabled: <a href=\"https:\/\/www.youtube.com\/watch?v=8yO2FBBfaB0\" title=\"16.2.2 Basics of Virtual Memory\">16.2.2 Basics of Virtual Memory (https:\/\/www.youtube.com\/watch?v=8yO2FBBfaB0)<\/a><\/noscript><\/div>\n<\/div>\n\n<\/div><h2 class=\"tabtitle\">Resources<\/h2>\n<div class=\"tabcontent\">\n\n<p><a href=\"https:\/\/docs.google.com\/presentation\/d\/1IyDAa0h9VEiv4W2NUh2j_2VmoTpx29sTteU3Qng-CRs\/edit?usp=sharing\">Teacher Presentation<\/a><\/p>\n<p>&nbsp;<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Virtual Memory Paging Memory paging is a memory management technique used to control sharing of memory resources belonging to a computer or virtual machine (VM). In this scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. A computer can address memory beyond the amount physically installed on the system.&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Virtual Memory &#038; Paging<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"off","neve_meta_content_width":100,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Virtual Memory &#038; Paging - IB Computer Science<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Virtual Memory &#038; Paging - IB Computer Science\" \/>\n<meta property=\"og:description\" content=\"&nbsp; Virtual Memory Paging Memory paging is a memory management technique used to control sharing of memory resources belonging to a computer or virtual machine (VM). In this scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. A computer can address memory beyond the amount physically installed on the system.&hellip;&nbsp;Read More &raquo;Virtual Memory &#038; Paging\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/\" \/>\n<meta property=\"og:site_name\" content=\"IB Computer Science\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-05T11:21:51+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/\",\"name\":\"Virtual Memory &#038; Paging - IB Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#website\"},\"datePublished\":\"2024-04-05T07:24:59+00:00\",\"dateModified\":\"2025-04-05T11:21:51+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"IB Computer Science\",\"item\":\"https:\/\/learnlearn.uk\/ibcs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Virtual Memory &#038; Paging\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#website\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/\",\"name\":\"IB Computer Science\",\"description\":\"- learnlearn..uk\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/ibcs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#organization\",\"name\":\"IB Computer Science\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png\",\"width\":300,\"height\":41,\"caption\":\"IB Computer Science\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Virtual Memory &#038; Paging - IB Computer Science","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/","og_locale":"en_GB","og_type":"article","og_title":"Virtual Memory &#038; Paging - IB Computer Science","og_description":"&nbsp; Virtual Memory Paging Memory paging is a memory management technique used to control sharing of memory resources belonging to a computer or virtual machine (VM). In this scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. A computer can address memory beyond the amount physically installed on the system.&hellip;&nbsp;Read More &raquo;Virtual Memory &#038; Paging","og_url":"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/","og_site_name":"IB Computer Science","article_modified_time":"2025-04-05T11:21:51+00:00","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/","url":"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/","name":"Virtual Memory &#038; Paging - IB Computer Science","isPartOf":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#website"},"datePublished":"2024-04-05T07:24:59+00:00","dateModified":"2025-04-05T11:21:51+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/ibcs\/virtual-memory-paging\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"IB Computer Science","item":"https:\/\/learnlearn.uk\/ibcs\/"},{"@type":"ListItem","position":2,"name":"Virtual Memory &#038; Paging"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/ibcs\/#website","url":"https:\/\/learnlearn.uk\/ibcs\/","name":"IB Computer Science","description":"- learnlearn..uk","publisher":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/ibcs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/ibcs\/#organization","name":"IB Computer Science","url":"https:\/\/learnlearn.uk\/ibcs\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png","contentUrl":"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png","width":300,"height":41,"caption":"IB Computer Science"},"image":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/ibcs\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"&nbsp; Virtual Memory Paging Memory paging is a memory management technique used to control sharing of memory resources belonging to a computer or virtual machine (VM). In this scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. A computer can address memory beyond the amount physically installed on the system.&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/1119"}],"collection":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/comments?post=1119"}],"version-history":[{"count":4,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/1119\/revisions"}],"predecessor-version":[{"id":1213,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/1119\/revisions\/1213"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/media?parent=1119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}