From patchwork Thu Aug 1 22:50:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11071471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A958A13A4 for ; Thu, 1 Aug 2019 22:50:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 994F628528 for ; Thu, 1 Aug 2019 22:50:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CDDE28644; Thu, 1 Aug 2019 22:50:58 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 E695928528 for ; Thu, 1 Aug 2019 22:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733159AbfHAWu4 (ORCPT ); Thu, 1 Aug 2019 18:50:56 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40983 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732058AbfHAWuy (ORCPT ); Thu, 1 Aug 2019 18:50:54 -0400 Received: by mail-pf1-f196.google.com with SMTP id m30so34907465pff.8 for ; Thu, 01 Aug 2019 15:50:54 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=VUEzYYkhp+BC4vL6yhQylrF9cJTyrVZWCRRlLtTmY5A=; b=h5p/LAPTV+gnSbwY0SA9Z5GN1J65J+oz0y/ALrt3c23VXhMMi6xbqgZsmyLqpAE8mX 02jLo+Mv6PWpBS9Nan6GE7fA6o6u7JNVO+5k4JOW+EKKvjXvJQJcwN87Cx4zPjyvOXiy txmswLBvYXaqvEDdwDBnFE6TtpFZEeLj9yXCBEYXu+AZNQPw/p0YEAxStslulun7QnDx daPs26ABbjA2zFzwpCmoZ41RSm7I74MU+2B8ucUguTpl6SE9Ytw7ApoCxK9TqRerFXBs eKkqmwqoTqhfTBHUYd/mJfbg1jXocXBFEyXDLSEWu0bb/yv8TIvEBlNKJNZfB+M8wmgg 5f3A== X-Gm-Message-State: APjAAAVs+fqgzoGhN85+itztNIHWLqFUBN1NI8GLZpFltNfVm6jkKnSf n2KkaJVPkX0gUQq2fDMPXO4= X-Google-Smtp-Source: APXvYqw51tX4aSKGR37uaxgzC+dCpw5NiuM1okQ4llUzhER/5BuSNJvzZOfPbOi1NuSsD+o/r/n1Sw== X-Received: by 2002:a62:d45d:: with SMTP id u29mr55860120pfl.135.1564699854172; Thu, 01 Aug 2019 15:50:54 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:202:4308:52a3:24b6:2c60]) by smtp.gmail.com with ESMTPSA id d12sm35472010pfn.11.2019.08.01.15.50.53 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 15:50:53 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Johannes Thumshirn , Christoph Hellwig , Ming Lei , Hannes Reinecke Subject: [PATCH v2 1/5] block: Declare several function pointer arguments 'const' Date: Thu, 1 Aug 2019 15:50:40 -0700 Message-Id: <20190801225044.143478-2-bvanassche@acm.org> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog In-Reply-To: <20190801225044.143478-1-bvanassche@acm.org> References: <20190801225044.143478-1-bvanassche@acm.org> MIME-Version: 1.0 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 Make it clear to the compiler and also to humans that the functions that query request queue properties do not modify any member of the request_queue data structure. Reviewed-by: Johannes Thumshirn Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Signed-off-by: Bart Van Assche Reviewed-by: Chaitanya Kulkarni --- block/blk-merge.c | 7 ++++--- include/linux/blkdev.h | 32 ++++++++++++++++---------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 57f7990b342d..8344d94f13e0 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -144,7 +144,7 @@ static inline unsigned get_max_io_size(struct request_queue *q, return sectors; } -static unsigned get_max_segment_size(struct request_queue *q, +static unsigned get_max_segment_size(const struct request_queue *q, unsigned offset) { unsigned long mask = queue_segment_boundary(q); @@ -161,8 +161,9 @@ static unsigned get_max_segment_size(struct request_queue *q, * Split the bvec @bv into segments, and update all kinds of * variables. */ -static bool bvec_split_segs(struct request_queue *q, struct bio_vec *bv, - unsigned *nsegs, unsigned *sectors, unsigned max_segs) +static bool bvec_split_segs(const struct request_queue *q, + const struct bio_vec *bv, unsigned *nsegs, + unsigned *sectors, unsigned max_segs) { unsigned len = bv->bv_len; unsigned total_len = 0; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 1ef375dafb1c..96a29a72fd4a 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1232,42 +1232,42 @@ enum blk_default_limits { BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL, }; -static inline unsigned long queue_segment_boundary(struct request_queue *q) +static inline unsigned long queue_segment_boundary(const struct request_queue *q) { return q->limits.seg_boundary_mask; } -static inline unsigned long queue_virt_boundary(struct request_queue *q) +static inline unsigned long queue_virt_boundary(const struct request_queue *q) { return q->limits.virt_boundary_mask; } -static inline unsigned int queue_max_sectors(struct request_queue *q) +static inline unsigned int queue_max_sectors(const struct request_queue *q) { return q->limits.max_sectors; } -static inline unsigned int queue_max_hw_sectors(struct request_queue *q) +static inline unsigned int queue_max_hw_sectors(const struct request_queue *q) { return q->limits.max_hw_sectors; } -static inline unsigned short queue_max_segments(struct request_queue *q) +static inline unsigned short queue_max_segments(const struct request_queue *q) { return q->limits.max_segments; } -static inline unsigned short queue_max_discard_segments(struct request_queue *q) +static inline unsigned short queue_max_discard_segments(const struct request_queue *q) { return q->limits.max_discard_segments; } -static inline unsigned int queue_max_segment_size(struct request_queue *q) +static inline unsigned int queue_max_segment_size(const struct request_queue *q) { return q->limits.max_segment_size; } -static inline unsigned short queue_logical_block_size(struct request_queue *q) +static inline unsigned short queue_logical_block_size(const struct request_queue *q) { int retval = 512; @@ -1282,7 +1282,7 @@ static inline unsigned short bdev_logical_block_size(struct block_device *bdev) return queue_logical_block_size(bdev_get_queue(bdev)); } -static inline unsigned int queue_physical_block_size(struct request_queue *q) +static inline unsigned int queue_physical_block_size(const struct request_queue *q) { return q->limits.physical_block_size; } @@ -1292,7 +1292,7 @@ static inline unsigned int bdev_physical_block_size(struct block_device *bdev) return queue_physical_block_size(bdev_get_queue(bdev)); } -static inline unsigned int queue_io_min(struct request_queue *q) +static inline unsigned int queue_io_min(const struct request_queue *q) { return q->limits.io_min; } @@ -1302,7 +1302,7 @@ static inline int bdev_io_min(struct block_device *bdev) return queue_io_min(bdev_get_queue(bdev)); } -static inline unsigned int queue_io_opt(struct request_queue *q) +static inline unsigned int queue_io_opt(const struct request_queue *q) { return q->limits.io_opt; } @@ -1312,7 +1312,7 @@ static inline int bdev_io_opt(struct block_device *bdev) return queue_io_opt(bdev_get_queue(bdev)); } -static inline int queue_alignment_offset(struct request_queue *q) +static inline int queue_alignment_offset(const struct request_queue *q) { if (q->limits.misaligned) return -1; @@ -1342,7 +1342,7 @@ static inline int bdev_alignment_offset(struct block_device *bdev) return q->limits.alignment_offset; } -static inline int queue_discard_alignment(struct request_queue *q) +static inline int queue_discard_alignment(const struct request_queue *q) { if (q->limits.discard_misaligned) return -1; @@ -1432,7 +1432,7 @@ static inline sector_t bdev_zone_sectors(struct block_device *bdev) return 0; } -static inline int queue_dma_alignment(struct request_queue *q) +static inline int queue_dma_alignment(const struct request_queue *q) { return q ? q->dma_alignment : 511; } @@ -1543,7 +1543,7 @@ static inline void blk_queue_max_integrity_segments(struct request_queue *q, } static inline unsigned short -queue_max_integrity_segments(struct request_queue *q) +queue_max_integrity_segments(const struct request_queue *q) { return q->limits.max_integrity_segments; } @@ -1626,7 +1626,7 @@ static inline void blk_queue_max_integrity_segments(struct request_queue *q, unsigned int segs) { } -static inline unsigned short queue_max_integrity_segments(struct request_queue *q) +static inline unsigned short queue_max_integrity_segments(const struct request_queue *q) { return 0; } From patchwork Thu Aug 1 22:50:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11071481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7687513A0 for ; Thu, 1 Aug 2019 22:51:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6842E28528 for ; Thu, 1 Aug 2019 22:51:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CA6628620; Thu, 1 Aug 2019 22:51:05 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 44C8728528 for ; Thu, 1 Aug 2019 22:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728904AbfHAWvD (ORCPT ); Thu, 1 Aug 2019 18:51:03 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:39276 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730457AbfHAWu4 (ORCPT ); Thu, 1 Aug 2019 18:50:56 -0400 Received: by mail-pf1-f196.google.com with SMTP id f17so30903510pfn.6 for ; Thu, 01 Aug 2019 15:50:56 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=WFknHuGrAVuRUIDZ0JwPLjzFM/nqpojzKm+Ph0JQmZA=; b=HWEAl3xWIN+voenZC1Kx6Dt3zcW5nztirJ2lPfahh4BUrAPdqJVWiGTdKroFLIOhxn TInQhTvNyqHrfJxvohYXRH9IcjcxqY2YfQhwCHCT1nhNkzcHTxLrdpS/rcArSlvoKqlA GcS78zWy14+DB9SMueeHJRzu1sdJ4hzL6EFa0dXfLYrIyW+BYmN0ZOgYt3Wc6yc6MfSK 2ph/cP7n2q/PWcUz6xAWLVTsRVO5JdEeJIpYaBtJhdHbgotKxoyuuBsvM0D3YAHJ1zlF 2Izd8GIunhRXJo4SiNfMJapX8mo0WPVb5aTInTgfuDAqva55CrSwFGGVMF3abDCWuUy2 6CKA== X-Gm-Message-State: APjAAAX/IdoHZpeY/WWSZMskFYuG54H82r72Wg14BhP8dlXHhTDqLS0S AzLGLm9MznFRKwN+OCb32RNUrDFP X-Google-Smtp-Source: APXvYqymGJgSsA5bCsSzCP3bljvW6IYDAGFmgcxvVCkoVk49SiahFOEaQhCcvHh/hIv6fLjeNEQC7w== X-Received: by 2002:a62:8643:: with SMTP id x64mr57818429pfd.7.1564699855526; Thu, 01 Aug 2019 15:50:55 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:202:4308:52a3:24b6:2c60]) by smtp.gmail.com with ESMTPSA id d12sm35472010pfn.11.2019.08.01.15.50.54 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 15:50:54 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Johannes Thumshirn , Christoph Hellwig , Ming Lei , Hannes Reinecke Subject: [PATCH v2 2/5] block: Document the bio splitting functions Date: Thu, 1 Aug 2019 15:50:41 -0700 Message-Id: <20190801225044.143478-3-bvanassche@acm.org> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog In-Reply-To: <20190801225044.143478-1-bvanassche@acm.org> References: <20190801225044.143478-1-bvanassche@acm.org> MIME-Version: 1.0 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 Since what the bio splitting functions do is nontrivial, document these functions. Reviewed-by: Johannes Thumshirn Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Signed-off-by: Bart Van Assche Reviewed-by: Chaitanya Kulkarni --- block/bio.c | 4 ++-- block/blk-merge.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/block/bio.c b/block/bio.c index 299a0e7651ec..0fff4eb9eb1e 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1842,8 +1842,8 @@ EXPORT_SYMBOL(bio_endio); * @bio, and updates @bio to represent the remaining sectors. * * Unless this is a discard request the newly allocated bio will point - * to @bio's bi_io_vec; it is the caller's responsibility to ensure that - * @bio is not freed before the split. + * to @bio's bi_io_vec. It is the caller's responsibility to ensure that + * neither @bio nor @bs are freed before the split bio. */ struct bio *bio_split(struct bio *bio, int sectors, gfp_t gfp, struct bio_set *bs) diff --git a/block/blk-merge.c b/block/blk-merge.c index 8344d94f13e0..51ed971709c3 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -195,6 +195,25 @@ static bool bvec_split_segs(const struct request_queue *q, return !!len; } +/** + * blk_bio_segment_split - split a bio in two bios + * @q: [in] request queue pointer + * @bio: [in] bio to be split + * @bs: [in] bio set to allocate the clone from + * @segs: [out] number of segments in the bio with the first half of the sectors + * + * Clone @bio, update the bi_iter of the clone to represent the first sectors + * of @bio and update @bio->bi_iter to represent the remaining sectors. The + * following is guaranteed for the cloned bio: + * - That it has at most get_max_io_size(@q, @bio) sectors. + * - That it has at most queue_max_segments(@q) segments. + * + * Except for discard requests the cloned bio will point at the bi_io_vec of + * the original bio. It is the responsibility of the caller to ensure that the + * original bio is not freed before the cloned bio. The caller is also + * responsible for ensuring that @bs is only destroyed after processing of the + * split bio has finished. + */ static struct bio *blk_bio_segment_split(struct request_queue *q, struct bio *bio, struct bio_set *bs, @@ -251,6 +270,19 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, return bio_split(bio, sectors, GFP_NOIO, bs); } +/** + * __blk_queue_split - split a bio and submit the second half + * @q: [in] request queue pointer + * @bio: [in, out] bio to be split + * @nr_segs: [out] number of segments in the first bio + * + * Split a bio into two bios, chain the two bios, submit the second half and + * store a pointer to the first half in *@bio. If the second bio is still too + * big it will be split by a recursive call to this function. Since this + * function may allocate a new bio from @q->bio_split, it is the responsibility + * of the caller to ensure that @q is only released after processing of the + * split bio has finished. + */ void __blk_queue_split(struct request_queue *q, struct bio **bio, unsigned int *nr_segs) { @@ -295,6 +327,17 @@ void __blk_queue_split(struct request_queue *q, struct bio **bio, } } +/** + * blk_queue_split - split a bio and submit the second half + * @q: [in] request queue pointer + * @bio: [in, out] bio to be split + * + * Split a bio into two bios, chains the two bios, submit the second half and + * store a pointer to the first half in *@bio. Since this function may allocate + * a new bio from @q->bio_split, it is the responsibility of the caller to + * ensure that @q is only released after processing of the split bio has + * finished. + */ void blk_queue_split(struct request_queue *q, struct bio **bio) { unsigned int nr_segs; From patchwork Thu Aug 1 22:50:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11071475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD4AE746 for ; Thu, 1 Aug 2019 22:50:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE51E28528 for ; Thu, 1 Aug 2019 22:50:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C273728606; Thu, 1 Aug 2019 22:50:59 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 B753728528 for ; Thu, 1 Aug 2019 22:50:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390104AbfHAWu5 (ORCPT ); Thu, 1 Aug 2019 18:50:57 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:39277 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732058AbfHAWu5 (ORCPT ); Thu, 1 Aug 2019 18:50:57 -0400 Received: by mail-pf1-f195.google.com with SMTP id f17so30903544pfn.6 for ; Thu, 01 Aug 2019 15:50:57 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=v78JLgMrSx/P5onOsxF4EDc4WPnU4qR8t9YihlIqQaU=; b=reu7sh9Hfb+pNwzBG9PzCusDvikglDMANnB2uHYp4GV5snAU6JKnKc4Vmdb6w/7+Te /dYcMf0ejGcTr+VrYd4ODkQdFn93b6I/qJFGx0xil5AEuvw8BFwcYEAIT9m3hs2Pvqiy YyLVE6p/ztLwZJnifiaevS9JAIw4Jr54c+GqbRHyivbgbhToj8h4FY7UDBEnnz2rxEmx WLJnpCnXXLLL0ZJ6bUlg6QdRYcGWbOT1r698+jD4D+KsUD6cuLn4Vl3/Xa6a0vfpdjre IOZsSmOd0zilLF6iZS65J8PStpKD4DjwexBoV9v2Fd1Gx+Mq7sWfOU/mJLnsNYKPeRmd EiYQ== X-Gm-Message-State: APjAAAVlKriORo89ZgHnFIQxFAsZJRKMk6UnDoc2eM6Zhe71H/QBYegz Vi3WcJMHdUubgJEwt1nfhcw= X-Google-Smtp-Source: APXvYqwGNpkamVrKl+/oxfrJHBlcmf+w3fU1mK05os9fKX6DQFDTeW0dfDtmK7paeuufjwZdq/C2ZA== X-Received: by 2002:a17:90a:384d:: with SMTP id l13mr1175179pjf.86.1564699856632; Thu, 01 Aug 2019 15:50:56 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:202:4308:52a3:24b6:2c60]) by smtp.gmail.com with ESMTPSA id d12sm35472010pfn.11.2019.08.01.15.50.55 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 15:50:55 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Johannes Thumshirn , Ming Lei , Hannes Reinecke Subject: [PATCH v2 3/5] block: Simplify bvec_split_segs() Date: Thu, 1 Aug 2019 15:50:42 -0700 Message-Id: <20190801225044.143478-4-bvanassche@acm.org> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog In-Reply-To: <20190801225044.143478-1-bvanassche@acm.org> References: <20190801225044.143478-1-bvanassche@acm.org> MIME-Version: 1.0 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 Simplify this function by by removing two if-tests. Other than requiring that the @sectors pointer is not NULL, this patch does not change the behavior of bvec_split_segs(). Reviewed-by: Johannes Thumshirn Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- block/blk-merge.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 51ed971709c3..7cea5050bbcf 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -167,17 +167,17 @@ static bool bvec_split_segs(const struct request_queue *q, { unsigned len = bv->bv_len; unsigned total_len = 0; - unsigned new_nsegs = 0, seg_size = 0; + unsigned seg_size = 0; /* * Multi-page bvec may be too big to hold in one segment, so the * current bvec has to be splitted as multiple segments. */ - while (len && new_nsegs + *nsegs < max_segs) { + while (len && *nsegs < max_segs) { seg_size = get_max_segment_size(q, bv->bv_offset + total_len); seg_size = min(seg_size, len); - new_nsegs++; + (*nsegs)++; total_len += seg_size; len -= seg_size; @@ -185,11 +185,7 @@ static bool bvec_split_segs(const struct request_queue *q, break; } - if (new_nsegs) { - *nsegs += new_nsegs; - if (sectors) - *sectors += total_len >> 9; - } + *sectors += total_len >> 9; /* split in the middle of the bvec if len != 0 */ return !!len; @@ -349,6 +345,7 @@ EXPORT_SYMBOL(blk_queue_split); unsigned int blk_recalc_rq_segments(struct request *rq) { unsigned int nr_phys_segs = 0; + unsigned int nr_sectors = 0; struct req_iterator iter; struct bio_vec bv; @@ -365,7 +362,8 @@ unsigned int blk_recalc_rq_segments(struct request *rq) } rq_for_each_bvec(bv, rq, iter) - bvec_split_segs(rq->q, &bv, &nr_phys_segs, NULL, UINT_MAX); + bvec_split_segs(rq->q, &bv, &nr_phys_segs, &nr_sectors, + UINT_MAX); return nr_phys_segs; } From patchwork Thu Aug 1 22:50:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11071477 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E566E746 for ; Thu, 1 Aug 2019 22:51:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D46B028528 for ; Thu, 1 Aug 2019 22:51:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C726128606; Thu, 1 Aug 2019 22:51:01 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 4FC7628528 for ; Thu, 1 Aug 2019 22:51:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733289AbfHAWu7 (ORCPT ); Thu, 1 Aug 2019 18:50:59 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37907 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388942AbfHAWu6 (ORCPT ); Thu, 1 Aug 2019 18:50:58 -0400 Received: by mail-pg1-f193.google.com with SMTP id f5so26176064pgu.5 for ; Thu, 01 Aug 2019 15:50:58 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=Em7UK3RYeN+WOGI1E/PxkPUM7IdJO+sUsMzC6fv5ULA=; b=puMarA9cPTrFR4t/itHv/ugMEJtFSCh5dbO+toYNqZhDumHastLDn4OMu4+iSe62Jr 6RvwThZ8GNMsZKRTSaMAboLVRBherb2mP4kEx5CC0jVvWqBdQuoGUw8w8Bobx46evB9s 2fWqbGJ79MlJuoy0qH0aCoQg7KHQAU6gjTT2uOYVpwOYQPirNt3SLUwy+hg9bWPZr1cF TTBOG5Q0UjYXdn5zUGfl3aqx2wS/VU4zP8Wa7ecrcVVQWMYHngWnwcTl2FbGcO1v4VWM dFhNS7PYvuBdO9560XVyUfkVJN4ttBx45K9x8iKWcFLn0yGMnrgD55/bXogSUveKJpAX epIw== X-Gm-Message-State: APjAAAUzevmp91nTGrHzL1wjWD/6TCm+oKdKP3scuyYLQh4uzc0qqthb imrKywVA/FsbICVQ9NOmEiw= X-Google-Smtp-Source: APXvYqzxuKfEtD7jGxVxS+GQp3FGBazzlOHztLaVHNHDCb9RlzduLmGBS31zQZKKcxG0fL6IUdrD2Q== X-Received: by 2002:a17:90a:346c:: with SMTP id o99mr1139951pjb.20.1564699857856; Thu, 01 Aug 2019 15:50:57 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:202:4308:52a3:24b6:2c60]) by smtp.gmail.com with ESMTPSA id d12sm35472010pfn.11.2019.08.01.15.50.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 15:50:57 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Ming Lei , Hannes Reinecke Subject: [PATCH v2 4/5] block: Simplify blk_bio_segment_split() Date: Thu, 1 Aug 2019 15:50:43 -0700 Message-Id: <20190801225044.143478-5-bvanassche@acm.org> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog In-Reply-To: <20190801225044.143478-1-bvanassche@acm.org> References: <20190801225044.143478-1-bvanassche@acm.org> MIME-Version: 1.0 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 Move the max_sectors check into bvec_split_segs() such that a single call to that function can do all the necessary checks. This patch optimizes the fast path further, namely if a bvec fits in a page. Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- block/blk-merge.c | 68 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 7cea5050bbcf..a6bc08255b1b 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -157,22 +157,36 @@ static unsigned get_max_segment_size(const struct request_queue *q, queue_max_segment_size(q)); } -/* - * Split the bvec @bv into segments, and update all kinds of - * variables. +/** + * bvec_split_segs - verify whether or not a bvec should be split in the middle + * @q: [in] request queue associated with the bio associated with @bv + * @bv: [in] bvec to examine + * @nsegs: [in,out] Number of segments in the bio being built. Incremented + * by the number of segments from @bv that may be appended to that + * bio without exceeding @max_segs + * @sectors: [in,out] Number of sectors in the bio being built. Incremented + * by the number of sectors from @bv that may be appended to that + * bio without exceeding @max_sectors + * @max_segs: [in] upper bound for *@nsegs + * @max_sectors: [in] upper bound for *@sectors + * + * When splitting a bio, it can happen that a bvec is encountered that is too + * big to fit in a single segment and hence that it has to be split in the + * middle. This function verifies whether or not that should happen. The value + * %true is returned if and only if appending the entire @bv to a bio with + * *@nsegs segments and *@sectors sectors would make that bio unacceptable for + * the block driver. */ static bool bvec_split_segs(const struct request_queue *q, const struct bio_vec *bv, unsigned *nsegs, - unsigned *sectors, unsigned max_segs) + unsigned *sectors, unsigned max_segs, + unsigned max_sectors) { - unsigned len = bv->bv_len; + unsigned max_len = (min(max_sectors, UINT_MAX >> 9) - *sectors) << 9; + unsigned len = min(bv->bv_len, max_len); unsigned total_len = 0; unsigned seg_size = 0; - /* - * Multi-page bvec may be too big to hold in one segment, so the - * current bvec has to be splitted as multiple segments. - */ while (len && *nsegs < max_segs) { seg_size = get_max_segment_size(q, bv->bv_offset + total_len); seg_size = min(seg_size, len); @@ -187,8 +201,8 @@ static bool bvec_split_segs(const struct request_queue *q, *sectors += total_len >> 9; - /* split in the middle of the bvec if len != 0 */ - return !!len; + /* tell the caller to split the bvec if it is too big to fit */ + return len > 0 || bv->bv_len > max_len; } /** @@ -229,34 +243,18 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, if (bvprvp && bvec_gap_to_prev(q, bvprvp, bv.bv_offset)) goto split; - if (sectors + (bv.bv_len >> 9) > max_sectors) { - /* - * Consider this a new segment if we're splitting in - * the middle of this vector. - */ - if (nsegs < max_segs && - sectors < max_sectors) { - /* split in the middle of bvec */ - bv.bv_len = (max_sectors - sectors) << 9; - bvec_split_segs(q, &bv, &nsegs, - §ors, max_segs); - } + if (nsegs < max_segs && + sectors + (bv.bv_len >> 9) <= max_sectors && + bv.bv_offset + bv.bv_len <= PAGE_SIZE) { + nsegs++; + sectors += bv.bv_len >> 9; + } else if (bvec_split_segs(q, &bv, &nsegs, §ors, max_segs, + max_sectors)) { goto split; } - if (nsegs == max_segs) - goto split; - bvprv = bv; bvprvp = &bvprv; - - if (bv.bv_offset + bv.bv_len <= PAGE_SIZE) { - nsegs++; - sectors += bv.bv_len >> 9; - } else if (bvec_split_segs(q, &bv, &nsegs, §ors, - max_segs)) { - goto split; - } } *segs = nsegs; @@ -363,7 +361,7 @@ unsigned int blk_recalc_rq_segments(struct request *rq) rq_for_each_bvec(bv, rq, iter) bvec_split_segs(rq->q, &bv, &nr_phys_segs, &nr_sectors, - UINT_MAX); + UINT_MAX, UINT_MAX); return nr_phys_segs; } From patchwork Thu Aug 1 22:50:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11071479 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C300746 for ; Thu, 1 Aug 2019 22:51:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F07EE28528 for ; Thu, 1 Aug 2019 22:51:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4D1D28606; Thu, 1 Aug 2019 22:51:02 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 81F2E28528 for ; Thu, 1 Aug 2019 22:51:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726268AbfHAWvB (ORCPT ); Thu, 1 Aug 2019 18:51:01 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:32970 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728904AbfHAWvA (ORCPT ); Thu, 1 Aug 2019 18:51:00 -0400 Received: by mail-pf1-f196.google.com with SMTP id g2so34901871pfq.0 for ; Thu, 01 Aug 2019 15:50:59 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=EhWldTClpduPmOO/VmISBa3rF5geaIGGYKKo8yPkexo=; b=NuRUgyKe9Gn2yGPI1NDzu0uPs3gDLx+xHNHVUraLQnOxzSOe7gY4gRkzfuFEdiVnWB IYeBgEwqkGWJI5XIfIUmg6vcxuZmRAvluZiigEU76gKlQrgqWT0wUjozJ+DT5YYPJpp4 dutIH4LCY2g2zNUcwPsUw2gkns4oJWqylPRBMzjuERuYJVTHvnEdcAjVjfO8zFMUYG5u PXQka42QHzpGGlg+eDDMI1lPFA+0lQ3ilEYVLfqocI3Yx5w+LF7iSnW53Qrz/Ey29r51 MzXWKGjTAQAnslgTgsUKm68L7MuXLK5cnJyyIGyolnw0AfYNhwdbAMpPv17Mrag2fy+f ml3g== X-Gm-Message-State: APjAAAWWgrTOiOS6gQhkUqnRABmj3zRiW4NBmXF1vfYkJFg0skmi/uud 69MH4/X6RMwOQ7seHhZ2yFo= X-Google-Smtp-Source: APXvYqzAEbp/QPfntLQwmfFIaVw6ieR3K/vZYR0eXEXNgFZ9xitps583DyC+XXHP+h7VhuiOf2dhuA== X-Received: by 2002:a62:6dc2:: with SMTP id i185mr56894680pfc.40.1564699859202; Thu, 01 Aug 2019 15:50:59 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:202:4308:52a3:24b6:2c60]) by smtp.gmail.com with ESMTPSA id d12sm35472010pfn.11.2019.08.01.15.50.57 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 15:50:58 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Christoph Hellwig , Ming Lei , Hannes Reinecke Subject: [PATCH v2 5/5] block: Improve physical block alignment of split bios Date: Thu, 1 Aug 2019 15:50:44 -0700 Message-Id: <20190801225044.143478-6-bvanassche@acm.org> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog In-Reply-To: <20190801225044.143478-1-bvanassche@acm.org> References: <20190801225044.143478-1-bvanassche@acm.org> MIME-Version: 1.0 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 Consider the following example: * The logical block size is 4 KB. * The physical block size is 8 KB. * max_sectors equals (16 KB >> 9) sectors. * A non-aligned 4 KB and an aligned 64 KB bio are merged into a single non-aligned 68 KB bio. The current behavior is to split such a bio into (16 KB + 16 KB + 16 KB + 16 KB + 4 KB). The start of none of these five bio's is aligned to a physical block boundary. This patch ensures that such a bio is split into four aligned and one non-aligned bio instead of being split into five non-aligned bios. This improves performance because most block devices can handle aligned requests faster than non-aligned requests. Since the physical block size is larger than or equal to the logical block size, this patch preserves the guarantee that the returned value is a multiple of the logical block size. Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- block/blk-merge.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index a6bc08255b1b..48e6725b32ee 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -132,16 +132,29 @@ static struct bio *blk_bio_write_same_split(struct request_queue *q, return bio_split(bio, q->limits.max_write_same_sectors, GFP_NOIO, bs); } +/* + * Return the maximum number of sectors from the start of a bio that may be + * submitted as a single request to a block device. If enough sectors remain, + * align the end to the physical block size. Otherwise align the end to the + * logical block size. This approach minimizes the number of non-aligned + * requests that are submitted to a block device if the start of a bio is not + * aligned to a physical block boundary. + */ static inline unsigned get_max_io_size(struct request_queue *q, struct bio *bio) { unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector); - unsigned mask = queue_logical_block_size(q) - 1; + unsigned max_sectors = sectors; + unsigned pbs = queue_physical_block_size(q) >> SECTOR_SHIFT; + unsigned lbs = queue_logical_block_size(q) >> SECTOR_SHIFT; + unsigned start_offset = bio->bi_iter.bi_sector & (pbs - 1); - /* aligned to logical block size */ - sectors &= ~(mask >> 9); + max_sectors += start_offset; + max_sectors &= ~(pbs - 1); + if (max_sectors > start_offset) + return max_sectors - start_offset; - return sectors; + return sectors & (lbs - 1); } static unsigned get_max_segment_size(const struct request_queue *q,