> @@ -269,20 +263,17 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, 
> loff_t length, void *data,
>       if (ctx->bio && bio_end_sector(ctx->bio) == sector)
>               is_contig = true;
>  
> -
>       /*
> -      * If we start a new segment we need to increase the read count, and we
> -      * need to do so before submitting any previous full bio to make sure
> -      * that we don't prematurely unlock the page.
> +      * We need to increase the read count before submitting any
> +      * previous bio to make sure that we don't prematurely unlock
> +      * the page.
>        */
>       if (iop)
> -             atomic_inc(&iop->read_count);
> +             atomic_add(plen, &iop->read_count);
> +
> +     if (is_contig &&
> +         __bio_try_merge_page(ctx->bio, page, plen, poff, &same_page))
> +             goto done;
>  
>       if (!ctx->bio || !is_contig || bio_full(ctx->bio, plen)) {

I think we can simplify this a bit by reordering the checks:

        if (iop)
                atomic_add(plen, &iop->read_count);

        if (ctx->bio && bio_end_sector(ctx->bio) == sector)
                if (__bio_try_merge_page(ctx->bio, page, plen, poff,
                                &same_page))
                        goto done;
                is_contig = true;
        }

        if (!is_contig || bio_full(ctx->bio, plen)) {
                // the existing case to allocate a new bio
        }

Also I think read_count should be renamed to be more descriptive,
something like read_bytes_pending?  Same for the write side.

Reply via email to