分片与压实的区别
在操作系统中,内存管理在最大化 CPU 利用率方面起着至关重要的作用,当空间分配给进程时,内存的一些损失(碎片)会导致内存的低效使用,而减少这种损失的技术之一(压缩) 用于优化内存空间。
碎片化
它是由于传染性内存分配而发生的,因为存在存储空间未达到最大值的现象。从而降低操作系统的性能。碎片有两种类型:外部碎片和内部碎片。
1. 外部:可用空间不连续,存储空间被划分为少量空洞时发生。 First fit 和 Best fit 都受到外部碎片的影响。
Example problem: Size of different non contagious small holes are 54 byte, 30 byte and 44 byte. Total non contagious size is- 54+30+44=128 bytes. Process request is 120 bytes.
Solution: Could not proceed due to non contiguous holes leads to external fragmentation.
2.内部:分配空间给进程后留在块中的内存导致内部碎片。分页存在内部碎片。内存内部碎片示例
Example problem: Available block size 255 bytes. Process size 250 bytes.
Solution:The process is allocated to the block, creating a hole of 5 bytes which leads to internal fragmentation.
压实
这是一种将孔(小内存块)向一个方向移动并将占用的块移动到另一侧的技术。大量的时间浪费在执行压缩上。
分片和压实的区别
S. No | Fragmentation | Compaction |
---|---|---|
1. | It is due to the creation of holes (small chunks of memory space). | It is to manage the hole. |
2. | This creates a loss of memory. | This reduces the loss of memory. |
3. | Sometimes, the process cannot be accommodated. | Memory is optimized to accommodate the process. |
4. | External Fragmentation may cause major problems. | It solves the issue of External Fragmentation. |
5. | It depends on the amount of memory storage and the average process size. | It depends on the number of blocks occupied and the number of holes left. |
6. | It occurs in contiguous and non-contiguous allocation. | It works only if the relocation is dynamic. |