microsoft / microsoft/snmalloc

Using mmap to zero memory: performance questions and CHERI incompatibility

Open
#642 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2k
Forks
138
Avg merge
11h 19m
Merged PRs (30d)
5

Description

PALPOSIX::zero uses mmap(MAP_FIXED) to map zero pages over the top as an "optimisation". However, there are two issues here:

  1. This requires VMEM permission on CHERI, but that's not always present here (in particular in the finish_alloc path).
  2. The heuristic here seems very wrong, as it's for any range that has page-aligned boundaries. For small allocations that's likely to hurt performance, having to go all the way into the kernel (maybe even IPI to shoot down the existing mappings, depending on the architecture, but at least do something to invalidate them), and once you get to the really large allocations where that is more performant does snmalloc really try and chunk them rather than just doing a raw mmap on demand? Short of data to inform whether and when it makes sense to use this optimisation I do not think it should be enabled by default.

The net result is we will likely be #if 0'ing this code out in CheriBSD.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading PALPOSIX::zero and the finish_alloc path, focusing on the mmap(MAP_FIXED) zeroing branch and its VMEM requirement. Measure the behavior for small and large page-aligned ranges, including mapping invalidation costs, and compare it with the allocator's handling of large allocations. Done means the performance tradeoff and CHERI behavior are established well enough to decide whether this optimization should remain enabled by default.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems, performance
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.