Operating System --- Memory Management

1. Short answer questions


1. The basic task of memory management is to provide a good memory environment for the concurrent execution of multi-programs. What aspects should a good storage environment include?

answer:


2. Can memory protection be implemented entirely by software? Why?

Answer: The main task of memory protection is to ensure that each program only runs in its own memory area. This requires the system to perform out-of-bounds checks on the addresses accessed by each instruction. If a cross-border occurs, the system should be able to detect it immediately and issue a cross-border interrupt request to discard the instruction. If each check is completely implemented by software, each time an instruction is executed, several instructions must be added to perform the out-of-bounds check function, which will undoubtedly reduce the execution speed of the program. Therefore, out-of-bounds checks are usually implemented by hardware and make the instructions The execution and the out-of-bounds check function are executed in parallel, so that the running speed of the program is not reduced. Of course, the processing after a boundary violation is discovered needs to be completed in cooperation with the software. Therefore, the memory protection function is completed by hardware and software.


3. Please explain what is relocation? Why relocation?

Answer: Relocation: The technology that allows jobs to move in memory during operation must be supported by the hardware address translation mechanism. That is, add a relocation register to the system and use it to load the starting address of the program in memory. When the program is executed, the memory address actually accessed is the relative address added to the address in the relocation register. This is called relocation. In the continuous allocation method, in order to use "fragments" to load jobs, small partitions scattered in the memory need to be spliced ​​into large partitions, which is called "splicing" or "compacting". However, since the compacted user program is in the memory The location has changed. If the addresses of the program and data are not modified, the program will not be executed, so relocation must be performed.

Standard answer:


4. What are the ways to implement dynamic relocation?

answer:


5. What methods can be used to load programs into memory? What situations are they suitable for?

answer:

(1) Absolute loading method, suitable for single-programming systems.

(2) Relocatable loading method, suitable for partitioned storage management systems.

(3) Dynamic runtime loading method, suitable for paging and segmented storage management systems.

 2.3 Suitable for multi-programming systems


6.What is static linking? What two problems need to be solved when linking statically?

answer:

The definition of static linking: Before running the program, each target and the library functions they require are linked into a complete assembly module, which will not be disassembled in the future. This kind of The method of linking in advance is called.


7. When writing a program, the source code must be compiled and linked to generate target code. What is linking? What problem does the link mainly solve? Briefly describe the main types of links and their advantages and disadvantages.

answer:

             Linking is a stage in the computer program construction process. Its main task is to combine one or more object files (including library files) generated by the compiler into an executable file, shared library or other type of object code. . The main problems solved by the link include:

          Symbol resolution: At compile time, the specific addresses of functions and variables have not yet been determined. These undetermined functions and variables are called "external symbols". One of the linker's tasks is to find the real addresses of these symbols and replace the corresponding references.

         Space and address allocation: The linker allocates space for each module and determines the address of each function and variable in the final output.

         Library processing: Programmers often use functions in the standard library or other libraries. The linker selects the required modules from the library and includes them in the final executable file.

The main types of links include:

Static linking 
  Advantages:
     - The generated executable file is independent and does not depend on external library files, making it easy to deploy and distribute.
     - Sometimes there may be better performance since all the code is in a single binary.
  Disadvantages:
     - If multiple programs use the same library, static linking will cause each program to have a copy of the library, wasting disk and memory resources.
     - If the library is updated, the application needs to be relinked and deployed.

Dynamic linking:
   -Advantages:
     -Save disk space and memory because multiple running programs can share a copy of the same library.
     - When libraries are updated, there is usually no need to relink and deploy the application.
   Disadvantages:
     - Library files are required at runtime. If library files are missing or incompatible with the application version, the program may not run.
     - Sometimes there may be additional performance overhead due to the need to resolve dynamic symbols and load shared libraries.

In actual development, static linking and dynamic linking have their own application scenarios, and which linking method to choose depends on the specific needs and goals of the project.

Standard answer:

        Linking is a linker that links together a set of compiled object modules and required library functions to form a complete load module.

