[Operating.System.Concepts(9th,2012.12)].Abraham.Silberschatz. Text Edition (Dinosaur Book - Operating System Concepts Original Book Ninth Edition) Reference Answers for After-school Exercises

Table of contents

Chap01 Introduction

Chap02 OS structure

Chap03 process

Chap04 thread

Chap05 Synchronization

Chap06 CPU Scheduling

Chap07 deadlock

Chap08 memory management strategy

Chap09 Virtual Memory Management

Chap10 Mass storage structure

Chap11 file system

Implementation of Chap12 file system

Chap13 I/O system


Written in front:

This answer is only for learning and reference sharing, and may not be reproduced without the author's permission;

The answers contained in this article are all standard answers, pure hand code, please rest assured to eat (CSDN designer!!! Do you know my pain!!! More than 36000 words!!!!!!). If you don't find the answer to the question you need, please add it in the comment area;

The serial number of the topic in the article corresponds to the sequence of the after-class exercises in the English version of the textbook;

Offline word version download link: Operating System Principles (Dinosaur Book Ninth Edition) Answers to After-Class Exercises-OS Documentation Resources-CSDN Library


Chap01 Introduction

1. What are the three main purposes of the OS?

  1. Provide computer users with an environment for conveniently and efficiently executing programs on computer hardware;
  2. Allocate individual resources of a computer as needed to solve a given problem, as fairly and efficiently as possible;
  3. As a control program, it has two main functions: (1) Supervise the execution of user programs to prevent errors and improper use of the computer; (2) Manage the operation and control of input/output devices.

2. We emphasize the need for an operating system to efficiently utilize computing hardware. When should an OS abandon this principle and "waste" resources? Why isn't such a system a real waste?

        A single-user system needs to maximize service for users. A GUI may "waste" CPU cycles, but it optimizes the user's interaction with the system.

3. What are the main difficulties a programmer must overcome when writing an operating system for a real-time environment?

        The main difficulty is keeping the operating system within the fixed time constraints of a real-time system. If a system doesn't complete a task within a certain period of time, it can bring down the entire system it's running on. Therefore, when writing an operating system for a real-time system, the writer must ensure that its scheduling scheme does not allow response times to exceed time limits.

4. Keeping in mind the various definitions of an operating system, consider whether an operating system should include applications such as web browsers and mail programs. Argument that it should and shouldn't, and support your answer.

One argument in favor of including popular applications in the operating system is that if the application is embedded in the operating system, it is likely to make better use of features in the kernel, so compared to applications running outside the kernel, it has performance advantages

Arguments against embedding applications in an operating system generally dominate: (1) applications are applications and not part of the operating system, (2) any performance advantage of running in the kernel would be negated by security vulnerabilities, ( 3) It bloats the OS.

5. How does the distinction between kernel mode and user mode come into play as a basic form of protection (security) for a system?

The distinction between kernel mode and user mode provides a basic form of protection in the following way. Certain instructions can only be executed when the CPU is in kernel mode. Similarly, hardware devices can only be accessed when a program is executing in kernel mode. You can control when interrupts are enabled or disabled only when the CPU is in kernel mode. Therefore, when executing in user mode, the capabilities of the CPU are very limited, enforcing the protection of critical resources.

6. Which of the following operations should be privileged?

a . Set the value of the timer. Yes

b. Read the clock.                      

c . Clear memory. Yes

d. Issue a trap command.          

e . Turn off interrupts. Yes

f . Modify the entries in the device state table. Yes

g. Switch from user mode to kernel mode.

h , Access input/output devices. Yes

7. Some early computers protected the operating system by placing it in a memory partition that neither user jobs nor the operating system itself could modify. Describe two difficulties you think such a plan might present.

Data required by the operating system (passwords, access controls, accounting information, etc.) must be stored in or passed through unprotected memory so unauthorized users can access the data.

8. Some CPUs provide more than two modes of operation. What are two possible uses of these multi-modes.

  1. Various modes can be used to provide more fine-grained security policies. For example, instead of just distinguishing between user mode and kernel mode, you can distinguish between different types of user modes. Maybe users belonging to the same group can execute each other's code. When one of the users runs the code, the computer enters the specified mode. When the computer is in this mode, group members can run code that belongs to anyone else in the group.
  2. Another possibility is to provide a different distinction in the kernel code. For example, a specific mode may allow a USB device driver to run. This means that USB devices can be serviced without having to switch to kernel mode, essentially allowing USB device drivers to run in quasi-user/kernel mode.

9. The timer can be used to calculate the current time. Briefly describe how this is achieved.

A program can use the following method to calculate the current time using a timer interrupt.

The program can set a timer for some time in the future and then go to sleep. When it is woken up by an interrupt, it can update its local state, which it uses to keep track of the number of interrupts it has received so far. It can then repeat the process, continually setting the timer interrupt and updating its local state when the interrupt is actually raised.

10. Give two reasons why cashes are useful. What problem do they solve? What problems can they cause? If a cash can be as large as the device it's cached on (e.g. a cache as large as a disk), why not make it so large and remove the device?

  1. Caching is useful when two or more components need to exchange data, and the components perform transfers at different speeds.
  2. Caching solves transport problems by providing an intermediate-speed buffer between components. If a fast device finds the data it needs in cache, there is no need to wait for a slower device. The data in the cache must be consistent with the data in the component. If a component's data value changes, and the data is also in the cache, the cache must also be updated. This is especially a problem in multiprocessor systems, where multiple processes may be accessing a piece of data.
  3. Components can be eliminated by caches of equal size, but only if: (A) the cache and the component have equivalent state preservation capacity (i.e., if the component retains its data when powered down), the cache must also retain the data at the same time (b) the cache Reasonably priced, as faster storage tends to be more expensive.

11. Distinguish between the client-server and peer-to-peer models of distributed systems.

  1. The client-server model clearly distinguishes the roles of client and server. Under this model, a client requests a service provided by a server.
  2. The peer-to-peer model does not have such strict roles. In fact, all nodes in the system are considered peers, and thus can act as clients or servers, or both. A node may request a service from another peer, or the node may actually provide such a service to other peers in the system.

12. In multiprogramming and time-sharing environments, multiple users share the system at the same time. This situation can lead to various security issues.

a . What are these two problems?

b . Can we ensure that time-sharing machines have the same security as dedicated machines? Explain your answer.

        a. Steal or copy user programs or data;

           Use system resources without authorization;

        b. No, it is thought that all artificially designed time-sharing system protection schemes may be destroyed.

14. Under what circumstances would it be better for a user to use a time-sharing system than a PC or single-user workstation?

When there are few other users, the workload is large, the hardware is fast, and time-sharing is reasonable, the full power of the system can be used to solve the user's problem. This problem can be solved faster than on a PC.

19. What is the purpose of the interruption? What is the difference between trap and interrupt? Can a trap be intentionally generated by a user program? If so, for what purpose?

Interrupts are hardware-generated flow changes in the system. An interrupt handler is called to handle the cause of the interrupt; control is then returned to the interrupted context and instruction.

A trap is a software-generated interrupt.

Interrupts can be used to signal I/O completion, avoiding the need for device polling. Traps can be used to call operating system routines or to catch arithmetic errors.

21. Some computer systems do not provide a special mode of operation on the hardware / is it possible to build a secure OS for these computer systems? Give an argument.

The operating system of such machines needs to be in control (or monitor mode) at all times. This can be achieved in two ways:

a : Software interpretation of all user programs (such as some BASIC, Java, and LISP systems). A software interpreter can provide things in software that hardware cannot.
b : All programs must be written in a high-level language, so that all object codes are generated by the compiler. The compiler will generate (inline or via a function call) guard checks to determine if hardware is missing.


Chap02 OS structure

1. What is the purpose of a system call?

Allows user-level processes to request operating system services.

2. What are the five main activities of an OS in process management?

a. Create and delete user and system processes

b. Suspend and resume the process

c. Provide process synchronization mechanism

d. Provide process communication mechanism

e. Provide deadlock handling mechanism

3. What are the three main activities of an OS in memory management?

a. Track which parts of memory are currently being used and by whom.

b. Decide which processes to load into memory when memory space is available.

c. Allocate and release memory space as needed

4. Three main activities of OS in mass storage management.

• Free space management.

• Storage allocation.

• Disk scheduling.

5. What is the purpose of the command interpreter? Why is it usually separated from the kernel?

It reads commands from a user or command file and executes them, usually by translating them into one or more system calls. It is usually not part of the kernel because the command interpreter is subject to change.

6. What system calls must the command interpreter or shell execute in order to start a new process?

In a Unix system, the fork system call needs to be executed first, and then the exec system call is executed to start a new process. The fork call clones the currently executing process, while the exec call overwrites the new process based on a different executable on the calling process.

7. What is the purpose of the system program?

System programs can be thought of as useful packages of system calls.

They provide users with basic functionality, so users do not need to write their own programs to solve common problems.

8. What are the main advantages of the layered system design approach? What are the disadvantages of using a layered approach?

advantage:

The system is easier to debug and modify because changes affect only limited parts of the system and not all parts of the operating system.

shortcoming:

信息只保存在需要的地方,并且只能在定义和限制的区域内访问,因此任何影响该数据的错误都必须限制在特定的模块或层中

9.列出操作系统提供的五项服务,并解释每项服务如何为用户带来便利。在哪些情况下,用户级程序不可能提供这些服务?解释你的答案。

  1. 程序执行。操作系统将文件的内容(或节)加载到内存中并开始执行。当用户级程序不被信任时无法提供。
  2. I/O操作。磁盘、磁带、串行线和其他设备必须以非常低的级别进行通信。用户只需指定设备和要在其上执行的操作,而系统会将该请求转换为特定于设备或控制器的命令。不受信任的用户级程序仅访问其所有权访问的并且未被使用中的设备。
  3. 文件系统操作。在文件创建、删除、分配和命名方面有许多用户不必执行的细节。磁盘空间块由文件使用,必须进行跟踪。删除文件需要删除名称文件信息并释放分配的块。还必须检查保护措施,以确保正确访问文件。用户程序既不能确保遵守保护方法,也不能在文件删除时仅分配空闲块和释放块。
  4. 通信。系统间的消息传递要求将消息转换为信息包,发送给网络控制器,通过通信介质传输,并由目标系统重新组装。必须进行数据包排序和数据更正。同样,用户程序可能无法协调对网络设备的访问,或者它们可能接收到目的地为其他进程的数据包
  5. 错误检测。错误检测发生在硬件和软件级别。在硬件层面,必须检查所有数据传输,以确保数据在传输过程中没有损坏。必须检查介质上的所有数据,以确保这些数据在写入介质后未发生更改。在软件层面,必须检查介质的数据一致性;例如,已分配和未分配的存储块数是否与设备上的总数匹配。在那里,错误通常与进程无关(例如,磁盘上的数据损坏),因此必须有一个全局程序(操作系统)来处理所有类型的错误。此外,通过操作系统处理错误,进程不需要包含捕获和更正系统上所有可能错误的代码

10.为什么有些系统将操作系统存储在固件中,而另一些系统将其存储在磁盘上?

对于某些设备,如手持PDA和蜂窝电话,可能无法为设备提供带有文件系统的磁盘。在这种情况下,操作系统必须存储在固件中。

11. How is the system designed to allow selection of which operating system to boot? What does the bootloader need to do?

Consider a system that wishes to run Windows XP and three different Linux distributions (such as RedHat, Debian, and Mandrake) simultaneously.

