操作系统文件分配策略_操作系统中的文件分配方法

操作系统中的文件分配方法包括连续分配、链接分配和索引分配。连续分配提供高效磁盘空间利用和快速访问,但易产生内外碎片;链接分配灵活,避免外部碎片,但访问速度慢;索引分配支持随机访问,解决外部碎片,但有空间浪费和大文件管理难题。
摘要由CSDN通过智能技术生成

操作系统文件分配策略

分配方法 (Allocation Method)

The allocation method defines how the files are stored in the disk blocks. The direct access nature of the disks gives us the flexibility to implement the files. In many cases, different files or many files are stored on the same disk. The main problem that occurs in the operating system is that how we allocate the spaces to these files so that the utilization of disk is efficient and the quick access to the file is possible. There are mainly three methods of file allocation in the disk. Each method has its advantages and disadvantages. Mainly a system uses one method for all files within the system.

分配方法定义文件如何存储在磁盘块中。 磁盘的直接访问特性使我们可以灵活地实现文件。 在许多情况下,不同的文件或许多文件存储在同一磁盘上。 操作系统中出现的主要问题是我们如何为这些文件分配空间,以便磁盘利用效率高,并且可以快速访问文件。 磁盘中主要有三种文件分配方法。 每种方法都有其优点和缺点。 主要是系统对系统中的所有文件使用一种方法。

  • Contiguous allocation

    连续分配

  • Linked allocation

    链接分配

  • Indexed allocation

    索引分配

The main idea behind contiguous allocation methods is to provide

连续分配方法背后的主要思想是提供

  • Efficient disk space utilization

    高效的磁盘空间利用

  • Fast access to the file blocks

    快速访问文件块

连续分配 (Contiguous allocation)

In this scheme, a file is made from the contiguous set of blocks on the disk. Linear ordering on the disk is defined by the disk addresses. In this scheme only one job is accessing the disk block b after that it accesses the block b+1 and there are no head movements. When the movement of the head is needed the head moves only from one track to another track. So the disk number that is required for accessing the contiguous allocation is minimal. Contiguous allocation method provides a good performance that’s why it is used by the IBM VM/CMS operating system. For example, if a file requires n blocks and is given a block b as the starting location, then the blocks assigned to the file will be: b, b+1, b+2,..., b+n-1. This means that given the starting block address and the length of the file (in terms of blocks required), we can determine the blocks occupied by the file. For a contiguous allocation the directory entry the address of the starting block and Length of the allocated portion.

在这种方案中,文件是由磁盘上连续的块集组成的。 磁盘上的线性顺序由磁盘地址定义。 在此方案中,只有一个作业正在访问磁盘块b,之后它才访问块b + 1,并且没有磁头移动。 当需要头部移动时,头部仅从一个轨道移动到另一轨道。 因此,访问连续分配所需的磁盘数量最少。 连续分配方法提供了良好的性能,这就是IBM VM / CMS操作系统使用它的原因。 例如,如果一个文件需要n个块,并以b作为起始位置,则分配给该文件的块将为: b,b + 1,b + 2,...,b + n-1 。 这意味着给定起始块地址和文件长度(以所需的块数为单位),我们可以确定文件所占用的块。 对于连续分配,目录条目的起始块的地址和分配部分的长度。

The file 'A' in the following figure starts from block 19 with length = 6 blocks. Therefore, it occupies 19, 20, 21, 22, 23, 24 blocks.

下图中的文件“ A”从块19开始,其长度= 6个块 。 因此,它占用19、20、21、22、23、24个块。

  • Each file in the disk occupies a contiguous address space on the disk.

    磁盘中的每个文件都占据磁盘上连续的地址空间。

  • In this scheme, the address is assigned in the linear fashion.

    在此方案中,以线性方式分配地址。

  • The is very easy to implement the contiguous allocation method.

    实现连续分配方法非常容易。

  • In the contiguous allocation technique, external fragmentation is a major issue.

    在连续分配技术中,外部碎片化是一个主要问题。

Advantages:

优点:

  1. In the contiguous allocation, sequential and direct access both are supported.

    在连续分配中,同时支持顺序访问和直接访问。

  2. For the direct access, the starting address of the kth block is given and further blocks are obtained by b+K,

    对于直接访问,给出第k个块的起始地址,并通过b + K获得其他块,

  3. This is very fast and the number of seeks is minimal in the contiguous allocation method.

    在连续分配方法中,这非常快并且搜寻次数最少。

Disadvantages:

