From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAD2BC433FE for ; Thu, 6 Jan 2022 20:21:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B7AF6B0072; Thu, 6 Jan 2022 15:21:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4674D6B0073; Thu, 6 Jan 2022 15:21:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3090F6B0074; Thu, 6 Jan 2022 15:21:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0128.hostedemail.com [216.40.44.128]) by kanga.kvack.org (Postfix) with ESMTP id 21C336B0072 for ; Thu, 6 Jan 2022 15:21:48 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D122D824C420 for ; Thu, 6 Jan 2022 20:21:47 +0000 (UTC) X-FDA: 79000983054.20.BEAC066 Received: from mail-ua1-f52.google.com (mail-ua1-f52.google.com [209.85.222.52]) by imf18.hostedemail.com (Postfix) with ESMTP id F27411C000C for ; Thu, 6 Jan 2022 20:21:34 +0000 (UTC) Received: by mail-ua1-f52.google.com with SMTP id e19so6492863uaa.11 for ; Thu, 06 Jan 2022 12:21:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TsNggRXYkwV4EUR9Ok29kqBUnZM3s7RXs5GPcRvP5bA=; b=QURTZ5evJ1YW/IO1Blizmr5ol7XadBDlAr3gAsHzRzmWyPahRo6daBfqWicPAoCORh FRNwZ1ayYFfTQc/EiGApBPDjjccy87v0oItyC4AuAkdssyGcG+FFgiC+KinME422CSSu 6kvNSr98Yq7+p9iJ7bTmWyQpCYpWfwBR8a9+EpxgSAtGrLs5JnpAF6eVSHvXJAVYLCyK TlQGfEAImvJw5xoAZKN3fQJTri+FCqMqmtZp06a1oaViYnvhyJCOlcKdTIZsL4MPlgH9 OsTYsbgv4oIh7A27qQabDEn9MOEuvITSFRuWp98w2RxhINCS7ltPI2XoJvOmiagsRffz X++g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TsNggRXYkwV4EUR9Ok29kqBUnZM3s7RXs5GPcRvP5bA=; b=KLQS+r18zrAKJg+2/xk+AB7Y07/XHlrA2TiEVdKa0h3Vzo7tZo5jTVBo9yYmQDDipS HxBVfdTZ3Qwn6RNm6XEwPkAjl8UAq874AfxFSDdIOsVsvaA+pvm8f2WmqOUu42P56s+b /q3latJUNPeVr0CfvRxibsRGDvSYVDNcdx6GPomZH4yn/O6jUF0m5VbH8N1MRaTV9dot AJKLlOVy6y65V+pBHhv+pKWpmCDi5LqIsj9AcTTYbPzCCJL+LnywpxwYNFrfTmgmpQRk vXTNjbq5V2CE0yTGyxT+IMYbwevYEqfssyl72rt7P1ZufLPbO9zE4Jl2lpoYZFiNrM84 TJyQ== X-Gm-Message-State: AOAM531SJYSPB2AboRq6KV8b8eQP5FDHl7KRxiwq0JqK6X9QCk5azA1e WiDrOmR8IZiESz0YLEPhqbB6+SRAOOOsqfe2XBr80A== X-Google-Smtp-Source: ABdhPJzxS3KUNw3tMwcrQJ3mdU2fzU0rZ/yi/kaPmi9KKMyMy9+ysGpHcGAVx5HN1pdKrJLf6dIaVj+7VV2O0XGWm70= X-Received: by 2002:ab0:2a48:: with SMTP id p8mr20072842uar.125.1641500506544; Thu, 06 Jan 2022 12:21:46 -0800 (PST) MIME-Version: 1.0 References: <20220106201359.1646575-1-longman@redhat.com> In-Reply-To: <20220106201359.1646575-1-longman@redhat.com> From: Mina Almasry Date: Thu, 6 Jan 2022 12:21:35 -0800 Message-ID: Subject: Re: [PATCH] selftests/vm: Make charge_reserved_hugetlb.sh work with existing cgroup setting To: Waiman Long Cc: Andrew Morton , Shuah Khan , Mike Kravetz , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=QURTZ5ev; spf=pass (imf18.hostedemail.com: domain of almasrymina@google.com designates 209.85.222.52 as permitted sender) smtp.mailfrom=almasrymina@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: F27411C000C X-Stat-Signature: eyi33tp1pi1qqxk5z7gjqap78u11aamu X-HE-Tag: 1641500494-591322 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Jan 6, 2022 at 12:14 PM Waiman Long wrote: > > 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. > > Fixes: 29750f71a9b4 ("hugetlb_cgroup: add hugetlb_cgroup reservation tests") > Signed-off-by: Waiman Long Thank you very much. Acked-by: Mina Almasry > --- > .../selftests/vm/charge_reserved_hugetlb.sh | 34 +++++++++++-------- > .../selftests/vm/hugetlb_reparenting_test.sh | 21 +++++++----- > .../selftests/vm/write_hugetlb_memory.sh | 2 +- > 3 files changed, 34 insertions(+), 23 deletions(-) > mode change 100644 => 100755 tools/testing/selftests/vm/charge_reserved_hugetlb.sh > mode change 100644 => 100755 tools/testing/selftests/vm/hugetlb_reparenting_test.sh > mode change 100644 => 100755 tools/testing/selftests/vm/write_hugetlb_memory.sh > > diff --git a/tools/testing/selftests/vm/charge_reserved_hugetlb.sh b/tools/testing/selftests/vm/charge_reserved_hugetlb.sh > old mode 100644 > new mode 100755 > index fe8fcfb334e0..a5cb4b09a46c > --- a/tools/testing/selftests/vm/charge_reserved_hugetlb.sh > +++ b/tools/testing/selftests/vm/charge_reserved_hugetlb.sh > @@ -24,19 +24,23 @@ if [[ "$1" == "-cgroup-v2" ]]; then > reservation_usage_file=rsvd.current > fi > > -cgroup_path=/dev/cgroup/memory > -if [[ ! -e $cgroup_path ]]; then > - mkdir -p $cgroup_path > - if [[ $cgroup2 ]]; then > +if [[ $cgroup2 ]]; then > + cgroup_path=$(mount -t cgroup2 | head -1 | awk -e '{print $3}') > + if [[ -z "$cgroup_path" ]]; then > + cgroup_path=/dev/cgroup/memory > 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 > + do_umount=1 > fi > fi > - > -if [[ $cgroup2 ]]; then > - echo "+hugetlb" >/dev/cgroup/memory/cgroup.subtree_control > -fi > +export cgroup_path > > function cleanup() { > if [[ $cgroup2 ]]; then > @@ -108,7 +112,7 @@ function setup_cgroup() { > > function wait_for_hugetlb_memory_to_get_depleted() { > 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. > while [ $(cat $path) != 0 ]; do > echo Waiting for hugetlb memory to get depleted. > @@ -121,7 +125,7 @@ function wait_for_hugetlb_memory_to_get_reserved() { > local cgroup="$1" > 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. > while [ $(cat $path) != $size ]; do > 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 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. > while [ $(cat $path) != $size ]; do > echo Waiting for hugetlb memory to reach size $size. > @@ -574,5 +578,7 @@ for populate in "" "-o"; do > done # populate > done # method > > -umount $cgroup_path > -rmdir $cgroup_path > +if [[ $do_umount ]]; then > + umount $cgroup_path > + rmdir $cgroup_path > +fi > diff --git a/tools/testing/selftests/vm/hugetlb_reparenting_test.sh b/tools/testing/selftests/vm/hugetlb_reparenting_test.sh > old mode 100644 > new mode 100755 > index 4a9a3afe9fd4..bf2d2a684edf > --- a/tools/testing/selftests/vm/hugetlb_reparenting_test.sh > +++ b/tools/testing/selftests/vm/hugetlb_reparenting_test.sh > @@ -18,19 +18,24 @@ if [[ "$1" == "-cgroup-v2" ]]; then > usage_file=current > fi > > -CGROUP_ROOT='/dev/cgroup/memory' > -MNT='/mnt/huge/' > > -if [[ ! -e $CGROUP_ROOT ]]; then > - mkdir -p $CGROUP_ROOT > - if [[ $cgroup2 ]]; then > +if [[ $cgroup2 ]]; then > + CGROUP_ROOT=$(mount -t cgroup2 | head -1 | awk -e '{print $3}') > + if [[ -z "$CGROUP_ROOT" ]]; then > + CGROUP_ROOT=/dev/cgroup/memory > mount -t cgroup2 none $CGROUP_ROOT > - sleep 1 > - echo "+hugetlb +memory" >$CGROUP_ROOT/cgroup.subtree_control > - else > + do_umount=1 > + fi > + 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 > + do_umount=1 > fi > fi > +MNT='/mnt/huge/' > > function get_machine_hugepage_size() { > hpz=$(grep -i hugepagesize /proc/meminfo) > diff --git a/tools/testing/selftests/vm/write_hugetlb_memory.sh b/tools/testing/selftests/vm/write_hugetlb_memory.sh > old mode 100644 > new mode 100755 > index d3d0d108924d..70a02301f4c2 > --- a/tools/testing/selftests/vm/write_hugetlb_memory.sh > +++ b/tools/testing/selftests/vm/write_hugetlb_memory.sh > @@ -14,7 +14,7 @@ want_sleep=$8 > reserve=$9 > > 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" > > -- > 2.27.0 >