selftests/vm: make charge_reserved_hugetlb.sh work with existing cgroup setting
The hugetlb cgroup reservation test charge_reserved_hugetlb.sh assume
that no cgroup filesystems are mounted before running the test. That is
not true in many cases. As a result, the test fails to run. Fix that
by querying the current cgroup mount setting and using the existing
cgroup setup instead before attempting to freshly mount a cgroup
filesystem.
Similar change is also made for hugetlb_reparenting_test.sh as well,
though it still has problem if cgroup v2 isn't used.
The patched test scripts were run on a centos 8 based system to verify
that they ran properly.
Link: https://lkml.kernel.org/r/20220106201359.1646575-1-longman@redhat.com
Fixes: 29750f71a9
("hugetlb_cgroup: add hugetlb_cgroup reservation tests")
Signed-off-by: Waiman Long <longman@redhat.com>
Acked-by: Mina Almasry <almasrymina@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
e9ea874a8f
commit
209376ed2a
@ -24,19 +24,23 @@ if [[ "$1" == "-cgroup-v2" ]]; then
|
|||||||
reservation_usage_file=rsvd.current
|
reservation_usage_file=rsvd.current
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cgroup_path=/dev/cgroup/memory
|
if [[ $cgroup2 ]]; then
|
||||||
if [[ ! -e $cgroup_path ]]; then
|
cgroup_path=$(mount -t cgroup2 | head -1 | awk -e '{print $3}')
|
||||||
mkdir -p $cgroup_path
|
if [[ -z "$cgroup_path" ]]; then
|
||||||
if [[ $cgroup2 ]]; then
|
cgroup_path=/dev/cgroup/memory
|
||||||
mount -t cgroup2 none $cgroup_path
|
mount -t cgroup2 none $cgroup_path
|
||||||
else
|
do_umount=1
|
||||||
|
fi
|
||||||
|
echo "+hugetlb" >$cgroup_path/cgroup.subtree_control
|
||||||
|
else
|
||||||
|
cgroup_path=$(mount -t cgroup | grep ",hugetlb" | awk -e '{print $3}')
|
||||||
|
if [[ -z "$cgroup_path" ]]; then
|
||||||
|
cgroup_path=/dev/cgroup/memory
|
||||||
mount -t cgroup memory,hugetlb $cgroup_path
|
mount -t cgroup memory,hugetlb $cgroup_path
|
||||||
|
do_umount=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
export cgroup_path
|
||||||
if [[ $cgroup2 ]]; then
|
|
||||||
echo "+hugetlb" >/dev/cgroup/memory/cgroup.subtree_control
|
|
||||||
fi
|
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
if [[ $cgroup2 ]]; then
|
if [[ $cgroup2 ]]; then
|
||||||
@ -108,7 +112,7 @@ function setup_cgroup() {
|
|||||||
|
|
||||||
function wait_for_hugetlb_memory_to_get_depleted() {
|
function wait_for_hugetlb_memory_to_get_depleted() {
|
||||||
local cgroup="$1"
|
local cgroup="$1"
|
||||||
local path="/dev/cgroup/memory/$cgroup/hugetlb.${MB}MB.$reservation_usage_file"
|
local path="$cgroup_path/$cgroup/hugetlb.${MB}MB.$reservation_usage_file"
|
||||||
# Wait for hugetlbfs memory to get depleted.
|
# Wait for hugetlbfs memory to get depleted.
|
||||||
while [ $(cat $path) != 0 ]; do
|
while [ $(cat $path) != 0 ]; do
|
||||||
echo Waiting for hugetlb memory to get depleted.
|
echo Waiting for hugetlb memory to get depleted.
|
||||||
@ -121,7 +125,7 @@ function wait_for_hugetlb_memory_to_get_reserved() {
|
|||||||
local cgroup="$1"
|
local cgroup="$1"
|
||||||
local size="$2"
|
local size="$2"
|
||||||
|
|
||||||
local path="/dev/cgroup/memory/$cgroup/hugetlb.${MB}MB.$reservation_usage_file"
|
local path="$cgroup_path/$cgroup/hugetlb.${MB}MB.$reservation_usage_file"
|
||||||
# Wait for hugetlbfs memory to get written.
|
# Wait for hugetlbfs memory to get written.
|
||||||
while [ $(cat $path) != $size ]; do
|
while [ $(cat $path) != $size ]; do
|
||||||
echo Waiting for hugetlb memory reservation to reach size $size.
|
echo Waiting for hugetlb memory reservation to reach size $size.
|
||||||
@ -134,7 +138,7 @@ function wait_for_hugetlb_memory_to_get_written() {
|
|||||||
local cgroup="$1"
|
local cgroup="$1"
|
||||||
local size="$2"
|
local size="$2"
|
||||||
|
|
||||||
local path="/dev/cgroup/memory/$cgroup/hugetlb.${MB}MB.$fault_usage_file"
|
local path="$cgroup_path/$cgroup/hugetlb.${MB}MB.$fault_usage_file"
|
||||||
# Wait for hugetlbfs memory to get written.
|
# Wait for hugetlbfs memory to get written.
|
||||||
while [ $(cat $path) != $size ]; do
|
while [ $(cat $path) != $size ]; do
|
||||||
echo Waiting for hugetlb memory to reach size $size.
|
echo Waiting for hugetlb memory to reach size $size.
|
||||||
@ -574,5 +578,7 @@ for populate in "" "-o"; do
|
|||||||
done # populate
|
done # populate
|
||||||
done # method
|
done # method
|
||||||
|
|
||||||
umount $cgroup_path
|
if [[ $do_umount ]]; then
|
||||||
rmdir $cgroup_path
|
umount $cgroup_path
|
||||||
|
rmdir $cgroup_path
|
||||||
|
fi
|
||||||
|
@ -18,19 +18,24 @@ if [[ "$1" == "-cgroup-v2" ]]; then
|
|||||||
usage_file=current
|
usage_file=current
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CGROUP_ROOT='/dev/cgroup/memory'
|
|
||||||
MNT='/mnt/huge/'
|
|
||||||
|
|
||||||
if [[ ! -e $CGROUP_ROOT ]]; then
|
if [[ $cgroup2 ]]; then
|
||||||
mkdir -p $CGROUP_ROOT
|
CGROUP_ROOT=$(mount -t cgroup2 | head -1 | awk -e '{print $3}')
|
||||||
if [[ $cgroup2 ]]; then
|
if [[ -z "$CGROUP_ROOT" ]]; then
|
||||||
|
CGROUP_ROOT=/dev/cgroup/memory
|
||||||
mount -t cgroup2 none $CGROUP_ROOT
|
mount -t cgroup2 none $CGROUP_ROOT
|
||||||
sleep 1
|
do_umount=1
|
||||||
echo "+hugetlb +memory" >$CGROUP_ROOT/cgroup.subtree_control
|
fi
|
||||||
else
|
echo "+hugetlb +memory" >$CGROUP_ROOT/cgroup.subtree_control
|
||||||
|
else
|
||||||
|
CGROUP_ROOT=$(mount -t cgroup | grep ",hugetlb" | awk -e '{print $3}')
|
||||||
|
if [[ -z "$CGROUP_ROOT" ]]; then
|
||||||
|
CGROUP_ROOT=/dev/cgroup/memory
|
||||||
mount -t cgroup memory,hugetlb $CGROUP_ROOT
|
mount -t cgroup memory,hugetlb $CGROUP_ROOT
|
||||||
|
do_umount=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
MNT='/mnt/huge/'
|
||||||
|
|
||||||
function get_machine_hugepage_size() {
|
function get_machine_hugepage_size() {
|
||||||
hpz=$(grep -i hugepagesize /proc/meminfo)
|
hpz=$(grep -i hugepagesize /proc/meminfo)
|
||||||
|
@ -14,7 +14,7 @@ want_sleep=$8
|
|||||||
reserve=$9
|
reserve=$9
|
||||||
|
|
||||||
echo "Putting task in cgroup '$cgroup'"
|
echo "Putting task in cgroup '$cgroup'"
|
||||||
echo $$ > /dev/cgroup/memory/"$cgroup"/cgroup.procs
|
echo $$ > ${cgroup_path:-/dev/cgroup/memory}/"$cgroup"/cgroup.procs
|
||||||
|
|
||||||
echo "Method is $method"
|
echo "Method is $method"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user