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.7 required=3.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 83A88ECE58E for ; Tue, 15 Oct 2019 09:01:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2D34B20659 for ; Tue, 15 Oct 2019 09:01:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D34B20659 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=tlen.pl Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CE0D98E0005; Tue, 15 Oct 2019 05:01:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C90A58E0001; Tue, 15 Oct 2019 05:01:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA6598E0005; Tue, 15 Oct 2019 05:01:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id 995FD8E0001 for ; Tue, 15 Oct 2019 05:01:25 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 3E72683B43CA for ; Tue, 15 Oct 2019 09:01:25 +0000 (UTC) X-FDA: 76045425330.11.copy10_c477e4c30a62 X-HE-Tag: copy10_c477e4c30a62 X-Filterd-Recvd-Size: 4190 Received: from mx-out.tlen.pl (mx-out.tlen.pl [193.222.135.142]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Oct 2019 09:01:24 +0000 (UTC) Received: (wp-smtpd smtp.tlen.pl 11047 invoked from network); 15 Oct 2019 11:01:22 +0200 Received: from unknown (HELO localhost.localdomain) (p.sarna@tlen.pl@[31.179.144.84]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP for ; 15 Oct 2019 11:01:22 +0200 From: Piotr Sarna To: linux-kernel@vger.kernel.org, mike.kravetz@oracle.com Cc: Piotr Sarna , linux-mm@kvack.org, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org Subject: [PATCH] hugetlbfs: add O_TMPFILE support Date: Tue, 15 Oct 2019 11:01:12 +0200 Message-Id: <22c29acf9c51dae17802e1b05c9e5e4051448c5c.1571129593.git.p.sarna@tlen.pl> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-WP-MailID: e93136fb553552c8e020d3da8703060d X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 0000000 [sUP0] 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: With hugetlbfs, a common pattern for mapping anonymous huge pages is to create a temporary file first. Currently libraries like libhugetlbfs and seastar create these with a standard mkstemp+unlink trick, but it would be more robust to be able to simply pass the O_TMPFILE flag to open(). O_TMPFILE is already supported by several file systems like ext4 and xfs. The implementation simply uses the existi= ng d_tmpfile utility function to instantiate the dcache entry for the file. Tested manually by successfully creating a temporary file by opening it with (O_TMPFILE|O_RDWR) on mounted hugetlbfs and successfully mapping 2M huge pages with it. Without the patch, trying to open a file with O_TMPFILE results in -ENOSUP. Signed-off-by: Piotr Sarna --- fs/hugetlbfs/inode.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 1dcc57189382..277b7d231db8 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -815,8 +815,11 @@ static struct inode *hugetlbfs_get_inode(struct supe= r_block *sb, /* * File creation. Allocate an inode, and we're done.. */ -static int hugetlbfs_mknod(struct inode *dir, - struct dentry *dentry, umode_t mode, dev_t dev) +static int do_hugetlbfs_mknod(struct inode *dir, + struct dentry *dentry, + umode_t mode, + dev_t dev, + bool tmpfile) { struct inode *inode; int error =3D -ENOSPC; @@ -824,13 +827,22 @@ static int hugetlbfs_mknod(struct inode *dir, inode =3D hugetlbfs_get_inode(dir->i_sb, dir, mode, dev); if (inode) { dir->i_ctime =3D dir->i_mtime =3D current_time(dir); - d_instantiate(dentry, inode); + if (tmpfile) + d_tmpfile(dentry, inode); + else + d_instantiate(dentry, inode); dget(dentry); /* Extra count - pin the dentry in core */ error =3D 0; } return error; } =20 +static int hugetlbfs_mknod(struct inode *dir, + struct dentry *dentry, umode_t mode, dev_t dev) +{ + return do_hugetlbfs_mknod(dir, dentry, mode, dev, false); +} + static int hugetlbfs_mkdir(struct inode *dir, struct dentry *dentry, umo= de_t mode) { int retval =3D hugetlbfs_mknod(dir, dentry, mode | S_IFDIR, 0); @@ -844,6 +856,12 @@ static int hugetlbfs_create(struct inode *dir, struc= t dentry *dentry, umode_t mo return hugetlbfs_mknod(dir, dentry, mode | S_IFREG, 0); } =20 +static int hugetlbfs_tmpfile(struct inode *dir, + struct dentry *dentry, umode_t mode) +{ + return do_hugetlbfs_mknod(dir, dentry, mode | S_IFREG, 0, true); +} + static int hugetlbfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) { @@ -1102,6 +1120,7 @@ static const struct inode_operations hugetlbfs_dir_= inode_operations =3D { .mknod =3D hugetlbfs_mknod, .rename =3D simple_rename, .setattr =3D hugetlbfs_setattr, + .tmpfile =3D hugetlbfs_tmpfile, }; =20 static const struct inode_operations hugetlbfs_inode_operations =3D { --=20 2.21.0