From patchwork Wed Nov 16 11:25:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tarun Sahu X-Patchwork-Id: 1704514 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=fVvJ4EZJ; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NC14M1FjFz23nB for ; Wed, 16 Nov 2022 22:27:47 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2359F3CD049 for ; Wed, 16 Nov 2022 12:27:44 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 8AD343CD054 for ; Wed, 16 Nov 2022 12:26:40 +0100 (CET) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id B50211A00CA3 for ; Wed, 16 Nov 2022 12:26:39 +0100 (CET) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AGBPeOf009815; Wed, 16 Nov 2022 11:26:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=hODmIogkps+ugJWIu3ioUlJhvwA6UiPKws/CfZsx918=; b=fVvJ4EZJCQ+zuWdu1C2n5wUszBjCdG2g6IKh3qZNptxcBSNi4CtJ2kkwOccHF3xPHET7 QpSNWJcVKvNmEDWlwD/ox441QFduZH6Pfq1zyT9vkTLRZcCxdWllF1HkQM6b2DOeClpj bLCmqAA2UMw2SuIozHWqn2l0tbmcpcIx6rbXUBF6UfGjNjFQGTxmypZ2fouHmV7s07g/ 8mMTbEFY7fdeQvOaeUDB2nVD5ox+vvTQRy9A1X155lHQEvFxTujETrxYXiiJdmkzXfsv 5kV8NTJnXozmRGIj+pPKnsLbqPLXb78ymUI7TaQKdjy0yvX5ffIpLc+vziRcK/5R2zLl Tg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvxygr0f7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:38 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2AGBQbe0012411; Wed, 16 Nov 2022 11:26:37 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvxygr0ev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:37 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2AGBKd0c016550; Wed, 16 Nov 2022 11:26:35 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06ams.nl.ibm.com with ESMTP id 3kt2rjdtqv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 11:26:35 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2AGBQW7f37814712 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Nov 2022 11:26:32 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 930D742045; Wed, 16 Nov 2022 11:26:32 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6D3FD4203F; Wed, 16 Nov 2022 11:26:30 +0000 (GMT) Received: from tarunpc.in.ibm.com (unknown [9.199.157.25]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 16 Nov 2022 11:26:30 +0000 (GMT) From: Tarun Sahu To: ltp@lists.linux.it Date: Wed, 16 Nov 2022 16:55:16 +0530 Message-Id: <20221116112516.261535-8-tsahu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221116112516.261535-1-tsahu@linux.ibm.com> References: <20221116112516.261535-1-tsahu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vOMpkc8GpksqmmL3ucPk1MdcQhJ5VQt- X-Proofpoint-ORIG-GUID: yeaNBZQy9oT7nN8MYwglCXicEZN39rIE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-16_02,2022-11-16_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 phishscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 spamscore=0 adultscore=0 bulkscore=0 impostorscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211160078 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v4 7/7] Hugetlb: Migrating libhugetlbfs fallocate_basic X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: geetika@linux.ibm.com, sbhat@linux.ibm.com, aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com, mike.kravetz@oracle.com Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Migrating the libhugetlbfs/testcases/fallocate_basic.c test Test Description: It tests basic fallocate functionality in hugetlbfs. Preallocate huge pages to a file in hugetlbfs, and then remove the pages via hole punch. Signed-off-by: Tarun Sahu --- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../hugetlb/hugefallocate/hugefallocate02.c | 90 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c diff --git a/runtest/hugetlb b/runtest/hugetlb index ca92dfcff..ec1fc2515 100644 --- a/runtest/hugetlb +++ b/runtest/hugetlb @@ -1,4 +1,5 @@ hugefallocate01 hugefallocate01 +hugefallocate02 hugefallocate02 hugemmap01 hugemmap01 hugemmap02 hugemmap02 diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore index cafdb5259..c0906f3d3 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -1,5 +1,6 @@ /cpuset/cpuset01 /hugetlb/hugefallocate/hugefallocate01 +/hugetlb/hugefallocate/hugefallocate02 /hugetlb/hugemmap/hugemmap01 /hugetlb/hugemmap/hugemmap02 /hugetlb/hugemmap/hugemmap04 diff --git a/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c b/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c new file mode 100644 index 000000000..d1e11dcbe --- /dev/null +++ b/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright (C) 2015 Oracle Corporation + * Author: Mike Kravetz + */ + +/*\ + * [Description] + * + * It tests basic fallocate functionality in hugetlbfs. Preallocate huge + * pages to a file in hugetlbfs, and then remove the pages via hole punch. + * + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "hugetlb.h" + +#define MAX_PAGES_TO_USE 5 +#define MNTPOINT "hugetlbfs/" + +static int fd = -1; +static long hpage_size; + +static void run_test(void) +{ + int err; + unsigned long max_iterations; + unsigned long free_initial, free_after, free_end; + + free_initial = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + max_iterations = MIN(free_initial, MAX_PAGES_TO_USE); + + fd = tst_creat_unlinked(MNTPOINT, 0); + + /* First preallocate file with max_iterations pages */ + err = fallocate(fd, 0, 0, hpage_size * max_iterations); + if (err) { + if (errno == EOPNOTSUPP) + tst_brk(TCONF, "fallocate() Operation is not supported"); + tst_res(TFAIL|TERRNO, "fallocate()"); + goto cleanup; + } + + free_after = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + if (free_initial - free_after != max_iterations) { + tst_res(TFAIL, "fallocate did not preallocate %lu huge pages", + max_iterations); + goto cleanup; + } + + /* Now punch a hole of the same size */ + err = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + 0, hpage_size * max_iterations); + if (err) { + tst_res(TFAIL|TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)"); + goto cleanup; + } + + free_end = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE); + TST_EXP_EQ_LU(free_end, free_initial); +cleanup: + SAFE_CLOSE(fd); +} + +static void setup(void) +{ + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024; +} + +static void cleanup(void) +{ + if (fd > 0) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .needs_root = 1, + .mntpoint = MNTPOINT, + .needs_hugetlbfs = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = run_test, + .hugepages = {3, TST_NEEDS}, +};