Each operating system will be stored on disk. During system boot, a special program (we call it the boot manager) decides which operating system to boot into. This means that the boot manager will run first during system startup, rather than initially booting into the operating system. It is this boot manager that is responsible for determining which system to boot into. Usually, the boot manager must be stored somewhere on the hard disk to be recognized during system startup. A boot manager usually gives the user a choice of the system to boot into; a boot manager is usually designed to boot to the default operating system if the user has no choice.

12. The services and functions provided by the operating system can be divided into two categories. Briefly describe the two categories and discuss their differences.

One type of service provided by an operating system is the enforcement of protection between different processes running concurrently on the system. A process is only allowed to access those memory locations associated with its address space. Also, processes are not allowed to corrupt files associated with other users. Processes are also not allowed to directly access devices without OS intervention. The second type of service provided by an operating system is to provide new functionality not directly supported by the underlying hardware. Virtual memory and file systems are two examples of new services provided by operating systems.

16. What are the advantages and disadvantages of using the same system call interface to manipulate files and devices?

Each device can be accessed like a file in the file system. Since most kernels handle devices through this file interface, it is relatively easy to add new device drivers by implementing hardware-specific code to support this abstract file interface. Therefore, this facilitates the development of user program code (which can be written to access devices and files in the same way) and device driver code (which can be written to support a well-defined API). The downside is that it may be difficult to capture the functionality of some devices in the context of the file access API, resulting in loss of functionality or loss of performance. Some of these problems can be overcome by using ioctl operations, which provide a common interface for process calls to operations on a device.

17. Can users use the system call interface provided by the operating system to develop a new command interpreter?

Users should be able to develop new command interpreters using the system call interface provided by the operating system. The command interpreter allows the user to create and manage processes and determine how they communicate (for example, through pipes and files). Since all of these functions can be accessed by user-level programs using system calls, it should be possible for a user to develop a new command-line interpreter.

21. What are the main advantages of the microkernel approach to system design? How do user programs and system services interact in a microkernel architecture? What are the disadvantages of using the microkernel approach?

Advantage:

(a) Adding new services does not require modifying the kernel

(b) It's more secure because more operations are done in user mode than in kernel mode (c) Simpler kernel design and features generally lead to a more reliable operating system.

User programs and system services interact in the microkernel architecture by using interprocess communication mechanisms such as message passing. These messages are sent by the operating system.

shortcoming:

Kernel performance suffers from the overhead associated with interprocess communication and the heavy use of the operating system's messaging capabilities to enable user processes and system services to interact with each other.

Knowledge points:

System calls are primarily written in high-level languages, and assembly language may be used for some low-level tasks.

There are three ways to pass parameters to the OS when calling the system:

  • via registers (easiest);
  • Store parameters in a table or block, and then place the address of the table or block in a register (there is no limit to the length or number of passed parameters);
  • Put or push parameters on the stack through the program;

System call types: process control, file management, device management, information maintenance, communication, protection.

The first question of OS design: defining goals and specifications;


Chap03 process

1. In the program shown in the figure, interpret the output on line A.

After using fork() to create a child process, the child process has its own memory address, and the return value in the child process is 0, that is, pid=0, and the value is changed to 20, because the value in the child process is different from the value memory address of the parent process , so the value of the parent process is still 5; in the parent process, fork() returns the process id of the child process>0, directly print PARENT: value = 5

2. Including the initial parent process, how many processes are created by the program shown in the figure?

A total of 8 processes are created.

3. The Sun UltraSPARC processor has multiple register sets. Describes what happens when a context switch occurs if a new context has been loaded into one of the register sets. What happens if the new context is in memory instead of the register set, and all register sets are in use?

It takes very little time for the CPU's current register set pointer to change to point to the set containing the new context. If the context is in memory, one of the contexts in the register set must be selected and moved into memory, and the new context must be loaded from memory into the set. This process takes slightly more time than systems using one set of registers, depending on how the replacement victim is chosen.

4. When a process uses the fork() operation to create a new process, which of the following states is shared by the parent process and the child process? a stack b heap c shared memory segment

There are shared memory segments that are shared between the parent process and the newly forked child process. Duplicate the stack for newly created processes.

5. Regarding the RPC mechanism, consider "exactly once" semantics. Will an algorithm that implements this semantics perform correctly even if the ACK message returned to the client is lost due to network issues? Describe the sequence of messages, and discuss whether "only once" is still preserved.

"Exactly once" semantics ensure that the remore procedure is executed only once. A common algorithm to ensure this combines an acknowledgment (ACK) scheme with a timestamp (or other incremental counter that allows the server to distinguish duplicate messages).

The general strategy is that the client sends an RPC to the server along with a timestamp. The client will also start a timeout clock. The client will then wait for one of two events: (1) it will receive an ACK from the server indicating that the remote procedure has executed, or (2) it will time out. If the client times out, it will assume the server cannot execute the remote procedure, so the client will call the RPC again, sending a later timestamp. The client may not receive the ACK for one of two reasons: (1) the server never received the original RPC, or (2) the server received and executed the RPC correctly, but the ACK was lost. In case (1), using the ACK allows the server to eventually receive and execute the RPC. In case (2), the server will receive a duplicate RPC and will use a timestamp to identify it as a duplicate to avoid performing the RPC again. It is important to note that the server must send a second ACK to the client to inform the client that the RPC has been performed.

6. Assume that distributed systems are prone to server failure. What mechanisms are needed to guarantee the semantics of "exactly once" RPC execution?

Servers should track information about which RPC operations are received, whether they were successfully performed, and the results associated with those operations in stable storage such as a disk log. When a server crash occurs and an RPC message is received, the server can check whether the RPC has been executed before, thus ensuring the semantics of executing the RPC "only once".

8. Describe the difference between the short-term scheduler, medium-term scheduler, and long-term scheduler.

In a batch system:

Short-Term Scheduler (CPU Scheduler) - Selects a process from those ready to execute and allocates the CPU.

Long-term scheduler (job scheduler) - select processes from the process buffer pool and add them to memory for execution.

Their main difference is the frequency of execution. The short-term scheduler must frequently select new processes for the CPU. The long-term scheduler is infrequent, because the long-term scheduler controls the multiprogramming process and must ensure the stability of the multiprogramming process. For this reason, the average speed of creating programs must be equal to the average speed of processes leaving the system. So the scheduling of long-lived programs is only needed when the process leaves the system.

In a time-sharing system:

The mid-term scheduler, which moves processes out of memory (or out of CPU contention), thereby reducing the degree of multiprogramming. The process is then reloaded into memory and resumes execution from the interrupt. Implement an exchange scheme.

9. Describe the actions taken by the kernel when context switching between processes

The kernel saves the old process state in its PCB and then loads the context of the new process scheduled for execution. The workload of context switching is closely related to hardware support. For example, some processors provide multiple register banks, and context switching only needs to change the pointers of register banks. Copy data between memory.

12. Including the initial parent process, how many processes are created by the program shown in the figure?

16 processes

13. Explain under what circumstances the line of code marked printf("line J") in the diagram is reached.

 When the child process is successfully created, call execlp() to load the code and static data of the /bin/ls program. If the call is successful, printf("line J") will never be executed ; if the call fails (if there is no /bin/ Executable programs such as ls ) will execute printf("line J") .

14. Using the program in the figure, determine the pid values ​​of rows A, B, C, and D (assuming the actual pids of the parent process and child process are 2600 and 2603, respectively).

A: pid=0
B: pid1 = 2603
C: pid = 2603
D: pid = 2600

Knowledge points:

1. The goal of multiprogramming: to maximize CPU utilization;

        The purpose of the time-sharing system is to quickly switch the CPU between processes so that the user can interact with the program while it is running;

2. For batch systems:

        Long-term scheduler: processes are selected from the buffer pool and added to memory for execution (controls the degree of multiprogramming).

        Short-Term Scheduler: Selects processes from those ready to execute and allocates CPUs.

        Difference: execution frequency;

For time-sharing systems:

        The core idea of ​​​​the mid-term scheduler: swap (swap): processes can be removed from memory, thereby reducing the degree of multiprogramming. Afterwards, the process can be brought back into memory and continue execution where it left off.

3. Client/Server Communication

        Socket (socket): only allows unstructured byte streams to be transferred between processes

        Remote Procedure Call (RPC): can be used to implement a distributed file system

        Pipe (pipe): Ordinary pipe: communication is one-way, only one-way communication is allowed, there is a parent-child relationship between processes, and it can only be used on the same machine.

                    Named pipes: Communication can be bidirectional, and the parent-child relationship is not necessary. After the communication process is completed, the named pipes still exist.

4. The PCB is created and managed by the OS.

5. When performing context switching: clock interrupt, I/O interrupt, trap, management scheduling


Chap04 thread

1. Provides three programming examples where multithreading provides better performance than a single-threaded solution.

1. A web server needs to accept requests for web pages, images, and sounds, and handle access requests from thousands of users at the same time.
2. A parallel application, such as matrix multiplication, where different parts of the matrix can be processed in parallel.
3. An interactive word processor, one thread for displaying graphics, one thread for responding to user keyboard input, and one thread for spelling and grammar checking in the background.

2. What are the two differences between user threads and kernel threads? In what situations is one better than the other?

1. The user thread is located above the kernel, and its management does not require kernel support, while the kernel thread is directly supported and managed by the operating system.

2. On systems that use a one-to-one model or a many-to-many model, user threads are scheduled by the thread library, and the kernel schedules kernel threads.

Kernel threads do not need to be associated with a process, whereas every user thread belongs to a process. Kernel threads are generally more expensive to maintain than user threads because they must be represented in kernel data structures.

3. Describe the actions the kernel takes when context switching between kernel-level threads.

A context switch between kernel threads usually needs to save the value of the CPU register of the thread being switched out , and restore the CPU register of the new thread being scheduled .

4. What resources are used when creating threads? How are they different from the method used when creating processes?

因为线程比进程小,所以创建线程通常比创建进程使用更少的资源。创建一个进程需要分配一个进程控制块(PCB),这是一个相当大的数据结构。PCB包括内存映射、打开的文件列表和环境变量。分配和管理内存映射通常是最耗时的活动。创建用户或内核线程都需要分配一个小数据结构来保存寄存器集、堆栈和优先级。

5.假设操作系统使用多对多模型将用户级线程映射到内核,并且映射是通过LWP完成的。此外,该系统允许开发人员创建用于实时系统的实时线程。是否需要将实时线程绑定到LWP?解释

是的。定时对于实时应用程序至关重要。如果线程标记为实时,但未绑定到LWP,则该线程可能必须等待连接到LWP后才能运行。考虑实时线程是否正在运行(连接到LWP),然后继续阻塞(即必须执行i/O,已被更高优先级的实时线程抢占,正在等待互斥锁等),而实时线程被阻塞时,它所连接的LWP已分配给另一个线程。

当实时线程计划再次运行时,它必须首先等待连接到LWP。通过将LWP绑定到实时线程,可以确保线程在调度后能够以最小的延迟运行。

6.提供两个编程示例,在这些示例中,多线程并不比单线程解决方案提供更好的性能。

顺序程序不适合多线程编程。例子:
1、一个计算个人纳税申报单的程序。
2、“shell”程序,如C-shell或Korn shell。这样的程序必须密切监视自己的工作空间,如打开的文件、环境变量和当前工作目录。

7.在什么情况下,使用多个内核线程的多线程解决方案比单处理器系统中的单线程解决方案提供更好的性能?

