-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory.h
119 lines (95 loc) · 2.7 KB
/
memory.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Simulates memory.
#include "intervaltree.h"
#include <stdbool.h>
#include <sys/queue.h>
#ifndef _MEMORY_
#define _MEMORY_
/*
- -
----------------------------------------------------------------------------------------------------------
- -
...|ppn,pnode,vpn,pid,vnode,overhead|ppn,pnode,vpn,pid,vnode,overhead|ppn,pnode,vpn,pid,vnode,overhead|...
- -
----------------------------------------------------------------------------------------------------------
- -
^*page
*/
typedef unsigned int* freelist_t;
// use a better name? unsigned long was appearing in too
// many places, it was getting quite long to type out
typedef unsigned long ul64;
typedef struct vpage_t {
// VIRTUAL page identified by <VPN, PID>
ul64 vpn; // virtual page number
ul64 pid; // process id
void* overhead; // for replacement policy
// page has a PHYSICAL location as well
bool inMemory;
ul64 currentPPN;
} VPage;
// Represents a page from memory, identified both by a pid, vpn pair and a ppn
// USE THIS AS VALUE IN TREES
typedef struct ppage_t {
ul64 ppn; // physical page number
SLIST_ENTRY(freelistnode_t) node;
VPage* virtualPage;
} PPage;
// allocated once we know the amount of pages (=pmem/pgsize)
/**
* Initialize Memory module.
* @param numberOfPhysicalPages amount of physical memory/page size
*/
void Memory_init(size_t numberOfPhysicalPages);
/**
* Accesses the physical page with a given ppn
* @param ppn index into memory
* @return PPage if present, NULL if not
*/
PPage* Memory_getPPage(ul64 ppn);
/**
* Accesses the virtual page with a given ppn
*/
VPage* Memory_getVPage(ul64 ppn);
/**
* Frees the page at a given ppn by sending the virtual page to backing store
*/
void Memory_evictPage(ul64 ppn);
/**
* Load a page in to memory
* @return none
*/
void Memory_loadPage(VPage* virtualPage, ul64 ppn);
/**
* @return the ppn of the next free page
*/
ul64 Memory_getFreePage();
/**
* @return true if there is a free page in memory
*/
bool Memory_hasFreePage();
/**
* @return the number of allocated pages, given by the allocated variable.
*/
int Memory_howManyAllocPages();
/**
* @return the size of memory in pages
*/
int Memory_getTotalSize();
/**
* Constructs a new Virtual Page given it's virtual identifier
* @param pid process id
* @param vpn virtual page number
* @param initOverhead function that returns pointer to overhead struct to store
* in vpage.
* Interface for initOverhead must match
* ```C
* Overhead* initOverhead(ul64 pid, ul64 vpn);
* ```
* @return pointer to new VPage struct.
*/
VPage* VPage_init(ul64 pid, ul64 vpn);
void VPage_free(VPage* vp);
// Page_destroy()
// replace(old page, new page)
// bool replace(PPage* old, PPage* new);
#endif