Title: ECS150 Discussion
1ECS150 Discussion
2Announcement
- Written Homework is assigned
- Program 2 is assigned (Team work)
- Due date 12/10/2004 at 5pm
- Signup sheet for HW1 will be posted in the
basement outside the TA room after the discussion
3MM in Minix - Overview
User Process
User Process
User Process
Init
. . . . . .
User Space
Policy
Memory Manager
File System
Terminal Task
Disk task
Clock Task
System Task
. . . . . .
Kernel Space
Process management
Mechanism
4MM in Minix
Original Memory Allocation
Now A is forking a child id fork()
B
Search the hole list
A
MINIX
5MM in Minix
As Child
After a FORK system call
B
B
Find the piece that is Big enough
A
A
Equal size initially
MINIX
6MM in Minix
C
As Child
B
B
B
A
A
A
MINIX
MINIX
MINIX
After the child does an EXEC
7MM in Minix
Remains same place till termination No swapped
out Never moved to another place No grow in the
allocated area No shrink in the allocated area
C
B
A
MINIX
8MM in Minix
After Process C terminates
C
It gets de-allocated from the Memory
B
B
A
A
MINIX
MINIX
9Memory Layout
Higher Memory Address
Stack
Data
Text
Lower Memory Address
10Relationship
Stack
B
Data
A
Text
11Process Tables
Memory Mgmt
FS
Process Mgmt
Process A
Process A
Process A
K
One-to-one relationship
12Header Files in /usr/src/mm
13mproc
- Array mp_seg
- Struct for text
- Virtual address
- Physical address
- Length of the segment
- Struct for data
- Virtual address
- Physical address
- Length of the segment
- Struct for Stack
- Virtual address
- Physical address
- Length of the segment
14/usr/src/mm/mproc.h
/ This table has one slot per process. It
contains all the memory management information
for each process. Among other things, it defines
the text, data and stack segments, uids and
gids, and various flags. The kernel and file
systems have tables that are also indexed by
process, with the contents of corresponding
slots referring to the same process in all
three. / EXTERN struct mproc struct mem_map
mp_segNR_SEGS/ points to text, data, stack
/ char mp_exitstatus / storage for status when
process exits / char mp_sigstatus / storage
for signal for killed procs / pid_t mp_pid /
process id / pid_t mp_procgrp / pid of process
group (used for signals) / pid_t mp_wpid / pid
this process is waiting for / int mp_parent /
index of parent process / code omitted
... message mp_reply / reply message to be sent
to one / mprocNR_PROCS
15/usr/include/minix/const.h
define NR_SEGS 3 / segments per
process/ define T 0 /proci.mem_mapT
is for text/ define D 1 /proci.mem_mapD
is for data/ define S 2
/proci.mem_mapS is for stack/
16/usr/include/minix/type.h
ifndef _TYPE_H define _TYPE_H ifndef
_MINIX_TYPE_H define _MINIX_TYPE_H / Type
definitions. / typedef unsigned int vir_clicks
/ virtual addresses and lengths in clicks
/ typedef unsigned long phys_bytes/ physical
addresses and lengths in bytes / typedef
unsigned int phys_clicks/ physical addresses
and lengths in clicks / struct mem_map
vir_clicks mem_vir / virtual address
/ phys_clicks mem_phys / physical address
/ vir_clicks mem_len / length /
17Program Files in /usr/src/mm
18Program Files in /usr/src/mm
19Memory Allocation/usr/src/mm/alloc.c
define NR_HOLES 128 / max entries in hole
table / ... PRIVATE struct hole phys_clicks
h_base / where does the hole begin?
/ phys_clicks h_len / how big is the hole?
/ struct hole h_next / pointer to next entry
on the list / holeNR_HOLES ... PRIVATE
struct hole hole_head / pointer to first hole
/ /Function alloc_mem/ hp hole_head while(
hp ! NIL_HOLE ) ... prev_ptr hp hp
hp-gth_next
20Program 2 Overview
- Struct MemSeq memdump (int PID)
- Struct MemSeq
-
- int PID
- unsigned int addr_begin
- unsigned int addr_end
- struct MemSeq Next
-
- Return value
- if (PID ! 0)
- return the range of mem addr for PID process
- next NULL if PID is valid
- else
- return addr_begin and addr_end for ALL the user
process - next for the last user process should be NULL
21(No Transcript)
22Useful command
- Grep for pattern match
- Usage grep PATTERN FILE
- Example
- Search for the string mem_map in directory
/usr/src/kernel among all the files - grep mem_map
- Does not work hierarchicaly
- CAN NOT DO
- search for the string mem_map in diretory
- /usr/src/