memory allocation method

There are two types of memory allocation : continuous memory allocation and discrete memory allocation . Different allocation methods have different allocation algorithms.

①Continuous memory allocation method

1) Fixed partition allocation

Divide memory into fixed-size blocks. Just put the program into a block. After the memory is divided into blocks, the block size does not change. Of course, the ways of dividing blocks are: all blocks are equal in size; divided blocks are not equal in size.

In this way, all memory block sizes are known before the actual memory allocation.

---- Fixed partition allocation is the simplest storage management method that can run multiple programs . This is to divide the memory user space into several fixed size (not equal size) areas, in each partition

Only one job is loaded in the user space, so dividing the user space into several partitions allows several jobs to run concurrently.

---- When there is a free partition, you can select a job of an appropriate size from the backup job queue of the external memory and load it into the partition. When the job ends, you can find another job from the backup job queue.

The job is called into this partition.

1) The method of dividing the partition

The user space of memory can be divided into several fixed-size partitions in the following two ways:

----  Equal partition size , that is, all memory partitions are equal in size.

The disadvantage is the lack of flexibility , that is, when the program is too small, it will cause a waste of memory space; when the program is too large, a partition is not enough to load the program, causing the program to fail to run.

Nonetheless, this division is still used when a computer is used to control multiple identical objects , because the memory space required by these objects is equal in size.

For example, the furnace temperature group control system uses one computer to control multiple identical smelting furnaces.

----  Partition size varies . In order to overcome the disadvantage of equal partition size and lack of flexibility, the memory area can be divided into several smaller partitions, a moderate amount of medium partitions, and a small number of large partitions.

In this way, the appropriate partition can be allocated to the program based on its size.

2) Memory allocation

In order to facilitate memory allocation, partitions are usually queued by size, and a partition usage table is established for them. Each table entry includes the starting address , size , and status (allocated or not) of each partition.

When a user program is to be loaded, the memory allocation program retrieves the table, finds an unallocated partition that satisfies the requirements, assigns it to the program, and then the state in the table entry

set to "Assigned". If a partition of sufficient size is not found, then refuse to allocate memory for the user program. Since the size of each partition is fixed, it will inevitably lead to a waste of storage space.

The following figure is the partition allocation table for the fixed partition allocation example:

 

As shown in the figure above, there are four fixed partitions, the partition sizes are 20KB, 40KB, 100KB, 200KB, and the starting addresses are 100KB, 120KB, 160KB, and 260KB.

Suppose there are 3 jobs now, job A (18KB), job B (37KB), job C (200KB), choose a suitable partition for it according to the size of the job.

---- Job A is 18KB, and partition 1 can be selected to be 20KB, which will generate 2KB internal fragmentation; (allocated)

---- Job B is 37KB, and partition 2 can be selected to be 40KB, which will generate 3KB of internal fragmentation; (allocated)

---- Job C is 200KB, select partition 4 is 200KB, no fragmentation is generated. (Assigned)

Three jobs have been allocated, and the remaining partition 3 is still a free partition and has not been allocated. (unassigned)

Each partition corresponds to two registers of upper and lower bounds for memory out-of-bounds protection. When the CPU accesses each memory address, it should satisfy:

---- The access address is greater than or equal to the content of the lower bound register, and less than or equal to the content of the upper bound register, otherwise an address out-of-bounds error will occur and the operation of the job will be terminated.

The memory allocation of the above three jobs is as follows:

---- The advantages and disadvantages of fixed partition allocation are as follows:

Pros: Simplest storage allocation available for multiprogramming systems, no external fragmentation.

Disadvantages: Multiple processes cannot share a main memory area, so storage space utilization is low and there is internal fragmentation.

2) Dynamic partition allocation

Click to open the link

A free list or free chain is required to record the memory area of ​​the space currently in the system. When memory is allocated, it is necessary to look up the space table or free chain to find a piece of memory to allocate to the current process.

Dynamic partition allocation algorithm:

a) First Fit Method

b) Cyclic first adaptation method

c) best fit method

d) Worst fit method

e) Quick adaptation method

3) Relocatable partition allocation

To put it bluntly, it is to increase the function of memory movement. After several times of memory allocation and reclamation, the free memory blocks are discontinuous. Through "relocation", the allocated memory is "compacted" in one piece to free up a large piece of free memory.

"Compact" requires overhead, such as the need to recalculate addresses

The discrete allocation method, whether it is paging or segmentation, directly puts the program into each discrete page. So there is no such thing as "compact".

Continuous memory allocation involves two operations: memory allocation and memory reclamation

②Discrete memory allocation method

内存资源是有限的,程序要运行,必须得加载到内存。如果内存已经满了,而现在又有新的程序要运行,怎么办?---SWAP

把当前不用的程序(数据)先换出内存,从而就有空间加载当前需要运行的程序的一部分数据进入内存,这样大大提高了内存的利用率。

由于牵涉到换入与换出,前面的连续内存分配方式就有点不适用了。因为,最明显的一个问题:对于连续内存分配方式,究竟换出哪部分数据呢?

而这种只装入部分"数据"就可以使程序运行的机制,就是虚拟存储器的本质。

1)分页存储管理点击打开链接 页面置换

2)分段存储管理 点击打开链接


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325769201&siteId=291194637