Segmentation och paging

¡Supera tus tareas y exámenes ahora con Quizwiz!

Paging

A storge mechanism that views the physical memory as fixed-size slots called page frames

Buddy Allocation

Allocates blocks of 2^n bytes. Memory blocks are divided into two to accommodate processes. Each memory block has it's "buddy" which can coalesce back together if both are free.

What does PTE contain?

An contains the virtual page number which used as an index. It aswell contains a bunch of flags such as vaild bit, protection bits, present bit, dirty bit and refrence bit.

Splitting

Assume we have a request for just a single byte of memory. In this case, the allocator will perform an action known assplitting: it will find a free chunk of memory that can satisfy the request and split it into two. The first chunk it will return to the caller; the second chunk will remainon the list.

Spatial locality

Being close together in space, i.e. memory address.

Dynamic Relocation

Hardware adds relocation register (base) to virtual addresses to get physical addresses, then compares the resulting address with the limit register to make sure it's in range - if not, it raises an exception

Page frame

It is the smallest fixed-length contiguous block of physical memory into which memory pages are mapped by the operating system. A transfer of pages between main memory and an auxiliary store, such as a hard disk drive, is referred to as paging or swapping.

Where does the page table lie?

It lies in the RAM memory

What must the OS do in the memory when perfoming a procces switch?

When the OS decides to stop running a process, it must save the values of the base and bounds registers to memory, in some per-process structure such as the process structure or process control block(PCB). Similarly, when the OS resumes a running process (or runs it the first time), it must set the values of the base and bounds on the CPU to the correct values for this process

TLB hit

A TLB lookup that succeeds at finding a valid address translation

Least Frequently Used (LFU)

A cache replacement policy that evicts which ever block has been used the least often, over some period of time.

Average Memory Access Time (AMAT)

A common metric to analyze computer memory system performance (i.e number of cache hits and misses). AMAT = TM + (PMiss · TD)

Address Space Identifier (ASID)

A field in the TBL that is needed to differentiate otherwise identical translation. Thus, with address-space identifiers, the TLB can hold translations from different processes at the same time without any confusion.

Multi-level Page Table

A paging scheme which consist of two or more levels of page tables in a hierarchical manner. It is also known as hierarchical paging. Each page table entry except the last level page table entry contains base address of the next level page table.

Optimal (replacment policy)

A replacement policy for swaping pages in virtual memory. A approach that replaces the page that will be accessed furthest in the future is the optimal policy, resulting in the fewest-possible cache misses.

Random (replacment policy)

A replacement policy for swaping pages in virtual memory. It picks a random page to replace under memory pressure. Random has properties similar to FIFO; it is simple to implement, but it doesn't really try to be too intelligent in picking which blocks to evict.

FIFO (replacment policy)

A replacement policy for swaping pages in virtual memory. The pages are simply placed in a queue when they enter the system; when a replacement occurs, the page on the tail of the queue (the "first-in" page) is evicted. FIFO has one great strength: it is quite simple to implement.

TLB

A translation lookaside buffer inside the MMU. It simply is a hardware chache of popular virtual-to-pyshical address translations; thus,a better name would be anaddress-translation cache. Upon each virtual memory reference, the hardware first checks the TLB to see if the desired translation is held therein; if so, the translation is performed (quickly) without having to consult the page table (which has all translations). Because of their tremendous performance impact, TLBs in a real sense makevirtual memory possible.

What inefficiencies does base and bounds have?

All of the space between the bounds is simply wasted. This type of waste is usually called internal fragmentation, as the space in side the allocated unit is not all used(i.e., is fragmented) and thus wasted.

Memory Virtualization

Allows networked, and therefore distributed, servers to share a pool of memory to overcome physical memory limitations, a common bottleneck in software performance. ... The memory pool may be accessed at the application level or operating system level.

Why can using paging as the core mechanism to support virtual memory lead to high performance overheads?

By chopping the address space into small, fixed-sized units (i.e., pages), paging requires a large amount of mapping information. Because that mapping information is generally stored inphysical memory, paging logically requires an extra memory lookup foreach virtual address generated by the program. Going to memory for translation information before every instruction fetch or explicit load or store is prohibitively slow.

