#9255: BFS uses unaligned memory access for BPlusTree data ------------------------------+------------------------------ Reporter: mmlr | Owner: axeld Type: bug | Status: new Priority: normal | Milestone: R1 Component: File Systems/BFS | Version: R1/Development Keywords: | Blocked By: Blocking: | Has a Patch: 0 Platform: All | ------------------------------+------------------------------ The BPlusTrees in BFS pack their data (key lengths and values) tightly on disk. These structures are then loaded into memory and used directly. Their offsets are calculated, a pointer is formed and the memory is accessed as an array. Since there is no alignment enforced, this can lead to unaligned access of the uint16 key lengths or off_t values. This is illegal from a language point of view, as pointers to a basic type are required to be aligned to the size of that type (so 8 bytes for the off_t). In practice this works on x86 as there unaligned access is just handled silently. However this breaks on processors that have these alignment restrictions like ARM (at least < v6). As unaligned memory access has to be broken up into multiple bus accesses behind the scenes, they do carry a performance penalty in any case and should therefore be avoided. To get further with the ARM port I've worked around the issue by implementing getters and setters for the array access and implementing the actual access through memcpy() that does not exhibit the alignment problem. As this introduces a rather large overhead for commonly used functionality in BFS, I am not going to apply this patch. I open this ticket to document the issue and possibly come up with solutions that don't carry as much overhead. -- Ticket URL: <http://dev.haiku-os.org/ticket/9255> Haiku <http://dev.haiku-os.org> Haiku - the operating system.