Managing physical memory

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

1 CMPT 300 Introduction to Operating Systems Virtual Memory Sample Questions.
The Linux Kernel: Memory Management
Memory Management in Linux (Chap. 8 in Understanding the Linux Kernel)
Memory management.
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
The ATA/IDE Interface Can we write a character-mode device driver for the hard disk?
File Systems.
Paging Hardware With TLB
4/14/2017 Discussed Earlier segmentation - the process address space is divided into logical pieces called segments. The following are the example of types.
UNIX’s “grand illusion” How Linux makes a hardware device appear to be a ‘file’
Linux Memory Issues An introduction to some low-level and some high-level memory management concepts.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
11/13/01CS-550 Presentation - Overview of Microsoft disk operating system. 1 An Overview of Microsoft Disk Operating System.
Timeout for some demos An instructive look at how the Linux Operating System sets up system data-structures.
Standard C Libraries Application Programmming Interface to System-Calls.
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?
Examining network packets Information about the RTL8139 needed for understanding our ‘watch235.c’ pseudo driver.
The ‘ioctl’ driver-function On implementing ‘show’ and ‘hide’ for the SiS 315 hardware cursor.
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
Memory Management.
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
Looking at kernel objects How a character-mode Linux device driver can be useful in viewing a ‘net_device’ structure.
A device-driver for Video Memory Introduction to basic principles of the PC’s graphics display.
Access to High Memory Introduction to the kernel functions ‘kmap()’ and ‘kunmap()
Introduction to the Intel x86’s support for “virtual” memory
CS2422 Assembly Language & System Programming September 22, 2005.
What’s needed to transmit? A look at the minimum steps required for programming our anchor nic’s to send packets.
Chapter 91 Translation Lookaside Buffer (described later with virtual memory) Frame.
Answers to the VM Problems Spring First question A computer has 32 bit addresses and a virtual memory with a page size of 8 kilobytes.  How many.
Linux Memory Management How does the Linux kernel keep track of the Virtual Memory Areas that each process uses?
1 Memory Management in Representative Operating Systems.
Computer Architecture Part III-C: Memory Access and Management.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Memory Management Ch.8.
CS 346 – Chapter 8 Main memory –Addressing –Swapping –Allocation and fragmentation –Paging –Segmentation Commitment –Please finish chapter 8.
CS 6560 Operating System Design Lecture 13 Finish File Systems Block I/O Layer.
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.
COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.2 Instructor: Lin Chen August 2013.
Memory Map, Programming Language, and Windows Dr. Harold D. Camp IT February 2007.
Operating Systems COMP 4850/CISG 5550 Page Tables TLBs Inverted Page Tables Dr. James Money.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
Paging Example What is the data corresponding to the logical address below:
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Paging Physical address space of a process can be noncontiguous Avoids.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
1 Memory Management (b). 2 Paging  Logical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter.
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Chapter 91 Logical Address in Paging  Page size always chosen as a power of 2.  Example: if 16 bit addresses are used and page size = 1K, we need 10.
Swap Space and Other Memory Management Issues Operating Systems: Internals and Design Principles.
ICOM Noack Memory management Virtual memory Paging and segmentation Demand paging Memory management hardware.
Windows XP Memory Management Aaron Lanoy and Jason Farnsworth.
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.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy.
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.
Memory Management 백 일 우
Operating Systems, Winter Semester 2011 Practical Session 9, Memory 1.
W4118 Operating Systems Instructor: Junfeng Yang.
Memory: Page Table Structure CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Chapter 2: The Linux System Part 4
Memory COMPUTER ARCHITECTURE
COMBINED PAGING AND SEGMENTATION
Paging and Segmentation
Introduction to the Intel x86’s support for “virtual” memory
Main Memory Session - 16.
Assembly Language for Intel-Based Computers, 5th Edition
Presentation transcript:

Managing physical memory Examining the Linux kernel’s ‘mem_map[]’ array