当内核线程发生页面错误时,可以切换到另一个内核线程,以一种有用的方式使用交错时间。另一方面,当发生页面错误时,单线程进程将无法执行有用的工作。因此,在程序可能出现频繁的页面错误或必须等待其他系统事件的情况下,多线程解决方案甚至在单处理器系统上也能执行得更好。

8. In a multithreaded process, which of the following components of program state are shared across threads? a register value b heap memory c global variable d stack memory

The threads of a multithreaded process share heap memory and global variables. Each thread has its own independent set of register values ​​and independent stack.

9. Can a multithreaded solution using multiple user-level threads achieve better performance on a multiprocessor system than on a uniprocessor system?

A multithreaded system consisting of multiple user-level threads cannot use different processors simultaneously in a multiprocessor system. The operating system sees only one process and does not schedule different threads of that process onto different processors. Therefore, there is no performance benefit to executing multiple user-level threads on a multiprocessor system.

11. Is it possible to have concurrency but not parallelism? Explain

possible. Parallelism of a system refers to the execution of multiple tasks at the same time, and concurrency refers to the ability of the system to support multiple tasks, allowing all tasks to make progress . Therefore, there is no parallelism, and concurrency can also be achieved through system scheduling.

15. Consider the following code snippet

 (1) How many unique processes are created? (2) How many unique threads are created?

(1) 6 processes

(2) 8 threads

Knowledge points:

  1. Each thread is a basic unit used by the CPU: it includes thread ID, program counter, register set, and stack. It shares code segments, data segments, and other OS resources with other threads of the same process.
  2. Advantages of multithreaded programming: responsiveness, resource sharing, economy, scalability.
  3. Multicore system programming challenges: identifying tasks, balancing, data partitioning, data dependencies, testing and debugging.
  4. Data parallelism: focus on distributing data on multiple computing cores and performing the same operation on each core;

Task parallelism: involves distributing tasks (threads) rather than data to multiple computing cores. Each thread performs a unique operation.


Chap05 Synchronization

1. In Section 5.4, we mentioned that disabling interrupts frequently may affect the system's clock. Explain why this is happening and how to minimize this effect.

系统时钟在每次时钟中断时更新。如果中断被禁用,特别是长时间禁用,则系统时钟可能很容易丢失正确的时间。系统时钟也用于调度目的。例如,进程的时间量表示为时钟滴答数。在每个时钟中断时,调度器确定当前正在运行的进程的时间量是否已过期。如果时钟中断被禁用,调度程序将无法准确分配时间量。通过仅在很短的时间内禁用时钟中断,可以将这种影响降至最低。

2.解释Windows、Linux和Solaris实现多种锁定机制的原因。描述他们使用自旋锁、互斥锁、信号量、自适应互斥锁和条件变量的情况。在每种情况下,解释为什么需要该机制。

这些操作系统根据应用程序开发人员的需要提供不同的锁定机制。自旋锁对于多处理器系统非常有用,因为在多处理器系统中,线程可以在繁忙的循环中运行(在短时间内),而不会产生放入睡眠队列的开销。互斥锁对于锁定资源很有用。Solaris 2使用自适应互斥锁,这意味着互斥锁在多处理器机器上通过自旋锁实现。信号量和条件变量是同步的更合适的工具,因为旋转在很长的时间内效率很低,所以当资源必须保持很长一段时间。

3.忙等待这个词是什么意思?操作系统中还有哪些其他类型的等待?可以完全避免忙碌的等待吗?解释你的答案。

忙等待是指进程在不放弃处理器的情况下,在循环中等待条件得到满足。或者,进程可以通过放弃处理器来等待,并阻塞某个条件,等待在将来的某个适当时间被唤醒。可以避免繁忙的等待,但会产生与将进程置于睡眠状态以及在达到适当的程序状态时必须将其唤醒相关的开销。

4.解释为什么自旋锁不适用于单处理器系统,但通常用于多处理器系统。

自旋锁不适用于单处理器系统,因为只有通过执行不同的进程才能获得将进程从自旋锁中断的条件。如果进程没有放弃处理器,其他进程就没有机会设置第一个进程取得进展所需的程序条件。在多处理器系统中,其他进程在其他处理器上执行,从而修改程序状态,以便从自旋锁释放第一个进程。

5.说明如果wait()和signal()信号量操作没有原子化执行,那么可能会违反互斥。

The wait operation atomically decrements the value associated with the semaphore. If two wait operations are performed on a semaphore while its value is 1, both operations may proceed to decrement the semaphore value, thus violating the mutual exclusion, if the two operations are not performed atomically.

6. Explain how to use binary semaphores to realize mutual exclusion between n processes.

n processes share a semaphore mutex, which is initialized to 1. Each process Pi is organized as follows:

do {

        wait(mutex);

        /* critical section */

        signal(mutex);

        /* remainder section */

} while (true);

10. Please explain: why the method of implementing synchronization primitives by disabling interrupts on a uniprocessor system is not suitable for user-level programs.

If the user-level program has the ability to disable interrupts, it can disable timer interrupts and prevent context switching from occurring, thereby preventing other processes from executing and monopolizing the processor.

11. Please explain why disabling interrupts is not suitable for implementing synchronization primitives in multiprocessor systems.

If multiple processes are running on different CPUs , and each process tries to enter a critical section, even if interrupts are disabled, other processes can still enter the critical section on other processors.

13. Please describe two kernel data structures that may have a race condition. Be sure to have a description of how the race condition might occur.

  1. A resource that two data structures/processes are waiting for to be freed and both processes try to access it;
  2. Handles when corresponding IDs must be created for two concurrently created processes.

23. Show how to use the test_and_set() instruction to implement wait() and signal() semaphore operations in a multiprocessor environment. The scheme should exhibit minimal busy waiting.

25. Please explain: Monitors and semaphores are equivalent because they can be used to implement solutions to the same type of synchronization problems.

A semaphore can be implemented using the following monitor code:

 Monitors can be implemented using semaphores in the following ways. Each condition variable is represented by a queue of threads waiting on the condition. Each thread has a semaphore associated with its queue entry. When a thread performs a wait operation, it creates a new semaphore (initialized to 0), adds the semaphore to the queue associated with the condition variable, and performs a blocking semaphore decrement operation on the newly created semaphore. When a thread performs a signal on a condition variable, the first process in the queue will wake up by incrementing the corresponding semaphore.

32. A file is shared between different processes, and each process has a unique number. This file can be accessed simultaneously by a plurality of processes, but following constraint is arranged: the sum of all unique numbers associated with all processes currently accessing this file must be less than n. Access to the file is coordinated by the write monitor.

 Knowledge points:

  1. Monitor (monitor): belongs to the abstract data type (ADT),
  2. Semaphore (Semaphore), spin lock (spinlock);
  3. Race condition: Multiple processes access and operate the same data concurrently and the execution results are related to a specific access sequence.

Chap06 CPU Scheduling

1. The CPU scheduling algorithm determines the execution order of its scheduling processes. If n processes are scheduled on one processor, how many different schedules are possible? Give a formula for n.

n!

2. Explain the difference between preemptive and non-preemptive scheduling.

Preemptive scheduling allows a process to be interrupted during execution, taking the CPU away and assigning it to another process.

Non-preemptive scheduling ensures that a process relinquishes control of the CPU only when it is done with the current CPU event.

3. Assume that the following processes arrive at the specified time for execution. Each process will run for the time listed. When answering the questions, use a non-obligatory plan and base all decisions on the information you have at the time you make them.

a. Using the FCFS scheduling algorithm, what is the average turnaround time for these processes?

b. Using the SJF scheduling algorithm, what is the average turnaround time for these processes?

c. The SJF algorithm should improve performance, but note that we choose to run process P1 at time 0 because we don't know that two shorter processes are coming soon. If the CPU is idle in the first cell, then use SJF scheduling to calculate the average turnaround time. Remember that processes P1 and P2 are waiting during this idle time, so their waiting time may increase. This algorithm can be called future knowledge scheduling.

a.10.53

b.9.53

c.6.86

Remember that turnaround time is make minus arrival time, so you must subtract arrival time to calculate turnaround time. If you forget to subtract the arrival time, FCFS is 11.

4. What are the advantages of having different timeslice sizes at different levels of a multi-level queue?

Processes that need to be serviced more frequently ( for example, interactive processes such as editors ) can be in a queue with a smaller amount of time. Processes that do not need to be serviced frequently can be in a queue with a larger time slice, requiring fewer context switches to complete processing, thus utilizing the computer more efficiently.

5. Many CPU scheduling algorithms are parameterized. For example, the RR algorithm requires a parameter to indicate the time slice. Multi-level feedback queues require parameters to define the number of queues, the scheduling algorithm for each queue, the criteria used to move processes between queues, etc.

Therefore, these algorithms are actually a set of algorithms (eg, the set of RR algorithms for all time slices, etc.). One set of algorithms may include another set of algorithms (for example, the FCFS algorithm is the RR algorithm with an infinite amount of time). What relationship (if any) exists between the following pairs of algorithm sets

a. Priority and SJF

b. Multi-level feedback queue and FCFS

c. Priority and FCFS

d. RR and SJF

a. The shortest job has the highest priority.

b. The lowest level of MLFQ is FCFS.

c. FCFS gives the highest priority to the job with the longest existence time.

d. no

6.假设一个调度算法(在短期CPU调度级别上)支持最近使用最少处理器时间的进程。为什么这个算法会支持I/O密集型的程序,而不会永久性地饥饿CPU密集型的程序?

它将有利于I/O密集型的程序,因为它们的CPU突发请求相对较短;然而,CPU密集型的程序不会饿死,因为I/O密集型的程序会相对频繁地放弃CPU来执行其I/O

7.区分PCS和SCS调度。

PCS调度在进程本地完成。这就是线程库如何将线程调度到可用的LWP上。SCS调度是操作系统调度内核线程的情况。在使用多对一或多对多的系统上,这两种调度模型有着根本的不同。在使用一对一的系统上,PCS和SCS是相同的。

8.假设操作系统使用多对多模型将用户级线程映射到内核,并且映射是通过使用LWP完成的。此外,该系统允许程序开发人员创建实时线程。是否需要将实时线程绑定到LWP?

是的,否则用户线程可能必须在实际调度之前竞争可用的LWP。通过将用户线程绑定到LWP,在等待可用LWP时没有延迟;可以立即调度实时用户线程。

9.传统的UNIX调度程序强制执行优先级数字和优先级之间的反向关系:数字越高,优先级越低。调度器使用以下功能每秒重新计算一次进程优先级:

优先级=(最近的CPU使用率/2)+基数,

其中基数=60,最近的CPU使用率指的是一个值,该值指示自上次重新计算优先级以来,进程使用CPU的频率。

假设进程P1的最近CPU使用率为40,进程P2为18,进程P3为10。重新计算优先级时,这三个流程的新优先级是什么?基于此信息,传统的UNIX调度程序是否会提高或降低CPU受限进程的相对优先级。

分配给流程的优先级分别为80、69和65。

调度器降低了CPU绑定进程的相对优先级。

10.为什么区分CPU密集型程序和I/O密集型程序对调用程序很重要?

I/O -bound programs have the property of performing only a small amount of computation before performing IO . Such programs usually do not use their full CPU capacity. On the other hand, CPU- intensive programs use their entire CPU without performing any IO- blocking operations. Thus, by giving higher priority to I/O -intensive programs and allowing them to execute before CPU- intensive programs, computer resources are better utilized.

