ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all...
Transcript of ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all...
![Page 1: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/1.jpg)
ICS143A: Principles of Operating Systems
Lecture 20: Memory management
Anton BurtsevMarch, 2017
![Page 2: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/2.jpg)
Xv6 Book, Chapter 1. KERNBASE limits the amount of memory a single process can use,
which might be irritating on a machine with a full 4 GB of RAM.
Would raising KERNBASE allow aprocess to use more memory?
![Page 3: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/3.jpg)
Xv6: physical page allocator
![Page 4: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/4.jpg)
Physical memory
![Page 5: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/5.jpg)
We need a smaller array to describe physical pages, e.g., mem_map[] in
Linux
![Page 6: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/6.jpg)
Memory allocation
![Page 7: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/7.jpg)
Simplest memory allocator
● Bitmap of all pages● Bootmem allocator in Linux
● Allocation searches for an unused page● Multiple sub-page allocations can be served from
the same page by advancing a pointer
● Works ok, but what is the problem?
![Page 8: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/8.jpg)
Boot memory allocator
● Bitmap of all pages● Allocation searches for an unused page
● Multiple sub-page allocations can be served from the same page by advancing a pointer
● Works ok, but what is the problem?● Linear scan of the bitmap
– Too long
![Page 9: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/9.jpg)
Buddy:Physical Memory Allocator
![Page 10: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/10.jpg)
Buddy memory allocator
![Page 11: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/11.jpg)
Buddy allocator
![Page 12: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/12.jpg)
What's wrong with buddy?
![Page 13: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/13.jpg)
What's wrong with buddy?
● Buddy allocator is ok for large allocations● E.g. 1 page or more
● But what about small allocations? ● Buddy uses the whole page for a 4 bytes allocation
– Wasteful● Buddy is still slow for short-lived objects
![Page 14: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/14.jpg)
Slab: Allocator for object of a fixed size
![Page 15: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/15.jpg)
Slab
● A 2 page slab with 6 objects
![Page 16: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/16.jpg)
Keeping track of free objects
● kmem_bufctl array is effectively a linked list
● First free object: 3● Next free object: 1
![Page 17: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/17.jpg)
A cache is formed out of slabs
![Page 18: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/18.jpg)
Slab is fine, but what's wrong?
![Page 19: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/19.jpg)
Slab is fine, but what's wrong?
● We can only allocate objects of one size
![Page 20: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/20.jpg)
Kmalloc(): variable size objects
● A table of caches● Size: 32, 64, 128, etc.
![Page 21: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/21.jpg)
NUMANon-uniform memory access
![Page 22: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/22.jpg)
Uniform and non-uniform memory access
● Parts of memory can be faster than others
![Page 23: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/23.jpg)
Uniform memory access (UMA)
![Page 24: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/24.jpg)
Nonuniform memory access (NUMA)
![Page 25: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/25.jpg)
Nodes
● Attempt to allocate memory from the current node● Fall back to the next node in list
– If ran out of local memory
![Page 26: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/26.jpg)
Nodes
![Page 27: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/27.jpg)
Zones
![Page 28: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/28.jpg)
Zones
![Page 29: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/29.jpg)
Linux memory management
![Page 30: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/30.jpg)
Linux memory management
![Page 31: ICS143A: Principles of Operating Systems Lecture 20 ... · Simplest memory allocator Bitmap of all pages Bootmem allocator in Linux Allocation searches for an unused page Multiple](https://reader033.fdocuments.us/reader033/viewer/2022042310/5ed73f14d37f9f58ca6a8ab0/html5/thumbnails/31.jpg)
Thank you!