How does the OS employ the use bit to approximate LRU?

By clock algorithm, note that this approach is not the only way to employ a use bit to approximate LRU, but is the way the book describes.

How does the hardware know the offset into a segment, and to which segment an address refers?

By explicit- or implicit approch

Hybrid (paging)

By making page tables smaller and using base to hold the physical address of the page table of that segment. While using the base to the hold the physical address of the page tabl eof that segment. The bounds register is used to indicate the end of the page table (i.e., how many valid pages it has).

Page table

Contains the base address of each page in physical memory. It's major role is to store address translations for each of the virtual pages of the address space, thus letting us know where in physical memory each page resides. Because page tables are so big, we don't keep any special on-chip hardware in the MMU to store the page table of the currently-running processes. Lies in the physical memory.

Address space

Creates an abstraction for the runnin programs view of the memory int the system. Contains the code, stack and heap. (kanske fixa den definition)

How does the TBL mange context switch?

Flush or ASID

Page fualt handler

If a page is not present and has been swapped to disk, the OS willneedto swap the page into memory in order to service the page fault. Thus, aquestion arises: how will the OS know where to find the desired page? Inmany systems, the page table is a natural place to store such information.Thus, the OS could use the bits in the PTE normally used for data such asthe PFN of the page for a disk address. When the OS receives a pagefaultfor a page, it looks in the PTE to find the address, and issues the requestto disk to fetch the page into memory. The process will be in the blocked state. Thus, the OS will be free to run other ready processes while the page fault is being serviced.

What problems can arrise with paging?

Implementing paging support without care will lead toaslower machine (with many extra memory accesses to access the pagetable) as well as memory waste (with memory filled with page tables in-stead of useful application data). We'll thus have to think a little harderto come up with a paging system that not only works, but works well.

Who Handles The TLB Miss?

In modern architectures software-managed TBL handels misses. When a miss occures the hardware pauses the current instruction stream, raises the privilege level to kernel mode, and jumps to a trap handler. This trap handler is code within the OS that is written with the express purpose of handling TLB misses. When run, the code will lookup the translation in the page table, use special "privileged" instructions to update the TLB, and return from the trap; at this point, the hardware retries the instruction (resulting in a TLB hit).

Dirty bit (page table)

Indicates whether the page has been modified since it was brought into memory.

Present bit (page table)

Indicates whether this page is in physical memory or on disk (i.e., it has beenswapped out).

Next Fit

Instead of always beginning the first-fit search at the beginning of the list,the next fit algorithm keeps an extra pointer to the location within the list where one was looking last. The idea is to spread the searches for free space throughout the list more uniformly, thus avoiding splintering of the beginning of the list. The performance of such an approach is quite similar to first fit, as an exhaustive search is once again avoided

Free list

Is a list of the ranges of the physical memory which are not currently in use.

Heap

Is used for dynamically-allocated, user-managed memory, such as that you might receive from a call to malloc()in C or new in an object-oriented language such as C++ or Java.

Stack

Is used to keep track of where a running program is in the function call chain, as well as to allocate local variables and pass parameters, and return values to and from routine.

Emulation

It fetchs insturction from a program that the OS wants to run and then interprets them. If used it used instead of LDE.

Protection bits (page table)

It indicates whether the page could be read from, written to, or executed from. Again, accessing a page in away not allowed by these bits will generate a trap to the OS.

Segmentation

It is a contiguous portion of the address space of a particular length, and in our canonical address space, we have three logically-different segments:code, stack,and heap. What segmentation allows the OS to do is to place each oneof those segments in different parts of physical memory, and thus avoid filling physical memory with unused virtual address space

Garbage collection

It is a dynamic memory management process that finds stranded blocks of memory and reallocates them. Like the noisy garbage trucks that rumble down our streets, a GC algorithms' job is to find stranded addresses, unused addresses, and clean them up. For exemple coalescing free chunks lying next to eachother.

Memory allocation

It is a process by which computer programs are assigned memory or space. Paging is a storage mechanism that allows OS to retrieve processes from the secondary storage into the main memory in the form of pages

Explicit approch in segment registers translation?

It is to chop up the address space into segments based on the top few bits of the virtual address; this technique was used in the VAX/VMSsystem[LL82]

