EEL-4713 Computer Architecture Virtual Memory Outline Memory

Total Page:16

File Type:pdf, Size:1020Kb

EEL-4713 Computer Architecture Virtual Memory Outline Memory Outline ° Recap of Memory Hierarchy EEL-4713 Computer Architecture ° Virtual Memory Virtual Memory ° Page Tables and TLB ° Protection vm.1 vm.2 Memory addressing - physical Virtual Memory? Provides illusion of very large memory – sum of the memory of many jobs greater than physical memory ° So far we considered addresses of loads/stores go directly to caches/memory – address space of each job larger than physical memory • As in your project Allows available (fast and expensive) physical memory to be efficiently utilized Simplifies memory management and programming ° This makes life complicated if a computer is multi-processed/multi-user • How do you assign addresses within a program so that you know other Exploits memory hierarchy to keep average access time low. users/programs will not conflict with them? Program A: Program B: Involves at least two storage levels: main and secondary store 0x100,1 store 0x100,5 Main (DRAM): nanoseconds, M/GBytes Secondary (HD): miliseconds, G/TBytes load R1,0x100 Virtual Address -- address used by the programmer Virtual Address Space -- collection of such addresses Memory Address -- address of word in physical memory also known as “physical address” or “real address” vm.3 vm.4 Memory addressing - virtual Basic Issues in VM System Design size of information blocks (pages) that are transferred from secondary (disk) to main storage (Mem) Program A: Program B: Page brought into Mem, if Mem is full some page of Mem must be released to make room for the new page --> store 0x100,1 store 0x100,5 replacement policy load R1,0x100 missing page fetched from secondary memory only on the occurrence of a page fault --> fetch/load policy disk Translation A: Translation B: mem cache 0x100 -> 0x40000100 0x100 -> 0x50000100 reg pages Use software and hardware to guarantee no conflicts frame Operating system: keep software translation tables Paging Organization Hardware: cache recent translations virtual and physical address space partitioned into blocks of equal size page frames pages vm.5 vm.6 Address Map Paging Organization Page size: Phys Addr (PA) Virt. Addr (VA) V = {0, 1, . , n - 1} virtual address space n can be > m unit of M = {0, 1, . , m - 1} physical address space 0 frame 0 1K 0 page 0 1K mapping Addr 1024 1 1K 1024 1 1K MAP: V --> M U {0} address mapping function Trans MAP also unit of MAP(a) = a' if data at virtual address a is present in physical 7168 7 1K transfer from address a' in M virtual to Physical physical = 0 if data at virtual address a is not present in M need to Memory memory allocate address in M 31744 31 1K Virtual Memory a missing item fault Name Space V Address Mapping fault 10 Page table stored in memory handler VA page no. Page offset One page table per process Processor Start of page table stored in 0 page table base register Addr Trans Main Secondary Page Table V – Is page in memory or on disk Mechanism Memory Memory Page Table a Base Reg a' Access index V Rights PA + (concatenation) into physical address OS performs page this transfer table table located physical in physical memory memory address vm.7 vm.8 Address Mapping Algorithm *Hardware/software interface If V = 1 (where is page currently stored?) then page is in main memory at frame address stored in table ° What checks does the processor perform during a load/store memory else page is located in secondary memory (location determined at access? process creation) • Effective address computed in pipeline is virtual Access Rights • Before accessing memory, must perform virtual-physical mapping R = Read-only, R/W = read/write, X = execute only - At hardware speed, critical to performance If kind of access not compatible with specified access rights, • If there is a valid mapping, load/store proceeds as usual; address then protection_violation_fault sent to cache, DRAM is the mapped address (physical addressed) • If there is no valid mapping, or if there is a protection violation, If valid bit not set then page fault processor does not know how to handle it - Throw an exception Terms: – Save the PC of the instruction that caused the exception so that Protection Fault: access rights violation; hardware raises exception, it can be retried later microcode, or software fault handler – Jump into an operating system exception handling routine Page Fault: page not resident in physical memory, also causes a trap; - O/S handles exception using its specific policies (Linux, usually accompanied by a context switch: current process Windows will behave differently) suspended while page is fetched from secondary storage; page faults - Once it finishes handling, issue “return from interrupt” usually handled in software by OS because page fault to instruction to recover PC and try instruction again secondary memory takes million+ cycles vm.9 vm.10 Virtual Address and a Cache TLBs VA PA miss A way to speed up translation is to use a special cache of recently used page table entries -- this has many names, but the most Trans- Main CPU Cache frequently used is Translation Lookaside Buffer or TLB lation Memory hit Virtual Address Physical Address Dirty Ref Valid Access data It takes an extra memory access to translate VA to PA This makes cache access very expensive, and this is the "innermost TLB access time comparable to, though shorter than, cache access time loop" that you want to go as fast as possible (still much less than main memory access time) ASIDE: Why access cache with PA at all? VA caches have a problem! synonym problem: 1. two different virtual addresses map to same physical address => two different cache entries holding data for the same physical address! (data sharing between different processes) 2. two same virtual addresses (from different processes) map to different physical addresses vm.11 vm.12 Translation Look-Aside Buffers Reducing Translation Time Just like any other cache, the TLB can be organized as fully associative, set associative, or direct mapped TLBs are usually small, typically not more than hundreds of entries. Machines with TLBs can go one step further to reduce # cycles/cache This permits large/full associativity. access They overlap the cache access with the TLB access Works because high order bits of the VA are used to look up in the TLB while low order bits are used as index into cache * Virtually indexed, physically tagged. hit VA PA miss TLB Main CPU Cache Lookup Memory Translation miss hit with a TLB Trans- lation data vm.13 1/2 t t 20 t vm.14 Overlapped Cache & TLB Access Problems With Overlapped TLB Access Overlapped access only works as long as the address bits used to index into the cache do not change as the result of VA translation assoc index This usually limits things to small caches, large page sizes, or high 32 1 K TLB lookup Cache n-way set associative caches if you want a large cache (e.g., cache size and page size need to match) 4 bytes Example: suppose everything the same except that the cache is 10 2 increased to 8 K bytes instead of 4 K: 00 11 2 cache index 00 Hit/ PA PA Data Hit/ This bit is changed Miss 20 12 Miss by VA translation, but page # disp 20 12 is needed for cache virt page # disp lookup = Solutions: go to 8K byte page sizes IF cache hit AND (cache tag = PA) then deliver data to CPU go to 2 way set associative cache (would allow you to continue to ELSE IF [cache miss OR (cache tag != PA)] and TLB hit THEN use a 10 bit index) access memory with the PA from the TLB ELSE do standard VA translation 1K 2 way set assoc cache 10 4 4 vm.15 vm.16 Hardware versus software TLB management Optimal Page Size Choose page that minimizes fragmentation ° The TLB misses can be handled either by software or hardware large page size => internal fragmentation more severe (unused memory) BUT increase in the # of pages / name space => larger page tables • Software: processor has instructions to modify TLB in the architecture; O/S handles replacement • E.g. MIPS In general, the trend is towards larger page sizes because • Hardware: processor handles replacement without need for instructions to store TLB entries -- memories get larger as the price of RAM drops • E.g. x86 -- the gap between processor speed and disk speed grows wider Larger pages can exploit more spatial locality in transfers between ° Instructions that cause TLB “flushes” are needed in hardware case too disk and memory -- programmers desire larger virtual address spaces Most machines at 4K-64K byte pages today, with page sizes likely to increase vm.17 vm.18 2-level page table Example: two-level address translation in x86 Root Page Tables Second Level Page Table 4 bytes PA 4 bytes PA Data Pages VA 10 10 12 Seg 0 256 P0 1 K D0 4 K directory CR3 . PA . PA . Seg 1 . P255 D1023 . table Seg 1 Mbyte, but allocated Allocated in PA 255 in system virtual addr User Virtual space Space 256K bytes in physical memory 8 8 10 12 38 2 x 2 x 2 x 2 = 2 vm.19 vm.20 Example: Linux VM Linux VM areas vm_area_struct! process virtual memory! ° Demand-paging task_struct! mm_struct! vm_end! • Pages are brought into physical memory when referenced mm! vm_start! mmap! vm_prot! ° Kernel keeps track of each process’ virtual address space using a mm_struct data structure shared libraries! • Which contains pointers to list of “area” structures vm_next! (vm_area_struct) vm_end! • Linked list of vm_area structures vm_start! associated with process vm_prot! • Start/end: data! - Bounds of each VM map • Prot: vm_next! - Protection info (r/w) text! vm_end! vm_start! vm_prot! vm_next! vm.21 vm.22 Linux fault handling VM “areas” ° Exception triggers O/S handling if address process virtual memory! out of bounds or protection violated ° Linked vm_area_struct structures vm_area_struct! ° A VM area: a part of the process virtual memory space that has a vm_end! ° Traverse vm_area list, check for bounds special rule for the page-fault handlers (i.e.
Recommended publications
  • Virtual Memory
    Chapter 4 Virtual Memory Linux processes execute in a virtual environment that makes it appear as if each process had the entire address space of the CPU available to itself. This virtual address space extends from address 0 all the way to the maximum address. On a 32-bit platform, such as IA-32, the maximum address is 232 − 1or0xffffffff. On a 64-bit platform, such as IA-64, this is 264 − 1or0xffffffffffffffff. While it is obviously convenient for a process to be able to access such a huge ad- dress space, there are really three distinct, but equally important, reasons for using virtual memory. 1. Resource virtualization. On a system with virtual memory, a process does not have to concern itself with the details of how much physical memory is available or which physical memory locations are already in use by some other process. In other words, virtual memory takes a limited physical resource (physical memory) and turns it into an infinite, or at least an abundant, resource (virtual memory). 2. Information isolation. Because each process runs in its own address space, it is not possible for one process to read data that belongs to another process. This improves security because it reduces the risk of one process being able to spy on another pro- cess and, e.g., steal a password. 3. Fault isolation. Processes with their own virtual address spaces cannot overwrite each other’s memory. This greatly reduces the risk of a failure in one process trig- gering a failure in another process. That is, when a process crashes, the problem is generally limited to that process alone and does not cause the entire machine to go down.
    [Show full text]
  • Requirements on Security Management for Adaptive Platform AUTOSAR AP R20-11
    Requirements on Security Management for Adaptive Platform AUTOSAR AP R20-11 Requirements on Security Document Title Management for Adaptive Platform Document Owner AUTOSAR Document Responsibility AUTOSAR Document Identification No 881 Document Status published Part of AUTOSAR Standard Adaptive Platform Part of Standard Release R20-11 Document Change History Date Release Changed by Description • Reworded PEE requirement [RS_SEC_05019] AUTOSAR • Added chapter ’Conventions’ and 2020-11-30 R20-11 Release ’Acronyms’ Management • Minor editorial changes to comply with AUTOSAR RS template • Fix spelling in [RS_SEC_05012] • Reworded secure channel AUTOSAR requirements [RS SEC 04001], [RS 2019-11-28 R19-11 Release SEC 04003] and [RS SEC 04003] Management • Changed Document Status from Final to published AUTOSAR 2019-03-29 19-03 Release • Unnecessary requirement [RS SEC Management 05006] removed AUTOSAR 2018-10-31 18-10 Release • Chapter 2.3 ’Protected Runtime Management Environment’ revised AUTOSAR • Moved the Identity and Access 2018-03-29 18-03 Release chapter into RS Identity and Access Management Management (899) AUTOSAR 2017-10-27 17-10 Release • Initial Release Management 1 of 32 Document ID 881: AUTOSAR_RS_SecurityManagement Requirements on Security Management for Adaptive Platform AUTOSAR AP R20-11 Disclaimer This work (specification and/or software implementation) and the material contained in it, as released by AUTOSAR, is for the purpose of information only. AUTOSAR and the companies that have contributed to it shall not be liable for any use of the work. The material contained in this work is protected by copyright and other types of intel- lectual property rights. The commercial exploitation of the material contained in this work requires a license to such intellectual property rights.
    [Show full text]
  • Common Object File Format (COFF)
    Application Report SPRAAO8–April 2009 Common Object File Format ..................................................................................................................................................... ABSTRACT The assembler and link step create object files in common object file format (COFF). COFF is an implementation of an object file format of the same name that was developed by AT&T for use on UNIX-based systems. This format encourages modular programming and provides powerful and flexible methods for managing code segments and target system memory. This appendix contains technical details about the Texas Instruments COFF object file structure. Much of this information pertains to the symbolic debugging information that is produced by the C compiler. The purpose of this application note is to provide supplementary information on the internal format of COFF object files. Topic .................................................................................................. Page 1 COFF File Structure .................................................................... 2 2 File Header Structure .................................................................. 4 3 Optional File Header Format ........................................................ 5 4 Section Header Structure............................................................. 5 5 Structuring Relocation Information ............................................... 7 6 Symbol Table Structure and Content........................................... 11 SPRAAO8–April 2009
    [Show full text]
  • Virtual Memory - Paging
    Virtual memory - Paging Johan Montelius KTH 2020 1 / 32 The process code heap (.text) data stack kernel 0x00000000 0xC0000000 0xffffffff Memory layout for a 32-bit Linux process 2 / 32 Segments - a could be solution Processes in virtual space Address translation by MMU (base and bounds) Physical memory 3 / 32 one problem Physical memory External fragmentation: free areas of free space that is hard to utilize. Solution: allocate larger segments ... internal fragmentation. 4 / 32 another problem virtual space used code We’re reserving physical memory that is not used. physical memory not used? 5 / 32 Let’s try again It’s easier to handle fixed size memory blocks. Can we map a process virtual space to a set of equal size blocks? An address is interpreted as a virtual page number (VPN) and an offset. 6 / 32 Remember the segmented MMU MMU exception no virtual addr. offset yes // < within bounds index + physical address segment table 7 / 32 The paging MMU MMU exception virtual addr. offset // VPN available ? + physical address page table 8 / 32 the MMU exception exception virtual address within bounds page available Segmentation Paging linear address physical address 9 / 32 a note on the x86 architecture The x86-32 architecture supports both segmentation and paging. A virtual address is translated to a linear address using a segmentation table. The linear address is then translated to a physical address by paging. Linux and Windows do not use use segmentation to separate code, data nor stack. The x86-64 (the 64-bit version of the x86 architecture) has dropped many features for segmentation.
    [Show full text]
  • Advanced X86
    Advanced x86: BIOS and System Management Mode Internals Input/Output Xeno Kovah && Corey Kallenberg LegbaCore, LLC All materials are licensed under a Creative Commons “Share Alike” license. http://creativecommons.org/licenses/by-sa/3.0/ ABribuEon condiEon: You must indicate that derivave work "Is derived from John BuBerworth & Xeno Kovah’s ’Advanced Intel x86: BIOS and SMM’ class posted at hBp://opensecuritytraining.info/IntroBIOS.html” 2 Input/Output (I/O) I/O, I/O, it’s off to work we go… 2 Types of I/O 1. Memory-Mapped I/O (MMIO) 2. Port I/O (PIO) – Also called Isolated I/O or port-mapped IO (PMIO) • X86 systems employ both-types of I/O • Both methods map peripheral devices • Address space of each is accessed using instructions – typically requires Ring 0 privileges – Real-Addressing mode has no implementation of rings, so no privilege escalation needed • I/O ports can be mapped so that they appear in the I/O address space or the physical-memory address space (memory mapped I/O) or both – Example: PCI configuration space in a PCIe system – both memory-mapped and accessible via port I/O. We’ll learn about that in the next section • The I/O Controller Hub contains the registers that are located in both the I/O Address Space and the Memory-Mapped address space 4 Memory-Mapped I/O • Devices can also be mapped to the physical address space instead of (or in addition to) the I/O address space • Even though it is a hardware device on the other end of that access request, you can operate on it like it's memory: – Any of the processor’s instructions
    [Show full text]
  • Virtual Memory in X86
    Fall 2017 :: CSE 306 Virtual Memory in x86 Nima Honarmand Fall 2017 :: CSE 306 x86 Processor Modes • Real mode – walks and talks like a really old x86 chip • State at boot • 20-bit address space, direct physical memory access • 1 MB of usable memory • No paging • No user mode; processor has only one protection level • Protected mode – Standard 32-bit x86 mode • Combination of segmentation and paging • Privilege levels (separate user and kernel) • 32-bit virtual address • 32-bit physical address • 36-bit if Physical Address Extension (PAE) feature enabled Fall 2017 :: CSE 306 x86 Processor Modes • Long mode – 64-bit mode (aka amd64, x86_64, etc.) • Very similar to 32-bit mode (protected mode), but bigger address space • 48-bit virtual address space • 52-bit physical address space • Restricted segmentation use • Even more obscure modes we won’t discuss today xv6 uses protected mode w/o PAE (i.e., 32-bit virtual and physical addresses) Fall 2017 :: CSE 306 Virt. & Phys. Addr. Spaces in x86 Processor • Both RAM hand hardware devices (disk, Core NIC, etc.) connected to system bus • Mapped to different parts of the physical Virtual Addr address space by the BIOS MMU Data • You can talk to a device by performing Physical Addr read/write operations on its physical addresses Cache • Devices are free to interpret reads/writes in any way they want (driver knows) System Interconnect (Bus) : all addrs virtual DRAM Network … Disk (Memory) Card : all addrs physical Fall 2017 :: CSE 306 Virt-to-Phys Translation in x86 0xdeadbeef Segmentation 0x0eadbeef Paging 0x6eadbeef Virtual Address Linear Address Physical Address Protected/Long mode only • Segmentation cannot be disabled! • But can be made a no-op (a.k.a.
    [Show full text]
  • Address Translation
    CS 152 Computer Architecture and Engineering Lecture 8 - Address Translation John Wawrzynek Electrical Engineering and Computer Sciences University of California at Berkeley http://www.eecs.berkeley.edu/~johnw http://inst.eecs.berkeley.edu/~cs152 9/27/2016 CS152, Fall 2016 CS152 Administrivia § Lab 2 due Friday § PS 2 due Tuesday § Quiz 2 next Thursday! 9/27/2016 CS152, Fall 2016 2 Last time in Lecture 7 § 3 C’s of cache misses – Compulsory, Capacity, Conflict § Write policies – Write back, write-through, write-allocate, no write allocate § Multi-level cache hierarchies reduce miss penalty – 3 levels common in modern systems (some have 4!) – Can change design tradeoffs of L1 cache if known to have L2 § Prefetching: retrieve memory data before CPU request – Prefetching can waste bandwidth and cause cache pollution – Software vs hardware prefetching § Software memory hierarchy optimizations – Loop interchange, loop fusion, cache tiling 9/27/2016 CS152, Fall 2016 3 Bare Machine Physical Physical Address Inst. Address Data Decode PC Cache D E + M Cache W Physical Memory Controller Physical Address Address Physical Address Main Memory (DRAM) § In a bare machine, the only kind of address is a physical address 9/27/2016 CS152, Fall 2016 4 Absolute Addresses EDSAC, early 50’s § Only one program ran at a time, with unrestricted access to entire machine (RAM + I/O devices) § Addresses in a program depended upon where the program was to be loaded in memory § But it was more convenient for programmers to write location-independent subroutines How
    [Show full text]
  • Lecture 12: Virtual Memory Finale and Interrupts/Exceptions 1 Review And
    EE360N: Computer Architecture Lecture #12 Department of Electical and Computer Engineering The University of Texas at Austin October 9, 2008 Disclaimer: The contents of this document are scribe notes for The University of Texas at Austin EE360N Fall 2008, Computer Architecture.∗ The notes capture the class discussion and may contain erroneous and unverified information and comments. Lecture 12: Virtual Memory Finale and Interrupts/Exceptions Lecture #12: October 8, 2008 Lecturer: Derek Chiou Scribe: Michael Sullivan and Peter Tran Lecture 12 of EE360N: Computer Architecture summarizes the significance of virtual memory and introduces the concept of interrupts and exceptions. As such, this document is divided into two sections. Section 1 details the key points from the discussion in class on virtual memory. Section 2 goes on to introduce interrupts and exceptions, and shows why they are necessary. 1 Review and Summation of Virtual Memory The beginning of this lecture wraps up the review of virtual memory. A broad summary of virtual memory systems is given first, in Subsection 1.1. Next, the individual components of the hardware and OS that are required for virtual memory support are covered in 1.2. Finally, the addressing of caches and the interface between the cache and virtual memory are described in 1.3. 1.1 Summary of Virtual Memory Systems Virtual memory automatically provides the illusion of a large, private, uniform storage space for each process, even on a limited amount of physically addressed memory. The virtual memory space available to every process looks the same every time the process is run, irrespective of the amount of memory available, or the program’s actual placement in main memory.
    [Show full text]
  • Virtual Memory
    CSE 410: Systems Programming Virtual Memory Ethan Blanton Department of Computer Science and Engineering University at Buffalo Introduction Address Spaces Paging Summary References Virtual Memory Virtual memory is a mechanism by which a system divorces the address space in programs from the physical layout of memory. Virtual addresses are locations in program address space. Physical addresses are locations in actual hardware RAM. With virtual memory, the two need not be equal. © 2018 Ethan Blanton / CSE 410: Systems Programming Introduction Address Spaces Paging Summary References Process Layout As previously discussed: Every process has unmapped memory near NULL Processes may have access to the entire address space Each process is denied access to the memory used by other processes Some of these statements seem contradictory. Virtual memory is the mechanism by which this is accomplished. Every address in a process’s address space is a virtual address. © 2018 Ethan Blanton / CSE 410: Systems Programming Introduction Address Spaces Paging Summary References Physical Layout The physical layout of hardware RAM may vary significantly from machine to machine or platform to platform. Sometimes certain locations are restricted Devices may appear in the memory address space Different amounts of RAM may be present Historically, programs were aware of these restrictions. Today, virtual memory hides these details. The kernel must still be aware of physical layout. © 2018 Ethan Blanton / CSE 410: Systems Programming Introduction Address Spaces Paging Summary References The Memory Management Unit The Memory Management Unit (MMU) translates addresses. It uses a per-process mapping structure to transform virtual addresses into physical addresses. The MMU is physical hardware between the CPU and the memory bus.
    [Show full text]
  • An Internet Protocol (IP) Address Is a Numerical Label That Is
    Computer Communication Networks Lecture No. 5 Computer Network Lectures IP address An Internet Protocol (IP) address is a numerical label that is assigned to devices participating in a computer network, that uses the Internet Protocol for communication between its nodes. An IP address serves two principal functions: 1- host or network interface identification 2- location addressing. Its role has been characterized as follows: "A name indicates what we seek. An address indicates where it is. A route indicates how to get there." The designers of TCP/IP defined an IP address as a 32-bit number and this system, known as Internet Protocol Version 4 or IPv4, is still in use today. However, due to the enormous growth of the Internet and the resulting depletion of available addresses, a new addressing system (IPv6), using 128 bits for the address, was developed in 1995. Although IP addresses are stored as binary numbers, they are usually displayed in human-readable notations, such as 208.77.188.166 (for IPv4), and 2001:db8:0:1234:0:567:1:1 (for IPv6). The Internet Protocol also routes data packets between networks; IP addresses specify the locations of the source and destination nodes in the topology of the routing system. For this purpose, some of the bits in an IP address are used to designate a sub network. As the development of private networks raised the threat of IPv4 address exhaustion, RFC 1918 set aside a group of private address spaces that may be used by anyone on private networks. They are often used with network address translators to connect to the global public Internet.
    [Show full text]
  • X86 Memory Protection and Translation
    x86 Memory Protection and Translation Don Porter CSE 506 Lecture Goal ò Understand the hardware tools available on a modern x86 processor for manipulating and protecting memory ò Lab 2: You will program this hardware ò Apologies: Material can be a bit dry, but important ò Plus, slides will be good reference ò But, cool tech tricks: ò How does thread-local storage (TLS) work? ò An actual (and tough) Microsoft interview question Undergrad Review ò What is: ò Virtual memory? ò Segmentation? ò Paging? Two System Goals 1) Provide an abstraction of contiguous, isolated virtual memory to a program 2) Prevent illegal operations ò Prevent access to other application or OS memory ò Detect failures early (e.g., segfault on address 0) ò More recently, prevent exploits that try to execute program data Outline ò x86 processor modes ò x86 segmentation ò x86 page tables ò Software vs. Hardware mechanisms ò Advanced Features ò Interesting applications/problems x86 Processor Modes ò Real mode – walks and talks like a really old x86 chip ò State at boot ò 20-bit address space, direct physical memory access ò Segmentation available (no paging) ò Protected mode – Standard 32-bit x86 mode ò Segmentation and paging ò Privilege levels (separate user and kernel) x86 Processor Modes ò Long mode – 64-bit mode (aka amd64, x86_64, etc.) ò Very similar to 32-bit mode (protected mode), but bigger ò Restrict segmentation use ò Garbage collect deprecated instructions ò Chips can still run in protected mode with old instructions Translation Overview 0xdeadbeef Segmentation 0x0eadbeef Paging 0x6eadbeef Virtual Address Linear Address Physical Address Protected/Long mode only ò Segmentation cannot be disabled! ò But can be a no-op (aka flat mode) x86 Segmentation ò A segment has: ò Base address (linear address) ò Length ò Type (code, data, etc).
    [Show full text]
  • Virtual Memory
    Saint LouisCarnegie University Mellon Virtual Memory CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant & O’Hallaron’s slides 1 Saint LouisCarnegie University Mellon Data Representation in Memory Memory organization within a process Virtual vs. Physical memory ° Fundamental Idea and Purpose ° Page Mapping ° Address Translation ° Per-Process Mapping and Protection 2 Saint LouisCarnegie University Mellon Recall: Basic Memory Organization • • • Byte-Addressable Memory ° Conceptually a very large array, with a unique address for each byte ° Processor width determines address range: ° 32-bit processor has 2 32 unique addresses ° 64-bit processor has 264 unique addresses Where does a given process reside in memory? ° depends upon the perspective… – virtual memory: process can use most any virtual address – physical memory: location controlled by OS 3 Saint LouisCarnegie University Mellon Virtual Address Space not drawn to scale 0xFFFFFFFF for IA32 (x86) Linux Stack 8MB All processes have the same uniform view of memory Stack ° Runtime stack (8MB limit) ° E. g., local variables Heap ° Dynamically allocated storage ° When call malloc() , calloc() , new() Data ° Statically allocated data ° E.g., global variables, arrays, structures, etc. Heap Text Data Text ° Executable machine instructions 0x08000000 ° Read-only data 0x00000000 4 Saint LouisCarnegie University Mellon not drawn to scale Memory Allocation Example 0xFF…F Stack char big_array[1<<24]; /* 16 MB */ char huge_array[1<<28]; /* 256 MB */ int beyond; char *p1, *p2, *p3, *p4; int useless() { return 0; } int main() { p1 = malloc(1 <<28); /* 256 MB */ p2 = malloc(1 << 8); /* 256 B */ p3 = malloc(1 <<28); /* 256 MB */ p4 = malloc(1 << 8); /* 256 B */ /* Some print statements ..
    [Show full text]