From patchwork Wed Jun 21 00:21:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9800451 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 7D2426038C for ; Wed, 21 Jun 2017 00:22:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B9062846B for ; Wed, 21 Jun 2017 00:22:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 601DF2849E; Wed, 21 Jun 2017 00:22:19 +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 DF8662846B for ; Wed, 21 Jun 2017 00:22:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752827AbdFUAWQ (ORCPT ); Tue, 20 Jun 2017 20:22:16 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:33629 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752774AbdFUAWN (ORCPT ); Tue, 20 Jun 2017 20:22:13 -0400 Received: by mail-pf0-f181.google.com with SMTP id 83so76891664pfr.0 for ; Tue, 20 Jun 2017 17:22:13 -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=8tiUlTFkl9xj2yZif6VrQcmmXE37puf9pajAr+1aflo=; b=EgsyIC7uDiMoOdXRhEXTBM/hB53D019PadTDpXsn6iohIrQvGgVS/F8x6fUxWb4DWN zSTzlKWBlGV3T0XUrbHBCLRlsFMb5J2Gfd7fw6K7+y9N0XPzhmI+8zd8ly5SsUeoq+kk ff70sL9G8sL91XBXEIkx4wFIEkGB9vNCNdX2n2ZTOHon42Uebw/g2oCVMpVJlBKR9vK1 rS6czvqSeUQu63yNQFEP4ztybRD+Se5+kHFW+/b21Q+SjGkRwJr8CBLbMIeCFf2VULKf QMyfMWKXJobMZ/N6y9lnIQ0N9bqDh2vAJ0CktJlcWDgV5iwxnmiHN3Y3t8CuycxCb4gd wzzw== 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=8tiUlTFkl9xj2yZif6VrQcmmXE37puf9pajAr+1aflo=; b=J2WNjU8v+i8k26ZpqJMbvKuaN+4PVsldptcwkmMf3dMOf2piTySpB79Ga2c7IAFQ8y H6B1+wvIdM35ekqGmKVukLJyaZba1G1SAbvJHrS5ggMpDqM7O5fZX2IboEhPrg2wzmwj 0nXPreQP4pm5ufAonI0cGcDZTA9oSPvzvx8s90wilPdADJt2AKqNSXsGI7txkm8YnwKb mgP7esp1wf/Fug7cD5Vbyr/dV2Q6+oPeog6dDyaf5OPaV1zC5OkwxzaRrzU1wpegaIZ/ 2BbDA1dyZ4wC4HS/cPNO293cEV5Gpr4Y9iVvdTiA47SXmywtRMv1KC06+zyppcDxPcBY +rTA== X-Gm-Message-State: AKS2vOwfGJYttKVKFC6FWfO5BnviZVjjRiWdK3k3f+tKI91fW5VnC5KB L1CkZTqgEhIa2AzY X-Received: by 10.98.155.18 with SMTP id r18mr33519321pfd.198.1498004532449; Tue, 20 Jun 2017 17:22:12 -0700 (PDT) Received: from localhost.localdomain (66.29.164.166.static.utbb.net. [66.29.164.166]) by smtp.gmail.com with ESMTPSA id f10sm13447835pfd.69.2017.06.20.17.22.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 17:22:11 -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, linux-nvme@lists.infradead.org, Jens Axboe Subject: [PATCH 2/9] block: add support for write hints in a bio Date: Tue, 20 Jun 2017 18:21:59 -0600 Message-Id: <1498004526-4543-3-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498004526-4543-1-git-send-email-axboe@kernel.dk> References: <1498004526-4543-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. Signed-off-by: Jens Axboe Reviewed-by: Christoph Hellwig --- block/blk-merge.c | 16 ++++++++++++++++ include/linux/blk_types.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/block/blk-merge.c b/block/blk-merge.c index cea544ec5d96..17cd0c3f872d 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -670,6 +670,14 @@ static struct request *attempt_merge(struct request_queue *q, return NULL; /* + * Don't allow merge of different streams, or for a stream with + * non-stream 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 @@ -788,6 +796,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 streams, or for a stream with + * non-stream IO. + */ + if ((rq->cmd_flags & REQ_WRITE_LIFE_MASK) != + (bio->bi_opf & REQ_WRITE_LIFE_MASK)) + return false; + return true; } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index e210da6d14b8..4ce71298e45b 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 */