11. Discuss how the following pairs of scheduling criteria can conflict in certain situations.

a. CPU utilization and response time
b. Average turnaround time and minimum wait time
c. I/O device utilization and CPU utilization

a. CPU Utilization and Response Time: If you minimize the overhead associated with context switching, CPU utilization increases. By performing context switches infrequently, the overhead of context switching can be reduced. However, this may increase the response time of the process.

b. Average turnaround time and minimum wait time: Minimize the average turnaround time by executing the shortest tasks first. However, such a scheduling strategy may starve long-running tasks, increasing their waiting time.

c. I/O device utilization and CPU utilization: Running long CPU-intensive tasks without context switching maximizes CPU utilization. Scheduling I/O-intensive programs as soon as they are ready to run maximizes I/O device utilization at the cost of context switching.

14. Assume that the exponential average formula is used to predict the length of the next CPU execution. When the following parameter values ​​are used, the meaning of the algorithm is:

If α. is 0 , the latest information has no effect on the prediction, and the formula always predicts 100ms .

If b.α is 0.99 , the most recent information is given a great weight, and the past history is hardly considered, and only the execution length of the previous CPU is used to simply predict the next CPU execution.

15. A variant of the round robin scheduler is the regression round robin scheduler. This scheduler assigns a time slice and priority to each process. The initial value of the time slice is 50ms. However, every time a process gets the CPU and uses up its entire timeslice (without blocking for I/O), its timeslice is increased by 10ms and its priority is increased. (The time slice of a process can be increased up to 100ms) When a process blocks before using up its entire time slice, its time slice is reduced by 5ms, while its priority remains the same. Which type of process (cpu-intensive or I/O-intensive) does the regression round robin scheduler prefer? Explain.

Prefer I/O -intensive programs, because it can always block I/O before the end of the time slice , and the priority remains unchanged, so it can be in the high-priority queue of the CPU for a long time and occupy the CPU for a long time.

16. Assume that there is a group of processes as follows, whose CPU execution time is in milliseconds:

Assume that processes arrive in the order of P1, P2, P3, P4, and P5, all arriving at time 0.

a . Draw 4 Gantt diagrams to demonstrate the process execution using each scheduling algorithm (FCFS, SJF, non-preemptive priority (a larger priority means higher priority) and RR (time slice = 2)) .

b . What is the turnaround time of each process under each scheduling algorithm in a?

c . What is the waiting time of each process under each scheduling algorithm in a?

d . Which scheduling algorithm has the smallest average waiting time (for all processes)?

a.

 b.

c.

d. The average waiting time of SJF is the smallest

17. The following processes are being scheduled using a preemptive round-robin scheduling algorithm. Each process is assigned a priority number, with higher numbers indicating higher relative priority. In addition to the processes listed below, the system also has an idle task (which consumes no CPU resources and is identified as Pidle). This task has a priority of 0 and is scheduled when the system has no other processes available to run. The length of the time slice is 10 units. If a process is preempted by a higher priority process, the preempted process is placed at the end of the queue.

a . Use the Gantt diagram to demonstrate the scheduling order of the processes
b . What is the turnaround time of each process?
c . What is the waiting time of each process?
d . What is the CPU usage ?

b. 

 c.

d.105/120 = 87.5%

19. Which of the following scheduling algorithms will cause starvation?

bSJF dpriority

24. Explain the difference between the following scheduling algorithms in favoring short processes:

a , FCFS does not favor short processes , short processes behind long processes will wait for a long time
b , RR treats both long and short processes equally and executes the same time slice , and the short cycle can complete execution at the earliest
c , multi-level feedback queue is similar to RR , give short processes a higher priority, while the priority of long processes will gradually decrease, and the short process will be completed first

Knowledge points:

Turnaround time (turnaround time): the time from process submission to completion;

Waiting time: the sum of the time spent waiting in the ready queue;

Response time: time from submission to first response;

FCFS: the average waiting time is very long, non-preemptive;

Shortest Job First Scheduling (SJF): Hungry

Exponential average: Let tn be the length of the nth CPU burst, and τn +1 be the predicted value of the next CPU burst. Then, for a, 0≤a≤1, define

 

tn contains recent information, τn stores past history

Shortest Remaining Time Scheduling (SRTF)

Priority scheduling (priority): generally low numbers represent high priority and will be hungry;

Round Robin Scheduling (RR):

time quantum or time slice;

multi-level queue scheduling

Multi-Level Feedback Queue Scheduling

Lottery scheduling is an adaptive scheduling method to solve the fairness problem

        ❑ Each process has some tickets

        ❑On each time slice, randomly select a ticket

        ❑ On average, the allocated CPU time is proportional to the number of tickets allocated to each job

Thread scheduling:

Many-to-many, many-to-one model, the thread library schedules user-level threads to run on the LWP, this scheme is called process contention range (PCS) , because the competing CPU is between different threads of the same process;

In order to determine which kernel-level thread is scheduled to the available CPU, the kernel uses the system contention scope (SCS) - the competition between all threads in the system, and the system using a one-to-one model only uses SCS;


Chap07 deadlock

1. List three examples of deadlocks that have nothing to do with the computer system environment.

Two cars cross a one-way bridge from opposite directions.

One person descends a ladder while the other climbs it.

Two trains approach each other on the same track.

2. Assume the system is in an unsafe state. Indicates that a process can complete its execution without entering a deadlock state.

An unsafe state doesn't necessarily cause a deadlock, it just means that we can't guarantee that a deadlock won't happen. Therefore, a system in an unsafe state may still allow all processes to complete without deadlocking. Consider a situation where the system allocates 12 resources among processes P0, P1, and P2. Resources are allocated according to the following policies:

There are currently two resources available. Since process P1 may complete, the system is in an unsafe state, so a total of four resources are freed. But we cannot guarantee that the P0 and P2 processes will be completed. However, the process may release resources before requesting any further resources. For example, process P2 may release one resource, thereby increasing the total number of resources to five. This allows process P0 to complete, which frees a total of nine resources, allowing process P2 to also complete.

3. Consider the following system:

 Use the banker's algorithm to answer the following questions:

a . Matrix Need content?

b . Is the system in a safe state?

c . If a request from process P1 arrives at (0,4,2,0), can the request be approved immediately.

a. The demand values ​​of processes P0 to P4 are (0, 0, 0, 0), (0, 7, 5, 0), (1, 0, 0, 2), (0, 0, 2, 0) respectively and (0, 6, 4, 2).

b. When the available value is equal to (1, 5, 2, 0), the process P0 or P3 can be run. Once process P3 runs, it releases its resources, allowing all other existing processes to run.

c. This will result in available values ​​of (1, 1, 0, 0). One sequence of processes that can be completed is P0, P2, P3, P1, and P4.

4. One possible way to prevent deadlock is to require a single higher-order resource to be requested before any other resource. For example, if multiple threads try to access synchronization objects A...E, a deadlock may occur. (Such synchronization objects can include mutexes, semaphores, condition variables, etc.) We can prevent deadlock by adding a sixth object F. Whenever a thread wants to acquire a synchronization lock on any object A··E, it must first acquire a lock on object F. This solution is called containment: the lock of objects A ... E is contained in the lock of object F. Compare this scheme with the circular wait scheme of Section 7.4.4.

This is probably not a good solution because the resulting range is too large. It is better to define a locking strategy with as narrow a scope as possible

5. Prove that the secure algorithm proposed in Section 7.5.3 requires an m × n2 order of operations.

Figure 7.1 provides the Java code that implements the banker's algorithm security algorithm (the complete implementation of the banker's algorithm is available as a source code download).

 It can be seen that the nested outer loops all provide n2 performance through n loops. Within these outer loops are two consecutive inner loops that loop m times. Therefore, the algorithm is O(m×n2).

6. Consider a computer system that runs 5000 jobs per month and has no deadlock prevention or deadlock avoidance scheme. Deadlocks occur about twice a month, and each deadlock operator has to kill and rerun about 10 jobs. Each job is worth about $2 (in CPU time), and the terminated jobs tend to be only about half done when they abort.

