|
|
Subscribe / Log in / New account

Implementing alignment guarantees for kmalloc()

Implementing alignment guarantees for kmalloc()

Posted Oct 21, 2019 16:48 UTC (Mon) by jreiser (subscriber, #11027)
In reply to: Implementing alignment guarantees for kmalloc() by vbabka
Parent article: Implementing alignment guarantees for kmalloc()

The new alignment guarantees are only for power of two sizes...   The result should be aligned to min(PAGE_SIZE, n & ~(-1+n)), which is the place value of the lowest-order '1' bit in the requested size (but limited to the sizeof one page). So if the request is for 40 bytes then the result should be 8-byte aligned. The rationale is: the alignment of a struct having that size.


to post comments

Implementing alignment guarantees for kmalloc()

Posted Oct 22, 2019 19:55 UTC (Tue) by wilevers (subscriber, #110407) [Link] (1 responses)

Try parsing this. Then again. Any questions?

Implementing alignment guarantees for kmalloc()

Posted Oct 23, 2019 14:20 UTC (Wed) by rweikusat2 (subscriber, #117920) [Link]

The expression was n & ~(-1 + n). That's a slightly steganographically obscured version of n & ~(n - 1). Assuming that n is some non-zero binary number, subtracting one from that causes the lowest set 1 bit to change to 0 and all 0 bits below it to 1. All other 1 bits of n are also 1 in n - 1. Hence n & ~(n - 1) leaves only the lowest bit of n set.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds