1 / 26

Minix Memory Management.

Minix Memory Management. Contiguous memory management. No swapping. A list of holes sorted in memory address order is maintained. Memory Allocation. Memory is allocated during: FORK and EXEC system calls.

silvio
Download Presentation

Minix Memory Management.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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. MInix memory management

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

  4. 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? MInix memory management

  5. 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. MInix memory management

  6. 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.) MInix memory management

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

  8. 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 MInix memory management

  9. 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. • Thetotal field of the header specifies the total amount of memory allocated to the process. MInix memory management

  10. 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 MInix memory management

  11. 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); MInix memory management

  12. 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 MInix memory management

  13. 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. MInix memory management

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

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

  16. 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]; MInix memory management

  17. 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. MInix memory management

  18. 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 MInix memory management

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

  20. 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 MInix memory management

  21. 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? MInix memory management

  22. 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. MInix memory management

  23. 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 iscalled by do_exec, contains the logic that determines if the new process can fit in memory. MInix memory management

  24. 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. MInix memory management

  25. 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)) MInix memory management

  26. 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 MInix memory management

More Related