One system programmer estimated that installing a deadlock avoidance algorithm (such as the banker's algorithm) in the system would increase the average execution time of each job by about 10%.

With the machines currently 30% idle, 5,000 jobs per month can still run, although turnaround times will increase by around 20% on average.

a . What is the reason for installing the deadlock avoidance algorithm?

b . What are the arguments against installing deadlock avoidance algorithms?

One reason for installing deadlock avoidance in the system is that we can be sure that deadlock will never occur. Additionally, all 5,000 jobs are still operational despite the increased turnaround time.

One argument against installing deadlock avoidance software is that deadlocks are rare and inexpensive when they do occur.

7.系统是否可以检测到其某些进程处于饥饿状态?如果你回答“是的,”解释它是如何做到的。如果您回答“否”,请解释系统如何处理饥饿问题.

饥饿是一个很难定义的话题,因为它对于不同的系统可能意味着不同的事情。为了这个问题的目的,我们将饥饿定义为一种情况,即一个进程在收到请求的资源之前必须等待一段合理的时间,可能是无限期的。检测饥饿的一种方法是首先确定一段时间T,这被认为是不合理的。当进程请求资源时,计时器启动。如果经过的时间超过T,则认为该进程已饥饿。

应对饥饿的一个战略是采取一项政策,只将资源分配给等待时间最长的进程。例如,如果进程Pa等待资源X的时间比进程Pb长,那么来自进程Pb的请求将被延迟,直到进程Pa的请求得到满足。

另一种策略将没有刚才提到的那么严格。在这种情况下,可以将资源授予等待时间少于另一个进程的进程,前提是另一个进程没有饥饿。

然而,如果另一个进程被认为是饥饿的,那么它的请求将首先得到满足。

8.考虑以下资源分配策略。允许随时请求和释放资源。如果由于资源不可用而无法满足对资源的请求,那么我们将检查所有被阻止等待资源的进程。如果一个被阻止的进程具有所需的资源,那么这些资源将从该进程中移除并提供给请求进程。阻塞进程正在等待的资源向量将增加,以包括被带走的资源。

例如,考虑一个具有三种资源类型的系统,可用向量初始化为(4,2,2)。如果进程P0要求(2,2,1),它就会得到它们。如果P1请求(1,0,1),它将得到它们。然后,如果P0请求(0,0,1),它将被阻止(资源不可用)。如果P2现在请求(2,0,0),它将获得可用的一个(1,0,0)和分配给P0的一个(因为P0被阻止)。P0的分配向量下降到(1,2,1),其需求向量上升到(1,0,1)。

a、 是否会发生死锁?如果你回答“是”,请举例说明。如果回答“否”,请指定无法发生的必要条件。

b、 是否会发生无限阻塞?解释你的答案

a、 无法发生死锁,因为存在抢占。

b. Yes. If a series of requests (such as those of process C) keep grabbing all the resources the process needs, the process may never get all the resources it needs.

9. Suppose you have written a deadlock avoidance security algorithm and are now asked to implement a deadlock detection algorithm. Can you simply use the safe algorithm code and redefine Max[i] = Waiting[i] + Allocation[i], where waiting[i] is a vector specifying the resource that process i is waiting for, allocation[i] as in defined in Section 7.5? Explain your answer.

The Max vector represents the maximum request that a process may issue. When computing the security algorithm, we use a demand matrix representing the maximum allocation. Another thought is Max=Need+Allocation. According to this question, the waiting matrix acts like a demand matrix, so Max=Waiting+Allocation.

10. Is it possible to have a deadlock involving only one single-threaded process? explain your answer

no. Hold and wait conditions are not met

17. Consider a system consisting of four resources of the same type shared by three processes, each requiring at most two resources. Shows that the system is deadlock-free.

If the system wants to become a deadlock, each process must occupy and request a resource. Assume that all three processes occupy a resource, and each process requests exactly one resource, and the system can just provide one resource for one of the processes. When the process Release all resources after completion, and will not cause deadlock.

19. Consider the problem of a philosopher dining, put the chopsticks in the center of the table, and the philosopher can use any two chopsticks. Suppose a request for chopsticks can only take one chopstick. Please describe a simple rule for judging whether a request can be satisfied without causing a deadlock.

Only when all philosophers have no two chopsticks and only one chopstick is left, if the philosopher requests his first chopstick, the request will be rejected.

23.

 Question: a. Demonstrate that the system is in a safe state by demonstrating possible safe sequences.

b. If a request from process P1 arrives at (1,1,0,0), can the request be granted immediately?

c. If a request from process P4 arrives at (0,0,2,0), can the request be granted immediately?

a. The safe sequence can be: p0, p3, p1, p2, p4 are in the safe state

b. It can be approved immediately. After p1’s request is approved, there are still security sequences p0, p3, p1, p2, and p4 in a secure state

c. No, if the request of p4 (0, 0, 2, 0) is approved, Available becomes (3, 3, 0, 1) where c resource does not meet the demand of any process, and the system is not safe

25. A one-lane bridge connects the two Vermont villages of North Tunbridge and South Tunbridge. Farmers from these two villages use the bridge to transport their produce to neighboring towns. If a northbound farmer and a southbound peasant were on the bridge at the same time, the bridge would stall. (Farmers in Vermont are stubborn and won't give up crossing the bridge), please design an algorithm in pseudocode that prevents deadlocks, using semaphores and/or mutexes. Don't have to worry about starvation (a situation where northbound farmers prevent southbound farmers from using bridges and vice versa).

semaphore bridge = 1;

void cross()

{

      while(true)

{

            wait(bridge);

            // After crossing the bridge and leaving

            signal(bridge);

      }

}

Knowledge points:

Necessary conditions for deadlock:

mutual exclusion (mutual exclusion);

hold and wait;

non-preemption (no preemption);

Circular wait.

Deadlock prevention: make at least one of the above conditions not true;

Deadlock avoidance (deadlock avoidance): By analyzing the maximum number of resources required by the process and the number of resources owned by the system to determine whether the system is safe.


Chap08 memory management strategy

1. Name two differences between logical address and physical address.

A logical address does not refer to an actual existing address; rather, it refers to an abstract address in an abstract address space. Contrast that with a physical address that refers to an actual physical address in memory. Logical addresses are generated by the CPU and translated into physical addresses by the memory management unit (MMU). Therefore, the MMU generates physical addresses.

2. Consider a system where a program can be divided into two parts: code and data. The CPU knows whether it wants instructions (instruction fetch) or data (data fetch or store). Therefore, two base address-bound registers are provided: one for instructions and one for data. The base-limit register pair is automatically read-only so that programs can be shared among different users. Discuss the pros and cons of this option.

The main advantage of this scheme is that it is an efficient code and data sharing mechanism. For example, only one copy of an editor or compiler needs to be kept in memory, and all processes that need to access the editor or compiler code can share this code.

Another advantage is to protect the code from erroneous modification.

The only downside is that code and data must be separated, which is usually observed in the code generated by the compiler.

3. Why is the page size always a power of 2?

Paging is implemented by splitting addresses into pages and offsets. The most efficient way is to decompose the address into X page bits and Y offset bits, rather than performing arithmetic on the address to calculate the page number and offset. Because each bit position represents a power of 2, splitting the address between bits results in a page size that is a power of 2

4. Consider a logical address space of 64 pages, 1024 words per page, mapped to 32 frames of physical memory.

a . How many bits are there in the logical address?

b . How many bits are there in the physical address?

a. 16

b. 15

5. What is the effect of allowing two entries in a page table to point to the same page frame in memory? Explains how this effect can be used to reduce the time it takes to copy large amounts of memory from one location to another. What effect does updating some bytes on one page have on another page?

By allowing two entries in the page table to point to the same page frame in memory, users can share code and data. Large programs such as text editors, compilers, and database systems can save a lot of memory space if the code is reentrant. Large amounts of memory can be "duplicated" by having different page tables point to the same memory location.

However, sharing non-entry code or data means that any user with access to the code can modify it, and those modifications will be reflected in other users' "copies".

6. Describe a mechanism by which a segment can belong to the address spaces of two different processes.

由于段表是基地址-界限寄存器的集合,当两个不同作业的段表中的条目指向相同的物理位置时,可以共享段。两个段表必须具有相同的基指针,并且两个进程中的共享段号必须相同

7.在动态链接的分段系统中,可以在进程之间共享分段,而无需它们具有相同的分段编号。

a、 定义一个允许静态链接和共享段的系统,而不要求段编号相同。

b、 描述一种分页方案,该方案允许在不要求页码相同的情况下共享页面。

这两个问题都导致程序能够引用自己的代码和数据,而不知道与地址相关的段或页码。MULTICS通过将四个寄存器与每个进程关联来解决此问题。一个寄存器有当前程序段的地址,另一个寄存器有堆栈的基址,另一个寄存器有全局数据的基址,依此类推。

所有引用都必须通过映射到当前段或页码的寄存器进行间接引用。通过更改这些寄存器,相同的代码可以在没有相同页码或段号的情况下为不同的进程执行。

8.在IBM/370中,通过使用密钥提供内存保护。

键是一个4位的量。每个2K内存块都有一个与其关联的密钥(存储密钥)。CPU还有一个与之关联的密钥(保护密钥)。仅当两个键相等或其中一个键为零时,才允许进行存储操作。以下哪种内存管理方案可以成功用于此硬件。

a.裸机

b.单用户系统

c.具有固定进程数的多道程序设计

d.具有可变进程数的多道程序设计

e.分页

f.分段

a、 无需保护,将系统密钥设置为0。

b、 在管理员模式下,将系统键设置为0。

c、 区域大小必须以2k字节的增量固定,并使用内存块分配密钥。

d、 同上。

e、 帧大小必须以2k字节为增量,为页分配键。

f、 段大小必须以2k字节为增量,为键分配段

12.大多数系统允许程序在执行期间为其地址空间分配更多的内存。在程序的堆段中分配的数据就是这种分配内存的一个例子。在以下方案中,支持动态内存分配需要什么:a.连续内存分配b.纯分段c.纯分页

连续内存分配:可能需要重新定位整个程序,因为没有足够的空间让程序增长其分配的内存空间。
纯分段:也可能需要重新定位需要扩展的段,因为没有足够的空间让段增长其分配的内存空间。
纯分页:在这种方案中,新页面的增量分配是可能的,而不需要重新定位程序的地址空间。

13.比较连续内存分配、纯分段和纯分页的主要内存组织方案,可以考虑以下问题:a.外部碎片b.内部碎片c.跨进程共享代码的能力

由于地址空间是连续分配的,并且随着旧进程的死亡和新进程的启动,孔就会出现,因此相邻的内存分配方案存在外部碎片问题。它也不允许进程共享代码,因为进程的虚拟内存段没有分解成非连续的细粒度段。

纯分段会受到外部碎片的影响,因为进程的一个段是连续地放置在物理内存中,当死进程的段被新进程的段取代时,就会出现碎片。然而,分段使进程能够共享代码;例如,两个不同的进程可以共享一个代码段,但有不同的数据段。

纯分页不会受到外部碎片的影响,而是会受到内部碎片的影响。进程是按页粒度分配的,如果没有完全利用页,就会导致内部碎片化和相应的空间浪费。分页还允许进程以页面的粒度共享代码。

14.在有分页功能的系统上,进程不能访问不属于它的内存;为什么?操作系统如何允许访问其他内存?为什么它应该或不应该

An address in a paging system is a logical page number and an offset. The physical page is found by searching the table against the logical page number to generate the physical page number. Because the operating system controls the contents of this table, it can restrict a process's access to only those physical pages allocated to that process. A process cannot reference a page it does not own because the page is not in the page table. To allow such access, the operating system need only allow entries for non-process memory to be added to the process's page tables. This is useful when two or more processes need to exchange data they just read and wrote to the same physical address (possibly at different logical addresses). This makes inter-process communication very efficient.

17. Compare paging and segmentation in terms of the amount of memory required by the address translation structures that translate virtual addresses into physical addresses

Paging requires more memory overhead to maintain translation structures.

Each segment requires only two registers: one to maintain the base address of the segment, and the other to maintain the range of the segment.

Paging, on the other hand, requires an entry per page, which provides the physical address where the page is located.

19. On many systems, the structure of a program binary is usually as follows. Code is stored starting at a small fixed virtual address such as 0. Following the code segment is the data segment for storing program variables. When the program starts executing, the stack is allocated at the other end of the virtual address space and allowed to grow towards lower virtual addresses. What is the significance of the above structure in the following scenarios: a. contiguous memory allocation b. pure segmentation c. pure paging

1) Contiguous memory allocation requires the operating system to allocate the entire virtual address space to the program when the program starts executing. This can be much higher than the actual memory requirements of the process.

2) Pure segmentation gives the operating system the flexibility to allocate a small range of segments at each program startup, and extend the segments if needed.

3) Pure paging does not require the operating system to allocate the largest range of virtual address space for the process at startup, but it still requires the operating system to allocate a large page table that spans all the virtual address space of the program. When a program needs to extend the stack or heap, it needs to allocate a new page, but the corresponding page table entries are pre-allocated.

20. Assuming a page size of 1 kb, what are the page numbers and offsets referenced by the following addresses (provided in decimal): a. 3085 b. 42095 c. 215201 d. 650000 e. 2000001

22.  What is the maximum capacity of physical memory?

If the address space is x bits, the maximum capacity of physical memory is 2^x byte

24. Consider a computer system with 32-bit logical addresses and a 4 kb page size. The system supports a maximum physical memory of 512mb. Then how many entries are there in the page table

2^20

25. Consider a paging system in which the page tables are stored in memory. a. If a memory reference takes 50 nanoseconds, how long does a paged memory reference take? b. If we add the tlb, and 75% of the page table references are in the tlb, what is the effective memory reference time? (Assume it takes 2 nanoseconds to look up a page table entry in the tlb, if one exists.)

a, 100ns, of which 50ns is used to refer to the page table, and 50ns is used to refer to the physical memory

b、0.75*(50ns + 2ns) + 0.25*100ns = 64ns

27. Explain why it is easier to share reentrant modules using segmentation than pure paging

Since segments are based on logical rather than physical divisions of memory, there can be only one entry in each user's segment table sharing a segment of any size. For paging, there must be a common entry in the page table for each shared page.

28. Consider the following segment table:

 What is the physical address of the following logical address

a. 0,430
b. 1,10
c. 2,500
d. 3,400
e. 4,112

a. 219 + 430 = 649

b. 2300 + 10 = 2310

c. illegal reference, trap to operating system

d. 1327 + 400 = 1727

e. illegal reference, trap to operating system

29. What is the purpose of page table paging?

In some cases paged page tables can become large enough that memory allocation problems can be simplified (by ensuring that all allocations are fixed-size pages rather than variable-size blocks), and it is also possible to swap page tables that are not currently in use part.

