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 X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56835C83003 for ; Wed, 29 Apr 2020 11:07:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E45F0206C0 for ; Wed, 29 Apr 2020 11:07:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E45F0206C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 562568E0005; Wed, 29 Apr 2020 07:07:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 512E18E0001; Wed, 29 Apr 2020 07:07:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 429578E0005; Wed, 29 Apr 2020 07:07:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id 2BB398E0001 for ; Wed, 29 Apr 2020 07:07:41 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C952545CD for ; Wed, 29 Apr 2020 11:07:40 +0000 (UTC) X-FDA: 76760617080.23.color35_42fc9b9506b1c X-HE-Tag: color35_42fc9b9506b1c X-Filterd-Recvd-Size: 7251 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Wed, 29 Apr 2020 11:07:40 +0000 (UTC) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03TB2w07171831; Wed, 29 Apr 2020 07:07:39 -0400 Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0b-001b2d01.pphosted.com with ESMTP id 30q7rpsh1r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 29 Apr 2020 07:07:39 -0400 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 03TB6LkF003713; Wed, 29 Apr 2020 11:07:38 GMT Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by ppma02wdc.us.ibm.com with ESMTP id 30mcu6m7fq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 29 Apr 2020 11:07:38 +0000 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 03TB7cYn52363530 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Apr 2020 11:07:38 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 36888124055; Wed, 29 Apr 2020 11:07:38 +0000 (GMT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6B92B124053; Wed, 29 Apr 2020 11:07:36 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.85.94.22]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 29 Apr 2020 11:07:36 +0000 (GMT) From: "Aneesh Kumar K.V" To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, "Aneesh Kumar K.V" Subject: [PATCH] khugeepaged: Replace the usage of system(3) in the test. Date: Wed, 29 Apr 2020 16:37:27 +0530 Message-Id: <20200429110727.89388-1-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676 definitions=2020-04-29_04:2020-04-29,2020-04-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 clxscore=1015 mlxlogscore=999 impostorscore=0 lowpriorityscore=0 malwarescore=0 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004290089 Content-Transfer-Encoding: quoted-printable 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: Some glibc version doesn't use CLONE_VM | CLONE_VFORK for system(3) imple= mentation and on such system, we find the test case fails. This is due to fork() ma= rking all the parent page table pages read-only to do a COW. Avoid the usage of system(3) in the test. Signed-off-by: Aneesh Kumar K.V --- tools/testing/selftests/vm/khugepaged.c | 105 +++++++++++++++++------- 1 file changed, 77 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/vm/khugepaged.c b/tools/testing/self= tests/vm/khugepaged.c index 490055290d7f..9b2d675c0fd3 100644 --- a/tools/testing/selftests/vm/khugepaged.c +++ b/tools/testing/selftests/vm/khugepaged.c @@ -21,6 +21,7 @@ static unsigned long page_size; static int hpage_pmd_nr; =20 #define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/" +#define PID_SMAPS "/proc/self/smaps" =20 enum thp_enabled { THP_ALWAYS, @@ -333,56 +334,104 @@ static void adjust_settings(void) success("OK"); } =20 -#define CHECK_HUGE_FMT "sed -ne " \ - "'/^%lx/,/^AnonHugePages/{/^AnonHugePages:\\s*%ld kB/ q1}' " \ - "/proc/%d/smaps" +#define MAX_LINE_LENGTH 500 =20 -static bool check_huge(void *p) +static bool check_for_pattern(FILE *fp, char *pattern, char *buf) { - char *cmd; + while (fgets(buf, MAX_LINE_LENGTH, fp) !=3D NULL) { + if (!strncmp(buf, pattern, strlen(pattern))) + return true; + } + return false; +} + +static bool check_huge(char *addr) +{ + bool thp =3D false; int ret; + FILE *fp; + char buffer[MAX_LINE_LENGTH]; + char addr_pattern[MAX_LINE_LENGTH]; =20 - ret =3D asprintf(&cmd, CHECK_HUGE_FMT, - (unsigned long)p, hpage_pmd_size >> 10, getpid()); - if (ret < 0) { - perror("asprintf(CHECK_FMT)"); + ret =3D snprintf(addr_pattern, MAX_LINE_LENGTH, "%08llx-", addr); + if (ret >=3D MAX_LINE_LENGTH) { + printf("%s: Pattern is too long\n", __func__); exit(EXIT_FAILURE); } =20 - ret =3D system(cmd); - free(cmd); - if (ret < 0 || !WIFEXITED(ret)) { - perror("system(check_huge)"); + + fp =3D fopen(PID_SMAPS, "r"); + if (!fp) { + printf("%s: Failed to open file %s\n", __func__, PID_SMAPS); exit(EXIT_FAILURE); } + if (!check_for_pattern(fp, addr_pattern, buffer)) + goto err_out; =20 - return WEXITSTATUS(ret); + ret =3D snprintf(addr_pattern, MAX_LINE_LENGTH, "AnonHugePages:%10lld k= B", hpage_pmd_size >> 10); + if (ret >=3D MAX_LINE_LENGTH) { + printf("%s: Pattern is too long\n", __func__); + exit(EXIT_FAILURE); + } + /* + * Fetch the AnonHugePages: in the same block and check whether it got + * the expected number of hugeepages next. + */ + if (!check_for_pattern(fp, "AnonHugePages:", buffer)) + goto err_out; + + if (strncmp(buffer, addr_pattern, strlen(addr_pattern))) + goto err_out; + + thp =3D true; +err_out: + fclose(fp); + return thp; } =20 -#define CHECK_SWAP_FMT "sed -ne " \ - "'/^%lx/,/^Swap:/{/^Swap:\\s*%ld kB/ q1}' " \ - "/proc/%d/smaps" =20 -static bool check_swap(void *p, unsigned long size) +static bool check_swap(void *addr, unsigned long size) { - char *cmd; + bool swap =3D false; int ret; + FILE *fp; + char buffer[MAX_LINE_LENGTH]; + char addr_pattern[MAX_LINE_LENGTH]; =20 - ret =3D asprintf(&cmd, CHECK_SWAP_FMT, - (unsigned long)p, size >> 10, getpid()); - if (ret < 0) { - perror("asprintf(CHECK_SWAP)"); + ret =3D snprintf(addr_pattern, MAX_LINE_LENGTH, "%08llx-", addr); + if (ret >=3D MAX_LINE_LENGTH) { + printf("%s: Pattern is too long\n", __func__); exit(EXIT_FAILURE); } =20 - ret =3D system(cmd); - free(cmd); - if (ret < 0 || !WIFEXITED(ret)) { - perror("system(check_swap)"); + + fp =3D fopen(PID_SMAPS, "r"); + if (!fp) { + printf("%s: Failed to open file %s\n", __func__, PID_SMAPS); exit(EXIT_FAILURE); } + if (!check_for_pattern(fp, addr_pattern, buffer)) + goto err_out; =20 - return WEXITSTATUS(ret); + ret =3D snprintf(addr_pattern, MAX_LINE_LENGTH, "Swap:%19lld kB", size = >> 10); + if (ret >=3D MAX_LINE_LENGTH) { + printf("%s: Pattern is too long\n", __func__); + exit(EXIT_FAILURE); + } + /* + * Fetch the Swap: in the same block and check whether it got + * the expected number of hugeepages next. + */ + if (!check_for_pattern(fp, "Swap:", buffer)) + goto err_out; + + if (strncmp(buffer, addr_pattern, strlen(addr_pattern))) + goto err_out; + + swap =3D true; +err_out: + fclose(fp); + return swap; } =20 static void *alloc_mapping(void) --=20 2.26.2