《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 7 Memory Management part1

OperatingSystemsCh7Memory Managementfrom a Programmer's Perspective1
Operating Systems Ch7 Memory Management from a Programmer’s Perspective 1

Why weneed memory management. The running program code requires memory- Because the CPU needs to fetch the instructions fromthe memoryforexecution We must keep several processes in memory-Improveboth CPUutilization and responsivenessMultiprogrammingIt is required to efficientlymanagethememory2
Why we need memory management • The running program code requires memory – Because the CPU needs to fetch the instructions from the memory for execution • We must keep several processes in memory – Improve both CPU utilization and responsiveness – Multiprogramming 2 It is required to efficiently manage the memory

TopicsinCh7Fromaprogrammer's perspective:user-spacememory managementWhat is the address space of a process?Howare the program code and data stored in memory?Howtoallocate/freememory (malloc()+free())?How much memory can be used in a program?What are segmentation and segmentation fault?From the kernel's perspective:Howto managethe memoryWhat is virtual memory?How to realize address mapping (paging)?Howto support very large programs (demand paging)?How to do page replacement?Whatis TLB?What is memory-mapped file?3
Topics in Ch7 3 What is the address space of a process? How are the program code and data stored in memory? How to allocate/free memory (malloc() + free())? How much memory can be used in a program? What are segmentation and segmentation fault? From a programmer’s perspective: user-space memory management What is virtual memory? How to realize address mapping (paging)? How to support very large programs (demand paging)? How to do page replacement? What is TLB? What is memory-mapped file? From the kernel’s perspective: How to manage the memory

Part 1:User-space memoryLocal variableDo you rememberthis?Contentof aprocess(inuser-spacememory)Dynamically-allocatedmemoryHowdoes each part usethe memory?Fromaprogrammer'sperspectiveGlobal variableLet's forgetabout thekernel for amoment.We are goingto explore theCode +user-spacememoryfirst.constantsProcess
4 Part 1: User-space memory Global variable Local variable Dynamically-allocated memory Code + constants Process Do you remember this? - Content of a process (in user-space memory) How does each part use the memory? - From a programmer’s perspective Let’s forget about the kernel for a moment. We are going to explore the user-space memory first

User-space memory management. Address space;Code & constantsData segment;Stack;Heap;Segmentation fault5
5 User-space memory management - Address space; - Code & constants; - Data segment; - Stack; - Heap; - Segmentation fault;

AddressspaceHow does a programmerlook at the memory space?Stack - Local variablesAn array of bytes?Heap -DynamicallyMemoryofaprocessisallocated memorydivided into segmentsData Segment & BsSThis way of arrangingGlobal and staticmemoryis calledvariablessegmentationCode + Constant6
Address space 6 Data Segment & BSS – Global and static variables Heap – Dynamically allocated memory Code + Constant Stack - Local variables How does a programmer look at the memory space? - An array of bytes? - Memory of a process is divided into segments - This way of arranging memory is called segmentation

