Re: bcopy and page faults

From: linux-os
Date: Fri Dec 17 2004 - 10:00:52 EST

On Fri, 17 Dec 2004, Horst von Brand wrote:

firnnauriel <rinoa012000@xxxxxxxxx> said:
In general, is there a correlation between the number
of page faults occurred in the system and bcopy's


If the page fault is high, will the
bcopy's performance become slower? Kindly enlighten me
on this. If you can provide a URL that will support
your answer, I will really appreciate it. Thank you
very much!

bcopy(3) copies stuff inside a process. If the memory areas copied from/to
are available in RAM, the copy will go at full speed. If not, there will be
delays (due to paging, etc). Now, the system might be paging like mad, but
the memory _this_ process requires is available (== full speed bcopy), or
there might be almost no paging activity, but the pages required for the
copy aren't in RAM (== slowest possible).

PS: Consider using memcpy(3), bcopy is non-standard.
Dr. Horst H. von Brand User #22616
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513

FYI `bcopy()` can copy overlapping buffers. It does this by
determining if the destination buffer is higher or lower than
the source buffer. If it's higher, it's an ordinary memcpy()
if it's lower, it copies backwards so that it doesn't end up
copying what was just copied, etc., the result being junk.

Both can cause page-faulting if the buffers are not in
memory. Because bcopy() has some additional starting logic,
it might be slower. Some POSIX man-pages claim that it's
deprecated and one should use memmove() instead. The Linux
man page claims one should use memcpy(), but this is wrong
because memcpy cannot successfully copy overlapping buffers.

So, if the buffers overlap, use memmove(). If not use memcpy().
This different usage might alert people who look at the code
in the future that there was some special reason for using

Dick Johnson
Penguin : Linux version 2.6.9 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at