Memory Management in XINU - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Memory Management in XINU

Description:

1) Only create() and kill() call getstk() and freestk() respectively. ... 2) The free list has a block which is exactly the same size. as the request. ... – PowerPoint PPT presentation

Number of Views:92
Avg rating:3.0/5.0
Slides: 13
Provided by: aaronr6
Category:

less

Transcript and Presenter's Notes

Title: Memory Management in XINU


1
Memory Management in XINU
  • CS454/554

2
Memory Management in XINU Requirements in
XINU - Program text, global data must remain
resident in main memory at all times. -
Stack space, heap space is allocated
dynamically. getmem() - allocates memory
starting at the lowest possible address
in the free space. getstk() - allocates memory
starting at the highest possible address in
the free space.
3
0
text
Program text
data
Global variables
bss
bss block started by symbol untrained
variable
heap
stack
max addr
4
freemem(addr, size) - lowest address of the
memory is expected. freestk(addr, size) -
highest address of the memory is
expected. Note 1) Only create() and kill() call
getstk() and freestk() respectively. This is
a guarantee that the stack space allocated to a
process will always be released when a
process exits. 2) getmem() and freemem() are
called by user processes directly. The system
does not keep record of such allocations. It is
the users responsibility to release storage
used for heap variables before the process
exits.
5
Implementation of XINU memory management Freelist
- blocks of free memory that are linked
together - ordered by increasing addresses
- global variable memlist points to the
first free block - while on the freelist,
each block contains a pointer to the next
free block, and the size of the current
block Structure used to define the free
block struct mblock struct mblock
mnext unsigned long int mlen
6
memlist is also declared to have the same
structure as a freeblock.
memlist
mnext
mnext
mlen
len
not free
mnext
mlen
7
freestk() is implemented by using
freemem() freestk(p, len) -gt freemem(struct
mblock x,(unsigned) (len)) where x
(unsigned)p - (unsigned)(roundew(len))
(unsigned) sizeof(int) roundew - round up to
the next even word getmem(nbytes) -
searches the freelist to find the first block of
memory large enough to satisfy the
request. (first-fit) - uses two pointers p,
q where p points to a block of suitable
size and q points to its predecessor.
8
if (size of free block size of request) then
delete block from the freelist and return its
address else partition off a piece of size n
bytes, link the remainder block on the
freelist leftover points to a piece that must
be returned to the freelist
9
mnext
memlist
qp p p-gtmnext
mlen
q
mnext
fitsq q fits p
mlen
p
mnext
mlen
10
Three cases for getstk() 1) The free list does
not have a large enough block, SYSERR is
returned. 2) The free list has a block which is
exactly the same size as the request. 3)
The free list has a block which is greater than
the size of the request.
11
freemem(block, size) if(q ! memlist
topblock) q-gtmlen size else block-gtmlen
size block-gtmnext p q-gtmnext block q
block if(addptr ((char)q, q-gtmlen)
p) q-gtmlen p-gtmlen p-gtmnext p-gtmnext
1
2
3
12
If the block of memory to be freed is in the
middle of the free area then part 2 of freemem()
does the work. If the block of memory to be
freed is at the top of the free area then part 1
of freemem() does the work. If the block of
memory to be freed is at the bottom of the free
area then part 2 3 of freemem() does the
work. If the block of memory to be freed takes
up all of the free area then part 1 3 of
freemem() does the work.
Write a Comment
User Comments (0)
About PowerShow.com