Skip to content

Commit ad7eff1

Browse files
committed
PGM Documentation Enhancements
Split PGM into 3 different section discussing the allocation, deallocation, and memory usage. Add new information regarding left/right allignment that was recently added. * docs/Deep Dive/Libpas/Internals.md
1 parent 33f7ef4 commit ad7eff1

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

docs/Deep Dive/Libpas/Internals.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,23 +1215,29 @@ page header tables even for the small bitfit page config.
12151215

12161216
### Probabilistic Guard Malloc
12171217

1218-
Probabilistic Guard Malloc (PGM) is a new allocator designed to catch use after free attempts and out of bounds accesses.
1219-
It behaves similarly to AddressSanitizer (ASAN), but aims to have minimal runtime overhead.
1220-
1221-
The design of PGM is quite simple. Each time an allocation is performed an additional guard page is added above and below the newly
1222-
allocated page(s). An allocation may span multiple pages. When a deallocation is performed, the page(s) allocated will be protected
1223-
using mprotect to ensure that any use after frees will trigger a crash. Virtual memory addresses are never reused, so we will never run
1224-
into a case where object 1 is freed, object 2 is allocated over the same address space, and object 1 then accesses the memory address
1225-
space of now object 2.
1226-
1227-
PGM does add notable memory overhead. Each allocation, no matter the size, adds an additional 2 guard pages (8KB for X86_64 and 32KB
1228-
for ARM64). In addition, there may be free memory left over in the page(s) allocated for the user. This memory may not be used by any
1229-
other allocation.
1230-
1231-
We added limits on virtual memory and wasted memory to help limit the memory impact on the overall system. Virtual memory for this
1232-
allocator is limited to 1GB. Wasted memory, which is the unused memory in the page(s) allocated by the user, is limited to 1MB.
1233-
These overall limits should ensure that the memory impact on the system is minimal, while helping to tackle the problems of catching
1234-
use after frees and out of bounds accesses.
1218+
Probabilistic Guard Malloc (PGM) is a new allocator designed to catch use after free attempts and out of bounds accesses.
1219+
It behaves similarly to AddressSanitizer (ASAN), but aims to have minimal runtime overhead.
1220+
1221+
#### Allocation
1222+
1223+
Each time an allocation is performed an additional guard page is added above and below the newly
1224+
allocated page(s). An allocation may span multiple pages. Allocations are either left or right aligned at random, which
1225+
ensures the catching of both overflow and underflow errors.
1226+
1227+
#### Deallocation
1228+
1229+
When a deallocation is performed, the page(s) allocated will be protected using `mprotect` to ensure that any use after frees will trigger a crash. Virtual memory addresses are never reused, so we will never run into a case where object 1 is freed, object 2 is allocated over the same address space, and object 1 then accesses the memory address space of now object 2.
1230+
1231+
#### Memory Usage
1232+
1233+
PGM does add notable memory overhead. Each allocation, no matter the size, adds an additional 2 guard pages (8KB for X86_64 and 32KB
1234+
for ARM64). In addition, there may be free memory left over in the page(s) allocated for the user. This memory may not be used by any
1235+
other allocation.
1236+
1237+
We added limits on virtual memory and wasted memory to help limit the memory impact on the overall system. Virtual memory for this
1238+
allocator is limited to 1GB. Wasted memory, which is the unused memory in the page(s) allocated by the user, is limited to 1MB.
1239+
These overall limits should ensure that the memory impact on the system is minimal, while helping to tackle the problems of catching
1240+
use after frees and out of bounds accesses.
12351241

12361242
## The Fast Paths
12371243

0 commit comments

Comments
 (0)