From patchwork Sat Jun 17 19:59:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9794367 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 A7084600F6 for ; Sat, 17 Jun 2017 20:00:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B490283FF for ; Sat, 17 Jun 2017 20:00:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FFA42843F; Sat, 17 Jun 2017 20:00:12 +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 27F68283FF for ; Sat, 17 Jun 2017 20:00:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752769AbdFQUAL (ORCPT ); Sat, 17 Jun 2017 16:00:11 -0400 Received: from mail-it0-f42.google.com ([209.85.214.42]:36152 "EHLO mail-it0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752426AbdFQUAJ (ORCPT ); Sat, 17 Jun 2017 16:00:09 -0400 Received: by mail-it0-f42.google.com with SMTP id m47so49547793iti.1 for ; Sat, 17 Jun 2017 13:00:08 -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=gwZOrqZzHbTc0ynxZ3Ov6hD47+8VxiiiMDZ503jNfbg=; b=Q9wYfN4vWN9dk2nFZ8AnHvwPWfFDPGq/hgmgH7mAlCwNqlTHP7FILJeZ7n/1vkKOcq NWDLoiAzEzBDs44gtMrggbmWplx+od7kba4Y4PJGC3NkQ+07YUUj1waPg+TnqjVc3WK7 ybNyPMsAEH4Z1N7F1hqA2mkahobMASFEBrC3iMwBX0NLgoUxGlBj0RFMOCM9whOl6HNA g/CQmzwHVOkRZBQVCqJGmhWr0N7ojbsnHEH45Ikr9rw9OHRTnVdeUWf18vWJWeMj3fFQ u6qdi6Wr3AGY5uZRYthZNQe5x+zkTb8Ug8k01ZXD47oTEckimJg0rzK8ruAuolPCBkqB E2Xw== 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=gwZOrqZzHbTc0ynxZ3Ov6hD47+8VxiiiMDZ503jNfbg=; b=SxPkOl4AGrMtcQAY9Uxnzbyu9CQdaCbAC3/J7Sf9MBaq8FIkR0puY7picV0RgrAguH hYmBwZQxlFmXwQ0s2SRMB0FF/RqxcemeeM/em9fzqHhkzoKob6CM5fbcOHhEdELRo9jd qaFcIiKXMvTxVEEjNpcPWBve15Ye0FCMHjjyJGiFanfR6sQtJdKqt2lJVVGSBknfuXYL M2NWOL3/Irr3/QJlhkro+h3vgNMnkt6zSRyKWuWbz/1/gQ2Ax1Vw/U+D3Cvw6ZcN68jw NQcaJaPWkQlpY97cozl8JeOtLivuunh8/1nOsdkC3H5HnOgOwWH42rY1jsY6lMDsxRID szHQ== X-Gm-Message-State: AKS2vOxyxTeyV3Wtc+fJHFrOOBN5ORu0VZfi8rIaFY41hP67ajurcCSR 5+ZwckHX0iEL2a+1 X-Received: by 10.36.91.71 with SMTP id g68mr7132478itb.54.1497729608130; Sat, 17 Jun 2017 13:00:08 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id w199sm537049iod.15.2017.06.17.13.00.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Jun 2017 13:00:07 -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: Sat, 17 Jun 2017 13:59:47 -0600 Message-Id: <1497729594-4707-5-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497729594-4707-1-git-send-email-axboe@kernel.dk> References: <1497729594-4707-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. 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 --- 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 */