Project: Main Memory Management - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Project: Main Memory Management

Description:

Right neighbor (easy): Use size of C ... represent each tag and size field as an unsigned integer (4 bytes) ... independent of block size and is distributed ... – PowerPoint PPT presentation

Number of Views:149
Avg rating:3.0/5.0
Slides: 23
Provided by: dc7
Category:

less

Transcript and Presenter's Notes

Title: Project: Main Memory Management


1
Project Main Memory Management
  • Textbook pages 492-495
  • ICS 145B
  • L. Bic

2
Assignment
  • Implement a main memory manager for variable size
    partitions using linked lists (section 7.2.2)
  • Compare different allocation strategies (section
    7.3) using simulation

3
Variable Partitions -- review
  • Memory not partitioned a priori
  • Each request is allocated portion of free space
  • Memory Sequence of variable-size blocks
  • Some are occupied, some are free (holes)
  • External fragmentation occurs
  • Adjacent holes (right, left, or both) must be
    coalesced to prevent increasing fragmentation

Figure 7-6
4
Linked List Implementation 1
  • Type/Size tags at the start of each Block
  • Holes (must be sorted by physical
    address)contain links to predecessor hole and to
    next hole
  • Checking neighbors of released block, e.g C
    below
  • Right neighbor (easy) Use size of C
  • Left neighbor (clever) Use sizes to find first
    hole to Cs right, follow its predecessor link to
    first hole on Cs left, and check if it is
    adjacent to C.

Figure 7-7a
5
Linked List Implementation 2
  • Better solution Replicate tags at end of blocks
  • Checking neighbors of released block C
  • Right neighbor Use size of C as before
  • Left neighbor Check its (adjacent) type/size
    tags
  • Holes do not need to be sorted in memory
  • A new hole is simply appended to the head or tail
    of the list

Figure 7-7b
6
Allocation Strategies
  • Problem Given a request for n bytes, find hole
    n
  • Constraints
  • Maximize memory utilization (minimize external
    fragmentation)
  • Minimize search time
  • Search Strategies (section 7.3)
  • First-fit Always start at same place. Simplest.
  • Next-fit Resume search. Improves distribution
    of holes.
  • Best-fit Closest fit. Avoid breaking up large
    holes.
  • Worst-fit Largest fit. Avoid leaving tiny hole
    fragments

7
Simulated Main Memory
  • define a character array of size mem_size
  • char mmmem_size
  • each character represents one byte of memory
  • represent each tag and size field as an unsigned
    integer (4 bytes)
  • use type casting to read/write integers into mm
  • holes may be linked using either
  • actual pointers (8 bytes)
  • integers (4 bytes) as indices into array mm
  • use type casting to read/write int/ptr into mm

8
The User Interface
  • int mm_init (int mem_size)
  • initialize character array mm to be a single hole
  • int mm_request(int n)
  • analogous to function malloc()
  • request a block of n consecutive bytes
  • return pointer to first usable byte (or mm index
    of first usable byte)
  • int mm_release(void p)
  • analogous to function free()
  • releases a previously requested block back to mm

9
The Simulation Experiment
  • invoke driver, which
  • generates streams of requests and releases using
    parameters
  • repeatedly invokes request/release functions
  • gather statistics in files for each request
  • repeat for different parameters and different
    allocation strategies
  • analyze, plot, describe results

10
The Simulation Experiment
  • what to vary
  • average request size n
  • distribution of request size
  • what to measure
  • average memory utilization
  • average search time

11
The Simulation Experiment
  • assume steady state
  • assume an unbounded queue of requests
  • the following behavior repeats
  • memory manager satisfies requests until no hole
    large enough exists
  • this is where search time is measured
  • memory does not change until next release
  • this is the period during which memory
    utilization is measured
  • memory manager processes release

