This repository has been archived by the owner on Dec 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMem.c
66 lines (61 loc) · 2.25 KB
/
Mem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "pagetable.h"
int virmem[200]; // 200 pages of virtual mem
int physmem[50]; // 50 frames of physical mem
/**
* Jobs require pages in the virtual mem, which gets
* loaded up in the physical mem which is of size 50.
* As the jobs are processed the virtual mem and
* physical mem get swapped out accorrdingly.
* Use a page table to track what is in and what is out
* of the memory
* Each page allocated for the Job must contain a string
* that concatenates the job numbers together for a
* total of 4digits, ie job 20 = 2020
*/
/**
* The physmem and virmem must reflect which algorithm
* is being used in the scheduling. Pages for the processed
* need not be continguious
* NOTE: Each frame contains one page...ie its a page frame
* Also assume that all pages required by all the processes
* area already full loaded in the 200 virtual mem space.
*/
// Should take the job and store it in the physical mem *valid for one job
void storemem(JobElement* list)
{
JobElement* Job = list;
PageTable Page;
int PageCount;
//*Assumming that no process requires all the memory allocations
while(list != NULL)
{
PageCount = Job-> numpage; // number of pages required by the job
// Dont care that the physicalmem is full
// physmem contains 50 frames
for(int k = 0, k < 50, k++)
{
if(physmem[k] == NULL) { // if there is an empty space
physmem[k] = Job->pages; // Place the Job page in here
PageCount--;
}
}
// after searching and filling an empty frame in the physicalmem
// and there is still more pages to be loaded for the job.
// Need to use the LRU algorithm to remove the pages from the mem.
// NOTE:The LRU places the removed algorithm into the virtual mem.
// and if theres not enough space in the virtual mem(200).
// perform an LRU in the virtual mem(200) to remove the
// pages from it.
if(PageCount != 0 ){
// LRU(physmem, PageCount); // Removes LRU pages, need PageCount just incase the first removal is not sufficient
qsort(table, 50, sizeof(frame),LRU); // sorts the physical mem with LRU at the start of the array
for(int k = 0, k <50, k++)
{
if(physmem[k] == NULL) {
physmem[k] = Job->pages;
PageCount--;
}
}
}
}
}