2018-08-21 15:23:22 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2018-08-23 17:39:32 -04:00
|
|
|
from sys import argv
|
|
|
|
|
2018-08-21 15:23:22 -04:00
|
|
|
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,
|
2019-04-10 08:42:32 -04:00
|
|
|
10240, 12288, 14336, 16384,
|
|
|
|
20480, 24576, 28672, 32768,
|
2019-04-10 16:32:24 -04:00
|
|
|
40960, 49152, 57344, 65536,
|
|
|
|
81920, 98304, 114688, 131072,
|
2018-08-21 15:23:22 -04:00
|
|
|
]
|
|
|
|
|
2018-08-23 17:39:32 -04:00
|
|
|
size_class_slots = [
|
2018-08-23 17:53:10 -04:00
|
|
|
256, 128, 85, 64, 51, 42, 36, 64,
|
2018-08-23 17:42:17 -04:00
|
|
|
51, 64, 54, 64,
|
2018-08-23 17:39:32 -04:00
|
|
|
64, 64, 64, 64,
|
|
|
|
64, 64, 64, 64,
|
|
|
|
16, 16, 16, 16,
|
|
|
|
8, 8, 8, 8,
|
|
|
|
8, 8, 8, 8,
|
2019-04-10 08:42:32 -04:00
|
|
|
6, 5, 4, 4,
|
|
|
|
2, 2, 2, 2,
|
2019-04-10 16:32:24 -04:00
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
2018-08-23 17:39:32 -04:00
|
|
|
]
|
|
|
|
|
2018-11-03 04:40:13 -04:00
|
|
|
fragmentation = [100 - 1 / 16 * 100]
|
2018-08-23 17:29:42 -04:00
|
|
|
|
|
|
|
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
|
2018-08-26 06:21:09 -04:00
|
|
|
fragmentation.append(100 - used * 100);
|
2018-08-23 17:29:42 -04:00
|
|
|
|
2018-08-21 15:23:22 -04:00
|
|
|
def page_align(size):
|
|
|
|
return (size + 4095) & ~4095
|
|
|
|
|
2018-08-26 06:21:09 -04:00
|
|
|
print("| ", end="")
|
2018-11-03 05:44:49 -04:00
|
|
|
print("size class", "worst case internal fragmentation", "slab slots", "slab size", "internal fragmentation for slabs", sep=" | ", end=" |\n")
|
2018-08-26 06:21:09 -04:00
|
|
|
print("| ", end='')
|
|
|
|
print("-", "-", "-", "-", "-", sep=" | ", end=" |\n")
|
|
|
|
for size, slots, fragmentation in zip(size_classes, size_class_slots, fragmentation):
|
2018-08-23 17:39:32 -04:00
|
|
|
used = size * slots
|
|
|
|
real = page_align(used)
|
2018-08-26 06:21:09 -04:00
|
|
|
print("| ", end='')
|
2019-06-12 13:28:03 -04:00
|
|
|
print(size, f"{fragmentation:.4}%", slots, real, str(100 - used / real * 100) + "%", sep=" | ", end=" |\n")
|
2018-08-23 17:39:32 -04:00
|
|
|
|
|
|
|
if len(argv) < 2:
|
|
|
|
exit()
|
|
|
|
|
2018-08-21 15:23:22 -04:00
|
|
|
max_bits = 256
|
|
|
|
max_page_span = 16
|
|
|
|
|
2018-08-23 17:29:42 -04:00
|
|
|
print()
|
|
|
|
|
2018-08-21 15:23:22 -04:00
|
|
|
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)
|