31. Compare the segmented paging scheme with the hashed page table scheme for handling large address spaces. Under what circumstances is one option preferred over the other

When a program only occupies a small portion of its large virtual address space, hashed page tables may be preferred because of its smaller size. However, a disadvantage of hashed page tables is that there are collisions when multiple pages are mapped to the same hashed page table entry. If many pages map to the same table entry, traversing the list corresponding to that hash table entry can incur significant overhead; in a segmented paging scheme, this overhead is minimal because each page table entry only Maintains information about a page.

Knowledge points:

  1. memory allocation:
    1. Multiple-partition method: When a partition is free, a process can be selected from the input queue to be transferred into the free partition.
    2. Variable partition scheme (variable-partition): The OS has a table to record which memory is available and which memory is used. Initially, all memory is available to user processes and thus can be used as a large block of available memory, called a hole .
  2. Dynamic storage-allocation problem (dynamic storage-allocation problem):
    1. first-fit: allocate the first hole that is large enough;
    2. Best-fit: allocate the smallest hole large enough;
    3. Worst-fit: assign the largest hole;
  3. Fragmentation:
    1. Both first-fit and best-fit have external fragmentation: storage is divided into a large number of small holes
    2. 50% rule: N allocatable blocks, there may be 0.5 external fragmented blocks, 1/3 of the memory is not available
    3. Internal fragmentation (internal fragmentation): the remaining space generated by allocating fixed-size blocks to processes;
    4. A solution to external fragmentation:
      1. Compaction: Move memory content and merge all free space. Only when relocation is dynamic and performed at runtime, compaction can be used;
      2. The logical address space of a process is allowed to be non-contiguous.
  4. Segmentation:

        Operation of logical address space, segment base address + segment boundary;

     5. Paging:

            Page: Divide logical memory into blocks of the same size;

            Frame: Divide physical memory into blocks of fixed size;

            Page number (p): index of page table, page offset (page offset, d);

                Pagination increases the time of context switching;

            TLB (translation buffer table): similar to cash;


Chap09 Virtual Memory Management

1. Under what circumstances does a page fault occur? Describes the action taken by the operating system when a page fault occurs.

A page fault occurs when a process tries to access a page that has not yet been brought into main memory. At this time, the process will be interrupted by the trap. The operating system checks the internal table of the process to confirm whether the reference is a valid reference. If it is an invalid reference, the process is terminated. If it is a valid reference, the page is read from the disk to the main memory. middle.

2. Suppose you have a page reference string for a process with m frames (all initially empty). The page reference string is of length p; there are n distinct page numbers in it. For any page replacement algorithm, answer the following questions:

a . What is the lower bound on the number of page faults?

b . What is the upper limit of the number of page faults?

      a. Because each page number must be read into memory once, there are at least n page faults;

b. When the page to be referenced is not in the memory each time, the maximum number of page faults is p.

3. For a system with 12-bit virtual and physical addresses and 256-byte pages, consider the page table shown in the diagram. The list of free page frames is D, E, F (that is, D is first in the list, E is second, and F is last).

 Convert the following virtual addresses to the equivalent physical addresses in hexadecimal. All numbers are in hexadecimal. (A dash in a page box indicates that the page is not in memory.)

  • 9EF
  • 111
  • 700
  • 0FF

• 9E F - 0E F

• 111 - 211

• 700 - D00

• 0F F - EFF

4. Consider the following page replacement algorithm. Rank the algorithms on a five-point scale from "terrible" to "perfect" based on page error rates. Separate those algorithms affected by Belady's anomaly from those not affected by Belady's anomaly.

a. LRU b. FIFO c. Best replacement d. Second chance replacement

 5. Discuss the hardware support required to support request paging.

For each memory access operation, the page table needs to be consulted to check whether the corresponding page is resident and whether the program has read and write permissions to access the page. These checks must be performed in hardware. The TLB can be used as a cache and improve the performance of lookup operations

6. Consider a two-dimensional array A:

int A[][] = new int[100][100];

Among them, A[0][0] is located at position 200 in the paging memory system with page size 200. The process that handles the matrix is ​​on page 0 (positions 0 to 199). So every instruction fetch will be from page 0.

For three page frames, using LRU replacement and assuming that page frame 1 contains the process and the other two are initially empty, how many page faults will the following array initialization loop generate?

 a.5000

b.50

7. Consider the following page citation string:

1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6.

Given one, two, three, four, five, six, or seven frames, how many page faults will the following replacement algorithm generate? Remember that all frames are initially empty, so your first unique page will cost an error.

• LRU replacement

• FIFO replacement

• Best Replacement

 8.假设您想要使用需要参考位的分页算法(例如二次机会替换或工作集模型),但硬件不提供参考位。简述如何在硬件未提供参考位的情况下模拟参考位,或者解释为什么不可能这样做。如果可能,请计算成本

可以使用硬件中支持的有效/无效位来模拟参考位。最初将位设置为无效。在第一次引用时,将生成操作系统的陷阱。操作系统将软件位设置为1,并将有效/无效位重置为有效

9.您已经设计了一种新的页面替换算法,您认为该算法可能是最佳的。在一些测试用例中,Belady的异常会发生。新算法是最优的吗?解释你的答案。

不。优化算法不会受到Belady异常的影响,因为根据定义,一个最佳算法将替换在最长时间内不会使用的页面。Belady的异常现象发生在页面替换算法逐出近期需要的页面时。最佳算法不会选择这样的页面。

10.分段与分页类似,但使用大小可变的“页面”定义两种基于FIFO和LRU页面替换方案的段替换算法。请记住,由于段的大小不同,因此选择要替换的段可能不够大,无法为所需的段保留足够的连续位置。考虑无法重新定位段的系统的策略,以及可以重新定位段的系统的策略.

a.先进先出。找到第一个足够大的段以容纳传入段。如果无法重新定位,并且没有一个段足够大,请选择内存连续的段组合,这些段“最接近列表中的第一个”,并且可以容纳新段。

如果可以重新定位,重新排列内存,使足够大的前N个段在内存中连续,以供传入段使用。在这两种情况下,将剩余空间添加到可用空间列表中。

b.LRU。选择时间最长且足够大的段,将剩余空间添加到可用空间列表中。如果没有一个段足够大,请选择在内存中连续(如果无法重新定位)且足够大的“最旧”段的组合。

如果可以重新定位,请将最旧的N段重新排列为在内存中连续,并用新段替换这些段。

11.考虑一个按需分页的计算机系统,其中multi programming的程度目前固定为4。最近对系统进行了测量,以确定CPU和分页磁盘的利用率。结果是以下备选方案之一。对于每种情况,发生了什么?多道程序设计的程度是否可以提高CPU利用率?请求分页有帮助吗?

a. CPU utilization is 13%; disk utilization is 97%

b. The CPU utilization rate is 87%; the disk utilization rate is 3%,

c. CPU utilization is 13%; disk utilization is 3%.

a. Jitter is occurring.

b. CPU utilization is high enough to keep things out of the way and increase the degree of multiprogramming.

c. Improve the degree of multiprogramming

12. We have a machine operating system that uses base and limit registers, but we modify the machine to provide page tables. Can page tables be set up to emulate base and limit registers? How could they, or why couldn't they?

If memory is allocated in fixed-size segments, page tables can be set up to emulate base and limit registers. This way, the base of the segment can be entered into the page table, and the valid/invalid bit is used to indicate that that part of the segment resides in memory. There will be some internal fragmentation issues.

15. Simplified views of thread states are Ready, Running, and blocked, where threads are either ready and waiting to be scheduled, running on a processor, or blocked (for example, waiting for I/O).

 Assuming a thread is running, answer the following questions and explain your answers:

a. If a page fault occurs, does the thread change state? If so, what state does it become?

b. If a TLB miss is resolved in the page table, does the thread change state? If so, what state does it become?

c. If the queue address reference is resolved in the page table, does the thread change state? If so, what state does it become?

a. Yes, it becomes blocked to wait for the completion of I/O, and then becomes Ready

b. Not necessarily, if the page is in memory, continue running, otherwise it becomes blocked to wait for the completion of I/O, and then becomes Ready

c. will not

17. What is the write-on-copy feature, and under what circumstances is it beneficial to use it? What hardware support is required to implement this feature

a. When two processes want to access the same page, such as the parent process and the child process created by it, the general method is to directly copy the page, and when using the copy-on-write method, the two processes share the page at the beginning, and Marking a page as copy-on-write eliminates the need to copy all pages at the beginning. Only when a process writes to a shared page, a copy of the page is created for the process to write to, and unmodified pages are still shared.

b. Hardware support: Write-protect pages marked as copy-on-write. Once a process initiates a write to the page, the operating system needs to check the page table to confirm whether the page is write-protected. If so, initiate a trap for the process Interrupt, the operating system then copies the page, allowing the process to write to the page copy.

18. A computer provides 232 bytes of virtual memory space to its users. This computer has 222 bytes of physical memory. Virtual memory is implemented through paging, with a page size of 4,096 bytes. The user process generates virtual address 11123456. Explain how the system establishes the corresponding physical location. Distinguish between software and hardware operations.

The binary of the virtual address has a total of 32 bits, and the upper 20 bits are the offset of the virtual address in the page table, and the lower 12 bits are the offset of the virtual address in the page

21. Consider the following page reference string 7, 2, 3, 1, 2, 5, 3, 4, 6, 7, 7, 1, 0, 5, 4, 6, 2, 3, 0 , 1 assuming three frames are paged, how many page faults will occur for the following replacement algorithm LRU replacement

FIFO replacement

Optimal replacement

LRU 18

FIFO 17

Optimal 13

22. The page table shown is a system that contains 16-bit virtual and physical addresses and 4,096-byte pages. The reference bit is set to 1 when the page is referenced. The thread periodically clears all values ​​of referenced bits. A dash in a page frame indicates that the page is not in memory. The page replacement algorithm is localized LRU and all numbers are in decimal.

a. Convert the following virtual addresses (in hexadecimal) to equivalent physical addresses. You can provide the answer in hexadecimal or decimal. Also set the correct reference bit for the entry in the page table.

 

 b. Using the above address as a guide, provide an example of a logical address (in hexadecimal) that would cause a page fault.

c. From which set of page frames will the LRU page replacement algorithm choose when resolving page faults?

a.• 0xE12C ->312C
• 0x3A9D->AA9D
• 0xA9D9->59D9
• 0x7001->E001
• 0xACA1->5CA1

b.0x4A9D

c. Will choose to replace the least recently used page frame

27. Consider a request paging system with time-measured utilization as follows:

For each of the following, please indicate if there is (or is likely to be) increased CPU utilization. Explain your answer.

a . Install a faster CPU.

b . Install a larger paging disk.

c . Improve the degree of multiprogramming.

d . Reduce the degree of multiprogramming.

e . Install more main memory.

f . Install faster hard drives or multiple controllers with multiple hard drives.

g . Add pre-pagination to the page fetching algorithm.

h , increase the page size.

a. Install a faster CPU. –no

b. Install a larger paging disk. --no

c. Increase the degree of multi-programming. –no

d. Reduce the degree of multiprogramming. --yes reduces the need to keep calling different pages

e. Increase main memory. –yes, more can also reside in main memory, reducing demand paging operations

f. Install a faster hard disk or multi-controller multi-hard disk. --yes, faster disk response can reduce the time required for paging operations