What the problem with FIFO and Randoms replacment policies?

It might kick out an important page, one that is about to be referenced again.

Page Table Entry (PTE)

It provides the base address of a 4 Kbyte page in physical memory called a Page Frame. The low order 12 bits of the original linear address supplies the offset into the page frame. Each task has its own Page Directory pointed to by processor control register CR3.

Base and Bounds

It refers to a simple form of virtual memory where access to computer memory is controlled by one or a small number of sets of processor registers called base and bounds registers. In its simplest form each user process is assigned a single contiguous segment of main memory.

First Fit

It simply finds the first block that is big enough and returns the requested amount to the user. As before, the remaining free space is kept free for subsequent requests. First fit has the advantage of speed — no exhaustive search of all the free spaces are necessary — but sometimes pollutes the beginning of the free list with small objects. Thus, how the allocator manages the free list's order becomes an issue. One approach is to use address-based ordering;by keeping the list ordered by the address of the free space, coalescing becomes easier, and fragmentation tends to be reduced

What does the MMU do in paging?

It takes VPN of a page in virtual memory and runs it throung the page table and finds PFN (Physical page frame).

Best Fit

It will search through the free list and find chunks of free memory that are as big or bigger than the requested size. Then, return the one that is the smallest in that group of candidates; this is the so called best-fit chunk . The intuition behind best fit is simple: by returning a block that is close to what the user asks, best fit tries to reduce wasted space. However, there is a cost; naive implementations pay a heavy performance penalty when performing an exhaustive search for the correct free block.

Valid Bit (page table)

Its common to indicate whether the particular translation is valid; for example, when a program starts running, it will have code and heap at one end of its address space, and the stack at the other. All the unused space in-between will be marked invalid, and if the process tries to access such memory, it will generate a trap to the OS which will likely terminate the process.Thus, the valid bit is crucial for supporting a sparse address space; by simply marking all the unused pages in the address space invalid, were move the need to allocate physical frames for those pages and thus save a great deal of memory

Why do we want to support a single large address space for a process?

Once again, the answer is convenience and ease of use. With a large address space, you don't have to worry about if there is room enough in memory for your program's data structures; rather, you just write the program naturally, allocating memory as needed. It is a powerful illusion that the OS provides, and makes your life vastly simpler.

Clock Algorithm and dirty pages

One small modification to the clock algorithm that is commonly made is the additional consideration of whether a page has been modified or not while in memory. The reason for this: if a page has been modified and is thus dirty, it must be written back to disk to evict it, which is expensive. If it has not been modified (and is thus clean), the eviction is free; the physical frame can simply be reused for other purposes without additional I/O. Thus, some VM systems prefer to evict clean pages over dirty pages. To support this behavior, the hardware should include a modified bit (a.k.a.dirty bit).

Reference bit (page table)

Sometimes used to track whether a page has been accessed, and is useful in determining which pages are popular and thus should be kept in memory; such knowledge is critical during page replacement.

What does each varibel stand for in: AMAT = TM + (PMiss · TD)?

TM represents the cost of accessing memory, TD the cost of accessing disk, and PMiss the probability of not finding the data in thecache (a miss); PMiss varies from 0.0 to 1.0, and sometimes we refer to a percent miss rate instead of a probability (e.g., a 10% miss rate means PMiss= 0.10). Note you always pay the cost of accessing the data in memory; when you miss, however, you must additionally pay the cost offetching the data from disk.

Static Relocation

The OS adjusts the addresses in a process at load time to reflect its location in memory

Linear page table

The OS indexes the array by the virtual page number (VPN), and looks up the page-table entry (PTE) at that index inorder to find the desired physical frame number (PFN).

Transparency in the virtualiztion of the memory?

The OS should implement virtual memory in a way that is invisible to the running program. Thus, the program shouldn't be aware of the factt hat memory is virtualized; rather, the program behaves as if it has its own private physical memory. Behind the scenes, the OS (and hardware)does all the work to multiplex memory among many different jobs, and hence implements the illusion.

Protection in the virtualiztion of the memory?

