CS139-lecture-20211109

image_2021-11-09-13-29-07

Memory Management #

image_2021-11-09-13-36-55 image_2021-11-09-13-39-18

  • recall, CPU does not have direct access to the disk, it must use the bus

image_2021-11-09-13-39-45

  • note that the OS itself is a program residing in memory

Addresses #

image_2021-11-09-13-44-59 image_2021-11-09-13-50-00

  • notice that logically, the address 99 and 100 are next to each other in the purple program. However, physically they are not adjacent (non contiguous).

There are other types of addresses:

Consider a variable declaration like:

var count;

This is considered a symbolic address. We as the programmer don’t know the actual physical address, but we have a symbol that represents the address.

Consider “14 bytes from the beginning of the module”.

This is considered a relocatable address.

Consider an address like 0x7401.

This is considered an absolute address.

The symbolic address becomes a relocatable address in the executable. The relocatable address in the executable will become an absolute address when the program is running.

image_2021-11-09-13-59-46 image_2021-11-09-14-04-50

Uni-programming #

In uni-programming, we can only run 1 program at once. So, only 1 program can exist in memory at a time. If we want to switch to the next program, we need to swap out process’s memory.

image_2021-11-09-14-05-16 image_2021-11-09-14-05-43

This ends up being inefficient due to slow I/O.

Multiple programs sharing memory #

image_2021-11-09-14-07-06 image_2021-11-09-14-07-30

Static relocation #

image_2021-11-09-14-10-20

  • Static relocation is “software based relocation.”
  • The loader does this during load time.

image_2021-11-09-14-10-37 image_2021-11-09-14-10-42

Dynamic relocation #

image_2021-11-09-14-14-30

  • dynamic relocation is “hardware based relocation.”

image_2021-11-09-14-14-45 image_2021-11-09-14-15-52 image_2021-11-09-14-15-56 image_2021-11-09-14-16-01 image_2021-11-09-14-16-06 image_2021-11-09-14-16-11 image_2021-11-09-14-16-16 image_2021-11-09-14-16-22

  • when \( P_1 \) tries to write to \( P_2 \) ’s address space, it will not be allowed (based on a simple check with the limit register).

image_2021-11-09-14-18-51 image_2021-11-09-14-18-56

Contiguous allocation #

Contiguous allocation is like the blue process in the drawing above. It is loaded into 1 contiguous place.

image_2021-11-09-14-26-30 image_2021-11-09-14-28-28

Allocation policies #

image_2021-11-09-14-30-33

  • “next fit” is basically “first fit” but starting at the position of the last allocated memory address
  • “best fit” requires an exhaustive search (or sort the list based on hole size)