Virtual Memory Simulation

Assignment 3

Dead Line 8 May 2011

Overall Goal of Assignment: To see searching, researching and development capabilities of students so as to see how they can handle challenging problems thrown to them.

1. Main Memory Allocation

Goal: To simulate and evaluate different memory allocation/deallocation techniques, first fit, next fit, best fit, and worst fit, when a linked list is used to keep track of memory usage.

Assume that the memory is 256 KB and is divided into units of 2 KB each. A process may request between 3 and 10 units of memory. Your simulation consists of three components: Memory component that implements a specific allocation/deallocation technique; request generation component that generates allocation/deallocation requests; and statistics reporting component that prints out the relevant statistics. The Memory component exports the following functions:

1. int allocate_mem (int process_id, int num_units): allocates num_units units of memory to a process whose id is process_id. If successful, it returns the number of nodes traversed in the linked list. Otherwise, it returns -1.

2. int deallocate_mem (int process_id): deallocates the memory allocated to the process whose id is process_id. It returns 1, if successful, otherwise –1.

3. int fragment_count( ): returns the number of holes (fragments of sizes 1 or 2 units).

You will implement a separate Memory component for each memory allocation/deallocation technique. The request generation component generates allocation and deallocation requests. For allocation requests, the component specifies the process id of the process for which memory is requested as well as the number of memory units being requested. For this simulation, assume that memory is requested for each process only once. For deallocation requests, the component specifies the process id of the process whose memory has to be deallocated. For this simulation, assume that the entire memory allocated to a process is deallocated on a deallocation equest. You may generate these requests based on some specific criteria, e.g. at random or from a memory allocation/deallocation trace obtained from some source.

There are three performance parameters that your simulation should calculate for all four techniques: average number of external fragments, average allocation time in terms of the average number of nodes traversed in allocation, and the percentage of times an allocation request is denied.

Generate 10,000 requests using the request generation component, and for each request, invoke the appropriate function of the Memory component for each of the memory allocation/deallocation technique. After every request, update the three performance parameters for each of the techniques.

The statistics reporting component prints the value of the three parameters for all four techniques at the end.

2. Virtual Memory Simulation

Goal: To simulate and evaluate a virtual memory system, and experiment with different page replacement algorithms. You will need a threads package, e.g. pThreads thread package.

Assume that you have a 16-bit address space, 16 KB of main memory, and 2 KB page size. Virtual memory simulation consists of three components: virtual address generation component, address translation component, and statistics reporting component. Implement each component by a separate thread.

The virtual address generation component generates a sequence of 16-bit virtual addresses and writes them in an integer buffer inBuffer of size 10. Write a function getNextVirtualAddress( ) for generating virtual addresses. This function may generate virtual addresses at random or based on a trace obtained from some source.

The address translation component implements virtual address to physical address translation using a page replacement algorithm. This component reads the next virtual address from inBuffer and translates that address to a physical address. It prints the virtual address and corresponding physical address in a file. It also increments an integer variable (numberOfPageFaults) on every page fault. Use appropriate bit operations (<<, >>, ~, |, &, etc.) to implement this address translation. Implement a separate version of this component for every page replacement algorithm you want to experiment with.

The statistics reporting component prints the total number of page faults

(numberOfPageFaults) at the end.

   Related Questions in Basic Computer Science

©TutorsGlobe All rights reserved 2022-2023.