Showing posts with label virtual memory. Show all posts
Showing posts with label virtual memory. Show all posts

Thursday, October 13, 2011

Memory Management, part 2

Another way to partition memory is Dynamic Partition.
Partitions vary depending on the size of a process. The placement with dynamic allocation
is to allocate exactly the size of a process in the memory.
However, when processes exit, holes might be created between every two processes.
This is called External Fragmentation.
When OS move processes down to eliminate holes, larger free space are created.
This action is called Memory Compaction.
We need to know what is the maximum size of a process at load time. Otherwise, we
must be able to add to its partition, potentially relocating it.

To keep track of memory allocation, we can use Bitmaps.

Placement Heuristics:
Memory compaction is time-consuming. We can reduce compaction if we systematically
allocate memory. The following techniques give us an idea how this can be achieved.
First-fit, allocate the first block large enough, appears to be the BEST choice, leave
external fragmentation at start of memory
Next-fit, allocate the block where previous search ends at, a variation of first-fit,
free space becomes fragmented more rapidly
Best-fit, scans through the blocks and finds the most suitable block in size,
small, unusable fragments
Worst-fit, find the largest block
Quick-fit, keep multiple free lists for common block sizes,
fast allocation, harder to coalesce

Relocation:
a way to change the physical memory reference

Dynamic relocation:
execution-time binding of addresses, hardware translates to physical addresses as instructions are executed.
base address + relative address = physical address <= limit address

Basic problems that cause internal fragmentation and external fragmentation and so on...:
we assume processes are allocated to contiguous block of memory

Solution: Paging

To be continued...


Wednesday, October 12, 2011

Memory Management

The Quiz 1 is coming soon I am kind of falling behind the schedule. I decide to spend some times
to go over the concepts that have been covered in the lecture so hopefully I won't "fail" this course the second time.

I've been dealing with the memory management problems all the time when I implementing
the thread sub-system and system call functions.
Why should each process has its own address space? Why do we even come to this abstraction?
First, we want to protect the OS from being modified or trashed or whatever easily because of easy access to physical memory.
Second, we want to run multiple programs at once.
When multiple programs are running, two programs present: protection and relocation.

Address space creates a kind of abstract memory for programs.
It is a set of addresses for processes to address memory.
Each process then owns its private address space, continuous and contiguous.

An important concept to remember is "Address Translation". It is the process of mapping addresses in the programs, mostly referred to the variables or symbolic addresses that
programmers use, into physical addresses.

To deal with memory problems, two strategies are commonly used: swapping and virtual memory.
Swapping means to swap process in and out from memory and to put the inactive process
on the disk. Virtual memory allows program to run even when they are partially in main memory. This is insane technology! I will go over it later since there's quite a few things.

In the lecture, we discussed about the Partition problem. Process will grow as they run.
We must determine whether to partition the memory into fixed-size chunks or dynamically
allocate the memory. We want to allocate extra memory for a process to reduce the overhead
associated with swapping processes that no longer fit in out from the memory.
It is somewhat complicated here. Let's start over again.
When the space is no longer large enough for a process, it will be swapped out and it has
to wait until a lager hole in the memory becomes available. The static/fixed-size allocation
is simpler to implement, but it creates Internal Fragmentation. In this case, memory
is wasted if process in a partition is smaller. For programs that are larger than the partitions,
we have Overlay problems. Then those programs have to get the hell out of the memory. (:<)

Gotta sleep now.
To be continued...