Presentation is loading. Please wait.

Presentation is loading. Please wait.

MInix memory management1 Minix Memory Management. Contiguous memory management. No swapping. A list of holes sorted in memory address order is maintained.

Similar presentations


Presentation on theme: "MInix memory management1 Minix Memory Management. Contiguous memory management. No swapping. A list of holes sorted in memory address order is maintained."— Presentation transcript:

1 MInix memory management1 Minix Memory Management. Contiguous memory management. No swapping. A list of holes sorted in memory address order is maintained.

2 MInix memory management2 Memory Allocation. Memory is allocated during: –FORK and EXEC system calls. When FORK or EXEC is executed, the hole list is searched using first fit for a hole that is big enough. Once the process is placed in memory, it remains in exactly the same place until it terminates.

3 MInix memory management3 Where is the memory management located in the Minix structure? How does the memory manager communicate with other parts of the system?

4 MInix memory management4 Memory Layout. Minix processes can use either combined I and D space or separate I and D space. What is I and D space? Processes using separate I and D space can use memory more efficiently. WHY?

5 MInix memory management5 Allocation and de-allocation of memory. Memory segment is allocated when: –FORK or EXEC is executed Memory segment is de-allocated when: – a process terminates –EXEC is successful after the FORK; I.e.memory allocated to the FORK is released.

6 MInix memory management6 Amount of memory allocated. Memory manager allocates the amount of main memory specified in the file’s header. For files using separate I and D space, only enough memory for stack and data is allocated during a FORK call. (The child’s and parent’s text memory is shared.)

7 MInix memory management7 Program stored on the disk. The executable file stored on the disk consists of the following components: Symbols table (used for debugging) Data Text Header

8 MInix memory management8 Program stored in main memory. The executable file stored in main memory consists of the following components: Stack Gap (for stack and data to grow) Data + bss Text

9 MInix memory management9 The file header. The file header contains the information about sizes of all components of the executable file (data+bss, text and stack) It contains a bit indicating whether I and D are separate or not. The total field of the header specifies the total amount of memory allocated to the process.

10 MInix memory management10 Changing the value of total. If the programmer knows that the total memory needed for the combined growth of the data and stack segments for the file a.out is at most 10K, he/she can give a command: $ chmem 10240 a.out

11 MInix memory management11 BRK and SBRK system calls. BRK and SBRK change the boundary between data and stack. char* addr1; char* addr2; int brkResult; addr1 = sbrk(0); printf("Current break: %#x\n", addr1); brkResult = brk(addr1 + 4096);

12 MInix memory management12 Messages. Memory manager is message driven. It awaits messages and takes actions upon receiving messages. The following message types are received by MM: –FORK, EXIT, WAIT, WAITPID, BRK –KILL, ALARM, SIGACTION –GETUID, GETPID, SETUID, SETGID

13 MInix memory management13 Data Structures. The MM has two main data structures: –process table and hole table MM process table is defined in: –usr/src/mm/mproc.h (line 16300) – the most important field is the array mp_seg, which has three entries for text, data and stack. –each entry is a structure that defines the virtual address, physical address, and the length of the segment.

14 MInix memory management14 Review mproc structure. What are other fields in it and what is their meaning?

15 MInix memory management15 Clicks. Memory is allocated using memory clicks. The size of a memory click is implementation dependent and in standard MINIX is 256 bytes. WHY?

16 MInix memory management16 Hole Table. Hole table is defined in src/mm/alloc.c #define NR_HOLES 128/* max # entries in hole table */ #define NIL_HOLE (struct hole *) 0 PRIVATE struct hole { phys_clicks h_base;/* where does the hole begin? */ phys_clicks h_len;/* how big is the hole? */ int h_free_mark; struct hole *h_next;/* pointer to next entry on the list */ } hole[NR_HOLES];

17 MInix memory management17 Operation of the Hole List The hole list is searched using first fit. The segment is allocated by reducing the hole size by the amount of memory allocated to the process. When a process is terminated, the memory segment used by it is placed back on the hole list. Adjacent holes are merged to create a single hole.

18 MInix memory management18 FORK’s algorithm. FORK creates a process by executing the following steps: –check to see if process table is full –allocate memory for the child’s process –copy parent’s data+stack and text to child’s memory –find a free process slot and copy parent’s slot to it. –enter child’s memory map in process table –choose pid for the child –tell kernel and file system about the child –report child’s memory map to the kernel –send reply messages to parent and child

19 MInix memory management19 What is a zombie state of a process and when does it happen?

20 MInix memory management20 EXEC’s algorithm. EXEC is the most complex system call in MINIX. Here are the steps of EXEC: –check to see if the file is executable. –read the header to get the segment and the total sizes –fetch the arguments and environment from the caller –allocate new memory and release the unneeded memory –copy stack, data and text segments to the new memory image –check for and handle setuid, setgid bits –fix up process table entry –tell kernel that process is now runnable

21 MInix memory management21 Allocating memory for EXEC. The hole table is searched to find a hole that is big enough to hold a new process. The old memory image (created by FORK) is not released until after a hole big enough to hold a new process is found. This approach is overly strict. WHY?

22 MInix memory management22 Possible Improvement of EXEC Current strict approach can be improved by checking if enough of memory will be available after the amount allocated by FORK is released. This is your requirement for project 5.

23 MInix memory management23 Project 5 hints - MINIX source code usr/sys/mm/proto.h –If you plan do add functions to the MM module, you need to prototype the usr/sys/mm/proto.h usr/src/mm/exec.c –The new_mem function, which is called by do_exec, contains the logic that determines if the new process can fit in memory.

24 MInix memory management24 usr/src/mm/alloc.c –Structure hole, array hole, hole_head pointer and free_slots pointer are defined here. –Function free_mem called by new_mem is defined here. This function returns a block of free memory to the hole list. –Function merge is called by free_mem and it merges two adjacent holes into one.

25 MInix memory management25 Project 5 hints -memcpy Memcpy is a function that allows to perform a quick copy of parts of main memory –e.g : you can copy contents of array old_array to array new_array using the following syntax: memcpy(new_array, old_array, sizeof(old_array))

26 MInix memory management26 Project 5 hints -chmem In order to test if your MM module does better job than the current Minix MM you may choose to use command chmem which changes the size of the data and stack segment in an executable file and show that exec that failed before does not fail with new MM running E.G. –chmem +3145728 myshell


Download ppt "MInix memory management1 Minix Memory Management. Contiguous memory management. No swapping. A list of holes sorted in memory address order is maintained."

Similar presentations


Ads by Google