1 / 33

Chapter 5 Memory Management ---- Memory Segment

Chapter 5 Memory Management ---- Memory Segment . Chen Yu yuchen@tsinghua.edu.cn. Outline. Introduction to Memory Segments Memory Segmemt Driver: seg_vn Memory mapped files Shared mapped files.  Memory segments characteristics.

spiro
Télécharger la présentation

Chapter 5 Memory Management ---- Memory Segment

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 5 Memory Management---- Memory Segment • Chen Yu • yuchen@tsinghua.edu.cn

  2. Outline • Introduction to Memory Segments • Memory Segmemt Driver: seg_vn • Memory mapped files • Shared mapped files

  3.  Memory segments characteristics • Memory segments manage the mapping of a linear range of virtual memory into an address space • allow both memory and devices to be mapped into an address space • allows different behaviors for different segments

  4. Segment Interface

  5. Segment associated data structures----Header File <vm/seg.h> • struct seg { • caddr_t s_base; /* base virtual address */ • size_t s_size; /* size in bytes */ • struct as *s_as; /* containing address space */ • seg_next s_next; /* next seg in this address space */ • struct seg *s_prev; /* prev seg in this address space */ • struct seg_ops *s_ops; /* ops vector: see below */ • void *s_data; /* private data for instance */ • };

  6. segment driver • a segment driver implementation is required to provide at least the following: • functions to create a mapping for a linear address range • page fault handling routines to deal with machine exceptions within that linear address range • a function to destroy the mapping

  7. Common Segment Drivers • The common Segment Drivers: • seg_vn: The vnode mappings into process address spaces are managed with the seg_vn device driver • seg_kmem: The segment from which the bulk of nonpageable kernel memory is allocated • seg_dev: Mapped hardware devices. • seg_kp, seg_spt, seg_map……

  8. Outline • Introduction to Memory Segments • Memory Segmemt Driver: seg_vn • Memory mapped files • Shared mapped files

  9.  seg_vn’s characteristics • seg_vn segment driver manages the following mappings into process address space • Executable text • Executable data • Heap and stack (anonymous memory) • Shared libraries • Mapped files

  10. The seg_vn Segment Driver Vnode Relationship

  11. Outline • Introduction to Memory Segments • Memory Segmemt Driver: seg_vn • Memory mapped files • Shared mapped files

  12. Characteristics of Memory mapped files • We can map a file into a process’s address space with the mmap system call • A vnode segment handles memory address translation and page faults for the memory range requested in the mmap system call • When we create a file mapping, we put the vnode and offset of the file being mapped into the segvn_data structure members, vp and offset.

  13. Creating a mapping for a file • Steps: • mmap() system call, • ufs_map() on UFS file system • segvn_create() function in seg_vn driver

  14. Outline • Introduction to Memory Segments • Memory Segmemt Driver: seg_vn • Memory mapped files • Shared mapped files

  15. Characteristics of Shared mapped files • The address space segment architecture makes it easy for two or more processes to map the same file into their address space • Each process has its own virtual memory mapping to the file, but they all share the same physical memory pages for the files.

  16. Figure about Shared Mapped Files

  17. mmap Shared Mapped File Flags

  18. Copy on Write: When & How • When • The copy-on-write process occurs when a process writes to a page that is mapped with MAP_PRIVATE • How • seg_vn implements a copy-on-write by setting the hardware MMU permissions of a segment to read-only and setting the segment permissions to read-write.

  19. End

  20. Chapter 9 Memory Management---- Anonymous Memory • Chen Yu • yuchen@tsinghua.edu.cn

  21. Outline • Instroduction to Anonymous memory • Anonymous memory layer • Swap space

  22. Characteristics of Anonymous Memory • Anonymous memory refers to pages that are not directly associated with a vnode. • process’s heap space • process’s stack • copy-on-write pages.

  23. Anonymous Memory Data Structures

  24. Anonymous Memory Data Structures

  25. Outline • Instroduction to Anonymous memory • Anonymous memory layer • Swap space

  26. Characteristics of Anonymous Memory Layer • Anonymous pages are created through the anon layer interfaces • The first time a segment receives a page fault, it allocates an anon map structure and puts a pointer to the anon header into the amp field of the anonymous map • Each anon slot points to an anon structure, which describes the virtual page of memory corresponding to the page-sized area in the address space.

  27. Data Structure • struct anon { • struct vnode *an_vp; /* vnode of anon page */ • struct vnode *an_pvp; /* vnode of physical backing store */ • anoff_t an_off; /* offset of anon page */ • anoff_t an_poff; /* offset in vnode */ • struct anon *an_hash; /* hash table of anon slots */ • int an_refcnt; /* # of people sharing slot */ • };

  28. Outline • Instroduction to Anonymous memory • Anonymous memory layer • Swap space

  29. The swapfs Layer • Swap space is used as a backing store for anonymous pages of memory • when we are short of memory, we can copy a page out to disk and free up a page of memory.

  30. Anon Slot Initialized to Virtual Swap Before Page-out

  31. Physical Swap After a Page-out Occurs

  32. Swap Allocation States

  33. End

More Related