-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakeSSD.py
More file actions
52 lines (43 loc) · 1.98 KB
/
MakeSSD.py
File metadata and controls
52 lines (43 loc) · 1.98 KB
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
# Inputs:
# num_partitions
# main_blocks_per_partition
# num_overprovisioned_erase_blocks
# static vs. dynamic allocation
# Outputs:
# SSD
def make_SSD(num_partitions, main_blocks_per_partition, num_overprovisioned_erase_blocks, is_static):
'''(int, int, float, bool) -> list of lists of lists
Creates nested lists to simulate the structure of an SSD. Takes the number of partitions, the number of main erase blocks per partition,
the total number of overprovisioned erase blocks, and a bool indicating whether overprovisioned erase blocks should be allocated statically.
If static provisioning, divides overprovisioned blocks by partitions, rounds up to integer, and adds that number of lists to each partition.
If dynamic, rounds number of overprovisioned erase blocks up to nearest integer and stores all overprovisioned blocks in separate list.
e.g.
>>>make_SSD(3, 4, 3.0, True)
[[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []]]
>>>make_SSD(3, 4, 3.0, False)
[[[], [], [], []], [[], [], [], []], [[], [], [], []], [[], [], []]
'''
SSD = []
# if it's static allocation, we add eraseblocks into the partitions
blocks_per_partition = main_blocks_per_partition
if is_static:
blocks_per_partition += int(-(-num_overprovisioned_erase_blocks // num_partitions))
i = 0
while i < num_partitions:
j = 0
partition = []
while j < blocks_per_partition:
partition.append([])
j += 1
SSD.append(partition)
i += 1
# if it's dynamic allocation, we put the overprovisioned blocks in an extra partition at the end
if not is_static:
num_overprovisioned_erase_blocks = int(-(-num_overprovisioned_erase_blocks // 1)) # rounds up to nearest int
j = 0
op_partition = []
while j < num_overprovisioned_erase_blocks:
op_partition.append([])
j += 1
SSD.append(op_partition)
return SSD