>



Memory Manager



This module handles allocation and deallocation of memory pages. The memory free list entry denotes the number of processes using(sharing) the memory page. Unused pages are therefore indicated by 0 in the corresponding entry in memory free list.



Function Number Function Name Arguments Return Value
GET_FREE_PAGE = 1 Get Free Page NIL Free Page number
RELEASE_PAGE = 2 Release Page Page Number NIL
GET_FREE_BLOCK = 3 Get Free Block NIL Free Block Number or -1
RELEASE_BLOCK = 4 Release Block Block Number, PID NIL
GET_CODE_PAGE = 5 Get Code Page Block Number Page Number
GET_SWAP_BLOCK = 6 Get Swap Block NIL Block Number


Get Free Page

Description : Returns the page number of a free page.

      Increment WAIT_MEM_COUNT field in the System Status Table

      while ( memory is full ){   /* Check the MEM_FREE_COUNT in the System Status Table */
        
                Set state of the process as ( WAIT_MEM , ____);
                Call the switch_context() function from the Scheduler Module.
    	}

	// There is a free page available for use.
	Decrement the WAIT_MEM_COUNT field and decrement the MEM_FREE_COUNT field in the System Status Table.
    
	loop through entries in the Memory Free List{
	/* Available pages for user processes are from 76- 127. See Memory Organisation. */
        if ( a free entry is found ){
              Set the Memory Free List entry as 1;
              Return the corresponding page number;
        }
    }
Called by fork and exec system calls. Also called by exception handler on page fault.

Release Page

Description : Decrements the entry corresponding to page in memory free list.

    Decrement the entry corresponding to the page in the Memory Free List;

    If Mem Free List entry becomes 0, increment the MEM_FREE_COUNT field in the System Status Table
    
    loop through the process table{ 
      if (the process state is ( WAIT_MEM , _ ) ){
            Set state of process as (READY , _ )
        }
    }

    return;
Called by the Free page table and Free UArea Page functions.

Note : Do not clear the contents of the page. A page may be shared by multiple processes and a call to release may not make the page free.

Get Free Block

Description : Returns the block number of a free disk block. Returns -1 if disk is full.

    loop through entries in the Disk Free List from DISK_FREE_AREA to DISK_SWAP_AREA - 1{ 	/* User Block, not preallocated to the OS or swap area */
        if ( a free entry is found ){
              Set the Disk Free List entry as 1;
              Return the corresponding block number;
        }
    }
    return -1;

Release Block

Description : Decrements the entry corresponding to the disk block in the disk free list.

    Set the Disk Free List entry corresponding to the block to 0.
    
    return;

Get Code Page

Description : Loads a single code page to memory given the block number of the page in the disk. It takes the block number and PID as an argument.

	/* If the required code page is already loaded by some other process, we simply increment the share count in the Mem Free List */

	Loop though code page entries in the disk map table of all processes
		If (the block number in the Disk Map Table entry matches the 
		block to be loaded, and it's corresponding page table entry is set to VALID) {
			increment the share count of the page in the Mem Free List.
			return the physical page number
		}

	/* The code page is not in memory, and has to be loaded from disk */

	Get a free memory page by calling the get_free_page() function.
	Load the disk block into memory page by calling the disk_load() function in the Device Manager Module.
	Return the memory page number to which the code block has been loaded.


Get Swap Block

Description : Returns the block number of a free disk block in the swap area.

    loop through entries in the Disk Free List from DISK_SWAP_AREA to DISK_SIZE - 1{ 	/* swap area */
        if ( a free entry is found ){
              Set the Disk Free List entry as 1;
              Return the corresponding block number;
        }
    }
    return -1;