Memory management.

Slides:



Advertisements
Similar presentations
Memory Management in Linux Anand Sivasubramaniam.
Advertisements

Chapter 12: File System Implementation
Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
Paging: Design Issues. Readings r Silbershatz et al: ,
Tutorial 8 March 9, 2012 TA: Europa Shang
Note on malloc() and slab allocation CS-502 (EMC) Fall A Note on malloc() and Slab Allocation CS-502, Operating Systems Fall 2009 (EMC) (Slides include.
The Linux Kernel: Memory Management
Memory Management in Linux (Chap. 8 in Understanding the Linux Kernel)
Kernel Memory Allocator
Allocating Memory Ted Baker  Andy Wang CIS 4930 / COP 5641.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Memory Management.
CSE506: Operating Systems Physical Page Reclamation.
File Systems.
Week 7 - Friday.  What did we talk about last time?  Allocating 2D arrays.
CSE506: Operating Systems Block Cache. CSE506: Operating Systems Address Space Abstraction Given a file, which physical pages store its data? Each file.
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
Linux Vs. Windows NT Memory Management Hitesh Kumar
1 Case Study 1: UNIX and LINUX Chapter History of unix 10.2 Overview of unix 10.3 Processes in unix 10.4 Memory management in unix 10.5 Input/output.
Operating Systems File Systems (in a Day) Ch
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
File System Implementation
OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.
1 Memory Management in Representative Operating Systems.
Memory Allocation CS Introduction to Operating Systems.
Memory Management in Windows and Linux &. Windows Memory Management Virtual memory manager (VMM) –Executive component responsible for managing memory.
Presentation of Chapter 4, LINUX Kernel Internals Zhihua (Scott) Jiang Computer Science Department University of Maryland, Baltimore County Baltimore,
CS 6560 Operating System Design Lecture 13 Finish File Systems Block I/O Layer.
Memory Addressing in Linux  Logical Address machine language instruction location  Linear address (virtual address) a single 32 but unsigned integer.
File System Implementation Chapter 12. File system Organization Application programs Application programs Logical file system Logical file system manages.
1 File Systems: Consistency Issues. 2 File Systems: Consistency Issues File systems maintains many data structures  Free list/bit vector  Directories.
Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations.
CS 241 Section Week #9 (11/05/09). Topics MP6 Overview Memory Management Virtual Memory Page Tables.
Lec 7aOperating Systems1 Operating Systems Lecture 7a: Linux Memory Manager William M. Mongan.
CS 153 Design of Operating Systems Spring 2015 Final Review 2.
Chapter 12. Memory Management. Overview Memory allocation inside the kernel is not as easy as memory allocation outside the kernel  The kernel simply.
File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted).
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Implementation.
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
CSE 351 Dynamic Memory Allocation 1. Dynamic Memory Dynamic memory is memory that is “requested” at run- time Solves two fundamental dilemmas: How can.
File Systems.  Issues for OS  Organize files  Directories structure  File types based on different accesses  Sequential, indexed sequential, indexed.
Linux Kernel Development Memory Management Pavel Sorokin Gyeongsang National University
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 4.
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a “cache” for secondary (disk) storage – Managed jointly.
W4118 Operating Systems Instructor: Junfeng Yang.
Memory Virtualization In Xen
Memory Management.
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.
Disk Cache Main memory buffer contains most recently accessed disk sectors Cache is organized by blocks, block size = sector’s A hash table is used to.
Chapter 2: The Linux System Part 4
Case Study 1: UNIX and LINUX
Paging Adapted from: © Ed Lazowska, Hank Levy, Andrea And Remzi Arpaci-Dussea, Michael Swift.
Filesystems.
Lecture 45 Syed Mansoor Sarwar
CS Introduction to Operating Systems
Making Virtual Memory Real: The Linux-x86-64 way
Lecture 32 Syed Mansoor Sarwar
Memory Allocation CS 217.
CSC 660: Advanced Operating Systems
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Semester Review Brian Kocoloski
Virtual Memory: Systems CSCI 380: Operating Systems
CSE 451 Autumn 2003 November 13 Section.
Kernel Memory Chris Gill, David Ferry, Brian Kocoloski
CSCI 380: Operating Systems William Killian
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Buddy Allocation CS 161: Lecture 5 2/11/19.
Paging Adapted from: © Ed Lazowska, Hank Levy, Andrea And Remzi Arpaci-Dussea, Michael Swift.
Presentation transcript:

Memory management

Linked Lists

structs and memory layout fox fox fox list.next list.next list.next list.prev list.prev list.prev

Linked lists in Linux fox fox fox list { .next .prev } list { .next node fox fox fox list { .next .prev } list { .next .prev } list { .next .prev }

What about types? Calculates a pointer to the containing struct struct list_head fox_list; struct fox * fox_ptr = list_entry(fox_list->next, struct fox, node);

List access methods struct list_head some_list; list_add(struct list_head * new_entry, struct list_head * list); list_del(struct list_head * entry_to_remove); struct type * ptr; list_for_each_entry(ptr, &some_list, node){ … } struct type * ptr, * tmp_ptr; list_for_each_entry_safe(ptr, tmp_ptr, &some_list, node) { list_del(ptr); kfree(ptr);

Page Frame Database /* Each physical page in the system has a struct page associated with * it to keep track of whatever it is we are using the page for at the * moment. Note that we have no way to track which tasks are using * a page */ struct page { unsigned long flags; // Atomic flags: locked, referenced, dirty, slab, disk atomic_t _count; // Usage count, atomic_t _mapcount; // Count of ptes mapping in this page struct { unsigned long private; // Used for managing page used in file I/O struct address_space * mapping; // Used to define the data this page is holding }; pgoff_t index; // Our offset within mapping struct list_head lru; // Linked list node containing LRU ordering of pages void * virtual; // Kernel virtual address

Memory Zones Linux groups memory into zones Not all memory addresses are the same ZONE_DMA: DMA memory (< 16MB) Really old I/O devices that have constrained addresses ZONE_DMA32: 32 bit DMA memory ( < 4GB) Older I/O devices that only support 32 bit DMA ZONE_NORMAL: Generic Kernel memory Always directly addressable by the kernel Linux groups memory into zones Based on the use cases for memory Allow allocations to occur in a given zone How?

Buddy Allocator Memory allocations are all backed by physical pages Kernel allocations are persistent Cannot be moved or swapped Must find contiguous sets of pages Allocations all come from free lists Linked list of unallocated resources Code example

Allocating pages Return entry/entries from page list Scans various lists for page(s) to allocate struct page * alloc_pages(gfp_t flags, int order); void * page_address(struct page * page) unsigned long page_to_pfn(struct page * pg);

kmalloc kernel version of malloc manages global heap, accessible by all kernel threads Returns kernel virtual addresses void * kmalloc(size_t size, gfp_t flags);

gfp_t What are these gfp_t flags? Some Examples: Directions to allocator Where to get the memory from What steps allocator can take to find memory Some Examples: Zone GFP_DMA, GFP_DMA32, GFP_NORMAL Behavior GFP_ATOMIC, GFP_KERNEL

vmalloc Linux limits the number of contiguous pages you can allocate MAX_ORDER typically is 11 (32MB) 2^11 pages What if you need to allocate more? Must do the allocation in virtual memory void * vmalloc(unsigned long size); Allocates a virtually contiguous address region Backed by physically discontinuous pages

Slab allocator Optimization for kernel allocations Provides a free list (or cache) of unused allocations of a certain type Don’t have to search for a free region Allocations become (almost) constant time Create special caches for certain types of common allocations i.e. network packets, inodes, process descriptors Allocate those types using a special allocator Slab subsystem dynamically ensures that enough memory is available Allocates and frees pages behind the scenes