Main types


8. Why should swap be introduced? What types of swaps can be divided into?

Answer: Answer: In a multi-channel environment, on the one hand, some processes in the memory are blocked because a certain event has not yet occurred, but it occupies a large amount of memory space, and sometimes all processes in the memory may even be blocked. Blocking forces the CPU to stop and wait; on the other hand, there are situations where many jobs are waiting on external memory and cannot enter the memory to run because there is no memory. Obviously this is a serious waste of system resources and reduces system throughput. In order to solve this problem, swap (also called swap) technology was introduced in the operating system. The entire process can be swapped in and out, or a part of the process (pages, segments) can be swapped in and out. The former is mainly used to alleviate the lack of memory in the current system, and the latter is mainly used to implement virtual storage.

9. In swap technology, what are the differences between the goals of file area management and the goals of swap space management?

answer:

         The main goal of file area management is to improve the utilization of file storage space and then increase the access speed to files. Therefore, the file area space management adopts a discrete allocation method.

        For The main goal of changing space management is to improve the speed of processing and replacement of the process , and then it is to improve the file storage space Utilization, therefore, the swap area space management adopts a continuous allocation method, and less consideration is given to the fragmentation problem in the external memory.


10. Why is it easier to share and protect information in a segmented system than in a paging system?

answer:

        Whether it is a paging system or a segmented system, multiple processes are allowed to share code or common data in the program. The way the paging system implements page sharing is to point the page table entries corresponding to the shared pages to the same memory block in the shared process. Since the address space of the paging system is one-dimensional, and the page division is automatically performed by the system, it will cause shared code or data and non-shared code or data to coexist on the same page, making it very difficult to share information. The segmented system is naturally divided into segments when users program. The information in each segment has a relatively complete logical meaning, which is just in line with the segmented storage system. Therefore, it is easier to implement information than paging. shared.​ 

        For the protection of information, it is also protected according to the logical unit of information, and it is also compatible with the segmented storage system. The OS should ensure that user processes only access shared information in allowed ways, while other people's non-shared information is not allowed to be accessed. Any form of access. The segmented system is easier to protect information than the paging system. We can protect each segment differently according to the meaning of each segment. For example, the access permission of the subprogram segment can only be executed, and the access permission of the data segment can only be executed. Permissions are read, write, etc.

Standard answer:


11. What are the main ways to improve memory utilization?

answer:

(1) Change the continuous allocation method to discrete allocation method;

(2) Add swap and coverage mechanisms;

(3) Introduce dynamic mechanism;

(4) Introducing a virtual memory mechanism;

(5) Introduce a memory sharing mechanism.


2. Calculation questions


12. Suppose a paging storage system has a fast table, in which most active page table entries can exist. If the page table is placed in memory, the memory access time is 1ns, the hit rate of the fast table is 85%, and the access time of the fast table is 0.1ns, what is the financial effect access time?

answer:

        In a paging storage system with a fast table, when calculating the effective access time, you need to pay attention to the time relationship between accessing the fast table and accessing the memory. Usually in the system, the fast table is accessed first, and then the memory is accessed when there is a miss; but if there are specific instructions in the question, you should pay attention to the difference when calculating. Calculation process: [(0.1+1)×85%+(0.1+1+1)×(1-85%)+]μs=1.25μs.

 Theory: 

        In this paged storage system, when memory needs to be accessed, the system first looks up the fast table (TLB). If the corresponding page table entry is found (that is, the fast table hits), the information is directly used for memory access; if it is not found (that is, the fast table misses), you need to first look up the page table entry from the memory, and then access the actual The data.

  1. Fast table hit: The access time at this time includes the time to look up the fast table and the actual memory access time.

  2. Fast table miss: The access time at this time includes the time to find the fast table, the time to obtain the page table entry from the memory, and the actual memory access time.


13. For a paging system that stores page tables in memory:
(1) If it takes 0.2μs to access the memory, what is the effective access time?
(2) If a cache table is added, and assuming that the probability of finding a page table entry in the cache table is as high as 90%, what is the effective access time s (assuming that it takes Time is 0)?

