I love it for the MCP server try adding a physical weight, this helps a lot with mapping, it's what I use, seems to be alright. Write it couple weeks so far love it.
import math
import hashlib
import json
class NVMEMapper:
def __init__(self, capacity_gb=1024, channels=8, dies_per_channel=4, blocks_per_die=4096, pages_per_block=256):
self.capacity_gb = capacity_gb
self.channels = channels
self.dies_per_channel = dies_per_channel
self.blocks_per_die = blocks_per_die
self.pages_per_block = pages_per_block
# Total pages in the "device"
self.total_pages = channels * dies_per_channel * blocks_per_die * pages_per_block
self.page_size_kb = 4 # Standard 4KB page
def get_physical_coordinates(self, filename):
"""
Simulates the mapping of a file to a physical location on the NVMe.
Uses a hash of the filename to simulate the FTL's distribution logic,
but weighted towards the 'inner edges' (lower LBAs) for this specific task.
"""
# Create a deterministic 'seed' from the filename
hasher = hashlib.sha256(filename.encode())
hash_int = int(hasher.hexdigest(), 16)
# In our theory, 'inner edges' are lower LBAs.
# We'll simulate 'density' by clustering files near LBA 0.
# Use a power distribution to favor smaller indices.
raw_index = hash_int % self.total_pages
inner_edge_index = int(math.pow(raw_index / self.total_pages, 2) * self.total_pages)
# Decompose index into physical geometry
page = inner_edge_index % self.pages_per_block
rem = inner_edge_index // self.pages_per_block
block = rem % self.blocks_per_die
rem = rem // self.blocks_per_die
die = rem % self.dies_per_channel
channel = rem // self.dies_per_channel
# Calculate Radial Coordinates (Theory)
# r = normalized distance from controller (channel 0, die 0)
# theta = angular position based on channel
r = (channel * self.dies_per_channel + die) / (self.channels * self.dies_per_channel)
theta = (channel / self.channels) * 360
return {
"physical": {
"channel": channel,
"die": die,
"block": block,
"page": page
},
"radial": {
"r": round(r, 4),
"theta": round(theta, 2),
"z": block # Using block height as Z-axis for 3D NAND theory
},
"lba": inner_edge_index
}
def generate_mapping_json(self, filename, metadata=None):
coords = self.get_physical_coordinates(filename)
mapping = {
"file": filename,
"coordinates": coords,
"logic": "Radial_Inner_Edge_Clustering",
"timestamp": "2024-10-23T00:00:00Z", # Placeholder
"density_score": round(1.0 - coords['radial']['r'], 4) # Higher density near r=0
}
if metadata:
mapping.update(metadata)
return mapping
if __name__ == "__main__":
mapper = NVMEMapper()
test_file = "boot_driver_hp_pavilion.py"
mapping_data = mapper.generate_mapping_json(test_file, {"type": "driver", "community": 7})
print(json.dumps(mapping_data, indent