aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fifo.py5
-rw-r--r--lru.py21
-rw-r--r--mem.py4
-rw-r--r--myMemory.12
-rwxr-xr-xmyMemory.py5
-rw-r--r--pageexception.py10
-rw-r--r--randomp.py6
-rw-r--r--readme.md4
-rw-r--r--secondchance.py7
9 files changed, 36 insertions, 28 deletions
diff --git a/fifo.py b/fifo.py
index c48629f..1881870 100644
--- a/fifo.py
+++ b/fifo.py
@@ -1,7 +1,7 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2 2
3# UPEM / Programmation système / Projet : Simulation de gestion de mémoire virtuelle 3# UPEM / System programming / Project: Memory paging simulator
4# Pacien TRAN-GIRARD et Adam NAILI 4# Pacien TRAN-GIRARD, Adam NAILI
5 5
6from mem import Memory 6from mem import Memory
7from pageexception import * 7from pageexception import *
@@ -24,4 +24,3 @@ class FifoPaginator:
24 if page in self.mem.virt: self.mem.remove_virt(page) 24 if page in self.mem.virt: self.mem.remove_virt(page)
25 overwritten = self._put_main(page) 25 overwritten = self._put_main(page)
26 if overwritten is not None: self.mem.put_virt(overwritten) 26 if overwritten is not None: self.mem.put_virt(overwritten)
27
diff --git a/lru.py b/lru.py
index 3042bba..53b122a 100644
--- a/lru.py
+++ b/lru.py
@@ -1,15 +1,19 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2 2
3# UPEM / System programming / Project: Memory paging simulator
4# Pacien TRAN-GIRARD, Adam NAILI
5
3from mem import Memory 6from mem import Memory
4from pageexception import * 7from pageexception import *
5 8
9
6class LruPaginator: 10class LruPaginator:
7 def __init__(self, mem): 11 def __init__(self, mem):
8 self.mem = mem 12 self.mem = mem
9 self._global_counter = 1 13 self._global_counter = 1
10 self._check_table = [0 for _ in range(len(mem.main)+len(mem.virt))] 14 self._check_table = [0 for _ in range(len(mem.main) + len(mem.virt))]
11 self._main_cursor = 0 15 self._main_cursor = 0
12 16
13 def _update_check_table(self, page): 17 def _update_check_table(self, page):
14 """ 18 """
15 >>> lru = LruPaginator(Memory(3,5)) 19 >>> lru = LruPaginator(Memory(3,5))
@@ -25,11 +29,11 @@ class LruPaginator:
25 29
26 def _check_where_to_replace(self): 30 def _check_where_to_replace(self):
27 """ 31 """
28 >>> lru = LruPaginator(Memory(3,5)) 32 >>> lru = LruPaginator(Memory(3, 5))
29 >>> lru._check_where_to_replace() 33 >>> lru._check_where_to_replace()
30 >>> print(lru._main_cursor) 34 >>> print(lru._main_cursor)
31 0 35 0
32 >>> lru.mem.main = [3,4,2] 36 >>> lru.mem.main = [3, 4, 2]
33 >>> lru._check_table = [1, 3, 6, 4, 5, 0, 0, 0] 37 >>> lru._check_table = [1, 3, 6, 4, 5, 0, 0, 0]
34 >>> lru._check_where_to_replace() 38 >>> lru._check_where_to_replace()
35 >>> print(lru._main_cursor) 39 >>> print(lru._main_cursor)
@@ -39,8 +43,10 @@ class LruPaginator:
39 if page is None: 43 if page is None:
40 self._main_cursor = self.mem.main.index(page) 44 self._main_cursor = self.mem.main.index(page)
41 return 45 return
46
42 min = self._check_table[self.mem.main[0]] 47 min = self._check_table[self.mem.main[0]]
43 self._main_cursor = 0 48 self._main_cursor = 0
49
44 for page in self.mem.main: 50 for page in self.mem.main:
45 if min > self._check_table[page]: 51 if min > self._check_table[page]:
46 min = self._check_table[page] 52 min = self._check_table[page]
@@ -54,13 +60,14 @@ class LruPaginator:
54 overwritten = self.mem.main[self._main_cursor] 60 overwritten = self.mem.main[self._main_cursor]
55 self.mem.main[self._main_cursor] = page 61 self.mem.main[self._main_cursor] = page
56 self._update_check_table(page) 62 self._update_check_table(page)
57 return overwritten 63 return overwritten
58 64
59 def load(self, page): 65 def load(self, page):
60 if not self.mem.page_in_range(page): raise PageException 66 if not self.mem.page_in_range(page): raise PageException
61 if page in self.mem.main: 67 if page in self.mem.main:
62 self._update_check_table(page) 68 self._update_check_table(page)
63 return 69 return
70
64 if page in self.mem.virt: self.mem.remove_virt(page) 71 if page in self.mem.virt: self.mem.remove_virt(page)
65 overwritten = self._put_main(page) 72 overwritten = self._put_main(page)
66 if overwritten is not None: self.mem.put_virt(overwritten) 73 if overwritten is not None: self.mem.put_virt(overwritten)
diff --git a/mem.py b/mem.py
index c83d69d..cc42eaf 100644
--- a/mem.py
+++ b/mem.py
@@ -1,7 +1,7 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2 2
3# UPEM / Programmation système / Projet : Simulation de gestion de mémoire virtuelle 3# UPEM / System programming / Project: Memory paging simulator
4# Pacien TRAN-GIRARD et Adam NAILI 4# Pacien TRAN-GIRARD, Adam NAILI
5 5
6 6
7class Memory: 7class Memory:
diff --git a/myMemory.1 b/myMemory.1
index 7ca425a..4de19ab 100644
--- a/myMemory.1
+++ b/myMemory.1
@@ -25,7 +25,7 @@ Selects and replaces a page randomly.
25.IP secondchance 25.IP secondchance
26"Second chance" strategy similar to FIFO, but avoiding swapping out pages requested twice while they are in the main memory. 26"Second chance" strategy similar to FIFO, but avoiding swapping out pages requested twice while they are in the main memory.
27.SH COMMANDS 27.SH COMMANDS
28The following commands can be used to interact with the simulator: 28The following commands can be used to interact with the simulator:
29.IP "A number" 29.IP "A number"
30Requests a page to be loaded in the main memory. 30Requests a page to be loaded in the main memory.
31.IP `p` 31.IP `p`
diff --git a/myMemory.py b/myMemory.py
index f3da2a0..02f6dbe 100755
--- a/myMemory.py
+++ b/myMemory.py
@@ -1,7 +1,7 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2 2
3# UPEM / Programmation système / Projet : Simulation de gestion de mémoire virtuelle 3# UPEM / System programming / Project: Memory paging simulator
4# Pacien TRAN-GIRARD et Adam NAILI 4# Pacien TRAN-GIRARD, Adam NAILI
5 5
6from mem import Memory 6from mem import Memory
7from pageexception import * 7from pageexception import *
@@ -52,4 +52,3 @@ if __name__ == '__main__':
52 args = argparser.parse_args() 52 args = argparser.parse_args()
53 assert args.mem_size < args.virtual_size 53 assert args.mem_size < args.virtual_size
54 main(args.mem_size, args.virtual_size, paginators[args.algorithm]) 54 main(args.mem_size, args.virtual_size, paginators[args.algorithm])
55
diff --git a/pageexception.py b/pageexception.py
index 9a1519d..8c95b95 100644
--- a/pageexception.py
+++ b/pageexception.py
@@ -1,3 +1,9 @@
1#!/usr/bin/env python3
2
3# UPEM / System programming / Project: Memory paging simulator
4# Pacien TRAN-GIRARD, Adam NAILI
5
6
1class PageException(Exception): 7class PageException(Exception):
2 def __init__(self): 8 def __init__(self):
3 super().__init__() 9 super().__init__()
diff --git a/randomp.py b/randomp.py
index 48e9abf..065b679 100644
--- a/randomp.py
+++ b/randomp.py
@@ -1,12 +1,13 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2 2
3# UPEM / Programmation système / Projet : Simulation de gestion de mémoire virtuelle
4# Pacien TRAN-GIRARD et Adam NAILI
5 3
6from random import randint 4from random import randint
7from mem import Memory 5from mem import Memory
8from pageexception import PageException 6from pageexception import PageException
9 7
8# UPEM / System programming / Project: Memory paging simulator
9# Pacien TRAN-GIRARD, Adam NAILI
10
10 11
11class RandomPaginator: 12class RandomPaginator:
12 def __init__(self, mem): 13 def __init__(self, mem):
@@ -32,4 +33,3 @@ class RandomPaginator:
32 if page in self.mem.virt: self.mem.remove_virt(page) 33 if page in self.mem.virt: self.mem.remove_virt(page)
33 overwritten = self._put_main(page) 34 overwritten = self._put_main(page)
34 if overwritten is not None: self.mem.put_virt(overwritten) 35 if overwritten is not None: self.mem.put_virt(overwritten)
35
diff --git a/readme.md b/readme.md
index b3c218f..60d19cb 100644
--- a/readme.md
+++ b/readme.md
@@ -1,5 +1,4 @@
1# UPEM / Programmation système / Projet : Simulation de gestion de mémoire virtuelle 1# UPEM / System programming / Project: Memory paging simulator
2
3 2
4## Usage 3## Usage
5 4
@@ -16,4 +15,3 @@
16## License 15## License
17 16
18Project distributed under the terms of the Creative Commons BY-NC-SA 3.0 license. 17Project distributed under the terms of the Creative Commons BY-NC-SA 3.0 license.
19
diff --git a/secondchance.py b/secondchance.py
index b0fb1f9..d6617de 100644
--- a/secondchance.py
+++ b/secondchance.py
@@ -1,7 +1,7 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2 2
3# UPEM / Programmation système / Projet : Simulation de gestion de mémoire virtuelle 3# UPEM / System programming / Project: Memory paging simulator
4# Pacien TRAN-GIRARD et Adam NAILI 4# Pacien TRAN-GIRARD, Adam NAILI
5 5
6from mem import Memory 6from mem import Memory
7from pageexception import * 7from pageexception import *
@@ -25,10 +25,9 @@ class SecondChancePaginator:
25 25
26 def load(self, page): 26 def load(self, page):
27 if not self.mem.page_in_range(page): raise PageException 27 if not self.mem.page_in_range(page): raise PageException
28 if page in self.mem.main: 28 if page in self.mem.main:
29 self._check_table[page] = 1 29 self._check_table[page] = 1
30 return 30 return
31 if page in self.mem.virt: self.mem.remove_virt(page) 31 if page in self.mem.virt: self.mem.remove_virt(page)
32 overwritten = self._put_main(page) 32 overwritten = self._put_main(page)
33 if overwritten is not None: self.mem.put_virt(overwritten) 33 if overwritten is not None: self.mem.put_virt(overwritten)
34