2 ms·
> But most code isn't performance critical. Wasting TLB slots on your unimportant code still pessimizes your hot code. > Thus trying to align functions to pag
by loeg 6y ago
> But most code isn't performance critical.
Wasting TLB slots on your unimportant code still pessimizes your hot code.
> Thus trying to align functions to page boundaries is just wasting memory.
No one aligns individual functions to page boundaries; you align the entire loadable code segment to a page (or preferably, superpage) boundary.
> Even in performance critical code, aligning to cache line sizes is enough and aligning to page boundaries doesn't provide any advantage.
This is a different kind of optimization (avoiding cache line contention) than I was talking about (optimizing TLB slot use).
Yes, forced page-alignment doesn't help cache line contention anymore than forced cacheline-alignment. But that's irrelevant for code, generally: (outside of self-modifying code, which is extremely uncommon) code doesn't share a cacheline with memory that will be mutated and thus doesn't contend in that way.
- bjourne 6y agoThen I don't know what you're getting at. Clearly the most efficient approach would be fitting your performance critical loop into one or at most two consecutive pages making the TLB a moot point.