Minix Memory Management. - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Minix Memory Management.

Description:

Minix Memory Management. Contiguous memory management. No swapping. A list of holes sorted in memory address order is maintained. Memory Allocation. – PowerPoint PPT presentation

Number of Views:180
Avg rating:3.0/5.0
Slides: 27
Provided by: DorotaH
Category:

less

Transcript and Presenter's Notes

Title: Minix Memory Management.


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

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.

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

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?

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.

6
Amount of memory allocated.
  • Memory manager allocates the amount of main
    memory specified in the files header.
  • For files using separate I and D space, only
    enough memory for stack and data is allocated
    during a FORK call. (The childs and parents
    text memory is shared.)

7
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
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
The file header.
  • The file header contains the information about
    sizes of all components of the executable file
    (databss, 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
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
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
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
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
  • Review mproc structure. What are other fields in
    it and what is their meaning?

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?

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 /
  • holeNR_HOLES

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.

18
FORKs algorithm.
  • FORK creates a process by executing the following
    steps
  • check to see if process table is full
  • allocate memory for the childs process
  • copy parents datastack and text to childs
    memory
  • find a free process slot and copy parents slot
    to it.
  • enter childs memory map in process table
  • choose pid for the child
  • tell kernel and file system about the child
  • report childs memory map to the kernel
  • send reply messages to parent and child

19
  • What is a zombie state of a process and when
    does it happen?

20
EXECs 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
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
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
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
  • 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
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
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
Write a Comment
User Comments (0)
About PowerShow.com