[llvm] [RFC] [msan] make MSan up to 20x faster on AMD CPUs (PR #171993)

Thurston Dang via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 12 09:48:23 PST 2025


https://github.com/thurstond requested changes to this pull request.

Thank you @azat, that's a fascinating result! And thanks @Camsyn for the root cause analysis.

One drawback is the increased memory usage: each page of user app memory will no longer be guaranteed to be perfectly shadowed by a single page of shadow (let's ignore the origin for simplicity, though the same principle applies), but may require two pages of shadow in the worst case. As a pathological example, suppose we write to the entirety of 1,000,000 non-contiguous 4K pages of user app memory:
* the unmodified MSan would need exactly 1,000,0000 4K pages of shadow memory
* this patched MSan would need 2,000,000 4K pages of shadow memory

Additionally, this increased memory usage would increase TLB pressure, and the amount of memory used by the kernel itself to maintain paging structures.

Of course, most cases won't be the pathological case above. If we have a k-page user app allocation, the patch will use k+1 pages of shadow (instead of k pages); and if that user allocation is adjacent to another allocation, it will be able to share the extra shadow page. Thus, how much of this is a problem in practice will require real-world benchmarking.

https://github.com/llvm/llvm-project/pull/171993


More information about the llvm-commits mailing list