selftests/mm: mremap_test: optimize execution time from minutes to seconds using...
authorDev Jain <dev.jain@arm.com>
Sat, 30 Mar 2024 17:35:56 +0000 (23:05 +0530)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 26 Apr 2024 03:56:32 +0000 (20:56 -0700)
commit7033c6cc96203eec738ff192829a18a4e12308dc
treef507f80fc9c0e6a409ae6c9da3daa4c0fe9e75a7
parentc7876a0cc6a0a74b407b10f9afe5d77920d803ba
selftests/mm: mremap_test: optimize execution time from minutes to seconds using chunkwise memcmp

Mismatch index is currently being checked by a brute force iteration over
the buffer.  Instead, break the comparison into O(sqrt(n)) number of
chunks, with the chunk size of this order only, where n is the size of the
buffer.  Do a brute-force iteration to print to stdout only when the
highly optimized memcmp() library function returns a mismatch in the
chunk.  The time complexity of this algorithm is O(sqrt(n)) * t, where t
is the time taken by memcmp(); for our test conditions, it is safe to
assume t to be small.

Link: https://lkml.kernel.org/r/20240330173557.2697684-3-dev.jain@arm.com
Signed-off-by: Dev Jain <dev.jain@arm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Kalesh Singh <kaleshsingh@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/mm/mremap_test.c