From patchwork Thu Jan 13 18:03:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12713035 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 609EAC433EF for ; Thu, 13 Jan 2022 18:03:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 790D76B0073; Thu, 13 Jan 2022 13:03:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 723D26B0074; Thu, 13 Jan 2022 13:03:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A7AE6B0075; Thu, 13 Jan 2022 13:03:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0052.hostedemail.com [216.40.44.52]) by kanga.kvack.org (Postfix) with ESMTP id 3CB066B0073 for ; Thu, 13 Jan 2022 13:03:36 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id ED07D18100DC2 for ; Thu, 13 Jan 2022 18:03:35 +0000 (UTC) X-FDA: 79026036390.24.FFC61B8 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf18.hostedemail.com (Postfix) with ESMTP id 70A011C0003 for ; Thu, 13 Jan 2022 18:03:35 +0000 (UTC) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20DHnBlD022208; Thu, 13 Jan 2022 18:03:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=XkA1nwfoP0Sp8QHd9U6BJ7gVnL28cHhiQKcW+WuhdVg=; b=xnu5T8xTO74O2SMo4/raLf00VcWvbvbR35nEfpouXy+3Q5YuI04CnbD4ruM/ue2BOvqq abUzh+VPNghEDhAjDjzG3e4jXc+jqvYI76kZ3M7DlUh4SWGPrsmcmW4mtnYpKpzpK9kb 4FJtmpxxkj6i0E7jBto9MUOGCCHSqCCKfyWDvt6yX4fBSjQUbyQJLkO/ybXGEhv6CufH X1wyFjlbKHaWJckKjXaBaBu3INZ+R9XQoUz1bC358wAPQeShBKnyVT36QLBsII3O4KYB CSjyvyU5mTz/W/DpbsQ3ECV7GO1Y74ff9k9R5s3ZDeGz9uqZS9ShKjKnBuiZxsM5ycxJ Dg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3djjm0h4ef-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Jan 2022 18:03:26 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20DI0JxH174179; Thu, 13 Jan 2022 18:03:25 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2172.outbound.protection.outlook.com [104.47.59.172]) by userp3030.oracle.com with ESMTP id 3deyr265nk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Jan 2022 18:03:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ObyCLs9RmUbVopTZWkWpPWZDLoVLglLVP0MKlJERl0ECmZSPs60qt/On7Na+ejpIgH6fW+9oOe6AFaX3Xk3+bhGlfy8TeX0CUR41J5MvQjV46UCVXCjUHukH+2hni8EPukfa+40lsIVBUSU5foyE6yeL53bJ3RygUmGWTdPPgSJysBdvESPna3v4apUdQxNdCweNj7wumH3wtdZrTDnSPswSNs9dhcbJ+Vm69pX1mtbzv3V7OUT3+9CL0di9vwX6VheGnF44QHNDdVmttiTPP+61gKmxOrPLVWHJfmcqLZ6NNeMxgpilTMWPiJhxCVmzlipdu10C5M/duSHkKU/2IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XkA1nwfoP0Sp8QHd9U6BJ7gVnL28cHhiQKcW+WuhdVg=; b=JOZAag0VDEDyHrPgOvXY8/Hab7nHUYHmTR3ETZNjIHzjxEDyjqeiyn6ISrypvu/pxpjmtx3BhVfiGqQqowOs6X53WiodQKW+gJcSwR3TVJdxoTSBPQ3dFgq8gaAsXGStBZ4uvr5E9eQ9A0Rs8F3O6tX0IcfNdfgXWusfVofXbrjtGQiFB/ce1ZU31e3Dbqifg4t54KTi3dSvJj4BPm/lo96H8NpUwHqXZkqLd02nJltrWEY6EAISw3IhrY+tO6VSIXfqXANpn1dFSeQSIybGitD+CaKx+uB4Jum2MqJp221KMX8sPiyuLuwjT9Vx0QeiSC7c2+QZ9MKXUcFoPSvezQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XkA1nwfoP0Sp8QHd9U6BJ7gVnL28cHhiQKcW+WuhdVg=; b=ynBpiulRivawsqmZI7cAymt5xzhn855VgrYnWtNzaR8Mau6kqPy5MzJIlKvkuzve9FPHwD0SRZu+44Hhd/NcZhi4gNrQLrPunVWezl3eJC8fHvOJ6fDsaR02P6Ea/DSNYoSO0i7JXmqK6CkZHUBBmBa+GEfS+40OvUAvZHaIICs= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BN6PR10MB1540.namprd10.prod.outlook.com (2603:10b6:404:47::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.9; Thu, 13 Jan 2022 18:03:22 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::8502:19a4:8a7f:ea73]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::8502:19a4:8a7f:ea73%7]) with mapi id 15.20.4888.011; Thu, 13 Jan 2022 18:03:22 +0000 From: Mike Kravetz To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Michal Hocko , Naoya Horiguchi , Axel Rasmussen , Peter Xu , Andrea Arcangeli , Mina Almasry , Shuah Khan , Andrew Morton , Mike Kravetz Subject: [RFC PATCH 1/3] mm: enable MADV_DONTNEED for hugetlb mappings Date: Thu, 13 Jan 2022 10:03:06 -0800 Message-Id: <20220113180308.15610-2-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220113180308.15610-1-mike.kravetz@oracle.com> References: <20220113180308.15610-1-mike.kravetz@oracle.com> X-ClientProxiedBy: BYAPR08CA0009.namprd08.prod.outlook.com (2603:10b6:a03:100::22) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2d285895-75d4-445b-5f96-08d9d6befce3 X-MS-TrafficTypeDiagnostic: BN6PR10MB1540:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MCe2MSO1lM4TrIA12Gtn8QJiKJOqapbL8/+1aG3UA6Zky8sKba30ACwo9i/xVRA1CsY3nvwbvqecvcN8q75SYxY9Xb9Z7BajyfppJBZmXGv/6SMQ2BMr7IZQmFWl86QIjrsYA877Vx1S1iECE1KDjuDFZCutOkUmFwpDdE929ekZJYnCTlwe6U4CMPobdn3LhMwphD+U73MUKzew4oY1vsVaNF9YvtAIoOrR1y+b3aD2GjohTy9ptErQqajANqZMjIh2S8prgxWNZWuSKzWQRXancLIxaGSjLTovRCcz5kv/jEZYOZVvQgjdOqknGj2V/1A7F0kA0bp5QSZfRv9Cv/Vo3XVbYtD2ulmfJuR9rm9ZlbYPY0z/pMGyU4Bf7dcvHbrVPA7na0KlIxxKU8k5CIsZeK3Y+x7pWCM4YX36y0oPc5VLFCdo5zmTeQXa7e2Vw/hg1MyNSGYV6s4CtmG+BWij+bwPqqN0d6GeG5vcsxoXEpLXAQuLq6EaiVlsoroQAbVplO0y2CQRQboK5JfgBs7txNTd8bLZe8EjdLv/snVWCrpL40doC57N3R7J4MnKbRhzK1wdUD+Y1oeUB8jxyC8Eoyy70iFFnBlFYhC1TxxzXvpcYfjH4QycUww7HD4ENA39km3BhCGik7ZwxXhixRatiHObxZ5i6T69HqtEENdXgaVrciqkP0OKbonUJwxgf0vGwLLmt64KCxSEdeXeSw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(6512007)(4326008)(2906002)(6506007)(316002)(52116002)(8936002)(38350700002)(66476007)(38100700002)(508600001)(54906003)(66946007)(107886003)(8676002)(66556008)(6666004)(26005)(7416002)(2616005)(1076003)(44832011)(5660300002)(86362001)(36756003)(83380400001)(6486002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +b18qfQvDpbeV2n6Sdac0RBsdRFaIYF1uf4tilum5ui2pOO+kknUgfB70uBMryKP6PUHCviLAKKkgbgzFGGpGr72Bx5ggFwipRBe1tO3sfI9oVZVFQDK9Y4JQE9Jhvj8E+5Rrca46Np9K8W/8U1w9bttQKynqP1bvdDQDNIUh9wjV7PnLQEz2aHK0JLPEK74uIO6JhIAbQMaAU1mScQWKsGHM6dI/Cuk7yi0ey5kCbC2VBo4PzWoUFs/D/t0VwcYEErB33yqr2MWE9jQgU/Fi/inr+eCfBhRS+B8BjgK5+A/eSVR9ssrTcoEGNwneiwfzDaO0vpTTWQqVyVQcqS7Vn7HDXZOFcfXguBJ2JY55XtoQq92PUbm6LIak/MFaKkmP1CS/RCzgt9WGYtY0yjyZcNuwVHfYCmkf9olYu2sKVnPQnJbbLpV/Bcdz7bZHJdSKF9UxZJlBdVJfjDVvmklLh9dTls/XYGxVnIO6+x5bkVUk+PQnTvvv4ZLCeX6F3lebFAKljCD95tzeUui8V1ScS27xDiFR8j+d1c0visjOfiVcAxJpvq9o/S7YVdObIrkZ0EBOyq32Yf2cHQPveWCBvddWMxSgfVyuTVk8QZPvR4UdGimcWDLpMa4TG4Uf/SNWfjbDwDuK4FEvNY4E3hkHezOJO75NT6pDdRAWXP9lLOGVXFlkEWQ820pO0K8pDtQksYNqiewt4unwIq5XEEP9FOuJfQQ/gNU/LDMbYuh/VUHHsvQ8b/CzfXsCyGr9D7b/jvWSXl6f6uTUHJJKZpag10Oa5ME6nfUFG2jtB2yiMH1IgYJM63moJ3l5GTFjBMFktY+Cj8c0fyMZnFbLV3IUejsB/G0tx9QS58qdZhpgCyKOHSSaHFDLhmsvzBRObLkRBDvmW2VA4UCV8t5Ww7Y4jYDupEW9EpxsMazjZzwdBDirNHJEnHfwgK+jZ4aFw/4HtD7FOZgIK3UJPDBsKmcN327J26mO/gya0L3YmAKjVb7cZ+Z5SMs/nUD1TWsLYr0H7dJwGoZ3YCu7Qqb7SSJKwaEqHreX9z5mE6fL1Mxr0nAQ3O9OXv/XrmHyLcYeaviA6eYSZj/M8bePBrXBiDbsoSH4w8aml5b02/13eOj2z54dtrzBKe1eQxcE3uM41AoqB4HCeNYbFBDskeHjsB7KhYusCsfr5cl8Di+mDyzNFe/VOiOKbcaj7k2mO9fhev+Ibz+/2k6QBoHi3uzNhcvSHR9x+PFjA8KAo2iegPumoO/0Cv9mChpnHpVLPk2FbvlMapNBwtSNV0B2fkyJADJ9VWkKaGpR/8XjjrF8cgh4Pz8BNYpPkafVz31FosTvrqtopluWdDi665yCBfOu4/og4NQ4zs6OPEVprdV/YzyjNF8Wl77EuDgK5dKCENk9CjurkPaT/cWjM837Gfq+niAE/6EWqWi81baz3ca0wmBrp0fmti1tDXm7YsdypM3spq8KfF8VyUALLmyMTsarsL41ts+xcC4v/vv9YeYrwu0apLr2HoeymOB9YP9p+HUlLrFZCjr5XgR7tzcfitoNyTejdH+01Zg/dkXcd0cvGOO/GDNP35wxN10HyO2fK/3RidWkXysWnAoBGfG23nSZ4P+BDmNSJ/+4NcCBhWNoDFSlZU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d285895-75d4-445b-5f96-08d9d6befce3 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2022 18:03:22.6413 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uCX3ALypmHhvnQDXeTs6DuvHeKadXgf08cEJtrU4fPBOspgJCSkNkV4pgHcw4Mx172+Fje7oWkClpWI+ONP+zg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR10MB1540 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10226 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 suspectscore=0 spamscore=0 mlxlogscore=809 adultscore=0 phishscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201130112 X-Proofpoint-GUID: 8mZ1G5AT_4PGwVt_mJz81B9JQlJFMBBz X-Proofpoint-ORIG-GUID: 8mZ1G5AT_4PGwVt_mJz81B9JQlJFMBBz X-Rspamd-Queue-Id: 70A011C0003 X-Stat-Signature: zdy1y3uhsdez9fhqx954mf4rsosg7ioc Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=xnu5T8xT; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ynBpiulR; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf18.hostedemail.com: domain of mike.kravetz@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=mike.kravetz@oracle.com X-Rspamd-Server: rspam02 X-HE-Tag: 1642097015-328050 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: MADV_DONTNEED is currently disabled for hugetlb mappings. This certainly makes sense in shared file mappings as the pagecache maintains a reference to the page and it will never be freed. However, it could be useful to unmap and free pages in private mappings. The only thing preventing MADV_DONTNEED (and MADV_FREE) from working on hugetlb mappings is a check in can_madv_lru_vma(). To allow support for hugetlb mappings create and use a new routine madvise_dontneed_valid_vma() that will allow hugetlb mappings. Signed-off-by: Mike Kravetz --- mm/madvise.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 8c927202bbe6..fc8992f4ae40 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -766,6 +766,11 @@ static long madvise_dontneed_single_vma(struct vm_area_struct *vma, return 0; } +static bool madvise_dontneed_valid_vma(struct vm_area_struct *vma) +{ + return (vma->vm_flags & VM_HUGETLB) || can_madv_lru_vma(vma); +} + static long madvise_dontneed_free(struct vm_area_struct *vma, struct vm_area_struct **prev, unsigned long start, unsigned long end, @@ -774,7 +779,7 @@ static long madvise_dontneed_free(struct vm_area_struct *vma, struct mm_struct *mm = vma->vm_mm; *prev = vma; - if (!can_madv_lru_vma(vma)) + if (!madvise_dontneed_valid_vma(vma)) return -EINVAL; if (!userfaultfd_remove(vma, start, end)) { @@ -796,7 +801,7 @@ static long madvise_dontneed_free(struct vm_area_struct *vma, */ return -ENOMEM; } - if (!can_madv_lru_vma(vma)) + if (!madvise_dontneed_valid_vma(vma)) return -EINVAL; if (end > vma->vm_end) { /* From patchwork Thu Jan 13 18:03:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12713036 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 66445C433EF for ; Thu, 13 Jan 2022 18:03:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D103B6B0074; Thu, 13 Jan 2022 13:03:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CBFBA6B0075; Thu, 13 Jan 2022 13:03:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC3816B0078; Thu, 13 Jan 2022 13:03:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0152.hostedemail.com [216.40.44.152]) by kanga.kvack.org (Postfix) with ESMTP id 9B76E6B0074 for ; Thu, 13 Jan 2022 13:03:43 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5764F7F50D for ; Thu, 13 Jan 2022 18:03:43 +0000 (UTC) X-FDA: 79026036726.24.3C44358 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf04.hostedemail.com (Postfix) with ESMTP id 6B16A4005D for ; Thu, 13 Jan 2022 18:03:34 +0000 (UTC) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20DHoWEx001477; Thu, 13 Jan 2022 18:03:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=YQ3Su0di5h0cNeLw+/WUi8BsF5y++YGdc+VsNgBESgo=; b=wXDMhuZaHTaoH6UtaibFAJEiT6cHBGeHO1MnGOFGcZ3pwgf1z49tvbrxH0kfkHXfcwV7 LGLfLp+Emb7Hz/2a8SPgbxj4HicBMVCz6ulR1V3F30GiOSZKnegMLW270lJ6r7YPG3k9 PAmU+pR0jGKkmmvdhEzZBS1nL9DwobfPRxzv8ndvZsjrvc+AGtLEBLbwA83iFY43Ks5u QwPfIj3LgCdcCQzU5qbQr4GlhnnDiWPqGcEjMW1UWLu/9nmt+sRq7fYP60mgAjXeg/dn iIboic9a8hy1xyd5UGi0fZagIU7d7hZZ8xWRoa/xCEAtDkaRZWb7VBjpqlNw9Yib8oN8 gA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3djkwj90hy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Jan 2022 18:03:28 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20DI27Rk000810; Thu, 13 Jan 2022 18:03:27 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by aserp3020.oracle.com with ESMTP id 3df2e86pqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Jan 2022 18:03:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cYtpfFZRDSSU5HlUYysMGsNOpKr/yj0DFPF7Xo4C6ZH8XDsByKkEj/TIZjdCm1AAAgK6MspYuccIrYkcQRhrU2JU2i/2tlaXugRhLuEfhqLNWBxWdz4a0Avy2mvOmnd8YZ1izCxid+oKwGBe4h5DkCsGCdHUm4id2xRTkD9Ek4Xkvq8pCm5kX2u0ezjKRWohxCtMgKdvsnLctsIJEjo16/2J9dRbdR4Aw8HLFoOn4q+MQzUki4zxTkIawktZMxmauVA/oJjBcX5/rloY1k1yXrlsuGPOfzDgLQaEd8nGp3UJCHUM8yONCHZU90p546uzqdmnwJ1rdkH6jCujGH6aqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YQ3Su0di5h0cNeLw+/WUi8BsF5y++YGdc+VsNgBESgo=; b=FwHL4dICbOF5wWgsAUeBR3g4aRcEgN33txwsJxA7Esp4HqBeVlMHBwQ7y1aRRQca1Qq/JSjGGGUyHVbVXdLWipNpiJH1rtoxYsWQYBazUuhUJ8P0tDCD5kvXG5ROrJG/qFKVYGGgurRQmcw10hT+izxPHvc88+GvMqAw4xFT2b4+SruOXqoecsU/lQKseeIab53cNLNkvZnQ3xEejGqbFMBjMdU69VbkKUiwWDbaPIL8Cs1KwZW1eHvi6PMw/8ROzXRm93ySWgGvkVpgrT57p7Cuuq8+ovFTdWeCUGJ3pVn3CaPYhnAFe2xfknRpVoXsy+DlONTYcwLhg+6KnuOQzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YQ3Su0di5h0cNeLw+/WUi8BsF5y++YGdc+VsNgBESgo=; b=BdIvRUCVJvUUnjtP63gUsaD6ArCDaDjZCIaP0DGzSd+cgkeENVq/Mh+P3VCpirWsXeDj2rTzX33jzqqKYFFjrkGiPUkXgVI21GplJBJvwDXWYyOYqOXXUI/zuZfHJ0MgAn9Mtmnc/3fAG54knrCNBYIrF/ifHDknMjgFl0m+N0U= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BLAPR10MB4865.namprd10.prod.outlook.com (2603:10b6:208:334::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Thu, 13 Jan 2022 18:03:25 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::8502:19a4:8a7f:ea73]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::8502:19a4:8a7f:ea73%7]) with mapi id 15.20.4888.011; Thu, 13 Jan 2022 18:03:25 +0000 From: Mike Kravetz To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Michal Hocko , Naoya Horiguchi , Axel Rasmussen , Peter Xu , Andrea Arcangeli , Mina Almasry , Shuah Khan , Andrew Morton , Mike Kravetz Subject: [RFC PATCH 2/3] selftests/vm: add hugetlb madvise MADV_DONTNEED MADV_REMOVE test Date: Thu, 13 Jan 2022 10:03:07 -0800 Message-Id: <20220113180308.15610-3-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220113180308.15610-1-mike.kravetz@oracle.com> References: <20220113180308.15610-1-mike.kravetz@oracle.com> X-ClientProxiedBy: BYAPR08CA0009.namprd08.prod.outlook.com (2603:10b6:a03:100::22) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fcd06160-aa68-4129-f369-08d9d6befe46 X-MS-TrafficTypeDiagnostic: BLAPR10MB4865:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9xWHcLZ4FwNQhVAs+Em+XPMrFSw4ho/BZgh2bGp1JckHF5JfGmNwaqxUwW8/5eml/G0HMVklSUFBQTpjjesAXo4FP3A95vvFTdIGOYZ1qYS6U9roZDut4QAi8oGiNnSSkXtgB9k2+tgGnynz4zyXJJtuguiMHPbuVTMkxM4vGIfK7SthljBDG0fwbjp/yXj3CF6SdxELiUmr/5sVdXCgtceP145xeCKlE+A4D+K+BaWoLw+cfvAP7LAxG6rSsma0dIKbuNysr0ZAtii58ARALr0vOpQN8749TCyxcJDqsEEH8F8d0ktJ4nMt+RsEEmqogxlJSryCi3rXxB3fyNCJTvPzKwwYY/vQxO5+r2mNdyNNBHLEnu2gKtJuo1Jg5FLIuUcmu1uylPjgVoE4693wMaNxkOa1sL3wZ39YFnzMoAP+nRvZG56zFVvwg3IzvsL/Fumk4cnVcz/rx6b1Bgssvh5zN2Eb+JZE7VwDvfXC1QgriIkWgSXcOUVhDHWQSSypb+bDFvYYC/ZwQnLWmHigWrzK2ndYgPNxSFmXt1pYERxQqIw/XL5lfDOllQiPO+hY0q3eFX8KDQyFCulM8gD64izyAQT9hbumAgTsjuGHVNxbrH8Cex/g8/22Zeit8QKbGrPXkIWc6vQ9hGwwZ8+D85HvMOLVdkZueQPMAwli9bNWmuOQlzwYEna86QNAelmgiQ/8/d62hlt4kqIFNgCCwDAhMDMeOFfpSSsWiU2IPiNuuF1LmWsxohRo24XnYiUd0TtqacIq4/ZtUeA4qxPg/sFa2I9HAldRv9GCBcBGnZY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(86362001)(966005)(6506007)(36756003)(44832011)(2906002)(1076003)(6486002)(2616005)(107886003)(508600001)(26005)(83380400001)(7416002)(5660300002)(66476007)(52116002)(186003)(66946007)(8936002)(38350700002)(6512007)(316002)(6666004)(38100700002)(66556008)(54906003)(8676002)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: knK9X1Y94Nxwk2bnz3V7wakl6FAc1nkR3ZbfS38EIbqghZXJMWNoPFoeDvpBY626vrJnQ/p96hyd3N533tAx/yv6NiH1xoA0eSYMTpUC9xjjNBfudxafEg0WETETFi4BmgkyupN6hr700nmJI0H1+qiHabTQC5Db+r3Ltw4nAfQh273WVfz3SOg+9E0mKm+UTksldmyOHTNY5JWqSfipjdD6JWJ2Y+CIF+GseGzBHYo+m+iCwTYpqN7Ka9+TJTe1052qTytgxysul0kQRxmg+/h8l+L1Fatd2D7eoPSuMnijUPHgZVzY2lYkSY0uObxhj34wiZIoHkQO9QDuD6f+WKGrLv+uaI0bHfxoSdgxW8EYF0iUrp5ZTTt3WOWPlgCn9ZOBcdoXhMYReEmzeyORkxZ++och8X7pTykf+O9j2X6LSd51TiSzhpPAbY6AYAHBF40bgTcTPyJLFoNNzogW1bDFioH2YqlLJ9xbGekbs2Ay73NO6bk7R2oft4ZDmGBT7BTovyyJk1jSwtWkmV/ZRCTVpz5/SkY5UlqU6uvA8hM36lebLsB08jhpu+iYCVM9d611fpHZSPrO7jDQB13Kib4aX15FwSMkXUBAfIG6hZUYFZ9w1OdFRt9Txh6+b7itjh4hhvzMhcoU2Uyjk7JmdtBj8VXMOAp8WTp4fx7EnE384xWvSGyrCn9FykJQnIP4TN27exF/PdYW1NrHg73D6I5VKKN4KEkUEVuPuOwJYfSUGjoK6IwoEWhKmxpSNoUVqtg43uywBHYNMFdOGu1BxiS2ArsfxRTohhBKPgwn1crN1h1xTAN7Rge3cza6bL14sJ6pvG4VrNdvkiqAqjZNm58GPVxFvsXyigcivpQ4mffY1tHTOca6oPNK9vvpmGkhm1ioN/zns2xpkW2jgCM51xwK4iXfzkjnzs8sDbe8et1M/tfc3aP0M45GJxp6JFn3e9gjRrQYXeZh3cRbLnN1furdIL/lJNq9SkkZJNI/Stj50iaC+vi00X05A61QYYse26D7/j/pLgV59o+wVPhfPc4BuPwIeC8OiGzuwULFv3AFt1QtTpA5UHLhUf9umPTMHU/tDurUuvFaaUUwue1WkigH7OyApbUAUmtYS4ZgdXEukbhDMGjyl9rJoWr8kVupvxlPrKNLsT/Wcz/4vbCcIYIiRhk4VWSBrVZAEX06wE0UjIpDUKZkuxTZCRCsGPlvqS8OdDJ361ICSALbD3pi5bRXy/2g6RuCdAVg0eLCgL2IL2wDkfnSqyWSqemKMYf41uOtYwAu3dE+Rq8Aq+GTPjoZVHY3Tbb9r/ev+DnSBWMKQ9Baf7M8gbNvSvYdb/nJJuD0z70gl6UXMA73zzoKx9YpWM5uGb9oRuM5JaHSj80wWlrz/Wck+UDSAHbkhplOsLQkmzdXN+wRRXI2Hs7IIPMPjJOAE60rLUpB/1WfhGTMt7HUnCGofksYGhs2n0/qe6Mlskx9Jf4JYGVxbjjJO2nb0g6eFalk3ejHOE2Uwc13ZNf5Mc5jPge1iP7j+K1HRb9nBxr5w5jwprcAuU8TgMrC7eIhCw+PDqXLjI2e7+kpCOIo52lj4wYaZ6wgtVRoffToB3scnayfrr8vPaf1YV6Snwb7SxVMfYeAIFClzjo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fcd06160-aa68-4129-f369-08d9d6befe46 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2022 18:03:25.0008 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hV/J4nLf9tzuX7P2TzSnPJe4WzWVXubzmiZqmsX4bjoqMOQao7rLWyg4mxzsIMOgtphd4tiV9gkhfNEIDTLlSw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4865 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10226 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201130112 X-Proofpoint-ORIG-GUID: PtHBPcDrbntrrTSgbnyH4bD9ezXTWk1e X-Proofpoint-GUID: PtHBPcDrbntrrTSgbnyH4bD9ezXTWk1e X-Rspamd-Queue-Id: 6B16A4005D X-Stat-Signature: 1qipbsua8mp6yp63f31igxb77konmp3p Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=wXDMhuZa; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=BdIvRUCV; spf=none (imf04.hostedemail.com: domain of mike.kravetz@oracle.com has no SPF policy when checking 205.220.165.32) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Rspamd-Server: rspam07 X-HE-Tag: 1642097014-370564 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: Now that MADV_DONTNEED support for hugetlb is enabled, add corresponding tests. MADV_REMOVE has been enabled for some time, but no tests exist so add them as well. Signed-off-by: Mike Kravetz --- tools/testing/selftests/vm/Makefile | 1 + tools/testing/selftests/vm/hugetlb-madvise.c | 315 +++++++++++++++++++ tools/testing/selftests/vm/run_vmtests.sh | 12 + 3 files changed, 328 insertions(+) create mode 100644 tools/testing/selftests/vm/hugetlb-madvise.c diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile index 1607322a112c..f60cf43bbf61 100644 --- a/tools/testing/selftests/vm/Makefile +++ b/tools/testing/selftests/vm/Makefile @@ -28,6 +28,7 @@ LDLIBS = -lrt -lpthread TEST_GEN_FILES = compaction_test TEST_GEN_FILES += gup_test TEST_GEN_FILES += hmm-tests +TEST_GEN_FILES += hugetlb-madvise TEST_GEN_FILES += hugepage-mmap TEST_GEN_FILES += hugepage-mremap TEST_GEN_FILES += hugepage-shm diff --git a/tools/testing/selftests/vm/hugetlb-madvise.c b/tools/testing/selftests/vm/hugetlb-madvise.c new file mode 100644 index 000000000000..de6f2088ad40 --- /dev/null +++ b/tools/testing/selftests/vm/hugetlb-madvise.c @@ -0,0 +1,315 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * hugepage-madvise: + * + * Basic functional testing of madvise MADV_DONTNEED and MADV_REMOVE + * on hugetlb mappings. + * + * Before running this test, make sure the administrator has pre-allocated + * at least MIN_FREE_PAGES hugetlb pages and they are free. In addition, + * the test takes an argument that is the path to a file in a hugetlbfs + * filesystem. Therefore, a hugetlbfs filesystem must be mounted on some + * directory. + */ + +#include +#include +#include +#include +#define __USE_GNU +#include + +#define USAGE "USAGE: %s \n" +#define MIN_FREE_PAGES 20 + +#define validate_free_pages(exp_free) \ + do { \ + int fhp = get_free_hugepages(); \ + if (fhp != (exp_free)) { \ + printf("Unexpected number of free huge " \ + "pages line %d\n", __LINE__); \ + exit(1); \ + } \ + } while (0) + +unsigned long huge_page_size; + +/* + * default_huge_page_size copied from mlock2-tests.c + */ +unsigned long default_huge_page_size(void) +{ + unsigned long hps = 0; + char *line = NULL; + size_t linelen = 0; + FILE *f = fopen("/proc/meminfo", "r"); + + if (!f) + return 0; + while (getline(&line, &linelen, f) > 0) { + if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) { + hps <<= 10; + break; + } + } + + free(line); + fclose(f); + return hps; +} + +unsigned long get_free_hugepages(void) +{ + unsigned long fhp = 0; + char *line = NULL; + size_t linelen = 0; + FILE *f = fopen("/proc/meminfo", "r"); + + if (!f) + return fhp; + while (getline(&line, &linelen, f) > 0) { + if (sscanf(line, "HugePages_Free: %lu", &fhp) == 1) + break; + } + + free(line); + fclose(f); + return fhp; +} + +void write_fault_pages(void *addr, unsigned long nr_pages) +{ + unsigned long i; + + for (i = 0; i < nr_pages; i++) + *((unsigned long *)(addr + (i * huge_page_size))) = i; +} + +void read_fault_pages(void *addr, unsigned long nr_pages) +{ + unsigned long i, tmp; + + for (i = 0; i < nr_pages; i++) + tmp += *((unsigned long *)(addr + (i * huge_page_size))); +} + +int main(int argc, char **argv) +{ + unsigned long free_hugepages; + void *addr, *addr2; + int fd; + + if (argc != 2) { + printf(USAGE, argv[0]); + exit(1); + } + + huge_page_size = default_huge_page_size(); + if (!huge_page_size) { + printf("Unable to determine huge page size, exiting!\n"); + exit(1); + } + + free_hugepages = get_free_hugepages(); + if (free_hugepages < MIN_FREE_PAGES) { + printf("Not enough free huge pages to test, exiting!\n"); + exit(1); + } + + fd = open(argv[1], O_CREAT | O_RDWR, 0755); + if (fd < 0) { + perror("Open failed"); + exit(1); + } + + /* + * Test MADV_DONTNEED on anonymous private mapping + */ + addr = mmap(NULL, 10 * huge_page_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, + -1, 0); + if (addr == MAP_FAILED) { + perror("mmap"); + exit(1); + } + write_fault_pages(addr, 10); + validate_free_pages(free_hugepages - 10); + + if (madvise(addr, 10 * huge_page_size, MADV_DONTNEED)) { + perror("madvise"); + exit(1); + } + + /* should free all pages in mapping */ + validate_free_pages(free_hugepages); + + (void)munmap(addr, 10 * huge_page_size); + + /* + * Test MADV_DONTNEED on private mapping of hugetlb file + */ + if (fallocate(fd, 0, 0, 10 * huge_page_size)) { + perror("fallocate"); + exit(1); + } + validate_free_pages(free_hugepages - 10); + + addr = mmap(NULL, 10 * huge_page_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE, fd, 0); + if (addr == MAP_FAILED) { + perror("mmap"); + exit(1); + } + + /* read should not consume any pages */ + read_fault_pages(addr, 10); + validate_free_pages(free_hugepages - 10); + + /* madvise should not free any pages */ + if (madvise(addr, 10 * huge_page_size, MADV_DONTNEED)) { + perror("madvise"); + exit(1); + } + validate_free_pages(free_hugepages - 10); + + /* writes should allocate private pages */ + write_fault_pages(addr, 10); + validate_free_pages(free_hugepages - 20); + + /* madvise should free private pages */ + if (madvise(addr, 10 * huge_page_size, MADV_DONTNEED)) { + perror("madvise"); + exit(1); + } + validate_free_pages(free_hugepages - 10); + + /* writes should allocate private pages */ + write_fault_pages(addr, 10); + validate_free_pages(free_hugepages - 20); + + /* + * The fallocate below certainly should free the pages associated + * with the file. However, pages in the private mapping are also + * freed. This is not the 'correct' behavior, but is expected + * because this is how it has worked since the initial hugetlb + * implementation. + */ + if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + 0, 10 * huge_page_size)) { + perror("fallocate"); + exit(1); + } + validate_free_pages(free_hugepages); + + (void)munmap(addr, 10 * huge_page_size); + + /* + * Test MADV_DONTNEED on shared mapping of hugetlb file + */ + if (fallocate(fd, 0, 0, 10 * huge_page_size)) { + perror("fallocate"); + exit(1); + } + validate_free_pages(free_hugepages - 10); + + addr = mmap(NULL, 10 * huge_page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (addr == MAP_FAILED) { + perror("mmap"); + exit(1); + } + + /* write should not consume any pages */ + write_fault_pages(addr, 10); + validate_free_pages(free_hugepages - 10); + + /* madvise should not free any pages */ + if (madvise(addr, 10 * huge_page_size, MADV_DONTNEED)) { + perror("madvise"); + exit(1); + } + validate_free_pages(free_hugepages - 10); + + /* + * Test MADV_REMOVE on shared mapping of hugetlb file + * + * madvise is same as hole punch and should free all pages. + */ + if (madvise(addr, 10 * huge_page_size, MADV_REMOVE)) { + perror("madvise"); + exit(1); + } + validate_free_pages(free_hugepages); + (void)munmap(addr, 10 * huge_page_size); + + /* + * Test MADV_REMOVE on shared and private mapping of hugetlb file + */ + if (fallocate(fd, 0, 0, 10 * huge_page_size)) { + perror("fallocate"); + exit(1); + } + validate_free_pages(free_hugepages - 10); + + addr = mmap(NULL, 10 * huge_page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (addr == MAP_FAILED) { + perror("mmap"); + exit(1); + } + + /* shared write should not consume any additional pages */ + write_fault_pages(addr, 10); + validate_free_pages(free_hugepages - 10); + + addr2 = mmap(NULL, 10 * huge_page_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE, fd, 0); + if (addr2 == MAP_FAILED) { + perror("mmap"); + exit(1); + } + + /* private read should not consume any pages */ + read_fault_pages(addr2, 10); + validate_free_pages(free_hugepages - 10); + + /* private write should consume additional pages */ + write_fault_pages(addr2, 10); + validate_free_pages(free_hugepages - 20); + + /* madvise of shared mapping should not free any pages */ + if (madvise(addr, 10 * huge_page_size, MADV_DONTNEED)) { + perror("madvise"); + exit(1); + } + validate_free_pages(free_hugepages - 20); + + /* madvise of private mapping should free private pages */ + if (madvise(addr2, 10 * huge_page_size, MADV_DONTNEED)) { + perror("madvise"); + exit(1); + } + validate_free_pages(free_hugepages - 10); + + /* private write should consume additional pages again */ + write_fault_pages(addr2, 10); + validate_free_pages(free_hugepages - 20); + + /* + * madvise should free both file and private pages although this is + * not correct. private pages should not be freed, but this is + * expected. See comment associated with FALLOC_FL_PUNCH_HOLE call. + */ + if (madvise(addr, 10 * huge_page_size, MADV_REMOVE)) { + perror("madvise"); + exit(1); + } + validate_free_pages(free_hugepages); + + (void)munmap(addr, 10 * huge_page_size); + (void)munmap(addr2, 10 * huge_page_size); + + close(fd); + unlink(argv[1]); + return 0; +} diff --git a/tools/testing/selftests/vm/run_vmtests.sh b/tools/testing/selftests/vm/run_vmtests.sh index a24d30af3094..f46988c5db35 100755 --- a/tools/testing/selftests/vm/run_vmtests.sh +++ b/tools/testing/selftests/vm/run_vmtests.sh @@ -119,6 +119,18 @@ else echo "[PASS]" fi +echo "-----------------------" +echo "running hugetlb-madvise" +echo "-----------------------" +./hugetlb-madvise $mnt/madvise-test +if [ $? -ne 0 ]; then + echo "[FAIL]" + exitcode=1 +else + echo "[PASS]" +fi +rm -f $mnt/madvise-test + echo "NOTE: The above hugetlb tests provide minimal coverage. Use" echo " https://github.com/libhugetlbfs/libhugetlbfs.git for" echo " hugetlb regression testing." From patchwork Thu Jan 13 18:03:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12713034 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 21DA8C433F5 for ; Thu, 13 Jan 2022 18:03:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 98CBC6B0071; Thu, 13 Jan 2022 13:03:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 93BD86B0073; Thu, 13 Jan 2022 13:03:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7673E6B0074; Thu, 13 Jan 2022 13:03:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0214.hostedemail.com [216.40.44.214]) by kanga.kvack.org (Postfix) with ESMTP id 64A456B0071 for ; Thu, 13 Jan 2022 13:03:35 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1E0F280EBF96 for ; Thu, 13 Jan 2022 18:03:35 +0000 (UTC) X-FDA: 79026036390.17.908FEC6 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf07.hostedemail.com (Postfix) with ESMTP id 604B440002 for ; Thu, 13 Jan 2022 18:03:34 +0000 (UTC) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20DHoEGl012528; Thu, 13 Jan 2022 18:03:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=mxp/9bxZKhjLHpZmvaOK5kFmw0ZCKbnZu0Fj7vRGUgU=; b=W5tOI6tqrQmlWzka5Xrd+aSImCraaePYIbYXGDEhGEU57regF/Sq0t4+NbcAdHMOh4Cw 0cpylPfyoSDtYE12GzSxC1XWxQG6Uc6lYmOjMFw/rs2ODEPRJeTxUzMpeqL37zcBdrkv Bz4xB2JtOeC6mTXobdSAvjpEV43zRbgDvuAFZV7/4d3OgRzgj9/CrTlaC5HPYkrvpY3R XNCuFpaT+DiPRQ5sF2sKYg+/gNBREr3ye4IPBVpGfdkSwrKtkFA8ZCq7bjoRAw/anSr6 k79pUNtvS+SGAT5VB1dgh3qpgUi3h4F14YxUtSrIh8e1KxP6ORqlZaKh6sOHlwva3ihv 7Q== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3djmhw0yus-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Jan 2022 18:03:29 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20DI27Rl000810; Thu, 13 Jan 2022 18:03:28 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by aserp3020.oracle.com with ESMTP id 3df2e86pqy-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Jan 2022 18:03:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HEu8uZ42nng9YkBxlgEp0Rbl13eIlG6dROFHgo3apvRmj1vK8H8feycelBg/TGre5c6LdiS/YpY5EIdTXpzvIMVIM9kTy3tM0GSKVRVwIX0UpEBn+aQSo5Lyiuzlw9z9J88f3YohNFyFbHmmdBcsvVAMEPyXLi6KULjuZ4iAoPXpaKpIhbdgf6VwqbIbQu8F2AMI/0r3KWFBtH1wRIEYL7pkOrQPi4BmmWBt4z5QSaZXype7zUX6jDL15fa2PUQUbFNqcrPL0gGwUC7II1l2ToGw3Q9rHtH1PxelrIYl5ISVi0OxV7pXCf2U5kjjw/hXj5J02DYCYpbmMGq+WKXriA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mxp/9bxZKhjLHpZmvaOK5kFmw0ZCKbnZu0Fj7vRGUgU=; b=jsQ1vmBJm8cjnkj69nLxoCbIjt9kNqB65oUGTL0ZKa2UpzufE14QQE8RMdaboQJs6jJHfLYL0d54JLi+WFysogWSedQ2+xJcb57BeEi4Fz07xcvX3kmV6a18LKYvgaINQ76nG2+kdsqf6iujTeZVtbLQkR+8sRLz+TQ9fb48hhGjqu9HsYBLyIF1c0bVTXpake/ieIt8yAzDYe1PR/OE06trSUR1szLNTROh1dEwVVLTMVXO6o3JdryI6CqL1n7B3JviETiLeuMRkSOfJ+XqvntptideZlg6snWhsOtO37n7eYLDxmwB46MRUSO1f/4fLvHmDrroAUqUNrn05ffvLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mxp/9bxZKhjLHpZmvaOK5kFmw0ZCKbnZu0Fj7vRGUgU=; b=yjdhNuwr780FVsh6M8Hy+pt0YK9YeGyLm5V2g8kdHxnbrK/mr2VIr0st5fUYMGqs8EbQhl3dW+Sd3WKqeQpxvFs1RbtiUfOWLuglDLCiNDaiOHwMX+hqDE4vd+ZkvDIk5IrTR6oooEWfv8ZJBweJBdJSxqJBKAgrIC/zTV/LePE= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BLAPR10MB4865.namprd10.prod.outlook.com (2603:10b6:208:334::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Thu, 13 Jan 2022 18:03:27 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::8502:19a4:8a7f:ea73]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::8502:19a4:8a7f:ea73%7]) with mapi id 15.20.4888.011; Thu, 13 Jan 2022 18:03:27 +0000 From: Mike Kravetz To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Michal Hocko , Naoya Horiguchi , Axel Rasmussen , Peter Xu , Andrea Arcangeli , Mina Almasry , Shuah Khan , Andrew Morton , Mike Kravetz Subject: [RFC PATCH 3/3] userfaultfd/selftests: enable huegtlb remap and remove event testing Date: Thu, 13 Jan 2022 10:03:08 -0800 Message-Id: <20220113180308.15610-4-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220113180308.15610-1-mike.kravetz@oracle.com> References: <20220113180308.15610-1-mike.kravetz@oracle.com> X-ClientProxiedBy: BYAPR08CA0009.namprd08.prod.outlook.com (2603:10b6:a03:100::22) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 886a9459-0061-4e45-d4d5-08d9d6beff7c X-MS-TrafficTypeDiagnostic: BLAPR10MB4865:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vZWAVXz74xuE7XuIjfS6obLbseRUG4Cri4wsDKOwSS4lysOTDc+sXXMypOOwP9Pqkj+MEYmgn+oi/BIVooH6cyE4xv/wG0/ptWTClcN2Zz2s7fdkSrqA59zHHN5S17OQ5ori+hUD5kHwq/yPRYCIxYsPQAkTi2MAaRtzXB0vYyrQ/xGCzd3k0Z6D4A05sbvgnuG28uGr/MilUf2PyJw4V2ooNevZr2nVHgT4LBTWMbstUSNzhw8Ej8myfeq8liH4Mpa/mqrnNrAcIpRKoMpZJa/qOYUq2AsyGTqNgbS4SpzP1l2XGCXzMyRa2XyDVqoflnvNy7JBXBRFZUbrwYziZYTP+EnwU7JKVpYeczw1zt23CY6CiaLjYfz0rouINz2KwtZlY92fxRnXuD162USCQF9nvxKANqus7PH73i1RBejt2CRKS/xMUP/G77WG6wQtLn8IpP/b6zLApjc9FtITpSxkcMkTjUh7PUUxHaITJkERsMtA10TSNFyjKHgD7LDdXawgunrALiO04NzBBN1fHWy6BXxRl68lfYsKYPsfN0ZHSzEwISJmp3EiAObAFUAoRf/w2qFyvexYxd5fHbjO6oVs43mJziQ/O95Sgm9Nt3SzwlFaP897AyqywRMJ0w4sb2+o9HID8e7w9h2t+5IdH+9flFQWPiLslBB2NQPo9yrdoK5jACCvcc+ZjQd24XRHaXscLisj1J8oSnRPuhUtVA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(86362001)(6506007)(36756003)(44832011)(2906002)(1076003)(6486002)(2616005)(107886003)(508600001)(26005)(83380400001)(7416002)(5660300002)(66476007)(52116002)(186003)(66946007)(8936002)(38350700002)(6512007)(316002)(6666004)(38100700002)(66556008)(54906003)(8676002)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lR53dJkamQz0wtTyI4S5g0hv0nEpsIMRPskqflsMLXhO9opdeTeO4ySbdhbyZ1g9h5iGz9VYnf35s8FVlnjbv6FCmJnS1+kWDwkV7MZ7sGYC8+ehp3P67YiytHNaEZVRZhA9UBVpquSCazYVIblX8BbGRUskpZCPIn+TvfUSoAQIPmaFtwSXpTCbsHFqDaBSg6om7N95ihi7msTMSivXdM6a6UInT5jhP63cf0cmRI5z6DQRAv0pc/T2G/nciFHhf4g2ju7Px49Fq/uZLp3VJNLYKHER0NABZQEmfq1lAu9bw9DDZ1FLp1CssSuGSHmKt/4n2VmX6jp/yF3dPEPi7wZcOEsn2G7WS+UVeUVU5zGkUBYKIBrzIinBU46u9ni7qDIfXlooRFS8P4tmSvuLNApKmMBZzcidGs7ewJ95s9b3hy2eE+gQJNf2zkgNx27c1jlqjGvkDguS8t4teB1oMpHrYT7ePtOQZemfxsq4Cw7tKryRa794xj8I1odDw9fy070FT6TL8Z79W4LKYBaLA4CbWoX+T5g2QFUMGm4Ouo+wVLWuior0wM4B57O3WgyMTKwmKP4b+Sw88pCubQD24OoarhcWkHhkUNBr02ysATdKexkssABn8yQVf/0rVRIpE0kb2Gnx+Q5SDhuJoKULhwzQpVa9OYaYm6iyL2jZSx9ruRKqA6lbrSBiK+MrD0jbY6tHNP0sCqPSrRIJmZFPquFQrDuUd6QnH/ZrlPTrx7sH768QmFoGd53ANtf2x0gcu348Y0FIOttniJAtw/Kup9MtLF4Le3tFoBgyV4obZL4TdIU2Srutfk7GTw1A6a26mX9QrhQuEbf2okquBObBtbwutucEsIAs2c8woa35+bolsiGUDv7uA2OiTKU9Cakv9damMyYtiCpbDNykmgC/bIOqW7spZ1Jp5/Z8GsiYaKA0jD8ycJMOy5o8gOnzjf2PNiDpFYpUEGtwQzP6Q/00QM9R205oLY/Taa9b0A8I2kxokny910HanIwTrGyYeFX64MBp4SNPgq8siRPIciwfr/1XnhsZrO7IPS1mMEH+3t8SBlTCsznlnAsgPgRrqJR443Y2lEDaegCus3Z7nu7M5dSxCSMgUJfYcnFoykP7JguCId6GmojnVS0/7sfXEBlclIRQcY9iRL42wUrj46Jk19qztLoVe3BMaRRNpEDNtBBkqC3/JrkvF5VnrhOXKsldt4EQh/oTonvUnHcJSkDWcfi4urGf6VIv9Pb7jnQzwP7+asLXFh+7VtzhUaTwqTCVkwcsn5aQzb7UpqB204gFcBW5Vtpy3HdB4ovcaA0MCwjJ+qstV/0JR+Fnm/UOVPwwnuoWjxxTmnrjww5HZIy7DUzGqsAR3eruEaYDWXNCNL/JYAPrhcn0Qo5aeCI15l/CHORaBH2grMT0kYX+FXrvrV4DwQ7LMaC4amBdK5eO2uhslzxEnsfSnTTijZuOn3CbSgRQhObFbddKqtLDD5PZh2XIlyItYjjmRly5h7abrv9LyKbBx003NucMiXoDLlSlrvBT3OEEfUz25OKWu5zTaqk0YQl16V7GAYWx5qm0UxE1qoDhPTQWkMeBXJXDOPXuf6uRyxinVxbb4UY/c5puLBVe/FMySsX20euCNGHhvW4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 886a9459-0061-4e45-d4d5-08d9d6beff7c X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2022 18:03:27.0168 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: r9cYHh0fmzZkvmsWRqMJtV14xcQ55NKvgP0URmHi3VzIb5x+cKb9D4IiIDaNWJl56/GRDL60WdkjrYbHvwPH2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4865 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10226 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201130112 X-Proofpoint-ORIG-GUID: WAhHB0GkEBvnPReH659UkpcjuLgUU9OB X-Proofpoint-GUID: WAhHB0GkEBvnPReH659UkpcjuLgUU9OB X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 604B440002 X-Stat-Signature: qmeb75zoqk1wcd1kh9xfw18m5h31k57d Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=W5tOI6tq; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=yjdhNuwr; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf07.hostedemail.com: domain of mike.kravetz@oracle.com has no SPF policy when checking 205.220.165.32) smtp.mailfrom=mike.kravetz@oracle.com X-HE-Tag: 1642097014-61573 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: With MADV_DONTNEED support added to hugetlb mappings, mremap testing can also be enabled for hugetlb. Modify the tests to use madvise MADV_DONTNEED and MADV_REMOVE instead of fallocate hole puch for releasing hugetlb pages. Signed-off-by: Mike Kravetz --- tools/testing/selftests/vm/userfaultfd.c | 67 ++++++++++++------------ 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 0b543a9a42b2..226f385158df 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -88,7 +88,6 @@ static bool test_uffdio_minor = false; static bool map_shared; static int shm_fd; static int huge_fd; -static char *huge_fd_off0; static unsigned long long *count_verify; static int uffd = -1; static int uffd_flags, finished, *pipefd; @@ -124,9 +123,9 @@ const char *examples = "./userfaultfd anon 100 99999\n\n" "# Run share memory test on 1GiB region with 99 bounces:\n" "./userfaultfd shmem 1000 99\n\n" - "# Run hugetlb memory test on 256MiB region with 50 bounces (using /dev/hugepages/hugefile):\n" + "# Run hugetlb memory test on 256MiB region with 50 bounces:\n" "./userfaultfd hugetlb 256 50 /dev/hugepages/hugefile\n\n" - "# Run the same hugetlb test but using shmem:\n" + "# Run the same hugetlb test but using shared file:\n" "./userfaultfd hugetlb_shared 256 50 /dev/hugepages/hugefile\n\n" "# 10MiB-~6GiB 999 bounces anonymous test, " "continue forever unless an error triggers\n" @@ -223,10 +222,13 @@ static void noop_alias_mapping(__u64 *start, size_t len, unsigned long offset) static void hugetlb_release_pages(char *rel_area) { - if (fallocate(huge_fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - rel_area == huge_fd_off0 ? 0 : nr_pages * page_size, - nr_pages * page_size)) - err("fallocate() failed"); + if (!map_shared) { + if (madvise(rel_area, nr_pages * page_size, MADV_DONTNEED)) + err("madvise(MADV_DONTNEED) failed"); + } else { + if (madvise(rel_area, nr_pages * page_size, MADV_REMOVE)) + err("madvise(MADV_REMOVE) failed"); + } } static void hugetlb_allocate_area(void **alloc_area) @@ -234,26 +236,37 @@ static void hugetlb_allocate_area(void **alloc_area) void *area_alias = NULL; char **alloc_area_alias; - *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, - (map_shared ? MAP_SHARED : MAP_PRIVATE) | - MAP_HUGETLB | - (*alloc_area == area_src ? 0 : MAP_NORESERVE), - huge_fd, *alloc_area == area_src ? 0 : - nr_pages * page_size); + if (!map_shared) + *alloc_area = mmap(NULL, + nr_pages * page_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | + (*alloc_area == area_src ? 0 : MAP_NORESERVE), + -1, + 0); + else + *alloc_area = mmap(NULL, + nr_pages * page_size, + PROT_READ | PROT_WRITE, + MAP_SHARED | + (*alloc_area == area_src ? 0 : MAP_NORESERVE), + huge_fd, + *alloc_area == area_src ? 0 : nr_pages * page_size); if (*alloc_area == MAP_FAILED) err("mmap of hugetlbfs file failed"); if (map_shared) { - area_alias = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_HUGETLB, - huge_fd, *alloc_area == area_src ? 0 : - nr_pages * page_size); + area_alias = mmap(NULL, + nr_pages * page_size, + PROT_READ | PROT_WRITE, + MAP_SHARED, + huge_fd, + *alloc_area == area_src ? 0 : nr_pages * page_size); if (area_alias == MAP_FAILED) err("mmap of hugetlb file alias failed"); } if (*alloc_area == area_src) { - huge_fd_off0 = *alloc_area; alloc_area_alias = &area_src_alias; } else { alloc_area_alias = &area_dst_alias; @@ -266,12 +279,7 @@ static void hugetlb_alias_mapping(__u64 *start, size_t len, unsigned long offset { if (!map_shared) return; - /* - * We can't zap just the pagetable with hugetlbfs because - * MADV_DONTEED won't work. So exercise -EEXIST on a alias - * mapping where the pagetables are not established initially, - * this way we'll exercise the -EEXEC at the fs level. - */ + *start = (unsigned long) area_dst_alias + offset; } @@ -424,7 +432,6 @@ static void uffd_test_ctx_clear(void) uffd = -1; } - huge_fd_off0 = NULL; munmap_area((void **)&area_src); munmap_area((void **)&area_src_alias); munmap_area((void **)&area_dst); @@ -919,10 +926,7 @@ static int faulting_process(int signal_test) struct sigaction act; unsigned long signalled = 0; - if (test_type != TEST_HUGETLB) - split_nr_pages = (nr_pages + 1) / 2; - else - split_nr_pages = nr_pages; + split_nr_pages = (nr_pages + 1) / 2; if (signal_test) { sigbuf = &jbuf; @@ -979,9 +983,6 @@ static int faulting_process(int signal_test) if (signal_test) return signalled != split_nr_pages; - if (test_type == TEST_HUGETLB) - return 0; - area_dst = mremap(area_dst, nr_pages * page_size, nr_pages * page_size, MREMAP_MAYMOVE | MREMAP_FIXED, area_src); if (area_dst == MAP_FAILED) @@ -1669,7 +1670,7 @@ int main(int argc, char **argv) } nr_pages = nr_pages_per_cpu * nr_cpus; - if (test_type == TEST_HUGETLB) { + if (test_type == TEST_HUGETLB && map_shared) { if (argc < 5) usage(); huge_fd = open(argv[4], O_CREAT | O_RDWR, 0755);