12
Outline of Driver
  • start in a steady state (memory already has full
    blocks and holes)
  • for (i0 iltsim_step i)
  • do
  • get size n of next request
  • mm_request(n)
  • while (request successful)
  • record memory utilization
  • select block p to be released
  • mm_release(p)

13
Driver Details
  • get size of next request
  • assume Gaussian distribution
  • generate each new request size using
  • n gauss(a, d)
  • a is the average request size
  • d is the standard deviation
  • discard values outside of valid memory sizes
  • a and d are the input parameters to be varied

14
Outline of Driver
  • start in a steady state (memory already has full
    blocks and holes)
  • for (i0 iltsim_step i)
  • do
  • get size n of next request
  • mm_request(n)
  • while (request successful)
  • record memory utilization
  • select block p to be released
  • mm_release(p)

15
Driver Details
  • select block to release
  • assume memory resident time is independent of
    block size and is distributed uniformly
  • select a block at random
  • how driver must keep track of all allocated
    blocks
  • use a linked list
  • determine number of list elements k
  • choose a random number p between 1 and k
  • release block recorded at position p of list

16
Outline of Driver
  • start in a steady state (memory already has full
    blocks and holes)
  • for (i0 iltsim_step i)
  • do
  • get size n of next request
  • mm_request(n)
  • while (request successful)
  • record memory utilization
  • select block p to be released
  • mm_release(p)

17
Driver Details
  • memory utilization
  • fraction of used memory
  • determine at each iteration
  • fraction of used memory add up block sizes,
    divide by total memory size (include tags in
    size?)
  • ratio holes/blocks count holes and blocks
    (groups only)
  • compute averages
  • does 50-rule hold? does formula for computing f
    hold? (pg. 223, groups only)
  • average search time
  • instrument mm_request() to count holes examined

18
Driver Details
  • Outline of experiment
  • choose a and d
  • run simulator (driver) with one strategy s1
    (sim_step times)
  • output average memory utilization us1 and average
    search time ss1
  • run simulator with another strategy s2 (sim_step
    times)
  • output average memory utilization us2 and average
    search time ss2
  • choose a different a
  • repeat steps 2-6
  • plot values of us1 and us2 against a (i.e., 2
    curves)
  • plot values of ss1 and ss2 against a (i.e., 2
    curves)
  • choose a different d and repeat steps 2-9 (with
    the same set of values of a)

19
Driver Details
  • starting in steady state
  • using the following loop, fill memory with
    random-size requests
  • do get size n of next request
  • mm_request(n)
  • while (request successful)
  • randomly choose 1/3 of all blocks and release
    them
  • repeat the above two steps several times

20
Summary of tasks
  • design and implement memory manager
  • mm_init, mm_request, mm_release functions
  • mm_request must support at least
  • two strategies if working alone
  • three strategies if in a group
  • design and implement driver
  • accept parameters (mem_size, a, d, strategy,
    sim_step)
  • run simulation experiment, store results in a
    file
  • determine under which conditions a given strategy
    performs better than another
  • vary one parameter each time
  • plot curves
  • interpret observations

21
Groups memory utilization
  • 50 rule (pages 221-223)
  • holes 0.5 p full_blocks
  • p probability of inexact match (remaining hole)
  • in practice p1, i.e., 1/3 of memory are holes
  • Test if holes is 50 of full_blocks)
  • but how much memory is wasted
  • (hole size ? block size)

22
Groups memory utilization
  • what is the unused fraction of space?
  • utilization depends on khole_size/block_size
  • unused_memory k/(k2)
  • intuition
  • k?? unused memory?1 (100 empty)
  • k1 unused memory?1/3 (50 rule)
  • k?0 unused memory?0 (100 full)
  • what determines k?
  • block size n relative to total memory size M
  • determined experimentally for example
  • n ? M/10 k0.22 f?0.1 ? less than 1/3 of
    memory wasted
  • n M/3 k2 f?0.5 ? more than 1/3 of
    memory wasted
  • Verify these numbers
Write a Comment
User Comments (0)
About PowerShow.com