Memory Management in Computer Systems: An In-Depth Look
Memory Management Requirements
a) Relocation: The ability to place a process in a different area of memory once it has been reloaded for execution.
b) Protection: Must be able to avoid interference (accidental or intentional) between processes so that a process cannot refer to memory locations occupied by another.
c) Behavior: When multiple processes need to access the same memory, memory management must be able to allow this access without compromising the protection discussed in paragraph b).
d) Logical Organization: This will be discussed throughout this issue. Over time, there have been many techniques to bring about this organization, such as the segmentation, which will be discussed later.
e) Physical Organization: This would be studied in the memory hierarchy.
Memory Hierarchy
From Wikipedia, the free encyclopedia
Jump to: navigation, search
The memory hierarchy is the pyramid organization of memory levels within computers. Its goal is to achieve the performance of a high-speed memory at the cost of a low-speed memory, based on the principle of locality of reference.
The basic points related to memory can be summarized as follows:
- Quantity
- Speed
- Cost
The question of quantity is simple: the more memory available, the more you use. The optimum speed for the memory is the speed at which the processor can work, so there is no waiting time between computations, used to fetch operands and store results. In sum, the cost of memory should not be excessive to make it feasible to construct an affordable device.
As might be expected, these are three competing factors, so we must find a balance. The following statements are valid:
- The lower the access time, the higher the cost.
- The higher the capacity, the higher the cost.
- The greater the ability, the lower the speed.
The aim is then to have enough memory capacity, with a speed that will serve to meet the demand for performance, and a cost that is not excessive. Thanks to a principle called proximity of references, it is feasible to use a mixture of different types and achieve a performance close to that of the faster memory.
Levels that make up the memory hierarchy typically are:
- Level 0: Registers
- Level 1: Cache
- Level 2: Main Memory
- Level 3: Hard Drive (with virtual memory mechanism)
- Level 4: Networks (currently considered a higher level of memory hierarchy)
When All Regions Have Fixed Size Limits
In this case, when a process must be loaded into memory:
- If it is of a size equal to or less than that of another set size (in the 8M drawing), it shall be in any partition that is free. In case all partitions are occupied, the OS will release a process from some partition and load this other process ready to run.
- If it is larger than (in the example above 8M) only part of that process will be charged (programmers design programs with the idea of loading only a part) and each time another is needed, the OS is responsible for loading it.
When All Regions Have Different Fixed Size Limits
In this case, there are two ways to assign a process to a partition:
Loading each process in the smallest partition in which it fits. In this case, there is a queue for each partition size.
Problem with this technique:
- There can be a partition with a queue and another empty for not having a process of similar size.
Loading each process in the smallest partition in which it fits. In this case, the processes are organized in a single queue and, for reasons of optimization, when a partition is free, the largest process that fits into it will be searched in the waiting queue.
Problem with this technique:
- Processes will take a long time to load because there are others that better meet the size requirement.
Dynamic Partitions
To overcome some of the difficulties of static partitioning, a solution called dynamic partitioning was developed. With this system, the partitions are variable in number and length so that when a process is loaded into memory, it is allocated exactly as much memory as it needs and no more. This method starts well but eventually leads to a situation in which there are a large number of small holes in the memory. As time passes, the memory begins to be more fragmented and performance lapses. To solve this, things like the following were invented:
- The location algorithms (to choose which is the best process, of those which are waiting to be loaded into memory).
- The replacement algorithms (system to choose which process to remove from memory and thus locate the new process).
- The compaction or displacement of the processes that are contiguous to make more free memory.
Concept of Real Memory or Primary Memory
It’s where programs and processes of a computer are implemented, and it is the real space that exists in memory for running processes. As this memory is generally more expensive than secondary memory, access to information contained in it is the fastest. Only the cache is faster than the main memory, but its cost is higher (remember the memory hierarchy seen in the introduction to computer systems).
Concept of Virtual Memory
The term virtual memory is associated with two concepts that are typically joined:
- The use of secondary storage to offer to all applications the illusion of having more RAM than it actually is in the system.
- Applications offer the illusion that they are alone in the system, and therefore, can use the full address space.
Related to virtual memory there are other concepts:
a) Address Space:
Addresses involved in the management of memory are:
- Physical Address: It is a real position in main memory.
- Logical Address: It is a reference to a memory location independent of the current assignment of data to memory. It suffers a series of transformations performed by the processor (the Memory Management Unit), before becoming a physical address.
- Relative Address: It is a type of logical address in which the address is expressed as a relative position to a known point.
NOTE: User programs always deal with virtual addresses; they never see the real physical addresses.
Memory Management Unit:
The memory management unit (MMU) is part of the processor. Its functions are:
- Convert logical addresses issued by the processes into physical addresses.
- Check that the conversion can be done.
- Check that the process trying to access a certain memory address has permission to do so.
Fragmentation
Fragmentation is the memory that is wasted by using memory management methods that were in previous methods.
Types of fragmentation:
- External Fragmentation: There is a total memory space to satisfy a requirement, but it is not contiguous.
- Internal Fragmentation: Memory allocated can be slightly larger than that required, this reference is internal to the partition, but not used.
Paging
It is a memory management technique in which memory space is divided into physical sections of equal size, called page frames (frames). Programs are divided into logical units, called pages, which have the same size as page frames. In this way, you can load a page of information on any page frame.
The pages serve as a storage unit and transfer between main memory and auxiliary or secondary memory. Each frame is identified by a management framework, which is in the physical position of the first word in the context of the page.
The pages of a program need not be contiguous in memory, although the programmer observes them in this way. Paging mechanisms allow correct correspondence between virtual addresses (given by the programs) and actual memory addresses that are referenced.
To control pages, a table must be maintained in memory, called a page map table (PMT) for each of the processes.
NOTE: When using virtual memory, addresses do not go directly to the memory bus, but go to a memory management unit (MMU).
Paging avoids the considerable problem of fitting the pieces of memory of varying sizes that have suffered the memory management schemes earlier. Because of its advantages over previous methods, paging, in its various forms, is used in many operating systems.
Features of paging:
- The logical address space of a process can be noncontiguous.
- Divide physical memory into fixed-size blocks called frames.
- Memory is divided into blocks of the same size called pages.
- It maintains information on the free frames.
- To run a program of size n pages, you need to find n frames and load the program.
- Establishes a page table to translate logical addresses to physical.
- Internal fragmentation occurs.
Advantages:
- You can start to run a program, loading only a part of it in memory, and the remainder is charged under the order.
- Pages need not be contiguous in memory.
- It is easy to control all pages since they have the same size.
- The address translation mechanism allows separate DAT concepts of address space and memory space. The whole mechanism is transparent to the user.
- It frees the developer from the restrictions set for a physical size of memory.
- It is not required to load an entire program in memory for execution, which may increase the number of multiprogrammed programs.
- It eliminates the problem of external fragmentation.
Disadvantages:
- The cost of hardware and software increases, the new information to be handled and the mechanism of address translation are necessary. Much more memory resources and CPU time are consumed for implementation.
- You must reserve memory areas for the PMT of the processes.
- The problem of internal fragmentation appears. Thus, if 5K is required for a program, but pages are 4K, 2 pages (8k) shall be assigned, with 3K left unused. The amount of open space left in this way may be greater than that of several pages, but may not be used.
Segmentation
- The memory is divided into blocks called variable-length segments.
- The virtual address is composed of two parts: a segment and a displacement.
- When you reference a segment that is not in memory, a segmentation fault occurs.
- It leads to external fragmentation.
- Facilitates the protection of memory and avoids internal fragmentation.
Paged Segmentation
It may be a combination of segmentation and paging to get advantages of both. Instead of treating a segment as a contiguous unit, it can be divided into pages. Each segment can be described by its own page table. The segments are usually multiples of pages in size, and not all pages need to be in main memory at once, plus pages of the same segment, even if they are contiguous in virtual memory, do not need to be contiguous in real memory.
More tables should be used.