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: 9788005 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 BC4F460231 for ; Thu, 15 Jun 2017 03:45:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B27EA23F88 for ; Thu, 15 Jun 2017 03:45:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A739227C2D; Thu, 15 Jun 2017 03:45:31 +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=unavailable 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 34B0E23F88 for ; Thu, 15 Jun 2017 03:45:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751958AbdFODp2 (ORCPT ); Wed, 14 Jun 2017 23:45:28 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:33336 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752033AbdFODp1 (ORCPT ); Wed, 14 Jun 2017 23:45:27 -0400 Received: by mail-pf0-f175.google.com with SMTP id 83so1831087pfr.0 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=C3Obr9y0+nt88LIFIieTniCxIqydWalUEkCZrCHj9kY95ZY7YJ7jUD120JJJIg8KL9 YrlAubvySmJJqcuaNdEK87M/cgGLdy31UDJC/YA+9wBu+708Ge1MyUmuUxW2M9vi6JQa 5epOqwp9TVddX/dI27iwQg5JAfcGSR3u/x2TyOqt17XZY503D4dGCbXxLot7WlLLRXCy 9F0pwGWPpL9izLwZbh4LcW2UPQ54vPXM7QvsUhauF4iN+R6K6tn53OHNohbUCqeuMa1T n48wcaSzaZokmYEp7nSgbpqhgyL5ddrTFczkyiHb4lo09skViETToNHwAcfrkDn3UYOh PM7Q== X-Gm-Message-State: AKS2vOwG/AchlNzM1n4er/rDtpA2eozUPzBJJQSZWtX2g5h9UV9l0tXh Z2m7Lcg4RUcv8D36bEzkOw== 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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 */