g. Add preprocessing to the page fetching algorithm. --yes, the CPU will get more data faster, so it will be used more. This is only the case if the paging operation can prefetch (i.e. some accesses are sequential).

h. Increase the page size - not necessarily, because when the page is increased, if the program reads the disk in order, then the operation of page calls will be reduced. If the program reads randomly, because the page becomes larger, the same as in Fewer pages are resident in memory, and more page faults are required.

30. The page replacement algorithm should minimize the number of page faults. We can minimize this by distributing heavily used pages evenly across all memory, rather than having them compete for a small number of page frames. We can associate with each page frame a counter that records the number of pages associated with that page frame. Then, to replace a page, we can search for the page frame with the smallest counter.

a . Use this basic idea to define a page replacement algorithm. Specifically address these issues:

i . What is the initial value of the counter?

ii . When to increment the counter?

iii . When will the counter decrease?

iv. How do I choose which pages to replace?

b . For the following quoted string with four page frames, how many page faults will your algorithm make?

1, 2, 3, 4, 5, 3, 4, 1, 6, 7, 8, 7, 8, 9, 7, 8, 9, 5, 4, 5, 4, 2.

c . For the quoted string in part b with four page frames, what is the minimum number of page faults for the optimal page replacement strategy?

  1.  
      1. 0
      2. when a new page is associated with the page frame
      3. When one of the associated pages of the page frame is no longer needed
      4. Select the page frame with the smallest counter, when the counter is the same, use FIFO
  2. 12
  3. 11

32. What is the cause of system jitter? How does the system detect jitter? Once jitter is detected, what can the system do to eliminate the problem?

Thrashing is caused by under-allocation of the minimum number of pages required by a process, which causes the process to suffer continuous page faults.

Systems can detect thrashing by evaluating CPU utilization levels compared to multiprogramming levels.

It can be eliminated by reducing the degree of multiprogramming.

33. Is it possible for a process to have two working sets, one representing data and the other representing code? Explain.

Possibly, in fact many processors provide two TLBs for this purpose. For example, code accessed by a process may maintain the same working set for a long period of time. However, the data accessed by the code may change, thus reflecting changes in the data access working set.

Knowledge points:

  1. Belady's Anomaly: For some page replacement algorithms, the page fault rate may increase as the number of allocated frames increases.
  2. FIFO : there will be belady exception
  3. Optimal page-replacement algorithm: replaces pages that will not be used for the longest time, resulting in the lowest possible page fault rate for a given number of frames;
  4. LRU (Least-Recent-Used algorithm) least recently used algorithm: replace the page that has not been used for the longest time;
  5. Second Chance Algorithm (Clock Algorithm): The most recently used page modifies the flag bit to 1. When page replacement is required, it loops in one direction to find the page replacement with the first flag bit set to 0. At the same time, the passed page marks bit changed to 0;
  6. Count-based page replacement
    1. Least Frequently Used (LFU): Replace the page with the smallest count, but when a page gets a huge count at the beginning and is no longer used later, it will take up a lot of memory, so the count can be moved to the right by one bit periodically , for exponential decay;
    2. Most Frequently Used (MFU): pages with the smallest count may have just been introduced and not yet used;
  7. Thrashing: A low-priority process is allocated fewer frames than the minimum required by the computer's architecture.

        Solution: reduce the degree of multiprogramming;

working-set model


Chap10 Mass storage structure

1. Besides FCFS scheduling, is disk scheduling useful in a single-user environment? Explain your answer.

在单用户环境中,I/O队列通常为空。对于一个块或一系列连续块,请求通常来自单个进程。在这些情况下,FCFS是一种经济的磁盘调度方法。但LOOK几乎同样易于编程,并且在多个进程执行并发I/O时,会提供更好的性能,例如当Web浏览器在后台检索数据,而操作系统正在分页,而另一个应用程序在前台处于活动状态时。

2.解释为什么SSTF调度倾向于使用中间磁道而不是最内侧和最外侧磁道。

磁盘的中心是到所有其他磁道的平均距离最小的位置。因此,磁头倾向于远离磁盘边缘。这是另一种思考方式。缸盖的当前位置将磁道分为两组。如果磁头不在磁盘的中心,并且新请求到达,则新请求更有可能位于包含磁盘中心的组中;因此,头部更有可能朝该方向移动。

3.为什么在磁盘调度中通常不考虑旋转延迟?您将如何修改SSTF、SCAN和C-SCAN以包括延迟优化?

大多数磁盘不会将其旋转位置信息导出到主机。即使他们这样做了,这些信息到达调度器的时间也不精确,并且调度器消耗的时间是可变的,因此旋转位置信息将变得不正确。此外,磁盘请求通常以术语形式给出逻辑块编号,并且逻辑块和物理位置之间的映射非常复杂。

4.为什么在多任务环境中,在系统上的磁盘和控制器之间平衡文件系统I/O很重要?

系统只能以其最慢瓶颈的速度执行。磁盘或磁盘控制器通常是现代系统中的瓶颈,因为它们的性能无法与CPU和系统总线的性能相媲美。通过平衡磁盘和控制器之间的I/O,单个磁盘和控制器都不会被淹没,从而避免了瓶颈。

5.从文件系统中重新读取代码页与使用交换空间存储代码页有哪些权衡?

如果代码页存储在交换空间中,则可以更快地将其传输到主存(因为交换空间分配的性能比一般的文件系统分配更快)。如果页面是在进程调用时复制到那里的,而不仅仅是按需调出以交换空间,那么使用交换空间可能需要启动时间。

此外,如果交换空间同时用于代码页和数据页,则必须分配更多的交换空间

6.有没有办法实现真正稳定的存储?解释你的答案。

Truly stable storage never loses data. The basic technique of stable storage is to maintain multiple copies of data so that if one copy is destroyed, the other copy is still available. But with any scheme, we can imagine a disaster large enough to destroy all copies.

7. It is sometimes said that tape is a sequential access medium and disk is a random access medium. In fact, whether a storage device is suitable for random access depends on the transfer size.

The term streaming rate refers to the ongoing data transfer rate, excluding the effects of access latency. In contrast, the effective transfer rate is the ratio of total bytes per second, including overhead times such as access latency.

Assume that in a computer, the access latency of the second-level cache is 8 nanoseconds, the streaming rate is 800 MB/s, the access latency of the main memory is 60 nanoseconds, and the streaming rate is 80 MB/s. The access latency was 15 ms and the streaming rate was 5 MB/s, and the tape drive had an access latency of 60 seconds and a streaming rate of 2 MB/s.

  • Random access results in a reduction in the device's effective transfer rate because no data is transferred during the access. For the described disk, what is the effective transfer rate if the average access is followed by streaming of (1) 512 bytes, (2) 8 KB, (3) 1 MB, and (4) 16 MB?
  • The utilization of a device is the ratio of the effective transfer rate to the streaming transfer rate. Calculate the disk drive utilization for each of the four transfer sizes given in part a.
  • Assume 25% (or higher) utilization is acceptable. Using the given performance data, calculate the minimum transfer size for the disk that provides acceptable utilization.
  • Complete the following sentences: A disk is a random-access device for transfers larger than ( ) bytes, and a sequential-access device for smaller transfers.
  • Calculate the minimum transfer size that provides acceptable utilization of cache, memory, and tape.
  • When is tape a random access device and when is it a sequential access device?

a. For 512 bytes, the effective transfer rate is calculated as follows.

ETR = transfer size / transfer time.

If X is the transfer size, then the transfer time is ((X/STR) + delay).

The transmission time is 15ms+ (512B/5MB per second) = 15.0097ms.

Therefore, the effective transfer rate is 512B/15.0097ms=33.12 KB/s.

8KB ETR = .47MB/sec.

ETR of 1MB = 4.65MB/sec.

16MB ETR = 4.98MB/sec.

b. 512B device utilization = 33.12 KB/s / 5MB/s =

.0064 = .8KB is 64 = 9.4%.

For 1MB = 93%.

For 16MB = 99.6%.

c. Calculate. 25=ETR/STR, solve for transfer size X.

STR=5MB, so 1.25MB/S=ETR.

1.25MB/S*((X/5)+。015)=X。

.25 times more. 01875=X.

X=。025MB。

d. The disk is a random access device for transfers larger than K bytes (where K > disk block size), and a sequential access device for smaller transfers.

e. Calculate the minimum transfer size for acceptable cache utilization:

STR=800MB, ETR=200, delay=8*10−9

200(XMB/800+8 X 10−9)=XMB。

.25XMB+1600*10−9=XMB。

X = 2.24 bytes.

Calculation memory:

STR=80MB,ETR=20,L=60*10-9。

20(XMB/80+60*10-9)=XMB。

.25XMB+1200*10−9=XMB。

X = 1.68 bytes.

Count the tapes:

STR=2MB,ETR=。5,L=60。

.5(XMB/2+60)=XMB。

.25XMB+30=XMB。

X=40MB。

8. Can a RAID level 1 organization achieve better performance in terms of read requests than a RAID level 0 organization (with non-redundant data striping)? If yes, how?

Yes, a RAID level 1 organization can achieve better read request performance. When performing a read operation, a RAID level 1 system can decide which of two copies of a block should be accessed to satisfy the request. This selection may be based on the current position of the heads, so performance optimizations can be achieved by choosing heads closer to the target data.

9. Except for FCFS, no disk scheduling rules are truly fair (starvation can occur) a. Explain why this assertion is true. b. Describe a method for modifying algorithms such as SCAN to ensure fairness. c. Explain why fairness is an important goal of time-sharing systems. d. Give three or more examples where it is important for the operating system to be unfair in handling I/O requests.

a. Except for FCFS, other scheduling algorithms are preemptive scheduling algorithms. When there are new scheduling requests close to the head, the scheduling requests far away from the head will be hungry.

b. Set a timer, and all scheduling requests exceeding a fixed duration will be arranged at the head of the waiting queue. c. The time-sharing system requires the computer to be able to quickly respond to the requests of all users, so it is necessary to avoid long-term waiting for some users' processes because they are not announced.

d. Kernel IO requests take precedence over user IO requests; high-priority process IO requests take precedence over low-priority process IO requests; paging and swapping take precedence over user IO requests

11. Suppose a disk drive has 5000 tracks, numbered from 0 to 4999. The drive is currently servicing a request for 2150 tracks, compared to a previous request of 1805 tracks. The queues waiting for requests are 2, 069 , 1 , 212 , 2 , 296 , 2 , 800 , 544 , 1 , 618 , 356 , 1, 523 , 4, 965 , 3681 in the order of FIFO starting from the current head position, For each disk scheduling algorithm below, what is the total distance (in tracks) that the disk arm has moved to satisfy all pending requests

a. FCFS
b. SSTF
c. SCAN
d. LOOK
e. C-SCAN
f. C-LOOK

13011 , 7586 , 7492 , 9205 , 7424 , 9137 respectively


Chap11 file system

1. Some systems automatically delete all user files when the user logs off or the job terminates, unless the user explicitly asks to keep them. Other systems retain all files unless the user explicitly deletes them. Discuss the relative merits of each approach.

The advantage of deleting all files not specifically saved by the user is that it minimizes the file space required for each user by not saving unnecessary or unnecessary files. Saving all files unless specifically deleted is safer for the user as it is unlikely to accidentally lose a file by forgetting to save it.

2. Why do some systems keep track of the type of file, while others leave it up to the user, and others don't implement multiple file types? Which system is "better".

