github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/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  
    18  KATA_KSM_THROTTLER="${KATA_KSM_THROTTLER:-yes}"
    19  PAYLOAD_ARGS="${PAYLOAD_ARGS:-tail -f /dev/null}"
    20  IMAGE="${IMAGE:-quay.io/prometheus/busybox:latest}"
    21  WAIT_TIME="60"
    22  
    23  function setup() {
    24  	sudo systemctl restart containerd
    25  	clean_env_ctr
    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  	CONTAINERD_RUNTIME="io.containerd.kata.v2"
    43  	sudo ctr image pull "${IMAGE}"
    44  
    45  	# Running the first container
    46  	sudo ctr run -d --runtime="${CONTAINERD_RUNTIME}" "${IMAGE}" test  sh -c "${PAYLOAD_ARGS}"
    47  
    48  	echo "Entering KSM settle mode on first container"
    49  	wait_ksm_settle "${WAIT_TIME}"
    50  
    51  	# Checking the pages merged for the first container
    52  	first_pages_merged=$(cat "${KSM_PAGES_SHARED}")
    53  
    54  	echo "Pages merged $first_pages_merged"
    55  
    56  	# Running the second container
    57  	sudo ctr run -d --runtime="${CONTAINERD_RUNTIME}" "${IMAGE}" test1  sh -c "${PAYLOAD_ARGS}"
    58  
    59  	echo "Entering KSM settle mode on second container"
    60  	wait_ksm_settle "${WAIT_TIME}"
    61  
    62  	# Checking the pages merged for the second container
    63  	second_pages_merged=$(cat "${KSM_PAGES_SHARED}")
    64  
    65  	echo "Pages merged $second_pages_merged"
    66  
    67  	# Compared the pages merged between the containers
    68  	echo "Comparing merged pages between containers"
    69  	[ "$second_pages_merged" -ge "$first_pages_merged" ] || die "The merged pages on the second container is less than the first container"
    70  
    71  }
    72  
    73  echo "Starting KSM test"
    74  run_with_ksm