缺点:

  1. Contiguous allocation method suffers internal as well as external fragmentation.

    连续分配方法遭受内部和外部碎片。

  2. In terms of memory utilization, this method is inefficient.

    在内存利用率方面,此方法效率低下。

  3. It is difficult to increase the file size because it depends on the availability of contiguous memory.

    很难增加文件的大小,因为它取决于连续内存的可用性。

Example:

例:

FileStartLength
Count02
Tr143
Mail196
List284
文件 开始 长度
计数 0 2
Tr 14 3
邮件 19 6
清单 28 4

链接分配 (Linked allocation)

The problems of contiguous allocation are solved in the linked allocation method. In this scheme, disk blocks are arranged in the linked list form which is not contiguous. The disk block is scattered in the disk. In this scheme, the directory entry contains the pointer of the first block and pointer of the ending block. These pointers are not for the users. For example, a file of six blocks starts at block 10 and end at the block. Each pointer contains the address of the next block. When we create a new file we simply create a new entry with the linked allocation. Each directory contains the pointer to the first disk block of the file. when the pointer is nil then it defines the empty file.

链接分配方法解决了连续分配的问题。 在这种方案中,磁盘块以不连续的链表形式排列。 磁盘块分散在磁盘中。 在此方案中,目录条目包含第一个块的指针和结束块的指针。 这些指针不适用于用户。 例如,六个块的文件从块10开始,到块结束。 每个指针都包含下一个块的地址。 当我们创建一个新文件时,我们只需创建一个带有链接分配的新条目。 每个目录都包含指向文件第一个磁盘块的指针。 当指针为nil时,它将定义空文件。

Advantages:

优点:

  1. In terms of the file size, this scheme is very flexible.

    就文件大小而言,此方案非常灵活。

  2. We can easily increase or decrease the file size and system does not worry about the contiguous chunks of memory.

    我们可以轻松地增加或减少文件大小,并且系统不必担心连续的内存块。

  3. This method free from external fragmentation this makes it better in terms of memory utilization.

    此方法没有外部碎片,因此在内存利用率方面更好。

Disadvantages:

缺点:

  1. In this scheme, there is large no of seeks because the file blocks are randomly distributed on disk.

    在这种方案中,由于文件块是随机分布在磁盘上的,因此不需要大量查找。

  2. Linked allocation is comparatively slower than contiguous allocation.

    链接分配比连续分配要慢。

  3. Random or direct access is not supported by this scheme we cannot access the blocks directly.

    此方案不支持随机或直接访问,我们无法直接访问块。

  4. The pointer is extra overhead on the system due to the linked list.

    由于链接列表,指针在系统上会产生额外的开销。

索引分配 (Indexed Allocation)

In this scheme, a special block known as the index block contains the pointer to all the blocks occupied by a file. each file contains its index which is in the form of an array of disk block addresses. The ith entry of index block point to the ith block of the file. The address of the index block is maintained by the directory. When we create a file all pointer is set to nil. A block is obtained from the free space manager when the first ith block is written. When the index block is very small it is difficult to hold all the pointers for the large file. to deal with this issue a mechanism is available. Mechanism includes the following:

在此方案中,称为索引块的特殊块包含指向文件所占据的所有块的指针。 每个文件都包含其索引,该索引采用磁盘块地址数组的形式。 索引块的第i个条目指向文件的第i个块。 索引块的地址由目录维护。 创建文件时,所有指针都设置为nil。 当第一个第i个块被写入时,将从可用空间管理器中获得一个块。 当索引块很小时,很难保存大文件的所有指针。 解决此问题的机制是可用的。 机制包括以下内容:

  • Linked scheme

    链接方案

  • Multilevel scheme

    多级方案

  • Combined scheme

    组合方案

Advantages:

优点:

  1. This scheme supports random access of the file.

    该方案支持文件的随机访问。

  2. This scheme provides fast access to the file blocks.

    该方案提供对文件块的快速访问。

  3. This scheme is free from the problem of external fragmentation.

    该方案没有外部碎片的问题。

Disadvantages:

缺点:

  1. The pointer head is relatively greater than the linked allocation of the file.

    指针头相对大于文件的链接分配。

  2. Indexed allocation suffers from the wasted space.

    索引分配遭受空间浪费。

  3. For the large size file, it is very difficult for single index block to hold all the pointers.

    对于大文件,单个索引块很难容纳所有指针。

  4. For very small files say files that expend only 2-3 blocks the indexed allocation would keep on the entire block for the pointers which is insufficient in terms of memory utilization.

    对于很小的文件,例如仅消耗2-3个块的文件,索引分配将保留整个块的指针,这在内存利用率方面是不够的。

翻译自: https://www.includehelp.com/operating-systems/file-allocation-method.aspx

操作系统文件分配策略

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值