The OS should make sure to protect processes from one another as well as the OS itself from processes. When one process performs a load, a store, or an instruction fetch,it should not be able to access or affect in any way the memory contentsof any other process or the OS itself (that is, anything out side its address space). Protection thus enables us to deliver the property ofisolationamong processes; each process should be running in its own isolated co-coon, safe from the ravages of other faulty or even malicious processes.

Efficiency in the virtualiztion of the memory?

The OS should strive to make the virtualization as efficientas possible, both in terms of time (i.e., not mak-ing programs run much more slowly) and space (i.e., not using too much memory for structures needed to support virtualization). In implementing time-efficient virtualization, the OS will have to rely on hardware support, including hardware features such as TLBs.

Page fault

The act of accessing a page that is not in physical memory but rather on the disk. Upon a page fault, the OS is invoked to service the page fault. A particular piece of code, known as a page-fault handler, runs, and must service the page fault.

Allocation

The action or process of allocating or sharing out something.

Segregated Lists

The basic idea is simple: if a particular application has one (or a few) popular-sized request that it makes, keep a separate list just to manage objects of that size; all other requests are forwarded to a more general memory allocator. By having a chunk of memory dedicated for one particular size of requests, fragmentation ismuch less of a concern; moreover, allocation and free requests can beserved quite quickly when they are of the right size, as no complicatedsearch of a list is required

How does bound work?

The bounds register is there to help with protection. Specifically, the processor will first check that the memory reference is within bounds to make sure it is legal. If a process generates a virtual address that is greater than the bounds, or one that is negative, the CPU will raise an exception, and the process will likely be terminated. The point of the bounds is thus to make sure that all addresses generated by the process are legal and within the "bounds" of the process

How does the Os know which way the segment grows?

The hardware most know which say a segment grows, which is accived via a simple bit.

Worst Fit

The opposite of best fit; find the largest chunk and return the requested amount; keep the remaining (large) chunk on the free list. Worst fit tries to thus leave big chunks free instead of lots of small chunks that can arise from a best-fit approach. Once again, however, a full search of free space is required, and thus this approach can becostly. Worse, most studies show that it performs badly, leading to excess fragmentation while still having high overheads

What should the OS do on a context switch when using segmentation?

The physical memory quickly be-comes full of little holes of free space, making it difficult to allocate new segments, or to grow existing ones. We call this problemexternal frag-mentation

What problems arrise with segmentation?

The problem is external fragmentation which occurs when managing free space in physical memory. When a new address space is created, the OS has to be able to find space in physical memory for its segments. Similar problems could occur when a request to grow a segment arrives; if the next so many bytes of physical space are not available, the OS will have to reject the request, even though theremay be free bytes available else where in physical memory

Page-replacement polic

The process of picking a page to kick out, or replace when the memory is full and the hardware wants to performe a swap place.

What happends if TLB misses occur often?

The program will likely run noticeably more slowly. Thus, it is our hope to avoid TLB misses as much as we can.

Memory Management Unit (MMU)

The run-time mapping from virtual to physical addresses (hardware device). Contains the bound and base register.

Virtualizing Memory

The running program thinks it is loaded into memory at a particular address and has a potentially very large address space. When, for example, process tries to perform a load at address 0 (which we will call a virtual address), somehow the OS, in tandem with some hardware support, will have to make sure the load doesn't actually go to physical address 0 but rather to physical address. This is the key to virtualization of memory, which underlies every modern computer system in the world

Swap Space

The space on the disk reserved for the full virtual memory space of a process.

Multiprogramming

The technique of keeping multiple programs in main memory at the same time, competing for the CPU.

Segmentation fault

The term arises from a memory accesson a segmented machine to an illegal address. Humorously, the term persists, even on machines with no support for segmentation at all. Or not so humorously, if you can't figure out why your code keeps faulting.

How does the OS know if the page is present in physical memory?f

The way the hardware determines this is through the present bit. If the present bit is set to one, it means the page is present in physical memory, if it is set to zero, the page is not in memory but rather on disk somewhere.

How does the OS speed up address translation in paging?

To speed address translation, we are going to add what is called a translation-lookaside buffer, or TLB.

Adress translation

