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 3795BC5321E for ; Mon, 26 Aug 2024 14:16:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD07A6B0082; Mon, 26 Aug 2024 10:16:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B59DE6B0085; Mon, 26 Aug 2024 10:16:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D3546B008A; Mon, 26 Aug 2024 10:16:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7CB096B0082 for ; Mon, 26 Aug 2024 10:16:29 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3BD5FC11C8 for ; Mon, 26 Aug 2024 14:16:29 +0000 (UTC) X-FDA: 82494596898.16.15E0626 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 236C014000B for ; Mon, 26 Aug 2024 14:16:25 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Emcc1jAp; spf=pass (imf26.hostedemail.com: domain of mcasquer@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=mcasquer@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724681672; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=c+nhWTyzd1EZSu9QxGO7u5TrkuVgATh5FsPGD0fQ+wc=; b=XqP1KaHz2oAE0uSmyrKFQ3Bwa6RyKQcOVjZ+XkoQmk4b0Lw1qwHb/hsUjxeJeGCiITYoPa v5VCoFSpRSmcLVSBgKt6iTKQFKqK9fuMCOdtRvUGvRr8T2UOehIlUTeagItHjTTJLv/2t/ Mu35Q6aGXu260t4jWw1VjkmmB1+ozfs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Emcc1jAp; spf=pass (imf26.hostedemail.com: domain of mcasquer@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=mcasquer@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724681672; a=rsa-sha256; cv=none; b=YxQlCdRxODTDb9Awv+A5DkkllJtrMTytEhedl+7Kys8dxoPPbGxllCSGkDXWmg5aIURlvB f+HQBaRGmoacJ7KS4iB0t49LEjvNEDocXnbzjnxztxbfROhAxSwInSulxhu0MgsUjlLN8N IuMitbVPpxzEQ24bY/rU1tkIPvMU2nE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724681785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c+nhWTyzd1EZSu9QxGO7u5TrkuVgATh5FsPGD0fQ+wc=; b=Emcc1jAp+MlSS4JByjqLP5UDdYrEWMq/NUGO3dyyIJlnrnQqjgsdnhEKo/s7aLxhevu9Q9 iBAdWTtMTF1YQtKTmKLxAb6AE73IHwbJgv5le99J162mimOauAe5+V9ncat5bcX8IdgzUE 5nBMHhRBMcR40PXG6k0cYYiej5rSexo= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-soVGuv88OLWHCSJTrY2cAw-1; Mon, 26 Aug 2024 10:16:20 -0400 X-MC-Unique: soVGuv88OLWHCSJTrY2cAw-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2f3f16a39e0so38510821fa.2 for ; Mon, 26 Aug 2024 07:16:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724681779; x=1725286579; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c+nhWTyzd1EZSu9QxGO7u5TrkuVgATh5FsPGD0fQ+wc=; b=kotUYZS69p8ZBd35cxYoBL/5Y5Ld3aND9Tfk90BxFdE4ep0ns+j6Zf1Mso9CeZEEHT J7wh8UJ2ZeQ4MAJ8ZACoUjbqEflHj20z6gK8fVnblwtjKiD2/68B6fuY7L+dl5kyEpqz JtTJrH35SZWmICpoTLg7Dk53SS1Om63+r/NyNlnlZXwSLChnBLTEN3/gb7Qw58zTm3ny dOuk13yhDxb5qqmRfuZwjygdedGr8p+VVK/Ia1tej7UQqrPNlJ5drEHFyNLpxdORS6Wd 5D/x0qvJ+szR//89fdKsktccc8WmvwScsrMXqTEnwfhtBnYc+qAMGoPZq0+IvMyFqyhw fSug== X-Forwarded-Encrypted: i=1; AJvYcCVWzU9qvT14tldQLC85CfbZfjXcSXndvoS07UiNxRH/j36Afhatg8NEYe5JyfS0KFzXUHNBjk33Ew==@kvack.org X-Gm-Message-State: AOJu0YyLVN53K9PgAfmeGtTKeek6qs7Q+ysXq1srtjLMlbSkBtefVFLD wi31K5CKlQeFypUJZCA1lC6TmfAhq52X3taFfkg0+PDgaKg2robKtZgtQPntGinZLBPfwH9dMgs 4fC32n2AWqregyHyYIYs7fWMoRDKU4rWefVBHWz9yUHftFU1OhshnGg8Zy8bXlNy2bm4A7iynjx 9T5Bd2U9O1UOcwUvy+HBHMRXc= X-Received: by 2002:a05:651c:1544:b0:2f3:d008:a54e with SMTP id 38308e7fff4ca-2f4f493a354mr82359991fa.36.1724681779196; Mon, 26 Aug 2024 07:16:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjsUTW2QGEs1pHXZ1pLASk+FK03mP2oVNdzWBn0IfbZdLgVs0FRFpTJwlH4BarayX187CLxqiwvqGZ4Zuf5wI= X-Received: by 2002:a05:651c:1544:b0:2f3:d008:a54e with SMTP id 38308e7fff4ca-2f4f493a354mr82359731fa.36.1724681778674; Mon, 26 Aug 2024 07:16:18 -0700 (PDT) MIME-Version: 1.0 References: <20240821123115.2068812-1-david@redhat.com> In-Reply-To: <20240821123115.2068812-1-david@redhat.com> From: Mario Casquero Date: Mon, 26 Aug 2024 16:16:07 +0200 Message-ID: Subject: Re: [PATCH v1] selftests/mm: fix charge_reserved_hugetlb.sh test To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Andrew Morton , Shuah Khan , Muchun Song , Mina Almasry X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 236C014000B X-Stat-Signature: yznxp4towz5w5sfd1ej34ge1duz896fq X-Rspam-User: X-HE-Tag: 1724681785-605317 X-HE-Meta: U2FsdGVkX1+/I4S/dIQNrO8p8d8Cz98dCBzbNMs6dCTdyG6nL2d+FZdR4DfrhcOsAmDYJKULZ0tUtAgq3y/Zr4Wt8Uimz3nBSneEygi3UEsTsbQCoz3B5xlQ4xkiCAC1vSroWuWoj5mUrnN2d7vycDQHNchBvg1zuDC+ZfvKuFpn2aGFx3XJVhK/gyx2V+xj0FBAk+gJiV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O7d6P+kQomLNaLcC49SZ62/MJx5yJ6XBf/vrWYmbcxnJeF8BWyqmYXgnBez/DxaTeW/F+UDIFGtrCG1E/AhBVdv3mz7Hg4Y2L5ct4RX23f3V0N8= 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: List-Subscribe: List-Unsubscribe: This patch has been successfully tested. All hugetlb kernel selftests pass = now. # SUMMARY: PASS=3D12 SKIP=3D0 FAIL=3D0 Tested by: Mario Casquero On Wed, Aug 21, 2024 at 2:31=E2=80=AFPM David Hildenbrand wrote: > > Currently, running the charge_reserved_hugetlb.sh selftest we can > sometimes observe something like: > > $ ./charge_reserved_hugetlb.sh -cgroup-v2 > ... > write_result is 0 > After write: > hugetlb_usage=3D0 > reserved_usage=3D10485760 > killing write_to_hugetlbfs > Received 2. > Deleting the memory > Detach failure: Invalid argument > umount: /mnt/huge: target is busy. > > Both cases are issues in the test. > > While the unmount error seems to be racy, it will make the test fail: > $ ./run_vmtests.sh -t hugetlb > ... > # [FAIL] > not ok 10 charge_reserved_hugetlb.sh -cgroup-v2 # exit=3D32 > > The issue is that we are not waiting for the write_to_hugetlbfs process > to quit. So it might still have a hugetlbfs file open, about which > umount is not happy. Fix that by making "killall" wait for the process > to quit. > > The other error ("Detach failure: Invalid argument") does not seem to > result in a test error, but is misleading. Turns out write_to_hugetlbfs.c > unconditionally tries to cleanup using shmdt(), even when we only > mmap()'ed a hugetlb file. Even worse, shmaddr is never even set for the > SHM case. Fix that as well. > > With this change it seems to work as expected. > > Fixes: 29750f71a9b4 ("hugetlb_cgroup: add hugetlb_cgroup reservation test= s") > Reported-by: Mario Casquero > Cc: Andrew Morton > Cc: Shuah Khan > Cc: Muchun Song > Cc: Mina Almasry > Signed-off-by: David Hildenbrand > --- > .../selftests/mm/charge_reserved_hugetlb.sh | 2 +- > .../testing/selftests/mm/write_to_hugetlbfs.c | 21 +++++++++++-------- > 2 files changed, 13 insertions(+), 10 deletions(-) > > diff --git a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh b/tool= s/testing/selftests/mm/charge_reserved_hugetlb.sh > index d680c00d2853a..67df7b47087f0 100755 > --- a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh > +++ b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh > @@ -254,7 +254,7 @@ function cleanup_hugetlb_memory() { > local cgroup=3D"$1" > if [[ "$(pgrep -f write_to_hugetlbfs)" !=3D "" ]]; then > echo killing write_to_hugetlbfs > - killall -2 write_to_hugetlbfs > + killall -2 --wait write_to_hugetlbfs > wait_for_hugetlb_memory_to_get_depleted $cgroup > fi > set -e > diff --git a/tools/testing/selftests/mm/write_to_hugetlbfs.c b/tools/test= ing/selftests/mm/write_to_hugetlbfs.c > index 6a2caba19ee1d..1289d311efd70 100644 > --- a/tools/testing/selftests/mm/write_to_hugetlbfs.c > +++ b/tools/testing/selftests/mm/write_to_hugetlbfs.c > @@ -28,7 +28,7 @@ enum method { > > /* Global variables. */ > static const char *self; > -static char *shmaddr; > +static int *shmaddr; > static int shmid; > > /* > @@ -47,15 +47,17 @@ void sig_handler(int signo) > { > printf("Received %d.\n", signo); > if (signo =3D=3D SIGINT) { > - printf("Deleting the memory\n"); > - if (shmdt((const void *)shmaddr) !=3D 0) { > - perror("Detach failure"); > + if (shmaddr) { > + printf("Deleting the memory\n"); > + if (shmdt((const void *)shmaddr) !=3D 0) { > + perror("Detach failure"); > + shmctl(shmid, IPC_RMID, NULL); > + exit(4); > + } > + > shmctl(shmid, IPC_RMID, NULL); > - exit(4); > + printf("Done deleting the memory\n"); > } > - > - shmctl(shmid, IPC_RMID, NULL); > - printf("Done deleting the memory\n"); > } > exit(2); > } > @@ -211,7 +213,8 @@ int main(int argc, char **argv) > shmctl(shmid, IPC_RMID, NULL); > exit(2); > } > - printf("shmaddr: %p\n", ptr); > + shmaddr =3D ptr; > + printf("shmaddr: %p\n", shmaddr); > > break; > default: > -- > 2.46.0 >