From: Jens Axboe <axboe@kernel.dk>
To: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org
Cc: adilger@dilger.ca, hch@infradead.org, martin.petersen@oracle.com,
Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 04/11] fs: add support for allowing applications to pass in write life time hints
Date: Fri, 16 Jun 2017 11:24:36 -0600 [thread overview]
Message-ID: <1497633883-21230-5-git-send-email-axboe@kernel.dk> (raw)
In-Reply-To: <1497633883-21230-1-git-send-email-axboe@kernel.dk>
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.
Set aside 3 bits in the iocb flags structure to carry this information
over from the pwritev2 RWF_WRITE_LIFE_* flags.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
fs/read_write.c | 12 +++++++++++-
include/linux/fs.h | 12 ++++++++++++
include/uapi/linux/fs.h | 10 ++++++++++
3 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/fs/read_write.c b/fs/read_write.c
index 19d4d88fa285..975fe1d46a59 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -675,10 +675,11 @@ EXPORT_SYMBOL(iov_shorten);
static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter,
loff_t *ppos, int type, int flags)
{
+ struct inode *inode = file_inode(filp);
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 +689,15 @@ 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) ||
+ mask_to_write_hint(inode->i_flags, S_WRITE_LIFE_SHIFT)) {
+ enum rw_hint hint;
+
+ hint = mask_to_write_hint(flags, RWF_WRITE_LIFE_SHIFT);
+
+ inode_set_write_hint(inode, hint);
+ kiocb.ki_flags |= write_hint_to_mask(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 472c83156606..a024b32259bf 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 3 bits for stream information, this allows 8 valid streams
+ */
+#define IOCB_WRITE_LIFE_SHIFT 7
+#define IOCB_WRITE_LIFE_MASK (BIT(7) | BIT(8) | BIT(9))
+
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 8fb3b5a6e1ec..0d9d331d3b61 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -374,4 +374,14 @@ enum rw_hint {
#define RWF_DSYNC 0x00000002 /* per-IO O_DSYNC */
#define RWF_SYNC 0x00000004 /* per-IO O_SYNC */
+/*
+ * Data life time write flags, steal 3 bits for that
+ */
+#define RWF_WRITE_LIFE_SHIFT 4
+#define RWF_WRITE_LIFE_MASK 0x00000070 /* 3 bits of write hints */
+#define RWF_WRITE_LIFE_SHORT (WRITE_LIFE_SHORT << RWF_WRITE_LIFE_SHIFT)
+#define RWF_WRITE_LIFE_MEDIUM (WRITE_LIFE_MEDIUM << RWF_WRITE_LIFE_SHIFT)
+#define RWF_WRITE_LIFE_LONG (WRITE_LIFE_LONG << RWF_WRITE_LIFE_SHIFT)
+#define RWF_WRITE_LIFE_EXTREME (WRITE_LIFE_EXTREME << RWF_WRITE_LIFE_SHIFT)
+
#endif /* _UAPI_LINUX_FS_H */
--
2.7.4
next prev parent reply other threads:[~2017-06-16 17:24 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-16 17:24 [PATCHSET v6] Add support for write life time hints Jens Axboe
2017-06-16 17:24 ` [PATCH 01/11] fs: add support for an inode to carry write hint related data Jens Axboe
2017-06-16 17:24 ` [PATCH 02/11] block: add support for write hints in a bio Jens Axboe
2017-06-16 17:24 ` [PATCH 03/11] blk-mq: expose stream write hints through debugfs Jens Axboe
2017-06-16 17:24 ` Jens Axboe [this message]
2017-06-16 17:24 ` [PATCH 05/11] fs: add fcntl() interface for setting/getting write life time hints Jens Axboe
2017-06-16 17:24 ` [PATCH 06/11] fs: add O_DIRECT support for sending down " Jens Axboe
2017-06-16 17:24 ` [PATCH 07/11] fs: add support for buffered writeback to pass down write hints Jens Axboe
2017-06-16 17:24 ` [PATCH 08/11] ext4: add support for passing in write hints for buffered writes Jens Axboe
2017-06-16 17:24 ` [PATCH 09/11] xfs: " Jens Axboe
2017-06-16 17:24 ` [PATCH 10/11] btrfs: " Jens Axboe
2017-06-16 17:24 ` [PATCH 11/11] nvme: add support for streams and directives Jens Axboe
2017-06-16 18:09 ` Christoph Hellwig
2017-06-16 19:41 ` Jens Axboe
2017-06-16 19:56 ` Jens Axboe
2017-06-17 12:21 ` Christoph Hellwig
2017-06-17 14:20 ` Jens Axboe
2017-06-17 15:03 ` Christoph Hellwig
2017-06-17 15:11 ` Jens Axboe
2017-06-17 15:43 ` Jens Axboe
2017-06-19 6:25 ` Christoph Hellwig
2017-06-19 14:31 ` Jens Axboe
2017-06-19 14:53 ` Jens Axboe
2017-06-19 18:53 ` Christoph Hellwig
2017-06-19 19:03 ` Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2017-06-17 19:59 [PATCHSET v7] Add support for write life time hints Jens Axboe
2017-06-17 19:59 ` [PATCH 04/11] fs: add support for allowing applications to pass in " Jens Axboe
2017-06-19 6:27 ` Christoph Hellwig
2017-06-19 14:56 ` Jens Axboe
2017-06-19 16:02 ` Jens Axboe
2017-06-19 18:58 ` Christoph Hellwig
2017-06-19 19:00 ` Jens Axboe
2017-06-19 19:10 ` Jens Axboe
2017-06-19 20:33 ` Jens Axboe
2017-06-20 2:06 ` Jens Axboe
2017-06-20 8:57 ` Christoph Hellwig
2017-06-20 12:43 ` Jens Axboe
2017-06-20 12:43 ` Christoph Hellwig
2017-06-20 12:45 ` Jens Axboe
2017-06-20 12:47 ` Christoph Hellwig
2017-06-20 12:51 ` Jens Axboe
2017-06-20 12:56 ` Christoph Hellwig
2017-06-20 13:00 ` Jens Axboe
2017-06-15 3:45 [PATCHSET v4] Add support for " Jens Axboe
2017-06-15 3:45 ` [PATCH 04/11] fs: add support for allowing applications to pass in " Jens Axboe
2017-06-15 4:15 ` Darrick J. Wong
2017-06-15 4:33 ` Jens Axboe
2017-06-15 8:19 ` Christoph Hellwig
2017-06-15 14:21 ` Jens Axboe
2017-06-15 15:23 ` Jens Axboe
2017-06-16 7:30 ` Christoph Hellwig
2017-06-16 14:35 ` Jens Axboe
2017-06-16 7:33 ` Christoph Hellwig
2017-06-16 14:35 ` Jens Axboe
2017-06-16 14:53 ` Jens Axboe
2017-06-16 15:52 ` Christoph Hellwig
2017-06-16 15:59 ` Jens Axboe
2017-06-16 16:14 ` Jens Axboe
2017-06-16 18:00 ` Christoph Hellwig
2017-06-16 18:02 ` Christoph Hellwig
2017-06-16 19:35 ` Jens Axboe
2017-06-15 11:24 ` Al Viro
2017-06-14 19:05 [PATCHSET v3] Add support for " Jens Axboe
2017-06-14 19:05 ` [PATCH 04/11] fs: add support for allowing applications to pass in " Jens Axboe
2017-06-14 20:26 ` Christoph Hellwig
2017-06-14 20:37 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1497633883-21230-5-git-send-email-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=adilger@dilger.ca \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.