mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 12:44:03 +02:00
selftests/mm: fix memleak in migration benchmark
Several early return paths in run_migration_benchmark() skip
hmm_buffer_free(), leaking the buffer. Replace with a single cleanup
label.
Link: https://lore.kernel.org/20260709081843.1451202-1-lihongfu@kylinos.cn
Fixes: 271a7b2e3c ("selftests/mm/hmm-tests: new throughput tests including THP")
Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: SJ Park <sj@kernel.org>
Acked-by: Balbir Singh <balbirs@nvidia.com>
Reviewed-by: Lorenzo Stoakes <ljs@kernel.org>
Reviewed-by: Balbir Singh <balbirs@nvidia.com>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Cc: Hongfu Li <lihongfu@kylinos.cn>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
0471cade0a
commit
f421d67d2c
|
|
@ -2829,8 +2829,11 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
|
|||
buffer->ptr = mmap(NULL, buffer_size, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
|
||||
if (buffer->ptr == MAP_FAILED)
|
||||
return -1;
|
||||
if (buffer->ptr == MAP_FAILED) {
|
||||
buffer->ptr = NULL;
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Apply THP hint if requested */
|
||||
if (use_thp)
|
||||
|
|
@ -2839,7 +2842,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
|
|||
ret = madvise(buffer->ptr, buffer_size, MADV_NOHUGEPAGE);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
goto cleanup;
|
||||
|
||||
/* Initialize memory to make sure pages are allocated */
|
||||
ptr = (int *)buffer->ptr;
|
||||
|
|
@ -2849,11 +2852,11 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
|
|||
/* Warmup iteration */
|
||||
ret = hmm_migrate_sys_to_dev(fd, buffer, npages);
|
||||
if (ret)
|
||||
return ret;
|
||||
goto cleanup;
|
||||
|
||||
ret = hmm_migrate_dev_to_sys(fd, buffer, npages);
|
||||
if (ret)
|
||||
return ret;
|
||||
goto cleanup;
|
||||
|
||||
/* Benchmark iterations */
|
||||
for (i = 0; i < iterations; i++) {
|
||||
|
|
@ -2862,7 +2865,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
|
|||
|
||||
ret = hmm_migrate_sys_to_dev(fd, buffer, npages);
|
||||
if (ret)
|
||||
return ret;
|
||||
goto cleanup;
|
||||
|
||||
end = get_time_ms();
|
||||
s2d_total += (end - start);
|
||||
|
|
@ -2872,7 +2875,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
|
|||
|
||||
ret = hmm_migrate_dev_to_sys(fd, buffer, npages);
|
||||
if (ret)
|
||||
return ret;
|
||||
goto cleanup;
|
||||
|
||||
end = get_time_ms();
|
||||
d2s_total += (end - start);
|
||||
|
|
@ -2886,9 +2889,9 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
|
|||
results->throughput_d2s = (buffer_size / (1024.0 * 1024.0 * 1024.0)) /
|
||||
(results->dev_to_sys_time / 1000.0);
|
||||
|
||||
/* Cleanup */
|
||||
cleanup:
|
||||
hmm_buffer_free(buffer);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user