From: Ming Lei <ming.lei@redhat.com>
To: Bart Van Assche <bvanassche@acm.org>
Cc: Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Keith Busch <kbusch@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Guenter Roeck <linux@roeck-us.net>
Subject: Re: [PATCH 03/10] block: Micro-optimize get_max_segment_size()
Date: Fri, 21 Oct 2022 10:17:19 +0800 [thread overview]
Message-ID: <Y1IBLyT1+JahApf/@T590> (raw)
In-Reply-To: <20221019222324.362705-4-bvanassche@acm.org>
On Wed, Oct 19, 2022 at 03:23:17PM -0700, Bart Van Assche wrote:
> This patch removes a conditional jump from get_max_segment_size(). The
> x86-64 assembler code for this function without this patch is as follows:
>
> 206 return min_not_zero(mask - offset + 1,
> 0x0000000000000118 <+72>: not %rax
> 0x000000000000011b <+75>: and 0x8(%r10),%rax
> 0x000000000000011f <+79>: add $0x1,%rax
> 0x0000000000000123 <+83>: je 0x138 <bvec_split_segs+104>
> 0x0000000000000125 <+85>: cmp %rdx,%rax
> 0x0000000000000128 <+88>: mov %rdx,%r12
> 0x000000000000012b <+91>: cmovbe %rax,%r12
> 0x000000000000012f <+95>: test %rdx,%rdx
> 0x0000000000000132 <+98>: mov %eax,%edx
> 0x0000000000000134 <+100>: cmovne %r12d,%edx
>
> With this patch applied:
>
> 206 return min(mask - offset, (unsigned long)lim->max_segment_size - 1) + 1;
> 0x000000000000003f <+63>: mov 0x28(%rdi),%ebp
> 0x0000000000000042 <+66>: not %rax
> 0x0000000000000045 <+69>: and 0x8(%rdi),%rax
> 0x0000000000000049 <+73>: sub $0x1,%rbp
> 0x000000000000004d <+77>: cmp %rbp,%rax
> 0x0000000000000050 <+80>: cmova %rbp,%rax
> 0x0000000000000054 <+84>: add $0x1,%eax
>
> Cc: Ming Lei <ming.lei@redhat.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Keith Busch <kbusch@kernel.org>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> block/blk-merge.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/block/blk-merge.c b/block/blk-merge.c
> index 58fdc3f8905b..35a8f75cc45d 100644
> --- a/block/blk-merge.c
> +++ b/block/blk-merge.c
> @@ -186,6 +186,14 @@ static inline unsigned get_max_io_size(struct bio *bio,
> return max_sectors & ~(lbs - 1);
> }
>
> +/**
> + * get_max_segment_size() - maximum number of bytes to add as a single segment
> + * @lim: Request queue limits.
> + * @start_page: See below.
> + * @offset: Offset from @start_page where to add a segment.
> + *
> + * Returns the maximum number of bytes that can be added as a single segment.
> + */
> static inline unsigned get_max_segment_size(const struct queue_limits *lim,
> struct page *start_page, unsigned long offset)
> {
> @@ -194,11 +202,10 @@ static inline unsigned get_max_segment_size(const struct queue_limits *lim,
> offset = mask & (page_to_phys(start_page) + offset);
>
> /*
> - * overflow may be triggered in case of zero page physical address
> - * on 32bit arch, use queue's max segment size when that happens.
> + * Prevent an overflow if mask = ULONG_MAX and offset = 0 by adding 1
> + * after having calculated the minimum.
> */
> - return min_not_zero(mask - offset + 1,
> - (unsigned long)lim->max_segment_size);
> + return min(mask - offset, (unsigned long)lim->max_segment_size - 1) + 1;
> }
Looks fine,
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Thanks,
Ming
next prev parent reply other threads:[~2022-10-21 2:17 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-19 22:23 [PATCH 00/10] Support DMA segments smaller than the page size Bart Van Assche
2022-10-19 22:23 ` [PATCH 01/10] block: Remove request.write_hint Bart Van Assche
2022-10-21 1:59 ` Ming Lei
2022-10-19 22:23 ` [PATCH 02/10] block: Constify most queue limits pointers Bart Van Assche
2022-10-21 2:01 ` Ming Lei
2022-10-19 22:23 ` [PATCH 03/10] block: Micro-optimize get_max_segment_size() Bart Van Assche
2022-10-21 2:17 ` Ming Lei [this message]
2022-10-19 22:23 ` [PATCH 04/10] block: Add support for small segments in blk_rq_map_user_iov() Bart Van Assche
2022-10-19 22:23 ` [PATCH 05/10] block: Introduce QUEUE_FLAG_SUB_PAGE_SEGMENTS Bart Van Assche
2022-10-19 22:23 ` [PATCH 06/10] block: Fix the number of segment calculations Bart Van Assche
2022-11-01 17:23 ` Bart Van Assche
2022-11-02 1:22 ` Ming Lei
2022-11-03 19:32 ` Bart Van Assche
2022-10-19 22:23 ` [PATCH 07/10] block: Add support for segments smaller than the page size Bart Van Assche
2022-10-19 22:23 ` [PATCH 08/10] scsi: core: Set the SUB_PAGE_SEGMENTS request queue flag Bart Van Assche
2022-10-19 22:23 ` [PATCH 09/10] scsi_debug: Support configuring the maximum segment size Bart Van Assche
2022-10-19 22:23 ` [PATCH 10/10] null_blk: " Bart Van Assche
2022-10-20 23:13 ` Damien Le Moal
2022-10-20 23:34 ` Bart Van Assche
2022-10-20 23:39 ` Damien Le Moal
2022-10-21 0:39 ` Bart Van Assche
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y1IBLyT1+JahApf/@T590 \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox