Bug 209821

Summary: KASAN: improve x2 memory overhead for kmalloc objects
Product: Memory Management Reporter: Andrey Konovalov (andreyknvl)
Component: SanitizersAssignee: MM/Sanitizers virtual assignee (mm_sanitizers)
Status: RESOLVED CODE_FIX    
Severity: normal CC: kasan-dev
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: upstream Subsystem:
Regression: No Bisected commit-id:

Description Andrey Konovalov 2020-10-22 21:29:43 UTC
As of [1] kmalloc return value is aligned to the size of the allocation for power-of-two kmalloc caches. As KASAN adds just a few bytes of metadata after each object, this results in x2 memory usage increase for such kmalloc caches.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=59bb47985c1db229ccff8c5deebecd54fc77d2a9
Comment 1 Andrey Konovalov 2022-10-18 18:57:26 UTC
This has been resolved for the Software and Hardware Tag-Based modes by moving stack trace handles from per-object metadata to the stack ring [1].

For Generic KASAN, the additional memory usage caused by the over-alignment of kmalloc objects is not that critical, as it introduces a significant memory overhead anyway.

Thus, this issue is considered resolved.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ca77f290cff1dfa095d71ae16cc7cda8ee6df495