Some systems allow different file operations based on file type (for example, ascii files can be read as streams, while database files can be read by block index). Other systems leave this interpretation of file data to the process, providing no assistance when accessing the data. The "better" approach depends on the needs of the processes on the system and what the user wants from the operating system. If the system is primarily running database applications, it may be more efficient for the OS to implement database type files and provide operations, rather than having every program implement the same thing (possibly in different ways). For general-purpose systems, it's best to implement only the basic file types, to keep the size of the operating system small and to allow maximum freedom to processes on the system.

3. Similarly, some systems support multiple types of structures for file data, while others only support byte streams. What are the pros and cons of each approach?

One advantage of system support for different file structures is that the support comes from the system; individual applications do not need to provide support. Also, if the system provides support for a different file structure, it may implement it more efficiently than the application.

The downside of having the system support defined file types is that it increases the size of the system. In addition, applications that may require different file types other than those provided by the system may not run on such systems.

Another strategy is that the operating system does not define support for file structures, but treats all files as a series of bytes. This is the approach taken by UNIX systems. The advantage of this approach is that it simplifies the operating system's support for the file system, since the system no longer needs to provide structures for different file types. Additionally, it allows applications to define the file structure, mitigating situations where the system may not be able to provide the file definitions required by a particular application.

4. Can you simulate a multi-level directory structure with a single-level directory structure that can use arbitrarily long names? If your answer is yes, please explain how this is done and compare this scenario to a multi-level directory scenario. If your answer is no, please explain what prevented the simulation from being successful. How would your answer change if filenames were limited to 7 characters?

If you can use arbitrarily long names, you can simulate multi-level directory structures. For example, this can be done using the character "." to indicate the end of a subdirectory. For example, the name Jim. The Java language F1 specifies that F1 is a file in the subdirectory java, and the subdirectory java is located in the root directory jim.

The above scenario cannot be used if the filename is limited to 7 characters, so in general the answer is no. In this case, the next best thing is to use a specific file as a symbol table (directory), map an arbitrarily long name (like jim.java.F1) to a shorter arbitrary name (like XX00743), then use Actual file access.

5. Explain the purpose of the open() and close() operations.

• The open() operation notifies the system that the named file is about to be activated.

• The close () operation informs the system that the user who issued the close operation no longer uses the specified file.

6. On some systems, authorized users can read and write subdirectories just like ordinary files.

  • Describe protection issues that may arise.
  • Recommend solutions to these protection issues.

a. One piece of information held in a directory entry is the file location. If the user can modify this location, other files can be accessed, breaking the access protection scheme.

b. Users are not allowed to directly write to subdirectories. Instead, system operations are provided to achieve this.

7. Consider a system that supports 5000 users. Suppose you want to allow 4990 of these users to be able to access a file.

a . How would you specify this protection scheme in UNIX?

b . Can you suggest another protection scheme that can be used for this purpose more efficiently than the one provided by UNIX?

a. There are two ways to achieve this:

i. Create an access control list containing all 4990 user names.

ii. Put these 4990 users in a group and set the group access accordingly. This scenario cannot always be implemented because user groups are limited by the system.

b. Universal access to files applies to all users, unless their names appear in access control lists with different access rights. With this scheme, you simply put the names of the remaining ten users in the access control list, but do not allow access.

8. The researchers suggest that instead of having an access list associated with each file (specifying which users can access the file and how), it is better to have a user control list associated with each user (specifying which files the user can access and how). Discuss the relative merits of the two options.

• Document control list. Since access control information is centralized in one place, it is easier to change access control information, which requires less space.

• User control list. This requires less overhead when opening the file

10. The open file table is used to maintain information about currently open files. Should the operating system maintain a separate table for each user, or just one table containing references to files currently accessed by all users? If the same file is accessed by two different programs or users, then the open-file table should Is there a separate entry? Explain.

Only one table is maintained containing all user-accessed files. When a file is accessed for the first time, it is added to the open file table, and subsequent processes specify the file through entries in the table when accessing the file. Also only delete the file from the system file table when it is not being used by any process. On the other hand, if two processes are accessing the file, separate state needs to be maintained to keep track of the current position of which parts of the file are being accessed by the two processes. This requires the OS to maintain separate entries for the two processes.

11. What are the advantages and disadvantages of providing mandatory locks instead of advisory locks that are used at the user's discretion?

The operating system forcibly prevents other processes from accessing locked files, which can ensure mutual exclusion to the maximum extent. In many cases, such strict methods are not required to ensure mutual exclusion, which reduces the parallelism of the system. Mutual exclusion can be guaranteed by other program constructs, such as memory locks. Also, mandatory locking will limit the flexibility of accessing files, may also cause deadlocks, and may increase the overhead associated with accessing files.

12. Provide examples of typical applications that access files according to the following methods:

• Sequential access

• Random access

Sequential access: editor and compiler;

Random Access: Large Database Computing

15. Give an example of an application that could benefit from random access to indexed files by the operating system.

Applications that maintain databases of entries can benefit from this support. For example, if a program is maintaining a student database, then access to the database cannot be modeled with any predetermined access pattern. Access to records is random, and locating records would be more efficient if the operating system provided some form of tree-based indexing.

17.有些系统通过维护一个文件的单一副本来提供文件共享。其他系统维护多个副本,每个共享文件的用户都有一个副本。讨论每种方法的相对优点。

对于单个副本,对一个文件的多个并发更新可能会导致用户获取不正确的信息,并使文件处于不正确的状态。如果有多个副本,就会产生存储浪费,而且多个副本之间可能不一致。


Chap12 文件系统的实现

2 如果一个系统允许在多个位置同时挂载一个文件系统,会发生什么问题?

导致相同的文件会有不同的文件路径,会导致一致性问题

3 为什么文件分配的位图必须保存在大容量存储中,而不是在主存中?

当位图存储在主存中,如系统崩溃,则位图会丢失,而存储在大容量存储设备上时,位图不会丢失

4 考虑一个支持连续、链接和索引分配策略的系统。在决定哪种策略最适合特定文件时,应该使用什么标准?

当文件较小且常被顺序访问时,可采用连续分配策略,当文件较大且常被连续访问时,可采用索引分配的策略,当文件较大且常被随机访问时可采用索引分配策略

6 缓存如何帮助提高性能?既然缓存如此有用,为什么系统不使用更多或更大的缓存呢?

缓存可以进行高速数据交换,由局部性原理实现将经常使用的数据读取到缓存中,提高将数据从低速存储设备传输到高速计算设备的效率,然而缓存的成本十分昂贵。

7 为什么操作系统动态分配内部表对用户有利?操作系统这样做的惩罚是什么?

动态分配内部表使得用户不会使用超过内部表的大小,提高了灵活性。然而动态改变内部表会增加内核结构的复杂性,使操作系统变得更复杂,增大开销。

9 考虑一个文件系统,它使用修改后的连续分配模式,并支持区段。文件是区段的集合,每个区段对应于一组连续的块。在这样的系统中一个关键问题是区段大小的可变性程度。以下方案的优缺点是什么:

a.所有区段的大小是相同的,大小是预先确定的。

b.区段可以是任意大小的,并且是动态分配的。

c.区段可以有几个固定的大小,这些大小是预先确定的。

For the scheme with the same segment size, it is a simplified continuous allocation, using a smaller free space list, which has a simple structure and low flexibility. For the scheme with free section size, the section size can be adjusted according to the file size, and there is the possibility of external fragmentation, which requires a more complex structure to realize dynamic sections, but it can improve the flexibility of allocation, and the complexity is relatively large. For the last one, different sizes of extents require different free space lists, and the complexity and flexibility are between ab and ab.

10 Compares the performance of three techniques for allocating disk blocks (consecutive, chained, and indexed) for sequential and random file access.

Continuous allocation only needs to be accessed once to obtain a disk block for both access methods; link allocation can reserve the address of the next block in memory to achieve sequential access, while in random access, if you want to access the i-th block, you need to access i disk access performance is poor. In index allocation, if the index block is in memory, it can be directly accessed. If there is a multi-level index structure, when accessing the block at the end of the file, all index blocks need to be read, and its performance depends on the structure of the index.

12 Consider a system where free space is kept in a free space list.

a. Suppose the pointer to the free list is lost. Can the system rebuild the free space list? Explain your answer.

b. Consider a file system similar to UNIX that uses index allocation. How many disk I/O operations might it take to read the contents of a small local file at /a/b/c? Assuming no disk blocks are currently cached.

c. Come up with a scheme to ensure that pointers are not lost due to memory faults.

aTo rebuild the free space list, you need to traverse the directory structure, determine the space in the disk space that is not used by files or directories, and link it in the free space list. bc

In order to rebuild the free list, a "garbage collection" needs to be performed. This will require searching the entire directory structure to determine which pages have been assigned to jobs. Those remaining unallocated pages can be relinked as free space lists.

14 Discuss how performance optimizations for filesystems make it difficult to maintain system consistency in the event of a computer crash.

When deferred updates are used to optimize system performance, if the system crashes without committing deferred updates, the consistency of the file system will be broken.


Chap13 I/O system

1. State three advantages of placing functionality in the device controller rather than in the kernel. State three shortcomings.

       advantage:

  1. Bugs are less likely to cause system crashes;
  2. Performance can be improved through the use of dedicated hardware and hard-coded algorithms;
  3. The kernel can be simplified by moving the algorithm out of the kernel

shortcoming:

  1. bugs are harder to fix
  2. Improved algorithms also require hardware updates
  3. Embedded algorithms may cause APP conflicts with the device, affecting performance

3. Why can a system use interrupt-driven I/O to manage a single serial port and use polled I/O to manage a front-end processor, such as a terminal concentrator?

Polling is more efficient than interrupt-driven when I/O is frequent and short-lived. A large number of I/O uses polling to reduce resource waste

5. How does DMA improve system concurrency? How does it complicate hardware design?

A DMA system increases system concurrency by allowing the CPU to perform tasks while transferring data across the system and memory buses. The hardware design is complicated because the DMA controller must be integrated into the system, and the system must allow the DMA controller to be the bus master. Cycle stealing may also be required in order to allow the CPU and DMA controller to share the use of the memory bus

8. When multiple interrupts from different devices occur almost simultaneously, a priority scheme can be used to determine the order in which interrupts are serviced. Discusses considerations when assigning priorities to different interrupts.

  1. Device-induced interrupts have higher priority than user-generated traps, so device interrupts can be used by processor system call code;
  2. Control device interrupts can be given higher priority
  3. Time-limited devices have higher priority
  4. Devices without data buffering have higher priority

9. What are the advantages and disadvantages of supporting memory-mapped I/O to device control registers?

advantage:

No special instructions in the instruction set are required, so protection rules do not need to be enforced;

shortcoming:

The memory translation unit needs to ensure that the memory addresses related to the device control registers are not accessed by user programs

11. In most multiprogramming systems, user programs access memory through virtual addresses, while the operating system accesses memory using raw physical addresses. How does this design affect user programs initiating I/O operations and the operating system performing I/O operations?

User programs usually specify a buffer for transferring data to or reading data from the device. This buffer exists in user space and is specified by a virtual address. The kernel needs to issue I/O operations and copy data between user buffers and its own kernel buffers before or after the I/O. In order to access a user buffer, the kernel needs to translate the virtual address provided by the user into the corresponding physical address.

12. What are the various performance overheads associated with interrupt servicing?

context switch overhead

Program restart overhead

Guess you like

Origin blog.csdn.net/YoOAOoY/article/details/125707447