From patchwork Thu Jun 15 16:42:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9789271 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 9CDF460384 for ; Thu, 15 Jun 2017 16:42:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FD4327F7F for ; Thu, 15 Jun 2017 16:42:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84D69286BF; Thu, 15 Jun 2017 16:42:28 +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 0B4202852E for ; Thu, 15 Jun 2017 16:42:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752030AbdFOQm0 (ORCPT ); Thu, 15 Jun 2017 12:42:26 -0400 Received: from mail-io0-f177.google.com ([209.85.223.177]:34024 "EHLO mail-io0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751773AbdFOQmT (ORCPT ); Thu, 15 Jun 2017 12:42:19 -0400 Received: by mail-io0-f177.google.com with SMTP id i7so15437527ioe.1 for ; Thu, 15 Jun 2017 09:42:18 -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=28hCrycpjfT8RcZ/m/HJIjHSJpcuP86q6WtlreOkbN0=; b=MVdGsGyrExynA45yW/Li7wzyxXRG7amlqiAVD7DE6NJicZBE46mRWeSfFWPuJY/fBN zTIHUz3cn+o/xWqsko79Qzq+MVeb2NtvszPS663sFuO9cdNpYzDBCO5i0zwe6UTPwHBQ ixq/HP8uqBoklAvlJ6iJ4WumKrHoFLnkc5BEiWR+F51F42rZ9ONGk6QSKcbF06Ut11Ch AqrffjDZZkX+cxgzN4zU4TjnCC1DG5WQM0WH5LpZvGDhgaAbDP6jaNPUs9n6Anwed21R cLmLT0+g61gywNDc4BWfWImfCamT4ZwtdoVR3UKWhL+ZGSqOUst6coxKyPBY498iwQMT 9+3A== 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=28hCrycpjfT8RcZ/m/HJIjHSJpcuP86q6WtlreOkbN0=; b=C4uDQNmES+Fn28XZJVlA/mA0p9Va25JmSjT2jtObTPSnKHQYJdKswXqck3NJzjvv0x XOhcXRo6Zz8lOHxNnLMq3iksDjP4gyAe++vkqCN/Q343Ef/L8duNL8MTrKtcGDgEKWZj Umph00XbXWnUtOc6aXlfwMGEv0g/AeDuoM3wkpYzFwLPMne+UUgcqsYHq5rbPlWb0BkM GEGqctv0zBWAej17U6i6Hyq0Oxrl3a01OFvJZKCQrI9Yco3FVc30L4sY4D5C4MYdjj3x fyfIesen+YI5t2wYw24RJUOPryTuSfgn5O6HbHxCP7MnMjk/SCGyAGMULgBLMF6tDpSd rZGw== X-Gm-Message-State: AKS2vOw4clZDSbooLNPY+fcKJH8UM6d6LlgZ7IXUHTuAUv7unHnjmU6K RRWIYRYPGDCr7ARq X-Received: by 10.107.10.84 with SMTP id u81mr6170182ioi.206.1497544937818; Thu, 15 Jun 2017 09:42:17 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id 97sm313476iot.25.2017.06.15.09.42.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Jun 2017 09:42:16 -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 03/12] fs: add support for an inode to carry write hint related data Date: Thu, 15 Jun 2017 10:42:01 -0600 Message-Id: <1497544930-19174-4-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497544930-19174-1-git-send-email-axboe@kernel.dk> References: <1497544930-19174-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 No functional changes in this patch, just in preparation for allowing applications to pass in hints about data life times for writes. Set aside 3 bits for carrying hint information in the inode flags. Adds the public hints as well, which are: WRITE_HINT_NONE No hints about write life time WRITE_HINT_SHORT Data written has a short life time WRITE_HINT_MEDIUM Data written has a medium life time WRITE_HINT_LONG Data written has a long life time WRITE_HINT_EXTREME Data written has an extremely long life tim Helpers are defined to store these values in flags, by passing in the shift that's appropriate for the given use case. Signed-off-by: Jens Axboe --- fs/inode.c | 11 +++++++++++ include/linux/fs.h | 29 +++++++++++++++++++++++++++++ include/uapi/linux/fs.h | 13 +++++++++++++ 3 files changed, 53 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index db5914783a71..cc8a05c4c1be 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2120,3 +2120,14 @@ struct timespec current_time(struct inode *inode) return timespec_trunc(now, inode->i_sb->s_time_gran); } EXPORT_SYMBOL(current_time); + +void inode_set_write_hint(struct inode *inode, enum write_hint hint) +{ + unsigned int flags = write_hint_to_mask(hint, S_WRITE_LIFE_SHIFT); + + if (flags != mask_to_write_hint(inode->i_flags, S_WRITE_LIFE_SHIFT)) { + inode_lock(inode); + inode_set_flags(inode, flags, S_WRITE_LIFE_MASK); + inode_unlock(inode); + } +} diff --git a/include/linux/fs.h b/include/linux/fs.h index 803e5a9b2654..bef0b350f890 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1828,6 +1828,14 @@ struct super_operations { #endif /* + * Expected life time hint of a write for this inode. This uses the + * WRITE_HINT_* encoding, we just need to define the shift. We need + * 3 bits for this. Next S_* value is 131072, bit 17. + */ +#define S_WRITE_LIFE_MASK 0x1c000 /* bits 14..16 */ +#define S_WRITE_LIFE_SHIFT 14 /* 16384, next bit */ + +/* * Note that nosuid etc flags are inode-specific: setting some file-system * flags just means all the inodes inherit those flags by default. It might be * possible to override it selectively if you really wanted to with some @@ -1873,6 +1881,26 @@ static inline bool HAS_UNMAPPED_ID(struct inode *inode) return !uid_valid(inode->i_uid) || !gid_valid(inode->i_gid); } +static inline unsigned int write_hint_to_mask(enum write_hint hint, + unsigned int shift) +{ + return hint << shift; +} + +static inline enum write_hint mask_to_write_hint(unsigned int mask, + unsigned int shift) +{ + return (mask >> shift) & 0x7; +} + +static inline unsigned int inode_write_hint(struct inode *inode) +{ + if (inode) + return mask_to_write_hint(inode->i_flags, S_WRITE_LIFE_SHIFT); + + return 0; +} + /* * Inode state bits. Protected by inode->i_lock * @@ -2757,6 +2785,7 @@ extern struct inode *new_inode(struct super_block *sb); extern void free_inode_nonrcu(struct inode *inode); extern int should_remove_suid(struct dentry *); extern int file_remove_privs(struct file *); +extern void inode_set_write_hint(struct inode *inode, enum write_hint hint); extern void __insert_inode_hash(struct inode *, unsigned long hashval); static inline void insert_inode_hash(struct inode *inode) diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 24e61a54feaa..58fbe0903016 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -356,6 +356,19 @@ struct fscrypt_key { #define SYNC_FILE_RANGE_WRITE 2 #define SYNC_FILE_RANGE_WAIT_AFTER 4 +/* + * Write life time hint values. + */ +enum write_hint { + WRITE_HINT_NONE = 0, + WRITE_HINT_SHORT, + WRITE_HINT_MEDIUM, + WRITE_HINT_LONG, + WRITE_HINT_EXTREME, +}; + +#define WRITE_HINT_MASK 0x7 /* 3 bits */ + /* flags for preadv2/pwritev2: */ #define RWF_HIPRI 0x00000001 /* high priority request, poll if possible */ #define RWF_DSYNC 0x00000002 /* per-IO O_DSYNC */