From patchwork Thu Jun 15 03:45:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9788003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 209E960231 for ; Thu, 15 Jun 2017 03:45:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1489523F88 for ; Thu, 15 Jun 2017 03:45:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0964B27C2D; Thu, 15 Jun 2017 03:45:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EA6B23F88 for ; Thu, 15 Jun 2017 03:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752059AbdFODp2 (ORCPT ); Wed, 14 Jun 2017 23:45:28 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:35030 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751958AbdFODp1 (ORCPT ); Wed, 14 Jun 2017 23:45:27 -0400 Received: by mail-pf0-f172.google.com with SMTP id l89so1805533pfi.2 for ; Wed, 14 Jun 2017 20:45:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OHGAnhPX5qADLjkQ4GD6vfOsTCKTppmZupMUIdsQmPY=; b=rGmATgDPQkaKoMC+9q2jNmYKKpn0iAkP3qSbnssqPD/iFX/q7XJPrNSPaAE/c5O/Fy 2y2PpU2NjnRU70vFKXhZiBjnp116xQstXYrFMfe9mlrTO3L2BwQ6mnvSLvb3mP3EHcNK CcerWLirlJ1+fCJ1qxQbuu0EQM+S9Q0M0igKbKXUlF2GMhevytjgbdQ6mFDJhxnpCdUY 2H5ysdJPQbGMv8lvpbJUzYFUJU7IxfWJ80Y9HE9z1PsB4VMUCMRzAK6vDvCKVzbWf5g4 44sTE5alpv7u5nqjtyyHjegAD8OlIIb/edwTjBAVHG8U3QuBTb7XnMGFOvx//q4Ij7Mj t2uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OHGAnhPX5qADLjkQ4GD6vfOsTCKTppmZupMUIdsQmPY=; b=NIC8UFsZLwBl2THf3HYbwN5xrwKH6qbEsJ/ukp0zJt6sURM1+DkXjgBsuwADHz83HN 6sgCE5xAZXNuTcjD5HJaVGJ2ODT4KxvBv9TMRWteRt9ZUR4mD3c6XUljDR355/E+CaMp FJoUhYMV84I5tlreoRV/96oWkRR8l3pKa4bBtv6qi9WDWLzoB0fI3KWZJGO88A4/qSQ6 BtTfdD8dgCH7p1ycVUyiJFX8aJ54bxUHsziX1jQcdir1DzEr+UQUaPAlj60J3UH22V6E XMJMqDIcd4lFM7R2GTJJqGO23VVngWS3gVV33t1WWZvfjclYumHL/n4ZoOIJuuxINFg2 WLrg== X-Gm-Message-State: AKS2vOxG7nw1uBogrjc0HXz+Ha+5bAnafZgxfSiPcXM0uGogjGFj/QKF 1VJ3xaJoZhaeZ/vf X-Received: by 10.84.218.134 with SMTP id r6mr3763040pli.288.1497498326634; Wed, 14 Jun 2017 20:45:26 -0700 (PDT) Received: from localhost.localdomain (66.29.164.166.static.utbb.net. [66.29.164.166]) by smtp.gmail.com with ESMTPSA id f71sm2532627pfd.98.2017.06.14.20.45.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 20:45:26 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: adilger@dilger.ca, hch@infradead.org, martin.petersen@oracle.com, Jens Axboe Subject: [PATCH 04/11] fs: add support for allowing applications to pass in write life time hints Date: Wed, 14 Jun 2017 21:45:05 -0600 Message-Id: <1497498312-17704-5-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497498312-17704-1-git-send-email-axboe@kernel.dk> References: <1497498312-17704-1-git-send-email-axboe@kernel.dk> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add four flags for the pwritev2(2) system call, allowing an application to give the kernel a hint about what on-media life times can be expected from a given write. The intent is for these values to be relative to each other, no absolute meaning should be attached to these flag names. Define IOCB flags to carry this over this information from the pwritev2 RWF_WRITE_LIFE_* flags. Reviewed-by: Andreas Dilger Signed-off-by: Jens Axboe --- fs/read_write.c | 9 ++++++++- include/linux/fs.h | 12 ++++++++++++ include/uapi/linux/fs.h | 10 ++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/fs/read_write.c b/fs/read_write.c index 47c1d4484df9..9cb2314efca3 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -678,7 +678,7 @@ static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter, struct kiocb kiocb; ssize_t ret; - if (flags & ~(RWF_HIPRI | RWF_DSYNC | RWF_SYNC)) + if (flags & ~(RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_WRITE_LIFE_MASK)) return -EOPNOTSUPP; init_sync_kiocb(&kiocb, filp); @@ -688,6 +688,13 @@ static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter, kiocb.ki_flags |= IOCB_DSYNC; if (flags & RWF_SYNC) kiocb.ki_flags |= (IOCB_DSYNC | IOCB_SYNC); + if (flags & RWF_WRITE_LIFE_MASK) { + struct inode *inode = file_inode(filp); + + inode->i_write_hint = (flags & RWF_WRITE_LIFE_MASK) >> + RWF_WRITE_LIFE_SHIFT; + kiocb.ki_flags |= inode->i_write_hint << IOCB_WRITE_LIFE_SHIFT; + } kiocb.ki_pos = *ppos; if (type == READ) diff --git a/include/linux/fs.h b/include/linux/fs.h index f4f9df8ed059..63798b67fcfe 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -269,6 +269,12 @@ struct writeback_control; #define IOCB_SYNC (1 << 5) #define IOCB_WRITE (1 << 6) +/* + * Steal 4-bits for stream information, this allows 16 valid streams + */ +#define IOCB_WRITE_LIFE_SHIFT 7 +#define IOCB_WRITE_LIFE_MASK (BIT(7) | BIT(8) | BIT(9) | BIT(10)) + struct kiocb { struct file *ki_filp; loff_t ki_pos; @@ -292,6 +298,12 @@ static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp) }; } +static inline int iocb_write_hint(const struct kiocb *iocb) +{ + return (iocb->ki_flags & IOCB_WRITE_LIFE_MASK) >> + IOCB_WRITE_LIFE_SHIFT; +} + /* * "descriptor" for what we're up to with a read. * This allows us to use the same read code yet diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 24e61a54feaa..58b7ee06b380 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -361,4 +361,14 @@ struct fscrypt_key { #define RWF_DSYNC 0x00000002 /* per-IO O_DSYNC */ #define RWF_SYNC 0x00000004 /* per-IO O_SYNC */ +/* + * Data life time write flags, steal 4 bits for that + */ +#define RWF_WRITE_LIFE_SHIFT 4 +#define RWF_WRITE_LIFE_MASK 0x000000f0 /* 4 bits of stream ID */ +#define RWF_WRITE_LIFE_SHORT (1 << RWF_WRITE_LIFE_SHIFT) +#define RWF_WRITE_LIFE_MEDIUM (2 << RWF_WRITE_LIFE_SHIFT) +#define RWF_WRITE_LIFE_LONG (3 << RWF_WRITE_LIFE_SHIFT) +#define RWF_WRITE_LIFE_EXTREME (4 << RWF_WRITE_LIFE_SHIFT) + #endif /* _UAPI_LINUX_FS_H */