selftests-mm-hmm-tests-new-throughput-tests-including-thp.patch removed from -mm tree
The quilt patch titled
Subject: selftests/mm/hmm-tests: new throughput tests including THP
has been removed from the -mm tree. Its filename was
selftests-mm-hmm-tests-new-throughput-tests-including-thp.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Balbir Singh <[email protected]>
Subject: selftests/mm/hmm-tests: new throughput tests including THP
Date: Wed, 1 Oct 2025 16:57:06 +1000
Add new benchmark style support to test transfer bandwidth for zone device memory operations.
Signed-off-by Balbir Singh <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Zi Yan <[email protected]>
Cc Joshua Hahn <[email protected]>
Cc Rakie Kim <[email protected]>
Cc Byungchul Park <[email protected]>
Cc Gregory Price <[email protected]>
Cc Ying Huang <[email protected]>
Cc Alistair Popple <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Baolin Wang <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc David Airlie <[email protected]>
Cc Simona Vetter <[email protected]>
Cc Ralph Campbell <[email protected]>
Cc Mika Penttilä <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Francois Dugast <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
tools/testing/selftests/mm/hmm-tests.c | 197 ++++++++++++++++++++++- 1 file changed, 196 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/hmm-tests.c renamed from tools/testing/selftests/mm/hmm-tests.c~selftests-mm-hmm-tests-new-throughput-tests-including-thp +196 -1
@@ -25,6 +25,7 @@#include <sys/stat.h> #include <sys/mman.h> #include <sys/ioctl.h> +#include <sys/time.h> /*
@@ -209,8 +210,10 @@ static void hmm_buffer_free(struct hmm_bif (buffer ==NULL )return ; -if (buffer->ptr) +if (buffer->ptr) {munmap (buffer->ptr, buffer->size); + buffer->ptr =NULL ; + }free (buffer->mirror);free (buffer); }
@@ -2657,4 +2660,196 @@ TEST_F(hmm, migrate_anon_huge_zero_err) buffer->ptr = old_ptr;hmm_buffer_free (buffer); } + +struct benchmark_results { +double sys_to_dev_time; +double dev_to_sys_time; +double throughput_s2d; +double throughput_d2s; +}; + +static double get_time_ms (void ) +{ +struct timeval tv; + +gettimeofday (&tv,NULL ); +return (tv.tv_sec *1000.0 ) + (tv.tv_usec /1000.0 ); +} + +static inline struct hmm_buffer *hmm_buffer_alloc (unsigned long size) +{ +struct hmm_buffer *buffer; + + buffer =malloc (sizeof (*buffer)); + + buffer->fd =-1 ; + buffer->size = size; + buffer->mirror =malloc (size); +memset (buffer->mirror,0xFF , size); +return buffer; +} + +static void print_benchmark_results (const char *test_name,size_t buffer_size, +struct benchmark_results *thp, +struct benchmark_results *regular) +{ +double s2d_improvement = ((regular->sys_to_dev_time - thp->sys_to_dev_time) / + regular->sys_to_dev_time) *100.0 ; +double d2s_improvement = ((regular->dev_to_sys_time - thp->dev_to_sys_time) / + regular->dev_to_sys_time) *100.0 ; +double throughput_s2d_improvement = ((thp->throughput_s2d - regular->throughput_s2d) / + regular->throughput_s2d) *100.0 ; +double throughput_d2s_improvement = ((thp->throughput_d2s - regular->throughput_d2s) / + regular->throughput_d2s) *100.0 ; + +printf ("\n=== %s (%.1f MB) ===\n" , test_name, buffer_size / (1024.0 *1024.0 )); +printf (" | With THP | Without THP | Improvement\n" ); +printf ("---------------------------------------------------------------------\n" ); +printf ("Sys->Dev Migration | %.3f ms | %.3f ms | %.1f%%\n" , + thp->sys_to_dev_time, regular->sys_to_dev_time, s2d_improvement); +printf ("Dev->Sys Migration | %.3f ms | %.3f ms | %.1f%%\n" , + thp->dev_to_sys_time, regular->dev_to_sys_time, d2s_improvement); +printf ("S->D Throughput | %.2f GB/s | %.2f GB/s | %.1f%%\n" , + thp->throughput_s2d, regular->throughput_s2d, throughput_s2d_improvement); +printf ("D->S Throughput | %.2f GB/s | %.2f GB/s | %.1f%%\n" , + thp->throughput_d2s, regular->throughput_d2s, throughput_d2s_improvement); +} + +/* +* Run a single migration benchmark +* fd: file descriptor for hmm device +* use_thp: whether to use THP +* buffer_size: size of buffer to allocate +* iterations: number of iterations +* results: where to store results +*/ +static inline int run_migration_benchmark (int fd,int use_thp,size_t buffer_size, +int iterations,struct benchmark_results *results) +{ +struct hmm_buffer *buffer; +unsigned long npages = buffer_size /sysconf (_SC_PAGESIZE); +double start, end; +double s2d_total =0 , d2s_total =0 ; +int ret, i; +int *ptr; + + buffer =hmm_buffer_alloc (buffer_size); + +/* Map memory */ + buffer->ptr =mmap (NULL , buffer_size,PROT_READ |PROT_WRITE , +MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 ); + +if (!buffer->ptr) +return -1 ; + +/* Apply THP hint if requested */ +if (use_thp) + ret =madvise (buffer->ptr, buffer_size,MADV_HUGEPAGE ); +else + ret =madvise (buffer->ptr, buffer_size,MADV_NOHUGEPAGE ); + +if (ret) +return ret; + +/* Initialize memory to make sure pages are allocated */ + ptr = (int *)buffer->ptr; +for (i =0 ; i < buffer_size /sizeof (int ); i++) + ptr[i] = i &0xFF ; + +/* Warmup iteration */ + ret =hmm_migrate_sys_to_dev (fd, buffer, npages); +if (ret) +return ret; + + ret =hmm_migrate_dev_to_sys (fd, buffer, npages); +if (ret) +return ret; + +/* Benchmark iterations */ +for (i =0 ; i < iterations; i++) { +/* System to device migration */ + start =get_time_ms (); + + ret =hmm_migrate_sys_to_dev (fd, buffer, npages); +if (ret) +return ret; + + end =get_time_ms (); + s2d_total += (end - start); + +/* Device to system migration */ + start =get_time_ms (); + + ret =hmm_migrate_dev_to_sys (fd, buffer, npages); +if (ret) +return ret; + + end =get_time_ms (); + d2s_total += (end - start); + } + +/* Calculate average times and throughput */ + results->sys_to_dev_time = s2d_total / iterations; + results->dev_to_sys_time = d2s_total / iterations; + results->throughput_s2d = (buffer_size / (1024.0 *1024.0 *1024.0 )) / + (results->sys_to_dev_time /1000.0 ); + results->throughput_d2s = (buffer_size / (1024.0 *1024.0 *1024.0 )) / + (results->dev_to_sys_time /1000.0 ); + +/* Cleanup */ +hmm_buffer_free (buffer); +return 0 ; +} + +/* +* Benchmark THP migration with different buffer sizes +*/ +TEST_F_TIMEOUT(hmm, benchmark_thp_migration, 120) +{ +struct benchmark_results thp_results, regular_results; +size_t thp_size =2 *1024 *1024 ;/* 2MB - typical THP size */ +int iterations =5 ; + +printf ("\nHMM THP Migration Benchmark\n" ); +printf ("---------------------------\n" ); +printf ("System page size: %ld bytes\n" ,sysconf (_SC_PAGESIZE)); + +/* Test different buffer sizes */ +size_t test_sizes[] = { + thp_size /4 ,/* 512KB - smaller than THP */ + thp_size /2 ,/* 1MB - half THP */ + thp_size,/* 2MB - single THP */ + thp_size *2 ,/* 4MB - two THPs */ + thp_size *4 ,/* 8MB - four THPs */ + thp_size *8 ,/* 16MB - eight THPs */ + thp_size *128 ,/* 256MB - one twenty eight THPs */ + }; + +static const char *const test_names[] = { +"Small Buffer (512KB)" , +"Half THP Size (1MB)" , +"Single THP Size (2MB)" , +"Two THP Size (4MB)" , +"Four THP Size (8MB)" , +"Eight THP Size (16MB)" , +"One twenty eight THP Size (256MB)" + }; + +int num_tests =ARRAY_SIZE (test_sizes); + +/* Run all tests */ +for (int i =0 ; i < num_tests; i++) { +/* Test with THP */ +ASSERT_EQ (run_migration_benchmark (self->fd,1 , test_sizes[i], + iterations, &thp_results),0 ); + +/* Test without THP */ +ASSERT_EQ (run_migration_benchmark (self->fd,0 , test_sizes[i], + iterations, ®ular_results),0 ); + +/* Print results */ +print_benchmark_results (test_names[i], test_sizes[i], + &thp_results, ®ular_results); + } +}TEST_HARNESS_MAIN
_
Patches currently in -mm which might be from [email protected] are