[Date Prev][Date Next]
LMDB data corruption/alignment issues on ARM
- To: email@example.com
- Subject: LMDB data corruption/alignment issues on ARM
- From: Martin Lucina <firstname.lastname@example.org>
- Date: Thu, 24 Apr 2014 21:08:18 +0200
- Content-disposition: inline
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lucina.net; s=dkim-201309; t=1398366478; bh=gN/PV2CwMf6KN0YkNrZODwedkv+H7Jmobj77ICTFXAs=; h=Date:From:To:Subject:From; b=VR2c3rMoZyQKF67B9VL4YAWWgtzP+LiuY0iIy6mDqxeviARf+if1FEKzmFr1cEurx L9mx7UjEDrnNDK8fm0drqZ4FMLmzkujO72OVKinqdLe4ViuBS0fe2Ee5RCCC4WuhVf /B65n7unb4mBHkbF4Gukr4AeH0vrcQxKPVtZHIgM6O2k444W6pjTcwb/vn71zTlnsZ WMaLCrH3uk0/Sk03y1SiZN8YsI9U+hu5w8npRL4rbSFIHtRfFyphcSxr2XTH6JgUTG 2nKDOmInTFT6ySjGXNRf1FpbpbRvV+uGJ6v3XTp+yUa54apqdTkSqS4wXzDiRqvelD gSPVvmzJZM5QQ==
- Mail-followup-to: email@example.com
- User-agent: Mutt/1.5.21 (2010-09-15)
I've just spent about two days chasing down a bug in my application using
LMDB, where if I ran the code on an ARM (and ARM only) platform, data
returned from mdb_get() would appear to be corrupted.
The symtomps were quite bizarre, I'm including them here in case someone
else sees something similar; you can skip to the conclusion if you're in a
a) data written by an application process using mdb_put() appeared correct
b) the same data read by a different application process using
mdb_cursor_get() would appear consistent when examined with a live GDB on
c) however, when actually running the application code, even under GDB,
some data would mysteriously be corrupted
d) single-stepping through one case of corruption lead me to a single LDR
instruction which appeared to load bogus data from memory. GDB showed the
same data (at the exact same memory address) as correct, i.e. not
e) the problem only occured on ARM and was always reproducible.
Much experimenting and googling later I found , the upshot of which is
that on some ARM platforms unaligned word accesses to data using LDR
produce *bogus* data. No exception, nothing, just silent data corruption.
My question is: Given that I'm storing C structs directly in LMDB, I need
to get at least word-aligned pointers back from LMDB in order to be able to
access the data safely.
I've not found anything in the documentation or the source about being able
to tweak alignment of key and data values; I *think* that all I need is an
option where LMDB would guarantee a minimum word (4 byte in this case)
alignment of data.
How hard would this be to implement? Would you consider such a feature?
The only workaround I can think of is explicitly copying all data I get
back from LMDB into aligned struct pointers; for obvious performance
reasons I don't want to do that.
See the second answer, and the link to the ARM documentation for the