I have to agree with cp's maintainer. I don't see how you can call (3)
or (4) a "bug-like feature", much less a bug.
I agree with most of the comments posted in response to
my "amusing true story." I think that for cc to enforce
4-byte alignment on large buffers with "round sizes" might
be a slight performance boost independent of any driver
bug, but I might be reluctant to make such a change due to
paranoia about unforeseen consequences.
And I agree that "bug-like feature" was a very poor
phrasing. I wanted a better phrasing, but didn't
spend more than 2 seconds trying to think of one.
And I might agree that "'cp' did nothing wrong", but for
cp's maintainer to refuse to make this simple change seems
inexplicable(*). Even ignoring that it bypasses the bug,
an aligned buffer is going to get better performance.
The mmap() usage was a recent change, so the potentially
misaligned
char buffer[512];
had presumably been used for all files previously.
(My memory is fuzzy. Buffer-size *might* have been some
other power-of-two, e.g. 4096.) A misaligned buffer
is going to give poorer performance than an aligned buffer
even if the kernel is just doing a memcpy()-type operation
from its own aligned buffer.
Efficiencies one doesn't bother with normally *should*
be of concern when writing a standard utility like 'cp.'
(* - The company needed paperwork and approvals for all
changes to existing programs; this may have affected
willingness to change.)
In a similar situation, I would use dd instead of cp. I don't know if
that would help in this case, though. I wonder if dd worries about
buffer alignment...
IIRC, 'dd' (unlike 'cp' and 'cat') did not use mmap() in any
case, but otherwise I don't recall its coding: Its behavior
was irrelevant to me. Please note that I didn't "need"
cp to examine disk labels.
Instead I thought the bug
should be circumvented before a customer, whether doing
something silly or not, found it.
James