From patchwork Fri Mar 4 16:10:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 8505111 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DC66A9F7CA for ; Fri, 4 Mar 2016 16:11:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C9FDA20114 for ; Fri, 4 Mar 2016 16:11:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6510D20145 for ; Fri, 4 Mar 2016 16:11:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759687AbcCDQLb (ORCPT ); Fri, 4 Mar 2016 11:11:31 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:58499 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759490AbcCDQL0 (ORCPT ); Fri, 4 Mar 2016 11:11:26 -0500 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.15.0.59/8.15.0.59) with SMTP id u24G9RX1031370; Fri, 4 Mar 2016 08:11:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=seHS4pSnqKKY+WoX9pfV3Zr7DeUbfdKVXqBvQkgaf00=; b=qy/rL/x3KHiyNke+crOuYGR4qG1UwN51NdDmI9vf87cT2c/LPw/WSxiRlNNibf9bkTaX kcx/JqSW6ZPPkCIm2kU8ko9ux5XQS3u8oIJNYMQOE2eRZVuKHLcvwdk7Eb13dwSMI/m7 sLG5VVk/bvd+RWwVDw2cjVQ2xjTzq08CC7I= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 21f6yj1f44-4 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Fri, 04 Mar 2016 08:11:23 -0800 Received: from localhost.localdomain (192.168.54.13) by mail.thefacebook.com (192.168.16.15) with Microsoft SMTP Server (TLS) id 14.3.248.2; Fri, 4 Mar 2016 08:11:00 -0800 From: Jens Axboe To: , CC: , , , Jens Axboe Subject: [PATCH 02/11] block: add support for carrying a stream ID in a bio Date: Fri, 4 Mar 2016 09:10:44 -0700 Message-ID: <1457107853-8689-3-git-send-email-axboe@fb.com> X-Mailer: git-send-email 2.4.1.168.g1ea28e1 In-Reply-To: <1457107853-8689-1-git-send-email-axboe@fb.com> References: <1457107853-8689-1-git-send-email-axboe@fb.com> MIME-Version: 1.0 X-Originating-IP: [192.168.54.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-03-04_07:, , signatures=0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The top bits of bio->bi_flags are reserved for keeping the allocation pool, set aside the next 16 bits for carrying a stream ID. That leaves us with support for 64k - 1 streams, 0 is reserved as a "stream not set" value. Add helpers for setting/getting stream ID of a bio. Signed-off-by: Jens Axboe --- block/bio.c | 5 ++++ block/blk-core.c | 4 ++++ include/linux/blk_types.h | 60 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/block/bio.c b/block/bio.c index cf7591551b17..d42e69c23271 100644 --- a/block/bio.c +++ b/block/bio.c @@ -584,6 +584,7 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src) bio->bi_rw = bio_src->bi_rw; bio->bi_iter = bio_src->bi_iter; bio->bi_io_vec = bio_src->bi_io_vec; + bio_set_streamid(bio, bio_get_streamid(bio_src)); } EXPORT_SYMBOL(__bio_clone_fast); @@ -689,6 +690,7 @@ integrity_clone: } } + bio_set_streamid(bio, bio_get_streamid(bio_src)); return bio; } EXPORT_SYMBOL(bio_clone_bioset); @@ -2037,6 +2039,9 @@ static void __init biovec_init_slabs(void) static int __init init_bio(void) { + BUILD_BUG_ON(BIO_FLAG_LAST > ((8 * sizeof(unsigned int)) - + BIO_POOL_BITS - BIO_STREAM_BITS)); + bio_slab_max = 2; bio_slab_nr = 0; bio_slabs = kzalloc(bio_slab_max * sizeof(struct bio_slab), GFP_KERNEL); diff --git a/block/blk-core.c b/block/blk-core.c index b83d29755b5a..e4b12693c567 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -2071,6 +2071,10 @@ blk_qc_t generic_make_request(struct bio *bio) struct request_queue *q = bdev_get_queue(bio->bi_bdev); if (likely(blk_queue_enter(q, false) == 0)) { + if (bio_streamid_valid(bio)) + blk_add_trace_msg(q, "StreamID=%u", + bio_get_streamid(bio)); + ret = q->make_request_fn(q, bio); blk_queue_exit(q); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 86a38ea1823f..fc63a82a9944 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -112,21 +112,23 @@ struct bio { /* * bio flags */ -#define BIO_SEG_VALID 1 /* bi_phys_segments valid */ -#define BIO_CLONED 2 /* doesn't own data */ -#define BIO_BOUNCED 3 /* bio is a bounce bio */ -#define BIO_USER_MAPPED 4 /* contains user pages */ -#define BIO_NULL_MAPPED 5 /* contains invalid user pages */ -#define BIO_QUIET 6 /* Make BIO Quiet */ -#define BIO_CHAIN 7 /* chained bio, ->bi_remaining in effect */ -#define BIO_REFFED 8 /* bio has elevated ->bi_cnt */ - -/* - * Flags starting here get preserved by bio_reset() - this includes - * BIO_POOL_IDX() - */ -#define BIO_RESET_BITS 13 -#define BIO_OWNS_VEC 13 /* bio_free() should free bvec */ +enum { + BIO_SEG_VALID = 0, /* bi_phys_segments valid */ + BIO_CLONED, /* doesn't own data */ + BIO_BOUNCED, /* bio is a bounce bio */ + BIO_USER_MAPPED, /* contains user pages */ + BIO_NULL_MAPPED, /* contains invalid user pages */ + BIO_QUIET, /* Mnake BIO Quiet */ + BIO_CHAIN, /* chained bio, ->bi_remaining in effect */ + BIO_REFFED, /* bio has elevated ->bi_cnt */ + BIO_OWNS_VEC, /* bio_free() should free bvec */ + BIO_FLAG_LAST, /* end of bits */ + /* + * Flags starting here get preserved by bio_reset() - this includes + * BIO_POOL_IDX() + */ + BIO_RESET_BITS = BIO_FLAG_LAST, +}; /* * top 4 bits of bio flags indicate the pool this bio came from @@ -134,9 +136,35 @@ struct bio { #define BIO_POOL_BITS (4) #define BIO_POOL_NONE ((1UL << BIO_POOL_BITS) - 1) #define BIO_POOL_OFFSET (32 - BIO_POOL_BITS) -#define BIO_POOL_MASK (1UL << BIO_POOL_OFFSET) #define BIO_POOL_IDX(bio) ((bio)->bi_flags >> BIO_POOL_OFFSET) +/* + * after the pool bits, next 16 bits are for the stream id + */ +#define BIO_STREAM_BITS (16) +#define BIO_STREAM_OFFSET (BIO_POOL_OFFSET - BIO_STREAM_BITS) +#define BIO_STREAM_MASK ((1 << BIO_STREAM_BITS) - 1) + +static inline unsigned long streamid_to_flags(unsigned int id) +{ + return (unsigned long) (id & BIO_STREAM_MASK) << BIO_STREAM_OFFSET; +} + +static inline void bio_set_streamid(struct bio *bio, unsigned int id) +{ + bio->bi_flags |= streamid_to_flags(id); +} + +static inline unsigned int bio_get_streamid(struct bio *bio) +{ + return (bio->bi_flags >> BIO_STREAM_OFFSET) & BIO_STREAM_MASK; +} + +static inline bool bio_streamid_valid(struct bio *bio) +{ + return bio_get_streamid(bio) != 0; +} + #endif /* CONFIG_BLOCK */ /*