github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/ksm/ksm_test.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2019,2021 Intel Corporation 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 # This will run two containers and will wait 8 # to the KSM to settle down and then it will 9 # check that the merged pages count is 10 # increasing 11 12 set -e 13 14 dir_path=$(dirname "$0") 15 source "${dir_path}/../../lib/common.bash" 16 source "${dir_path}/../../metrics/lib/common.bash" 17 source "/etc/os-release" || source "/usr/lib/os-release" 18 19 KATA_KSM_THROTTLER="${KATA_KSM_THROTTLER:-yes}" 20 PAYLOAD_ARGS="${PAYLOAD_ARGS:-tail -f /dev/null}" 21 IMAGE="${IMAGE:-quay.io/prometheus/busybox:latest}" 22 WAIT_TIME="60" 23 24 function setup() { 25 restart_containerd_service 26 check_processes 27 save_ksm_settings 28 set_ksm_aggressive 29 } 30 31 function teardown() { 32 clean_env_ctr 33 check_processes 34 restore_ksm_settings 35 } 36 37 trap teardown EXIT 38 39 function run_with_ksm() { 40 setup 41 42 sudo ctr image pull "${IMAGE}" 43 44 # Running the first container 45 sudo ctr run -d --runtime="${CTR_RUNTIME}" "${IMAGE}" test sh -c "${PAYLOAD_ARGS}" 46 47 echo "Entering KSM settle mode on first container" 48 wait_ksm_settle "${WAIT_TIME}" 49 50 # Checking the pages merged for the first container 51 first_pages_merged=$(cat "${KSM_PAGES_SHARED}") 52 53 echo "Pages merged $first_pages_merged" 54 55 # Running the second container 56 sudo ctr run -d --runtime="${CTR_RUNTIME}" "${IMAGE}" test1 sh -c "${PAYLOAD_ARGS}" 57 58 echo "Entering KSM settle mode on second container" 59 wait_ksm_settle "${WAIT_TIME}" 60 61 # Checking the pages merged for the second container 62 second_pages_merged=$(cat "${KSM_PAGES_SHARED}") 63 64 echo "Pages merged $second_pages_merged" 65 66 # Compared the pages merged between the containers 67 echo "Comparing merged pages between containers" 68 [ "$second_pages_merged" -ge "$first_pages_merged" ] || die "The merged pages on the second container is less than the first container" 69 70 } 71 72 echo "Starting KSM test" 73 run_with_ksm