From patchwork Mon Jun 19 17:04:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9796911 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 654336020B for ; Mon, 19 Jun 2017 17:05:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A15A26E97 for ; Mon, 19 Jun 2017 17:05:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EB5927EE2; Mon, 19 Jun 2017 17:05:15 +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 95C7327F8F for ; Mon, 19 Jun 2017 17:05:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752601AbdFSRFM (ORCPT ); Mon, 19 Jun 2017 13:05:12 -0400 Received: from mail-it0-f50.google.com ([209.85.214.50]:38507 "EHLO mail-it0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751082AbdFSRFJ (ORCPT ); Mon, 19 Jun 2017 13:05:09 -0400 Received: by mail-it0-f50.google.com with SMTP id b205so47103451itg.1 for ; Mon, 19 Jun 2017 10:05:09 -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=+5dKjGWyQ4Pc7xuox84vOyWsDibBQK5FH39ll3Clac0=; b=LRBFLpDW1yq6/dYkj4qJuQXO6N0GKRsFrnR4Az+Omexnsw1a6+Djq9AY/M6QkSEiA9 qpI4J8HldowgHhRWSQQZFh53rbT4D+Gb41a6Civ3id2YbkMPv4f1yEv59c6CYBXEge/K d7MnG6xSaC26CpvLxSu1eY0Gvx5UAtEsCMwaIlWP2kfCQHBQflDWfejPnS78NNqdJqaJ +NKAFBpWOlaVeX803VfUKOpo7I7HzMYb90dpwlssbybJCSQP7+gdO5QPujbLYEyi4dVn 2LAQ9AeJIrUEKZHb7dqz4ItgHFtGwJ6vO4GVQ4WJ7k0M8LOSxQH0NdnREQrWCLgs6QvY ja/g== 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=+5dKjGWyQ4Pc7xuox84vOyWsDibBQK5FH39ll3Clac0=; b=GJGQAmEchN2c6tXgjeKbRunh3D3Bw9ez3Izda7ene4Im2ajg6hRAaZw62oostCqdk6 brwcKFwm+eTJfMvsvn6s8dmAdyfKg8RgxEXRpJhzAMBnTgZew1PUBu12elXhbfj/DXPT 8/ss3vuykNY4nUFFirHBwrhmpgWSe/Nz6WgwD+emjWQJhCIDmvitnxiDCQ3CFNmLilvI +oNXpEi6+N4FOmtsp6gAFjAhtJ0meWiM1m2Oz/X6+dfeH/MaQvk7QmLOgUyHQv62Rt7F y5vfqrybi8Crl2nFH5qDpHjlelVEddqVvZD54pmEjQwpOB4/zyPohKhbvmBR0+qvBTU6 N5Wg== X-Gm-Message-State: AKS2vOy/8fMlomESSpiJ2kQYMJfJM58560GJhkli2espEheK8Ln3BK0m OtQWRbEPZ1FXymWkcA18Lg== X-Received: by 10.36.121.216 with SMTP id z207mr22154970itc.86.1497891908147; Mon, 19 Jun 2017 10:05:08 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id 3sm6770522ith.7.2017.06.19.10.05.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Jun 2017 10:05: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, linux-nvme@lists.infradead.org, Jens Axboe Subject: [PATCH 2/9] block: add support for write hints in a bio Date: Mon, 19 Jun 2017 11:04:55 -0600 Message-Id: <1497891902-25737-3-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497891902-25737-1-git-send-email-axboe@kernel.dk> References: <1497891902-25737-1-git-send-email-axboe@kernel.dk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 --- block/blk-merge.c | 16 ++++++++++++++++ include/linux/blk_types.h | 20 ++++++++++++++++++++ 2 files changed, 36 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 dcd45b15a3a5..fde216924aa3 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; @@ -220,6 +221,9 @@ enum req_flag_bits { __REQ_PREFLUSH, /* request for cache flush */ __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 */ @@ -240,6 +244,12 @@ enum req_flag_bits { #define REQ_PREFLUSH (1ULL << __REQ_PREFLUSH) #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) @@ -331,4 +341,14 @@ struct blk_rq_stat { u64 batch; }; +static inline unsigned int write_hint_to_opf(enum rw_hint hint) +{ + return hint << __REQ_WRITE_HINT_SHIFT; +} + +static inline enum rw_hint opf_to_write_hint(unsigned int opf) +{ + return (opf & REQ_WRITE_LIFE_MASK) >> __REQ_WRITE_HINT_SHIFT; +} + #endif /* __LINUX_BLK_TYPES_H */