The patch titled Subject: lib/string: optimized memmove has been added to the -mm tree. Its filename is lib-string-optimized-memmove.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/lib-string-optimized-memmove.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/lib-string-optimized-memmove.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Matteo Croce <mcroce@xxxxxxxxxxxxx> Subject: lib/string: optimized memmove When the destination buffer is before the source one, or when the buffers doesn't overlap, it's safe to use memcpy() instead, which is optimized to use a bigger data size possible. This "optimization" only covers a common case. In future, proper code which does the same thing as memcpy() does but backwards can be done. Link: https://lkml.kernel.org/r/20210702123153.14093-3-mcroce@xxxxxxxxxxxxxxxxxxx Signed-off-by: Matteo Croce <mcroce@xxxxxxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxxxxxxxxx> Cc: David Laight <David.Laight@xxxxxxxxxx> Cc: Drew Fustini <drew@xxxxxxxxxxxxxxx> Cc: Emil Renner Berthing <kernel@xxxxxxxx> Cc: Guo Ren <guoren@xxxxxxxxxx> Cc: Nick Desaulniers <ndesaulniers@xxxxxxxxxx> Cc: Nick Kossifidis <mick@xxxxxxxxxxxx> Cc: Palmer Dabbelt <palmer@xxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- lib/string.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) --- a/lib/string.c~lib-string-optimized-memmove +++ a/lib/string.c @@ -975,19 +975,13 @@ EXPORT_SYMBOL(memcpy); */ void *memmove(void *dest, const void *src, size_t count) { - char *tmp; - const char *s; + if (dest < src || src + count <= dest) + return memcpy(dest, src, count); + + if (dest > src) { + const char *s = src + count; + char *tmp = dest + count; - if (dest <= src) { - tmp = dest; - s = src; - while (count--) - *tmp++ = *s++; - } else { - tmp = dest; - tmp += count; - s = src; - s += count; while (count--) *--tmp = *--s; } _ Patches currently in -mm which might be from mcroce@xxxxxxxxxxxxx are revert-mm-page_alloc-make-should_fail_alloc_page-static.patch lib-string-optimized-memcpy.patch lib-string-optimized-memmove.patch lib-string-optimized-memset.patch