Monday, July 12, 2021

CST 334 Operating Systems Module 3: Memory Virtualization

 

1.0 Topics Covered this week

1.0.1Define "address space", "physical address" and "virtual address"
  • Address Space - An easy to use abstraction of physical memory. Contains all of the memory state of the running program including the code, stack and heap.
 
  • The code is the instructions of the program that is running.
  • The stack is used by the running program to keep track of where it is in the function call chain as well as to allocate local variables and pass parameters and return values to and from routines.
  • The heap is used for dynamically-allocated, user managed memory such as that you might receive a call to malloc() in C or new in objected oriented language such as C++ or Java.
  • Physical Address - the actual address in physical memory where the running program is stored. It is calculated by finding the virtual address + some offset value.
  • Virtual Address - In computing, a virtual address space (VAS) or address space is the set of ranges of virtual addresses that an operating system makes available to a process. The range of virtual addresses usually starts at a low address and can extend to the highest address allowed by the computer's instruction set architecture and supported by the operating system's pointer size implementation, which can be 4 bytes for 32-bit or 8 bytes for 64-bit OS versions. This provides several benefits, one of which is security through process isolation assuming each process is given a separate address space.

1.0.2 List and explain problems related to memory addressing

  • How can the OS build this abstraction of a private, potentially large address space for multiple running processes (all sharing memory) on top of a single, physical memory?
  • Virtualizing Memory: When the OS does this, we say the OS is virtualizing memory, because the running program thinks it is loaded into memory at a particular ad- dress (say 0) and has a potentially very large address space (say 32-bits or 64-bits).
  • When, for example, process A in Figure 13.2 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 320KB (where A is loaded into memory).

1.0.3 Simulate the mechanics of the base-and-bounds translation scheme  

1.0.4 Explain how base-and-bounds addresses the design goals of memory management

  • The three main goals of the OS is efficiency, control, and flexibility.
  • Efficiency is OS dictates that we make use of hardware support, which at first will be quite rudimentary (e.g., just a few registers) but will grow to be fairly complex (e.g., TLBs, page-table support, and so forth, as you will see).
  • Control in OS implies that the OS ensures that no application is allowed to access any memory but its own; thus, to protect applications from one another, and the OS from applications, we will need help from the hardware here too.
  • Flexibility in OS implies that programs be able to use their address spaces in whatever way they would like, thus making the system easier to program.
  • In dynamic relocation(base and bounds), we'll need two hardware registers within each CPU: one is called the base register, and the other the bounds (sometimes called a limit register). This base and bounds pair is going to allow us to place the address space anywhere we'd like in physical memory, and do so while ensuring that the process can only access its own address space.
  • In the dynamic relocation process, each program is written and compiled as if it is loaded at address zero. However, 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 the process is running. Now, when any memory reference is generated by the process, it is translated by the processor in the following manner: physical address = virtual address + base

1.0.5 Explain what garbage collection is. Garbage Collection

  • If you let your garbage pile up for more than a week, things can get rather nasty. Imagine letting it pile up for months.

    In an operating system, garbage piles up rather quickly. Memory is reserved, allocated, re-allocated, and swapped across processes. Often there are memory leaks, which is when memory is allocated to a program or a process, but never released back to the OS.

    Individual programs also reserve and use memory, and a lot of times that memory isn't given back. It can become stranded. Therefore, an operating system needs its own way to keep things clean.

    Garbage collection (GC) in an operating system (OS) 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. How this is performed can vary, as there are different strategies, or algorithms, to achieve this purpose.

1.0.6 Use malloc() and free() correctly in C code. malloc(), free()

  • malloc() - The C library function void *malloc(size_t size) allocates the requested memory and returns a pointer to it.
    • Declaration: Following is the declaration for malloc() function. 
        • void *malloc(size_t size)  
        • size − This is the size of the memory block, in bytes.
    • Return Value: This function returns a pointer to the allocated memory, or NULL if the request fails

  • free() - The C library function void free(void *ptr) deallocates the memory previously allocated by a call to calloc, malloc, or realloc.
    • Declaration: void free(void *ptr)  
    • Parametersptr − This is the pointer to a memory block previously allocated with malloc, calloc or realloc to be deallocated. If a null pointer is passed as argument, no action occurs. 
    • Return value: This function does not return any value.
1.0.7 Explain virtual memory using segmentation.
  • Because the process stack and heap are not too big, all of the space between the two is simply wasted. This type of waste is usually called internal fragmentation as the space inside the allocated unit is not all used and thus wasted.
  • A segment is just 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.
  • Segmentation allows the OS to place each one of those segments in different parts of physical memory, and thus avoid filling physical memory with unused virtual address space.
  • Supporting many segments requires even further hardware support, with a segment table of some kind stored in memory. Such usually support the creation of a very large number of segments, and thus enable a system to use segments in more flexible ways than we have thus far discussed.

1.0.8 Simulation address translation with segmentation


  •  

1.0.9 Perform automated edits with sed(). sed()

  • How to use sed, a special editor for modifying files automatically. If you want to write a program to make changes in a file, sed is the tool to use.  
  • See link webpage on how to use. 

1.0.10 Automate builds with make. makefile.

  • You need a file called a makefile to tell make what to do. Most often, the makefile tells make how to compile and link a program. 
  • When make recompiles the editor, each changed C source file must be recompiled. If a header file has changed, each C source file that includes the header file must be recompiled to be safe. Each compilation produces an object file corresponding to the source file. Finally, if any source file has been recompiled, all the object files, whether newly made or saved from previous compilations, must be linked together to produce the new executable editor.  
  • See the link.

1.0.11 Write simple awk programs. awk

  • a program that you can use to select particular records in a file and perform operations upon them.
  • Why is AWK so important? It is an excellent filter and report writer. Many UNIX utilities generates rows and columns of information. AWK is an excellent tool for processing these rows and columns, and is easier to use AWK than most conventional programming languages. It can be considered to be a pseudo-C interpretor, as it understands the same arithmatic operators as C. AWK also has string manipulation functions, so it can search for particular strings and modify the output. AWK also has associative arrays, which are incredible useful, and is a feature most computing languages lack. Associative arrays can make a complex problem a trivial exercise. 
  • See link.  

 

No comments:

Post a Comment

CST 499 Capstone - Week 8 Learning Journal Final Entry

This is the very last entry of the journal of your CS Online learning!  Keeping regular journals is a great way for us to grow, both profe...