Transforming a virtual address into a physical address is exactly thetechnique we refer to as address translation; that is, the hardware takes a virtual address the process thinks it is referencing and transforms it in to a physical address which is where the data actually resides. Because this relocation of the address happens at runtime, and because we can movea ddress spaces even after the process has started running, the techniqueis often referred to as dynamic relocation[M65].

What goals are there when the OS is virtualizing meemory?

Transparency, efficiency and protection

Protection bits (segmentation)

Used in code sharing and adds a few bits per segment,indicating whether or not a program can read or write a segment, or perhaps execute code that lies within the segment. By setting a code segment to read-only, the same code can be shared across multiple processes, with-out worry of harming isolation; while each process still thinks that it is accessing its own private memory, the OS is secretly sharing memory which cannot be modified by the process, and thus the illusion is preserved.

How does the OS keep a small amount of the memor free?

Via high watermark(HW) and low watermark(LW). When the OS notices that there are fewer than LW pages available, a background thread that is responsible for freeing memory runs. The thread evicts pages until there are HW pages available. The background thread, sometimes called the swap daemon or page daemon, then goes to sleep, happy that it has freed some memory for running processes and the OS to use.

Flush

When a context switches occur flush empties out the TBL before running the next process. However, there is a cost: each time a process runs, it must incur TLB misses as it touches its data and code pages. If the OS switches between processes frequently, this cost may be high.

How does base work?

When a program starts running, the OS decides where in physical memory it should be loaded and sets the base register to that value. When any memory reference is generated by the process, it is translated by the processor in the following manner: physical address = virtual address + base

Clock Algorithm

When a replacement must occur, the OS checks if the clock hand is pointed to page P that has a use bit of 1 or 0. If 1, this implies that page P was recently used and thus is not a good candidate for replacement. Thus, the use bit for P is set to 0 (cleared), and the clock hand is incremented to the next page (P+ 1). The algorithm continues until it finds a use bit that is set to 0, implying this page has not been recently used (or, in the worst case, that all pages have been and that we have now searched through the entire set of pages, clearing all the bits).

Coalescing

When returning a free chunk in memory, look carefully at the addresses of the chunk you are returning as well as the nearby chunks of free space; if the newly-freed space sits right next to one (or two, as in this example) existing free chunks, merge them into a single larger free chunk.

Slab allocation

When the kernel boots up, it allocates a number of objectcaches for kernel objects that are likely to be requested frequently (such aslocks, file-system inodes, etc.); the object caches thus are each segregated free lists of a given size and serve memory allocation and free requests quickly. When a given cache is running low on free space, it requests some slabs of memory from a more general memory allocator.

When is it the the easiest for the OS to move an address space?

When the process is stopped (i.e., not running). To move a process's address space, the OS first deschedules the process; then, the OS copies the address space from the current location to the new location; finally, the OS updates the saved base register (in the process structure) to point to the new location.

TLB miss

a TLB lookup that fails because the TLB does not contain a valid translation for that virtual address. Assuming that the virtual memory reference generated by the process is valid and accessible, it updates the TLB with the translation.

Trashing

a state in which the CPU performs 'productive' work less, and 'swapping' more. The CPU is busy in swapping pages so much that it can not respond to users' programs and interrupts as much as required. Thrashing occurs when there are too many pages in memory, and each page refers to another page.

How does the OS emebedd a free list?

is a data structure used in a scheme for dynamic memory allocation. It operates by connecting unallocated regions of memory together in a linked list, using the first word of each unallocated region as a pointer to the next. https://www.cs.unm.edu/~crandall/operatingsystems20/slides/12-Free-List-Management.pdf page 5

Segment table

keeps track of segments in main memory, each entry has the base address in memory, the length of the segment, and protection information

Where does the code of a running program lay?

the code of a program (the instructions) lay in the address space, aswell does the stack and the heap.


Conjuntos de estudio relacionados

Chapter 5: The Expenditure Cycle

View Set

Psychosocial Mental Health Review Ch. 15-- Leik Content

View Set

CC ch. 8 Dysrhythmia Interpretation and Management

View Set

Info and Network Security Chapter 14

View Set

Micro Chapter 9 - Quiz and Homework Questions

View Set

POLS 2306 - TX Gov - CH 12 Criminal Justice Policy in Texas

View Set