answer:

(1) Non-use comfort table :

Each memory access actually requires two real memory accesses: one to get the page table entry, and one to get the actual data.

So effective access time = 2 × memory access time = 2 × 0.2μs = 0.4μs

Therefore, the effective access time is 0.4μs.

(2) Usage comfort table :

Fast table (or TLB: Translation Lookaside Buffer) is used to cache page table entries, which greatly reduces the time of page table query.

Consider two situations:

  1. Fast table hit: only one memory access is needed at this time.
  2. Fast table miss: 2 memory accesses are required at this time.

Effective access time = Fast table hit probability × 1 memory access time + Fast table miss probability × 2 memory access times = 0.9 × 0.2μs + 0.1 × 0.4μs = 0.18μs + 0.04μs = 0.22μs


14. A certain system uses paging storage management, with 32 pages of logical space, 2KB per page, and 1MB of physical space.
(1) Write the format of the logical address.
(2) If access permissions, etc. are not considered, how many entries are there in the page table of the process? How many digits are there in each item?
(3) If the physical space is reduced by half, what changes should be made to the page table structure accordingly?

answer:

The meaning of the question: Logical space = 32 pages Each page size = 2KB = (2^{11})B (because 1KB = 2^{10})B)
Physics Space = 1MB = (2^{20})B

(1) Write the format of the logical address: 

The logical address consists of the page number and the address within the page. The page number is used to index the page table, and the intra-page address represents the offset within the page.

-Page Number: Since there are 32 pages in total, (log_2 32 = 5) bits are needed to represent it.
  
- Page Offset: Since the size of each page is 2KB = (2^{11})B, 11 bits are needed to represent it.

Therefore, the logical address format is: [5-digit page number | 11-digit page address]

**(2) If access permissions, etc. are not considered, how many entries are there in the page table of the process? How many digits are there in each item? **

- The number of entries in the page table is the same as the number of pages in the logical space, which is 32 entries.
- The size of each item is determined by the physical address space. The number of pages corresponding to 1MB of physical space is: (frac{1MB}{2KB} = 512) pages. Therefore, (log_2 512 = 9) bits are needed to represent the physical page number.

Therefore, there are at least 9 digits for each item.

**(3) If the physical space is reduced by half, what changes should be made to the page table structure accordingly? **

Reducing the physical space by half means that the new physical space is 0.5MB = (2^{19})B. Divided by 2KB per page, the new physical space page number is 256 pages. Therefore, the new physical page number requires (log_2 256 = 8) bits to represent.

Therefore, when the physical space is reduced by half, each entry in the page table is reduced from the original 9 bits to 8 bits.

15. It is known that a certain paging system has a memory capacity of 64KB and a page size of 1KB. For a 4-page job, its)
Pages 1, 2, and 3 are used respectively. Allocated to blocks 2, 4, 6, and 7 of memory.
(1) Convert the decimal logical addresses 1023, 2500, 3500, and 4500 into physical addresses.
(2) Taking the decimal logical address 1023 as an example, draw the address conversion process diagram.

answer:

The meaning of the question: first calculate their page numbers and intra-page addresses (divided by the page size, the quotient is the page number, and the remainder is the intra-page address).

        Memory capacity = 64KB Page size = 1KB = 2^10=1024B The page mapping of a job is as follows: 1→2,2→4,3→6,4→71→2,2→4,3→6,4→7

        Because each page is 1KB, the lower 10 bits (bits 0-9) of the logical address are the page address, and the higher bits are used to represent the page number.

