Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/ublk: add hugetlbfs shmem_zc test for loop target

Add test_shmem_zc_02.sh which tests the UBLK_IO_F_SHMEM_ZC zero-copy
path on the loop target using a hugetlbfs shared buffer. Both kublk and
fio mmap the same hugetlbfs file with MAP_SHARED, sharing physical
pages. The kernel's PFN matching enables zero-copy — the loop target
reads/writes directly from the shared buffer to the backing file.

Uses standard fio --mem=mmaphuge:<path> (supported since fio 1.10),
no patched fio required.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://patch.msgid.link/20260331153207.3635125-9-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Ming Lei and committed by
Jens Axboe
d4866503 2f1e9468

+69
+1
tools/testing/selftests/ublk/Makefile
··· 53 53 TEST_PROGS += test_part_02.sh 54 54 55 55 TEST_PROGS += test_shmemzc_01.sh 56 + TEST_PROGS += test_shmemzc_02.sh 56 57 57 58 TEST_PROGS += test_stress_01.sh 58 59 TEST_PROGS += test_stress_02.sh
+68
tools/testing/selftests/ublk/test_shmemzc_02.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + # Test: shmem_zc with hugetlbfs buffer on loop target 4 + # 5 + # kublk and fio both mmap the same hugetlbfs file (MAP_SHARED), 6 + # so they share physical pages. The kernel PFN match enables 7 + # zero-copy I/O without socket-based fd passing. 8 + 9 + . "$(cd "$(dirname "$0")" && pwd)"/test_common.sh 10 + 11 + ERR_CODE=0 12 + 13 + _prep_test "shmem_zc" "loop target hugetlbfs shmem zero-copy test" 14 + 15 + if ! _have_program fio; then 16 + echo "SKIP: fio not available" 17 + exit "$UBLK_SKIP_CODE" 18 + fi 19 + 20 + if ! grep -q hugetlbfs /proc/filesystems; then 21 + echo "SKIP: hugetlbfs not supported" 22 + exit "$UBLK_SKIP_CODE" 23 + fi 24 + 25 + # Allocate hugepages 26 + OLD_NR_HP=$(cat /proc/sys/vm/nr_hugepages) 27 + echo 10 > /proc/sys/vm/nr_hugepages 28 + NR_HP=$(cat /proc/sys/vm/nr_hugepages) 29 + if [ "$NR_HP" -lt 2 ]; then 30 + echo "SKIP: cannot allocate hugepages" 31 + echo "$OLD_NR_HP" > /proc/sys/vm/nr_hugepages 32 + exit "$UBLK_SKIP_CODE" 33 + fi 34 + 35 + # Mount hugetlbfs 36 + HTLB_MNT=$(mktemp -d "${UBLK_TEST_DIR}/htlb_mnt_XXXXXX") 37 + if ! mount -t hugetlbfs none "$HTLB_MNT"; then 38 + echo "SKIP: cannot mount hugetlbfs" 39 + rmdir "$HTLB_MNT" 40 + echo "$OLD_NR_HP" > /proc/sys/vm/nr_hugepages 41 + exit "$UBLK_SKIP_CODE" 42 + fi 43 + 44 + HTLB_FILE="$HTLB_MNT/ublk_buf" 45 + fallocate -l 4M "$HTLB_FILE" 46 + 47 + _create_backfile 0 128M 48 + BACKFILE="${UBLK_BACKFILES[0]}" 49 + 50 + dev_id=$(_add_ublk_dev -t loop --shmem_zc --htlb "$HTLB_FILE" "$BACKFILE") 51 + _check_add_dev $TID $? 52 + 53 + _run_fio_verify_io --filename=/dev/ublkb"${dev_id}" \ 54 + --size=128M \ 55 + --mem=mmaphuge:"$HTLB_FILE" 56 + ERR_CODE=$? 57 + 58 + # Delete device first so daemon releases the htlb mmap 59 + _ublk_del_dev "${dev_id}" 60 + 61 + rm -f "$HTLB_FILE" 62 + umount "$HTLB_MNT" 63 + rmdir "$HTLB_MNT" 64 + echo "$OLD_NR_HP" > /proc/sys/vm/nr_hugepages 65 + 66 + _cleanup_test "shmem_zc" 67 + 68 + _show_result $TID $ERR_CODE