From: Peter C. <pe...@co...> - 2015-05-06 01:46:12
|
On Wed, May 06, 2015 at 01:55:36AM +0200, Rhialto wrote: > On Tue 05 May 2015 at 20:33:12 -0300, Peter Cordes wrote: > > The only issue I can see with requiring source alignment for mmapped > > files. Any thoughts on this? 4-byte alignement should be safe to > > assume, since par2 block sizes have to be multiples of 4B. > > mmap has an option for aligning its "allocation": MAP_ALIGNED(n). > However the manpage I have does not make clear how that interacts with > "odd" offsets into the file that you may ask for. Similarly it mentions > that the requested length of the file should be a multiple of the > pagesize (or extra mapping will occur). But it doesn't mention the > offset here either. At least on Linux, alignment of file data relative to memory page boundaries matches alignment of data relative to the start of the file. So if you had a block that started at byte 60 of a file, your source buffer will only be 4-byte aligned unless the data is copied out of the page cache to a temporary buffer. Also, I don't see any documentation for MAP_ALIGNED in the Linux man pages for mmap, and even google doesn't find anything. If anything, you could control whether it rounds up your mapping request instead of rejecting unaligned mapping, maybe. But virtual memory maps by page; you can't the CPU to give a process an offset map of a physical page. -- #define X(x,y) x##y Peter Cordes ; e-mail: X(peter@cor , des.ca) "The gods confound the man who first found out how to distinguish the hours! Confound him, too, who in this place set up a sundial, to cut and hack my day so wretchedly into small pieces!" -- Plautus, 200 BC |