(1) Convert the decimal logical addresses 1023, 2500, 3500, and 4500 into physical addresses:

  • 1023 meeting place

    • Page number: 1023/1024= 0 (first page)
    • In-page address: 1023 % 1024 = 1023
    • Physical page number: 2
    • Physical address = 2 × 1024+ 1023 = 3071
  • 2500 meeting places

    • Page number: 2500/1024 = 2 (third page)
    • In-page address: 2500 % 1024 = 452
    • Physical page number: 6
    • Physical address = 6 × 1K + 452 = 6596
  • 3500 meeting place

    • Page number: 3500/1024 = 3 (the fourth page)
    • In-page address: 3500 % 1024 = 428
    • Physical page number: 7
    • Physical address = 7 × 1024+ 932 = 7596
  • 4500 meeting place

    • Page number: 4500/1024​ = 4
    • From the meaning of the question, it is obvious that there are only 4 pages, so the logical address 4500 is invalid and cannot be converted into a physical address.

(2) The specific images are as follows:


16. It is known that the page length of a certain system is 4KB, the size of each page table entry is 4B, and a multi-layer paging strategy is used to map the 64-bit user address space. If the top-level page table is limited to occupy only 1 page, ask how many levels of paging strategies it can adopt.

answer:

        Method 1: As can be seen from the question, the user address space of the system is 2(64)B, and the page size of is 4KB , so the job can have up to (2^64)/(2^12) (that is, 2^52) pages, and the size of the page table is 2^(52)*4, or 2^(54)B. Therefore, the page table can be divided into 2 (42) page table pages, and a two-level page table can be established for it. The size of the two-level page table is 2 (44)B. By analogy, we can know that the lengths of its level 3, 4, 5, and 6 page tables are 2^(34)B, 2^(24)B, 2^(14)B, and 2^(4)B respectively, so A 6-layer paging strategy must be adopted.

         Method 2: The page size is 4KB=2^(12)B, and the page table entry 4B=2^(2)B, so one page can store 2^(12)/2^(2)=2(10) pages table entry, so the number of layers = INT [64/10] = 6 layers.

Standard answer:


17. For the segment table shown in Table 5-2, please change the logical address (0,137), (1,4000), (2,3600), (5,230)
Convert to physical address.
 

Segment table 5-2
Section number memory starting address Duan Chang
0 50K 10KB
1 60K 3KB
2 70K 5KB
3 120K 8KB
4 150K 4KB

answer:

The corresponding physical address of (0,137) is: 50K+137 = 50*1024+137 = 51337;

The intra-segment offset address of (1,4000) is out of bounds and is an illegal logical address;

The corresponding physical address of (2,3600) is: 70K+3600 = 75280

The segment number of (5,230) is out of bounds and is an illegal logical address.

3. Comprehensive application questions


18. A certain system uses dynamic partition allocation to manage memory. The memory space is 640KB, and the low-end 40KB stores the OS. When the system allocates space for user jobs, it starts from the low address area. For the following sequence of job requests, draw a diagram representing the final image of memory after memory allocation and deallocation using the first-fit algorithm. The job request sequence is as follows:
Job 1 applies for 200KB, job 2 applies for 70KB; job 3 applies for 150KB, job 2 releases 70KB; job 4 applies for 80KB, job 3 releases 150KB; job 5 applies for 100KB, and job 6 applies for 60KB; operation 7 applies for 50KB, and operation 6 releases 60KB.

answer:

Standard answer:


19. A certain OS adopts segmented storage management. The user area memory is 512KB. The free blocks are linked into the free block table, and the first half of the free block (the small address part) is intercepted during allocation. Initially all are idle. After executing the application and release operation sequence request(300KB), request(100KB), release (300KB), request (150KB), request(5OKB), request(90KB):
(1) If Using the first-fit algorithm, what free blocks are in the free block table (indicate size and starting address)?
(2) If the best adaptation algorithm is used, what free blocks are there in the free block table (indicate the size and starting address)?
(3) If you subsequently apply for 80KB, what will be the consequences of the above two situations? What does this mean?

answer:

Given by the meaning of the question: User area memory size = 512KB; initially, all memory is free, that is, there is a free block starting from address 0 with a size of 512KB.

Execute the given sequence of operations:

request(300KB): allocate 300KB of memory request(100KB): allocate 100KB of memory
release(300KB): release the first requested 300KB request(150KB): allocate 150KB of memory
request(50KB): allocate 50KB of memory request(90KB): allocate 90KB of memory

