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 E15DAC4345F for ; Fri, 3 May 2024 01:09:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 573766B0099; Thu, 2 May 2024 21:09:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 523516B0098; Thu, 2 May 2024 21:09:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EABD6B009D; Thu, 2 May 2024 21:09:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1D31A6B0098 for ; Thu, 2 May 2024 21:09:40 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C1704C05EC for ; Fri, 3 May 2024 01:09:39 +0000 (UTC) X-FDA: 82075302078.22.54D23BE Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf15.hostedemail.com (Postfix) with ESMTP id DDA3BA0011 for ; Fri, 3 May 2024 01:09:37 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=SWcgzLCo; spf=pass (imf15.hostedemail.com: domain of prakash.sangappa@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=prakash.sangappa@oracle.com; dmarc=pass (policy=quarantine) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714698578; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=SOvRaCHY7bt9fC7qYTTsBnsQzRZD7sei+4AUOOD1e8k=; b=Ktv/WkVmgS7oJjNCE8R4OE8DnSn2Ycny965bHeFX9ymVI+hF/ShRx9RBHumcHJBExBGFF3 12EmakNY9/6gB8oxBeklM1tW37eBuuqjYQ/FPOu4r0N1gJp+6QGZwUmLPzJ7IO5yO5ujsm AYD9SbhjbV61k3v0zx4NwL8HBKXoixw= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=SWcgzLCo; spf=pass (imf15.hostedemail.com: domain of prakash.sangappa@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=prakash.sangappa@oracle.com; dmarc=pass (policy=quarantine) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714698578; a=rsa-sha256; cv=none; b=l0tb2jFnKlHPHPNebbgotTVHg70zVpDtoxr8aF6rtTMqQ7y/YOlKikOTG4glnHO5zJxa05 opyG0CjUVw95N1gGqmMj//nIeNdldK5lWHoSKO+S+YyFtQx1Jqr7tC4gs2Dxfea+mZL1KG ftr3/9qAiW0IQ6LBqAxTbQvijE+EkZ8= Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 442MYgZj012962; Fri, 3 May 2024 01:09:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2023-11-20; bh=SOvRaCHY7bt9fC7qYTTsBnsQzRZD7sei+4AUOOD1e8k=; b=SWcgzLCoKoprCz5eH0JHybg0yOvc1q1lNvjMNrhZGP4OapN23OsbPzYIPwGq9sqEzfDg SDnWFSQSEW6K3eQqSi1dkyThwx+HWVrfMixxiE2JSxro/OQb7lurm9bmqW9QA3e7noTW x6CMwHfbRt2/8zxdHVix3A9L0Dvxrt2EuoLaBvAkkEk2QMlxR0t5EVuzTFjhO0tqCKEB EoO9zHmGzY3iOa+++Lse/06ojVLNLKojfHS3J1lae/iUjvlycOQeTvcji38rNiSat495 QK0qsNB9/Tf+6WYEa3h0YcrFuJc/81zqb6laSpSextqXLNcuicCAAwO5voL96FCvyDKI wg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrswvyaeq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 03 May 2024 01:09:25 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 4430KuIh006237; Fri, 3 May 2024 01:09:24 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqtbp7xv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO); Fri, 03 May 2024 01:09:24 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 44319NBo035083; Fri, 3 May 2024 01:09:24 GMT Received: from pp-thinkcentre-m82.us.oracle.com (dhcp-10-132-95-245.usdhcp.oraclecorp.com [10.132.95.245]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqtbp7xd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO); Fri, 03 May 2024 01:09:23 +0000 From: Prakash Sangappa To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: muchun.song@linux.dev, akpm@linux-foundation.org, willy@infradead.org, prakash.sangappa@oracle.com Subject: [RFC PATCH 0/1] Address hugetlbfs mmap behavior Date: Thu, 2 May 2024 18:21:09 -0700 Message-Id: <1714699270-7360-1-git-send-email-prakash.sangappa@oracle.com> X-Mailer: git-send-email 2.7.4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_15,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2405030006 X-Proofpoint-GUID: XZp9uBYBIBI46k7qNuUGbkZdyVssn5-1 X-Proofpoint-ORIG-GUID: XZp9uBYBIBI46k7qNuUGbkZdyVssn5-1 X-Rspam-User: X-Rspamd-Queue-Id: DDA3BA0011 X-Rspamd-Server: rspam06 X-Stat-Signature: kb34e9qdn9w5spkfmkhufh5h864bgpmo X-HE-Tag: 1714698577-835525 X-HE-Meta: U2FsdGVkX19ODYGGVY1U6IvCaIZzlhliLAWsXMlBjATMe0Ntg9MRpgNSyJF/XqucENKwC/QESoIzwzq/4GWsF8l55zVzfaJthaNto5ynDuDKy6PgmuWdYXeGkJhKQqgoCiKUVei+w6RFoIM5GploB51Aizsgsz+PKFzUG+GSg+f/qfCgCapH6bc/bTyZEQr5odS9AZ6p2S2OL9eTdSKGaULitQPpa9Ux1FBP1nizJIsAZ7QRrqLjGn6DE4ziqc6L4owTY+2EwauwTbI3MaJOgzUxgC+bFgQwP59hwwwT10UmTyL0qXwMxRj06AwWilRgKPyo2D/sPv5sSoYp0VxDXfbyfAezjsfCSuTaqi5A1HMEsiYFolQnbVvzzlYl2EnRo24EjtxFCtZazgKkJAmzzzmHEEK74HRNJAt8lxNbKkPhR9zkLO6bXjZJWHbLlJTJffaJVor5SLgk/4DmpXWYSkndt8GkKFFqSYpjzhFkysLpDBkTr+ZcME/ZUJmqhThxaRAY3EqnKpBLfXJ9mONDwV4wYbHRA2dvsb2wNWvDBSFH5dddBDlBVRO8kz0t4VO8v1LeVauYtxSvkUzy1/DE5jWOYEndeM7Qg7CxZlb0v2AJSuNdjab6/1loicl3yBookjlvNRbQ2p9S2oCg7CxZal/JH00I3lzzn1JiwyI4ATR/QKWMXboJ9CAyGS86MFDBvLP92CGKfHj30QFp1h6YazGFQAuDwsvG0BIfoFWJHBq2Vy5SnG5jgt44fc70PqFyO6SH9IxwplK+CNH/7MEEyhnqKtmkLMPiE28iWwX4eN5yt1+uAl/gFAXVDKeO+2JKkXsefG9LeFf6nlxtpXMO0B/TtDGkiRMwFEYazq6KHUxD3OlVO1Tm3ZwQfr2nfGvhhk4WvYj1gXdhAM512JM7Y6q2nNjzQETBoKBCDmhEsvZZjc+QrOBYL+f1/V/m6sG110nY7SJEpk6dTXtR38u Be87vjdv NrHfpOdv7SDoLaLD/ZrwTnNpweTSPOn6nMsCOxKC6C6gGud7a9eIPa11m1eL3D1/OSfuGpiQ90sDb/oudzXdEX54Bt1BHTGyHVJE6alKJnrSBa4L2E1KBniP/CmeikY9VgLNeiozGHkIEPbGZx84WS6FqtKuobrWsmFCX0bVglWdPq4qiNul8iU0rEuKQOqd2tRuvcUpJLJDJb5k/z68FYp9/OjXUnXFQguJmPGrVydZ5ffU= 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 proposes to fix hugetlbfs mmap behavior so that the file size does not get updated in the mmap call. The current behavior is that hugetlbfs file size will get extended by a PROT_WRITE mmap(2) call if mmap size is greater then file size. This is not normal filesystem behavior. There seem to have been very little discussion about this. There was a patch discussion[1] a while back, implying hugetlbfs file size needs extending because of the hugetlb page reservations. Looks like this was not merged. It appears there is no correlation between file size and hugetlb page reservations. Take the case of PROT_READ mmap, where the file size is not extended even though hugetlb pages are reserved. On the other hand ftruncate(2) to increase a file size does not reserve hugetlb pages. Also, mmap with MAP_NORESERVE flag extends the file size even though hugetlb pages are not reserved. Hugetlb pages get reserved(if MAP_NORESERVE is not specified) when the hugeltbfs file is mmapped, and it only covers the file's offset,length range specified in the mmap call. Issue: Some applications would prefer to manage hugetlb page allocations explicity with use of fallocate(2). The hugetlbfs file would be PROT_WRITE mapped with MAP_NORESERVE flag, which is accessed only after allocating necessary pages using fallocate(2) and release the pages by truncating the file size. Any stray access beyond file size is expected to generate a signal. This does not work properly due to current behavior which extends file size in mmap call. To address this issue, hugetlbfs behavior needs to be fixed to not extend file size in mmap(2) call. However changing current hugetlbfs behavior could potentially break some applications. Therefore this patch proposes a mount option to hugetlbfs to choose the mmap behavior of not extending file size. Use of a mount option was suggested by Matthew Wilcox, This patch adds a 'nommapfilesz' mount option to hugetlbfs mount option. The mount option name can be changed if there is a better name suggested. Submitting this patch as a RFC to get feedback on the approach and if there is any reason that requires file size to be extended by mmap in hugetlbfs case. [1] https://lore.kernel.org/lkml/200603081828.k28ISgg10244@unix-os.sc.intel.com/ Prakash Sangappa (1): hugetlbfs: Add mount option to choose normal mmap behavior fs/hugetlbfs/inode.c | 19 ++++++++++++++++++- include/linux/hugetlb.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) -- 2.7.4