-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
calculate_waste.py
executable file
·81 lines (67 loc) · 2.08 KB
/
calculate_waste.py
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
#!/usr/bin/env python3
from sys import argv
size_classes = [
16, 32, 48, 64, 80, 96, 112, 128,
160, 192, 224, 256,
320, 384, 448, 512,
640, 768, 896, 1024,
1280, 1536, 1792, 2048,
2560, 3072, 3584, 4096,
5120, 6144, 7168, 8192,
10240, 12288, 14336, 16384,
20480, 24576, 28672, 32768,
40960, 49152, 57344, 65536,
81920, 98304, 114688, 131072,
]
size_class_slots = [
256, 128, 85, 64, 51, 42, 36, 64,
51, 64, 54, 64,
64, 64, 64, 64,
64, 64, 64, 64,
16, 16, 16, 16,
8, 8, 8, 8,
8, 8, 8, 8,
6, 5, 4, 4,
2, 2, 2, 2,
1, 1, 1, 1,
1, 1, 1, 1,
]
fragmentation = [100 - 1 / 16 * 100]
for i in range(len(size_classes) - 1):
size_class = size_classes[i + 1]
worst_case = size_classes[i] + 1
used = worst_case / size_class
fragmentation.append(100 - used * 100);
def page_align(size):
return (size + 4095) & ~4095
print("| ", end="")
print("size class", "worst case internal fragmentation", "slab slots", "slab size", "internal fragmentation for slabs", sep=" | ", end=" |\n")
print("| ", end='')
print("-", "-", "-", "-", "-", sep=" | ", end=" |\n")
for size, slots, fragmentation in zip(size_classes, size_class_slots, fragmentation):
used = size * slots
real = page_align(used)
print("| ", end='')
print(size, f"{fragmentation:.4}%", slots, real, str(100 - used / real * 100) + "%", sep=" | ", end=" |\n")
if len(argv) < 2:
exit()
max_bits = 256
max_page_span = 16
print()
print("maximum bitmap size is {}-bit".format(max_bits))
print("maximum page span size is {} ({})".format(max_page_span, max_page_span * 4096))
for size_class in size_classes:
choices = []
for bits in range(1, max_bits + 1):
used = size_class * bits
real = page_align(used)
if real > 65536:
continue
pages = real / 4096
efficiency = used / real * 100
choices.append((bits, used, real, pages, efficiency))
choices.sort(key=lambda x: x[4], reverse=True)
print()
print("size_class:", size_class)
for choice in choices[:10]:
print(choice)