All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: reorder bio::__bi_remaining for better packing
@ 2019-10-24 17:31 David Sterba
  2019-10-25 20:13 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: David Sterba @ 2019-10-24 17:31 UTC (permalink / raw)
  To: linux-block; +Cc: David Sterba

Simple reordering of __bi_remaining can reduce bio size by 8 bytes that
are now wasted on padding (measured on x86_64):

struct bio {
        struct bio *               bi_next;              /*     0     8 */
        struct gendisk *           bi_disk;              /*     8     8 */
        unsigned int               bi_opf;               /*    16     4 */
        short unsigned int         bi_flags;             /*    20     2 */
        short unsigned int         bi_ioprio;            /*    22     2 */
        short unsigned int         bi_write_hint;        /*    24     2 */
        blk_status_t               bi_status;            /*    26     1 */
        u8                         bi_partno;            /*    27     1 */

        /* XXX 4 bytes hole, try to pack */

        struct bvec_iter   bi_iter;                      /*    32    24 */

        /* XXX last struct has 4 bytes of padding */

        atomic_t                   __bi_remaining;       /*    56     4 */

        /* XXX 4 bytes hole, try to pack */
[...]
        /* size: 104, cachelines: 2, members: 19 */
        /* sum members: 96, holes: 2, sum holes: 8 */
        /* paddings: 1, sum paddings: 4 */
        /* last cacheline: 40 bytes */
};

Now becomes:

struct bio {
        struct bio *               bi_next;              /*     0     8 */
        struct gendisk *           bi_disk;              /*     8     8 */
        unsigned int               bi_opf;               /*    16     4 */
        short unsigned int         bi_flags;             /*    20     2 */
        short unsigned int         bi_ioprio;            /*    22     2 */
        short unsigned int         bi_write_hint;        /*    24     2 */
        blk_status_t               bi_status;            /*    26     1 */
        u8                         bi_partno;            /*    27     1 */
        atomic_t                   __bi_remaining;       /*    28     4 */
        struct bvec_iter   bi_iter;                      /*    32    24 */

        /* XXX last struct has 4 bytes of padding */
[...]
        /* size: 96, cachelines: 2, members: 19 */
        /* paddings: 1, sum paddings: 4 */
        /* last cacheline: 32 bytes */
};

Signed-off-by: David Sterba <dsterba@suse.com>
---
 include/linux/blk_types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index d688b96d1d63..1e7eeec16458 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -153,10 +153,10 @@ struct bio {
 	unsigned short		bi_write_hint;
 	blk_status_t		bi_status;
 	u8			bi_partno;
+	atomic_t		__bi_remaining;
 
 	struct bvec_iter	bi_iter;
 
-	atomic_t		__bi_remaining;
 	bio_end_io_t		*bi_end_io;
 
 	void			*bi_private;
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] block: reorder bio::__bi_remaining for better packing
  2019-10-24 17:31 [PATCH] block: reorder bio::__bi_remaining for better packing David Sterba
@ 2019-10-25 20:13 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2019-10-25 20:13 UTC (permalink / raw)
  To: David Sterba, linux-block

On 10/24/19 11:31 AM, David Sterba wrote:
> Simple reordering of __bi_remaining can reduce bio size by 8 bytes that
> are now wasted on padding (measured on x86_64):
> 
> struct bio {
>          struct bio *               bi_next;              /*     0     8 */
>          struct gendisk *           bi_disk;              /*     8     8 */
>          unsigned int               bi_opf;               /*    16     4 */
>          short unsigned int         bi_flags;             /*    20     2 */
>          short unsigned int         bi_ioprio;            /*    22     2 */
>          short unsigned int         bi_write_hint;        /*    24     2 */
>          blk_status_t               bi_status;            /*    26     1 */
>          u8                         bi_partno;            /*    27     1 */
> 
>          /* XXX 4 bytes hole, try to pack */
> 
>          struct bvec_iter   bi_iter;                      /*    32    24 */
> 
>          /* XXX last struct has 4 bytes of padding */
> 
>          atomic_t                   __bi_remaining;       /*    56     4 */
> 
>          /* XXX 4 bytes hole, try to pack */
> [...]
>          /* size: 104, cachelines: 2, members: 19 */
>          /* sum members: 96, holes: 2, sum holes: 8 */
>          /* paddings: 1, sum paddings: 4 */
>          /* last cacheline: 40 bytes */
> };
> 
> Now becomes:
> 
> struct bio {
>          struct bio *               bi_next;              /*     0     8 */
>          struct gendisk *           bi_disk;              /*     8     8 */
>          unsigned int               bi_opf;               /*    16     4 */
>          short unsigned int         bi_flags;             /*    20     2 */
>          short unsigned int         bi_ioprio;            /*    22     2 */
>          short unsigned int         bi_write_hint;        /*    24     2 */
>          blk_status_t               bi_status;            /*    26     1 */
>          u8                         bi_partno;            /*    27     1 */
>          atomic_t                   __bi_remaining;       /*    28     4 */
>          struct bvec_iter   bi_iter;                      /*    32    24 */
> 
>          /* XXX last struct has 4 bytes of padding */
> [...]
>          /* size: 96, cachelines: 2, members: 19 */
>          /* paddings: 1, sum paddings: 4 */
>          /* last cacheline: 32 bytes */
> };

This is great, obviously been too long since this kind of thing was
looked at by myself. Thanks, applied.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-25 20:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-24 17:31 [PATCH] block: reorder bio::__bi_remaining for better packing David Sterba
2019-10-25 20:13 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.