From patchwork Mon Jun 26 15:37:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9809943 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 704A0603F3 for ; Mon, 26 Jun 2017 15:38:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 758CE28641 for ; Mon, 26 Jun 2017 15:38:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A93E2863A; Mon, 26 Jun 2017 15:38: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.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 CDEE12861E for ; Mon, 26 Jun 2017 15:38:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751768AbdFZPi0 (ORCPT ); Mon, 26 Jun 2017 11:38:26 -0400 Received: from mail-io0-f177.google.com ([209.85.223.177]:34233 "EHLO mail-io0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751456AbdFZPiL (ORCPT ); Mon, 26 Jun 2017 11:38:11 -0400 Received: by mail-io0-f177.google.com with SMTP id r36so2995611ioi.1 for ; Mon, 26 Jun 2017 08:38:11 -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=GWsWLFQ7sFk5nKhLu3Zy0jcQW15KSGeBdu5iKwI4Ni0=; b=ZAzpUYZXEXxmTcceKc1dLwa8seN+hMA/p8jHYwlz4Dz7XP44VfWLEFklafxO9sBWx5 m24H7lAK/Sq9dS083Q38uwkxyAV630/PjzYijVdyxeTlVGHl0b57Kj4dO5L1arfcScE6 SGkHCiSELQXxnjRO2LExcVXc4s/PCCUMT5EzGEwAUhAt4e0ZEFVdoiSpppLdt8M7nhR7 1QW3gmTQx3I12+eA9Eie+wW3QQUgRhcqRb8RQkuZZsDCfgA1AWySJuNMw3+5mmsHJg0x RclriTYDW9s818r104bKdSwMVS8u7a/Y4/qC89YOcXRorgGbgUgkJPOg6LaG87lwa09K 8zjQ== 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=GWsWLFQ7sFk5nKhLu3Zy0jcQW15KSGeBdu5iKwI4Ni0=; b=DBsY6qMoFnNHN+FFOm4tz4Y1H/Q4I72RFG1YCdSkqbdYFtV9yxiKXeoioehZZYvS/C lNLaUTD1/YxRymnzDDBIkyb2M79XlmpZ3QyDBvyD2VD8gWBsnIE8FIvPl3+zVkfUeKAs c+Rqp0awPIjR4UPzeSFRIYktSnipd+a6VqNVQMZeaDvToRMDLJoCyALn6UZ2+bLPflFQ rMCvonZ/bElySUS1PKiJnQ+F+3ziWZ9PMcLw1SUSbbWMdFrM8GxjFI2tQw5sfGr600F5 f18ekZ2+7Zlg8lVcgUIJaVl05M8S8q0pFDJLNKe0J8+FLadFuiu7YgDVqwfpq9xO6/h/ k4TQ== X-Gm-Message-State: AKS2vOxqoDJ7zP7Wj0aLM7MATMOClUdq9JpXMq9Ub5SvsxE2BUxIj9RP 94K5TxzEkhdc2WHomjmSsQ== X-Received: by 10.107.168.221 with SMTP id e90mr1044494ioj.68.1498491490353; Mon, 26 Jun 2017 08:38:10 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id b69sm33425itb.23.2017.06.26.08.38.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Jun 2017 08:38:09 -0700 (PDT) From: Jens Axboe To: linux-block@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, hch@lst.de, martin.petersen@oracle.com, Jens Axboe Subject: [PATCH 2/9] block: add support for write hints in a bio Date: Mon, 26 Jun 2017 09:37:53 -0600 Message-Id: <1498491480-16306-3-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498491480-16306-1-git-send-email-axboe@kernel.dk> References: <1498491480-16306-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, we just set aside 3 bits in the bio/request flags, which can be used to hold a WRITE_LIFE_* life time hint. Ensure that we don't merge requests that have different life time hints assigned to them. Reviewed-by: Martin K. Petersen Reviewed-by: Christoph Hellwig Signed-off-by: Jens Axboe --- block/blk-merge.c | 16 ++++++++++++++++ fs/inode.c | 9 +++++++++ include/linux/blk_types.h | 31 +++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 4 files changed, 58 insertions(+) diff --git a/block/blk-merge.c b/block/blk-merge.c index 5df13041b851..be1e955db75e 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -673,6 +673,14 @@ static struct request *attempt_merge(struct request_queue *q, return NULL; /* + * Don't allow merge of different write hints, or for a hint with + * non-hint IO. + */ + if ((req->cmd_flags & REQ_WRITE_LIFE_MASK) != + (next->cmd_flags & REQ_WRITE_LIFE_MASK)) + return NULL; + + /* * If we are allowed to merge, then append bio list * from next to rq and release next. merge_requests_fn * will have updated segment counts, update sector @@ -791,6 +799,14 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) !blk_write_same_mergeable(rq->bio, bio)) return false; + /* + * Don't allow merge of different write hints, or for a hint with + * non-hint IO. + */ + if ((rq->cmd_flags & REQ_WRITE_LIFE_MASK) != + (bio->bi_opf & REQ_WRITE_LIFE_MASK)) + return false; + return true; } diff --git a/fs/inode.c b/fs/inode.c index defb015a2c6d..66cc431c9a96 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2131,3 +2131,12 @@ void inode_set_write_hint(struct inode *inode, enum rw_hint hint) inode_unlock(inode); } } + +/* + * Returns block write hint mask for the inode + */ +unsigned int inode_hint_to_opf(struct inode *inode) +{ + return write_hint_to_opf(inode_write_hint(inode)); +} +EXPORT_SYMBOL(inode_hint_to_opf); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index e210da6d14b8..0d44dce19d9f 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -7,6 +7,7 @@ #include #include +#include struct bio_set; struct bio; @@ -223,6 +224,10 @@ enum req_flag_bits { __REQ_RAHEAD, /* read ahead, can fail anytime */ __REQ_BACKGROUND, /* background IO */ + __REQ_WRITE_HINT_SHIFT, /* 3 bits for life time hint */ + __REQ_WRITE_HINT_PAD1, + __REQ_WRITE_HINT_PAD2, + /* command specific flags for REQ_OP_WRITE_ZEROES: */ __REQ_NOUNMAP, /* do not free blocks when zeroing */ @@ -244,6 +249,13 @@ enum req_flag_bits { #define REQ_RAHEAD (1ULL << __REQ_RAHEAD) #define REQ_BACKGROUND (1ULL << __REQ_BACKGROUND) +#define REQ_WRITE_SHORT (WRITE_LIFE_SHORT << __REQ_WRITE_HINT_SHIFT) +#define REQ_WRITE_MEDIUM (WRITE_LIFE_MEDIUM << __REQ_WRITE_HINT_SHIFT) +#define REQ_WRITE_LONG (WRITE_LIFE_LONG << __REQ_WRITE_HINT_SHIFT) +#define REQ_WRITE_EXTREME (WRITE_LIFE_EXTREME << __REQ_WRITE_HINT_SHIFT) + +#define REQ_WRITE_LIFE_MASK (0x7 << __REQ_WRITE_HINT_SHIFT) + #define REQ_NOUNMAP (1ULL << __REQ_NOUNMAP) #define REQ_NOWAIT (1ULL << __REQ_NOWAIT) @@ -335,4 +347,23 @@ struct blk_rq_stat { u64 batch; }; +static inline unsigned int write_hint_to_opf(enum rw_hint hint) +{ + return hint << __REQ_WRITE_HINT_SHIFT; +} + +/* + * Don't let drivers see WRITE_LIFE_NOT_SET, return NONE for that + */ +static inline enum rw_hint opf_to_write_hint(unsigned int opf) +{ + enum rw_hint ret; + + ret = (opf & REQ_WRITE_LIFE_MASK) >> __REQ_WRITE_HINT_SHIFT; + if (ret == WRITE_LIFE_NOT_SET) + ret = WRITE_LIFE_NONE; + + return ret; +} + #endif /* __LINUX_BLK_TYPES_H */ diff --git a/include/linux/fs.h b/include/linux/fs.h index 0ef5d110d2bc..86888a6ccad1 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1912,6 +1912,8 @@ static inline bool HAS_UNMAPPED_ID(struct inode *inode) return !uid_valid(inode->i_uid) || !gid_valid(inode->i_gid); } +extern unsigned int inode_hint_to_opf(struct inode *inode); + static inline unsigned int write_hint_to_mask(enum rw_hint hint, unsigned int shift) {