

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The instructions for a lab exercise on memory management in a paging system. The exercise involves simulating the allocation and deallocation of memory blocks in a paged memory system using shared memory mechanisms provided in linux. The student is required to write two programs, one for the parent process and another for the child processes, to manage the memory block table and page table mapping. The output should show the memory block status and the events of memory allocation and deallocation.
Typology: Lab Reports
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Proper management of memory in a paging system relies on proper maintenance of the memory block table, which records the number of free memory blocks and the allocation status of these blocks. This lab exercise simulates the allocation and deallocation of memory blocks in a paged memory system. To complete this project you will need to use ipc mechanisms provided on linux, including shmget, shmctl, shmop, and all others that you have used in previous lab exercises. To help you learn about these systems calls, two sample programs named shmp.cpp and shmc.cpp are provided for your reference. To understand this shared memory mechanism please reference manual pages for shmget, shmctl, shmop. Assume that there are a total of 50 memory blocks available to user processes. Initially all blocks are free. A memory block table is used to keep track of the status of these memory blocks. Before a user process can begin its execution, the kernel must first determine the number of memory blocks the process needs, create a page table, acquire all the memory blocks for the user process, and record the page-to-memory block mapping in the process’ page table before the user process is initiated. Since the memory block table may be accessed by a number of processes at a time, its access must therefore be guarded via a mutual exclusion semaphore. A counting semaphore may be used to keep track of the number of remaining free blocks. Blocks allocated to a process need not be contiguous. For this project you will need to write two programs. One program serves as the parent process that starts by creating and initializing the shared memory block table as well as the required semaphores. It should then create a number of identical child processes each to perform the task as outlined below. Use a loop in the parent process to control the child process creation. The number of child processes to be created is supplied by user in the command line, and a pause between 0 and 4 (number to be generated randomly) seconds will take place between each two consecutive loop iterations. And then finally the parent process should remove the shared memory block table and the semaphores that it has created when all of its child processes have terminated. Logic of child process: Generate an integer random number n between 5 and 25 (inclusive); Allocate space big enough for a page table of size n; Attach to the shared memory block table. P(n_free, n); // n_free is a counting semaphore. This P operation attempts to decrement n_free by n. P(mutex); // mutex is a mutual exclusion semaphore to guard the execution of the following critical section. Update memory block table and record the block numbers of the n allocated blocks in the process’ page table; V(mutex); Detach from the shared memory block table; Sleep for a random number of seconds; // simulates the execution of the user process Attach to the shared memory block table; P(mutex); Update memory block table as a result of the memory release; V(mutex); V(n_free,n); // this V operation increments n_free by n & wakeup a waiting process, if any Detach from the shared memory block table; Release the space used for the page table; Suggestion for output: Sufficient output must be generated to allow the tracing of all activities. Specifically, a line of output in the format as shown below for every event that occurs should be useful for tracing: PID Event ( 50 bits representing the status of the 50 memory blocks, if event that causes status change ) where the output fields are defined as follows: PID shows the process ID of the process that causes the event to occur. Event is any one of the following list of relevant events: REQ n : a process requests for n memory blocks ALL n : a process is allocated n memory blocks REL n : a process releases n memory blocks
Sample output: PID Event Memory Block Status ( 1 = in use, 0 = free ) 0123456789 0123456789 0123456789 0123456789 0123456789 <- Block#s 0000000000 0000000000 0000000000 0000000000 0000000000 <- Initially 6213 REQ 25 6213 ALL 25 1111111111 1111111111 1111100000 0000000000 0000000000 6214 REQ 17 6214 ALL 12 1111111111 1111111111 1111111111 1111111111 1100000000 6215 REQ 10 1111111111 1111111111 1111111111 1111111111 1100000000 6213 REL 25 0000000000 0000000000 0000011111 1111111111 1100000000 6215 ALL 10 1100000000 0000000000 0000011111 1111111111 1111111111
... ... The above output shows the history of three processes in terms of their memory allocations. It begins with process 6213 requesting for 25 blocks of memory, followed by the same process being allocated the requested number of blocks (blocks 0-24 as shown in the memory block status). Then process 6214 requests for 22 blocks and is allocated blocks 25- afterward. After that, process 6215’s request for 10 blocks cannot be satisfied due to insufficient memory, until process 6213 releases its 25 blocks it was allocated. Note that these output lines will be generated by multiple concurrent processes. Therefore, the use of the standard output device (the monitor) should be properly controlled. Do the following for this assignment: