Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas789 authored Jun 13, 2024
1 parent afdcb0e commit 8d173bd
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Implementation

1. Allocate and Deallocate Physical Pages
**Functionality**:
#### 1. Allocate and Deallocate Physical Pages
**Functionality**:

- `allocatePhysicalPage()` uses `mmap` to allocate a 4KB physical page.
- Destructor `~MemoryManager()` uses `munmap` to deallocate physical pages.

**Code**:
```
void* allocatePhysicalPage() {
void* page = mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
Expand All @@ -25,3 +26,27 @@ MemoryManager::~MemoryManager() {
}
}
```

#### Data and Metadata Size Constraints
- **Slot Size**: Each slot is defined to have a total size of 8 bytes.
- **Metadata**: Each slot contains 2 bytes of metadata.
- `virtualPageId` uses 15 bits.
- `occupiedFlg` uses 1 bit.

Given these constraints, the remaining space in each slot is available for data storage.

- **Data Size**: 8 bytes (total slot size) - 2 bytes (metadata) = 6 bytes available for data.

**Details:**

**Slot Size Definition (8B)**:
```static constexpr size_t SLOT_SIZE = 8; // 8 bytes per slot```

**Metadata Structure (2B)**:
```
struct ArrMetadata {
uint16_t virtualPageId : 15; // 15 bits for virtualPageId
bool occupiedFlg : 1; // 1 bit for the occupied flag
};
```
"Using `uint16_t`, normally occupies 16 bits (2B). But by using 15 bits for `virtualPageId` and 1 bit for `occupiedFlg` as bit-fields in `ArrMetadata`, a compact metadata size of 2 bytes per slot was achieved, leaving 6 bytes for data storage."

0 comments on commit 8d173bd

Please # to comment.