We consider two algorithms respectively:

(1) First adaptation algorithm:

1. After allocating 300KB, free blocks: [300KB, 512KB-300KB = 212KB]
2. After allocating 100KB, free blocks: [400KB, 112KB]
3. After releasing 300KB, free blocks: [0KB, 300KB], [400KB, 112KB]
4. After allocating 150KB, free blocks: [150KB, 150KB], [ 400KB, 112KB]
5. After allocating 50KB, free blocks: [200KB, 100KB], [400KB, 112KB]
6. After allocating 90KB, free blocks :[200KB, 100KB], [490KB, 22KB]

(2) Best adaptation algorithm:

1. After allocating 300KB, free blocks: [300KB, 212KB]
2. After allocating 100KB, free blocks: [400KB, 112KB]
3. After releasing 300KB, free blocks: [0KB, 300KB], [400KB, 112KB]
4. After allocating 150KB, free blocks: [0KB, 150KB], [400KB, 112KB]
5. After allocating 50KB, free blocks: [0KB, 100KB], [450KB, 62KB]
6. After allocating 90KB, free blocks: [0KB, 10KB], [450KB, 62KB]

(3) The consequences of subsequent application for 80KB:

        For the first-fit algorithm: 80KB can be allocated from a 100KB free block starting at position 200KB. The remaining free blocks are: [280KB, 20KB], [490KB, 22KB].
  
        For the best adaptation algorithm: 80KB can be allocated from the 62KB free block starting at position 450KB, but this block is too small, so the allocation request will fail this time. The remaining free blocks remain unchanged and are: [0KB, 10KB], [450KB, 62KB].

        The best-fit algorithm may result in a large number of small free blocks, which makes memory requests for large blocks more likely to fail, even though the total available free space may be large enough. This illustrates the problem of fragmentation, especially internal fragmentation. The best fit policy may result in more internal fragmentation, while the first fit policy may result in inefficient use of memory, but in this case it is able to satisfy the 80KB request.

Standard answer:

First adaptation algorithm:

Best fit algorithm:

(3)

20. The free partition of a certain system is shown in Table 5-3, and a variable partition allocation strategy is used to process jobs. The existing job sequences are 96KB, 20KB, and 200KB. If the first adaptation algorithm and the best adaptation algorithm are used to process these job sequences, which algorithm can meet the requirements of the job sequence? Why?

Table 5-3 Free partition table
Section number memory starting address Duan Chang
0 32K 100KB
1 10KB 150K
2 5KB 200K
3 218KB 220K
4 96KB 530K

answer:

         If the best adaptation algorithm is used, when applying for a 96K storage area, partition No. 5 is selected. The size of partition No. 5 is consistent with the size of the requested space. This entry should be deleted from the free partition table; then when applying for 20K, partition No. 1 is selected. partition, partition No. 1 has 12K left after allocation; finally applied for 200K, selected partition No. 4, and left 18K after allocation. Obviously, using the best adaptation algorithm for memory allocation can meet the needs of this job sequence. After allocating memory space for the job sequence, the free partition table is shown in Table (a).

        If the first adaptation algorithm is used, when applying for a 96K storage area, partition No. 4 is selected, and partition No. 4 has 122K left after allocation; then applies for 20K, selects partition No. 1, and leaves 12K after allocation; finally applies for 200K, None of the five existing partitions can meet the requirements, and the job is waiting. Obviously, the first adaptation algorithm is used for memory allocation, which cannot meet the needs of this job sequence. The free partition table at this time is shown in Table (b).

Free partition table after allocation

(a)

Partition number

size

initial address

1

12K

100K

2

10K

150K

3

5K

200K

4

18K

220K

(b)

Partition number

size

initial address

1

12K

100K

2

10K

150K

3

5K

200K

4

122K

220K

5

96K

530K

Guess you like

Origin blog.csdn.net/qq_63976098/article/details/134102853