‘kmap()’ Recall that our ‘dram.c’ device-driver used the kernel’s ‘kmap()’ function This function offered us a uniform way of accessing a page of physical memory, no matter which memory-zone it belonged to In order to understand our ‘dram.c’ device driver’s ‘read()’ method, we need to study how the Linux kernel’s ‘kmap()’ works

Direct ‘linear’ mapping kernel-space (1GB) user-space (3GB) kernel-space (1GB) 896MB HIGH MEMORY 896MB virtual addresses

‘kmap()’ hides page differences For physical pages in the lowest memory zones (i.e., bottom 896MB), a direct map exists into kernel-space, so kmap() is trivial for these pages: they are visible to the kernel at predictable locations But for physical pages in ‘high memory’, they’re not always ‘mapped’ -- and even if mapped, the addresses aren’t predictable

Pentium ‘page frames’ The system’s physical memory is made up of fixed-size blocks (called ‘page frames’) For the Intel x86 architecture, the size of each page frame is 4096 bytes (=0x1000) You can tell which page a byte lies in from its physical address: byte at 0x00012345 lies in page-number 0x12 (at offset 0x345) The kernel’s ‘num_physpages’ variable is equal to the total number of page frames

The ‘struct page’ object The Linux kernel uses a data-structure to keep track of each physical page frame This data-structure is called a ‘struct page’ The size of each ‘struct page’ is 32-bytes These ‘struct page’ objects form an array, named ‘mem_map[]’, whose number of entries is the ‘num_physpages’ value

The ‘struct page’ fields struct page ( 8 longwords ) flags _count _mapcount private mapping index lru.next lru.prev The ‘struct page’ definition is in the <linux/mm.h> header along with the declaration for the ‘mem_map[ ]’ array

The ‘mem_map[ ]’ array . . . mem_map[ 0 ] mem_map[ 1 ] mem_map[ 2 ] describes page frame 0 mem_map[ 1 ] describes page frame 1 mem_map[ 2 ] describes page frame 2 mem_map[ 3 ] etc. mem_map[ 4 ] mem_map[ 5 ] . . .

The ‘flags’ field This field consists of individual bits which indicate the page frame’s current status Examples: PG_locked bit 0 PG_uptodate bit 3 PG_dirty bit 4 PG_active bit 6 PG_highmem bit 8 PG_reserved bit 11

Other ‘struct page’ fields … ‘_count’ is the page frames usage count ‘_mapcount’ is how many pte’s contain it ‘private’ is used in managing swap-space ‘index’ gives the frame’s offset in a mmap ‘lru.next’ points to next element in link-list ‘lru.prev’ points to prev element in link-list

Lots of ‘struct page’ objects Our classroom machines have 1GB RAMs So number of page-frames is: 1GB / 4KB i.e., roughly a quarter-million page-frames And their uses are dynamically changing! So studying them all in action isn’t trivial

We can use ‘/dev/dram’ If we can locate the ‘mem_map[ ]’ array, we can use our ‘dram’ device-driver and our ‘fileview’ tool to at least look at a few of the ‘struct page’ array-entries We could write a program that examines the ‘flags’ field for every page frame, to gather some statistics about their usage

In-class exercise #1 Use the ‘newinfo’ wizard to quickly build a module that will create a ‘/proc/mem_map’ pseudo-file showing where ‘mem_map[ ]’ is located, and how many entries are in it You’ll need to convert the virtual address of ‘mem_map[ ]’ into its physical addrress in order to find it in ‘/dev/dram’ (via ‘lseek’)

In-class exercise #2 Write a developer-tool application that will read the entire ‘mem_map[ ]’ array, so it can show the contents of all ‘struct page’ array-entries (in hexadecimal format) on the display monitor (all quarter-million!) You can pipe your program-output through the ‘more’ program (to see the info slowly) Include page-use statistics in your output