Addressspaceintmain(void)(int *malloc ptr=malloc(4);What is theprocess address space?char *constant ptr -"hello";printf("Localvariable=%15pln,&malloc_ptr);printf("malloc()space%15p/n,malloc_ptr);Increasingprintf("Global variable=%15pn",&global int):printf("Code &constant-%15pn",constant ptr);addressStack - Local variablesreturn o;$/addrHeap -DynamicallyLocal variable=0xbfa8938callocated memorymalloc()space0x915c008-Global variable=0x804a0200x8048550Code &constant=Data Segment &BssGlobal and staticvariablesNoteTheaddresses are not necessarilytheCode + Constantsamein different processes7
Address space 7 Data Segment & BSS – Global and static variables Heap – Dynamically allocated memory Code + Constant Stack - Local variables Increasing address $ ./addr Local variable = 0xbfa8938c malloc() space = 0x915c008 Global variable = 0x804a020 Code & constant = 0x8048550 $ _ Note The addresses are not necessarily the same in different processes What is the process address space?

AddressspaceHowlargeistheaddress space?oxf=111111bit+16'bitsIncreasingoxffffffff0x100000000addressStack - Local variables2^324GHeap-Dynamicallyallocated memoryIna32-bitsystem,OneaddressmapstoonebyteThe maximum amount of memoryDataSegment &Bssin a process is 4GB.Global and staticNotevariablesThisis the so called logical addressspaceCode + ConstantEachprocesshasitsownaddressspace, and it can reside in any partof the physical memory8
8 Address space Data Segment & BSS – Global and static variables Heap – Dynamically allocated memory Code + Constant Stack - Local variables 0xffffffff = 0x100000000 - 1 1 ‘1’ bit + 16 ‘0’ bits = 2^32 - 1 = 4G - 1 0xf = 1111 In a 32-bit system, - One address maps to one byte. - The maximum amount of memory in a process is 4GB. Increasing address Note - This is the so called logical address space - Each process has its own address space, and it can reside in any part of the physical memory How large is the address space?

User-space memory managementAddress space; Code & constants;Data segment;Stack;Heap;Segmentation fault:9
9 User-space memory management - Address space; - Code & constants; - Data segment; - Stack; - Heap; - Segmentation fault;

Program code&constants·A program is an executable fileStackAprocessisnotboundedtooneprogram codeHeap- Remember exec*() family?Data SegmentThe program code requires&BSSmemory space because...- The CPU needs to fetch theCodeConstantinstructions from the memoryforexecution.(intel)instructionCore"i710
Program code & constants • A program is an executable file • A process is not bounded to one program code. – Remember exec*() family? • The program code requires memory space because. – The CPU needs to fetch the instructions from the memory for execution. 10 Data Segment & BSS Heap Code + Constant Stack instruction
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 6 Process Scheduling.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 5 Process Communication & Synchronization -Part 2.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 5 Process Communication & Synchronization(part1).pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 4 Threads.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 3 Process Concepts & Operations(part2)from Kernel's Perspective.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 3 Process Concepts & Operations(part1).pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 2 Operating System Structures.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 1 Overview of an Operating System.pdf
- 《计算机网络》课程教学资源(PPT课件)第六章 应用层.pptx
- 《计算机网络》课程教学资源(PPT课件)第五章 传输层.pptx
- 《计算机网络》课程教学资源(PPT课件)第四章 网络层.pptx
- 《计算机网络》课程教学资源(PPT课件)第三章 数据链路层.pptx
- 《计算机网络》课程教学资源(PPT课件)第二章 物理层.pptx
- 《计算机网络》课程教学资源(PPT课件)第一章 概述.pptx
- 《智能算法设计与应用》课程教学大纲 Intelligent Algorithm Design and Application.docx
- 《数字导航技术》课程教学资源(书籍文献)计算机视觉-马颂德.pdf
- 《C语言程序设计》课程参考文献:Programming languages — C(PDF电子书,英文版).pdf
- 《操作系统》课程教学资源(PPT课件)课程简介 Operating System.pptx
- 《操作系统》课程教学资源(PPT课件)第1章 操作系统引论.pptx
- 《操作系统》课程教学资源(PPT课件)第2章 进程的描述和控制.pptx
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 7 Memory Management part2.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 8 Mass Storage.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 9 File Systems part1.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 9 File Systems part2.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 10 Details of FAT32.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 10 Details of Ext2/3 File System.pdf
- 北京工业大学:信息科学技术学院《C#程序设计基础》课程教学大纲 Fundamentals of Programming Principle and Practice in C#.pdf
- 北京工业大学:计算机学院本科课程教学大纲汇编(2024).pdf
- 揭阳职业技术学院:《计算机应用基础》课程授课教案(讲义,2025).pdf
- 《C语言程序设计》课程教学课件(PPT讲稿)第10章 对文件的输入输出.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第01章 程序设计和C语言.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第02章 算法——程序的灵魂.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第03章 最简单的C程序设计——顺序程序设计.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第04章 选择结构程序设计.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第05章 循环结构程序设计.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第06章 利用数组处理批量数据.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第07章 用函数实现模块化程序设计.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第08章 善于利用指针.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第09章 用户自己建立数据类型.pptx
