Linux Memory Issues An introduction to some low-level and some high-level memory management concepts.

Slides:



Advertisements
Similar presentations
Memory Management Unit
Advertisements

Memory Management Unit
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
16.317: Microprocessor System Design I
4/14/2017 Discussed Earlier segmentation - the process address space is divided into logical pieces called segments. The following are the example of types.
Configuring the Operating System Configure Performance Options Processor scheduling and memory usage Virtual memory Memory for network performance Configure.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
IA32 Paging Scheme Introduction to the Intel x86’s support for “virtual” memory.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
UQC152H3 Advanced OS Memory Management under Linux.
IA-32 Processor Architecture
11/13/01CS-550 Presentation - Overview of Microsoft disk operating system. 1 An Overview of Microsoft Disk Operating System.
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
Vacuum tubes Transistor 1948 ICs 1960s Microprocessors 1970s.
1 Hardware and Software Architecture Chapter 2 n The Intel Processor Architecture n History of PC Memory Usage (Real Mode)
Linux Memory Management High-Level versus Low-Level.
Chapter 8.3: Memory Management
Memory Management (II)
Linux Vs. Windows NT Memory Management Hitesh Kumar
“Virtual” Memory How does the OS kernel provide “private” and “shared” memory areas to multiple concurrent processes?
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
Memory Management 2010.
Linux Memory Issues Introduction. Some Architecture History 8080 (late-1970s) 16-bit address (64-KB) 8086 (early-1980s) 20-bit address (1-MB) (mid-’80s)
The kernel’s task list Introduction to process descriptors and their related data-structures for Linux kernel version
1 Last Class: Introduction Operating system = interface between user & architecture Importance of OS OS history: Change is only constant User-level Applications.
Introduction to the Intel x86’s support for “virtual” memory
CS2422 Assembly Language & System Programming September 22, 2005.
Chapter 91 Translation Lookaside Buffer (described later with virtual memory) Frame.
Silberschatz, Galvin and Gagne  Operating System Concepts Segmentation Memory-management scheme that supports user view of memory. A program.
Protected Mode. Protected Mode (1 of 2) 4 GB addressable RAM –( to FFFFFFFFh) Each program assigned a memory partition which is protected from.
Linux Memory Management How does the Linux kernel keep track of the Virtual Memory Areas that each process uses?
1 OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
1 CSC 539: Operating Systems Structure and Design Spring 2005 Memory management  swapping  contiguous allocation  paging  segmentation  segmentation.
Memory Management in Windows and Linux &. Windows Memory Management Virtual memory manager (VMM) –Executive component responsible for managing memory.
Address Translation Mechanism of 80386
1/2002JNM1 With 20 bits, 1,048,576 different combinations are available. Each memory location is assigned a different combination. Each memory location.
Memory Addressing in Linux  Logical Address machine language instruction location  Linear address (virtual address) a single 32 but unsigned integer.
The Intel Microprocessors. Real Mode Memory Addressing Real mode, also called real address mode, is an operating mode of and later x86-compatible.
Linux Virtual Memory for Intel Processor
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
CS 6560 Operating System Design Lecture 8: Memory Management.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Memory Addressing / Kernel Modules.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
Memory Addressing in Linux (Chap. 2, Understanding the Linux Kernel) J. H. Wang Oct. 20, 2008.
Paging Example What is the data corresponding to the logical address below:
80386DX.
1 i386 Memory Management Professor Ching-Chi Hsu 1998 年 4 月.
The Microprocessor and Its Architecture A Course in Microprocessor Electrical Engineering Department University of Indonesia.
ICOM Noack Memory management Virtual memory Paging and segmentation Demand paging Memory management hardware.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy.
What is a Process ? A program in execution.
Microprocessor and Assembly Language Addressing Models
Memory Management Chapter 5 Advanced Operating System.
Memory Management 백 일 우
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Example: The Intel 32 and 64-bit Architectures Dominant industry chips.
Linux 2.6 Memory Management Joseph Garvin. Why do we care? Without keeping multiple process in memory at once, we loose all the hard work we just did.
Virtual Memory: Systems
Address Translation Mechanism of 80386
143A: Principles of Operating Systems Lecture 5: Address translation
Virtual Memory: Systems
Operating Modes UQ: State and explain the operating modes of X86 family of processors. Show the mode transition diagram highlighting important features.(10.
Virtual Memory: Systems
Microprocessor and Assembly Language Addressing Models
Page Replacement Implementation Issues
Introduction to the Intel x86’s support for “virtual” memory
Introduction to the Pentium’s support for “virtual” memory
Assembly Language for Intel-Based Computers, 5th Edition
Chapter 1: Introduction CSS503 Systems Programming
Virtual Memory and Paging
Presentation transcript:

Linux Memory Issues An introduction to some low-level and some high-level memory management concepts

Some Architecture History 8080 (late-1970s) 16-bit address (64-KB) 8086 (early-1980s) 20-bit address (1-MB) (mid-’80s) 24-bit address (16-MB) (late-’80s) 32-bit address (4-GB) (late-’90s) 36-bit address (64-GB) Core2 (mid-2000s) 40-bit address (1-TB)

‘Backward Compatibility’ Many buyers resist ‘early obsolescence’ New processors need to run old programs Early design-decisions leave their legacy 8086 could run recompiled 8080 programs 80x86 can still run most 8086 applications Win95/98 could run most MS-DOS apps But a few areas of incompatibility existed

Linux must accommodate legacy Legacy elements: hardware and firmware CPU: reset-address and interrupt vectors ROM-BIOS: data area and boot location Display Controllers: VRAM & video BIOS Support chipsets: 15MB ‘Memory Window’ DMA: 24-bit memory-address bus SMP: combined Local and I/O APICs

Other CPU Architectures Besides IA-32, Linux runs on other CPUs (e.g., PowerPC, MC68000, IBM360, Sparc) So must accommodate their differences –Memory-Mapped I/O –Wider address-buses –Non-Uniform Memory Access (NUMA)

Nodes, Zones, and Pages Nodes: to accommodate NUMA systems However 80x86 doesn’t support NUMA So on 80x86 Linux uses just one ‘node’ Zones: to accommodate distinct regions Three ‘zones’ on 80x86: –ZONE_DMA (memory below 16-MB) –ZONE_NORMAL (from 16-MB to 896-MB) –ZONE_HIGHMEM (memory above 896-MB)

Zones divided into Pages 80x86 supports 4-KB page-frames Linux uses an array of ‘page descriptors’ Array of page descriptors: ‘mem_map[]’ physical memory is ‘mapped’ by CPU

How 80x86 Addresses RAM Two-stages:‘segmentation’ plus ‘paging’: –First: logical address  linear address –Then: linear address  physical address CPU employs special caches: –Segment-registers contain ‘hidden’ fields –Paging uses ‘Translation Lookaside Buffer’

Logical to Linear selector GDTR segment-registeroperand-offset virtual address-space memory segment global descriptor table base-address and segment-limit descriptor

Segment Descriptor Format Limit[ ] Base[ ] Base[ ]Base[ ] Limit [ ] 310

Linear to Physical physical address-space offsettable-index linear address CR3 dir-index page frame page directory page table

CR3 and CR4 Register CR3 holds the physical address of the current task’s page-directory table Register CR4 was added in the so software would have the option of “turning on” certain advanced new CPU features, yet older software still could execute (by just leaving the new features “turned off”)

Example: Page-Size Extensions can map either 4KB or 4MB pages With 4MB pages: middle table is omitted Entire 4GB address-space is subdivided into MB-pages Demo-module: ‘cr3.c’ creates a pseudo-file showing the values in CR3 and in CR4

Linear to Physical physical address-space offset linear address CR3 dir-index page frame page directory 4-MB page-frames

PageTable Entry Format Frame Address 0 31 Frame attributes 1112 Some Frame Attributes: P : (present=1, not-present=0) R/W : (writable=1, readonly=0) U/S : (user=1, supervisor=0) D : (dirty=1, clean=0) A : (accessed=1, not-accessed=0) S : (size 4MB = 1, size 4KB = 0)

Visualizing Memory Our ‘pgdir.c’ module creates a pseudo-file that lets users see a visual depiction of the CPU’s current ‘map’ of ‘virtual memory’ Virtual address-space (4-GB) –subdivided into 4MB pages (1024 pels) –Text characters: 16 rows by 64 columns

Virtual Memory Visualization Shows which addresses are ‘mapped’ Display granularity is 4MB Data is gotten from task’s page-directory Page-Directory location is in register CR3 Legend: ‘-’ = frame not mapped ‘3’ = r/w by supervisor ‘7’ = r/w by user

Assigning memory to tasks Each Linux process has a ‘process descriptor’ with a pointer inside it named ‘mm’: struct task_struct { pid_tpid; char comm[16]; struct mm_struct*mm; /* plus many additional fields */ };

struct mm_struct It describes the task’s ‘memory map’ Where’s the code, the data, the stack? Where are the ‘shared libraries’? What are attributes of each memory area? How many distinct memory areas? Where is the task’s ‘page directory’?

Demo: ‘mm.c’ It creates a pseudo-file: ‘/proc/mm’ Allows users to see values stored in some of the ‘mm_struct’ object’s important fields

Virtual Memory Areas Inside ‘mm_struct’ is a pointer to a list Name of this pointer is ‘mmap’ struct mm_struct { struct vm_area_struct*mmap; /* plus many other fields */};

Linked List of VMAs Each ‘vm_area_struct’ points to another struct vm_area_struct { unsigned longvm_start; unsigned longvm_end; unsigned longvm_flags; struct vm_area_struct*vm_next; /* plus some other fields */};

Structure relationships VMA mm_struct task_struct *mm *mmap Linked list of ‘vm_area_struct’ structures The ‘process descriptor’ for a task Task’s mm structure

Demo ‘vma.c’ module It creates a pseudo-file: /proc/vma Lets user see the list of VMAs for a task Also shows the ‘pgd’ field in ‘mm_struct’ EXERCISE Compare our demo to ‘/proc/self/maps’

In-class exercise #2 Try running our ‘domalloc.cpp’ demo It lets you see how a call to the ‘malloc()’ function would affect an application list of ‘vm_area_struct’ objects NOTE: You have to install our ‘vma.ko’ kernel-object before running ‘domalloc’