Skip to content

Better pack struct zio_prop #17619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Better pack struct zio_prop #17619

wants to merge 1 commit into from

Conversation

amotin
Copy link
Member

@amotin amotin commented Aug 11, 2025

By using precisely sized fields it is possible to reduce the size of this structure and respectively struct zio it is included into by 40 bytes (from 92 to 52).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Quality assurance (non-breaking change which makes the code more robust against bugs)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

By using precisely sized fields it is possible to reduce the size
of this structure and respectively struct zio it is included into
by 40 bytes (from 92 to 52).

Signed-off-by:  Alexander Motin <[email protected]>
@amotin amotin requested a review from robn August 11, 2025 20:24
@amotin amotin added the Status: Code Review Needed Ready for review and testing label Aug 11, 2025
Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice. For reviewers, after this commit here's the packed struct as reported by pahole.

struct zio_prop {
        enum zio_checksum          zp_checksum:8;        /*     0: 0  4 */
        enum zio_compress          zp_compress:8;        /*     0: 8  4 */

        /* Bitfield combined with next fields */

        uint8_t                    zp_complevel;         /*     2     1 */
        uint8_t                    zp_level;             /*     3     1 */
        uint8_t                    zp_copies;            /*     4     1 */
        uint8_t                    zp_gang_copies;       /*     5     1 */

        /* Bitfield combined with previous fields */

        dmu_object_type_t          zp_type:8;            /*     4:16  4 */
        dmu_object_type_t          zp_storage_type:8;    /*     4:24  4 */
        boolean_t                  zp_dedup:1;           /*     8: 0  4 */
        boolean_t                  zp_dedup_verify:1;    /*     8: 1  4 */
        boolean_t                  zp_nopwrite:1;        /*     8: 2  4 */
        boolean_t                  zp_brtwrite:1;        /*     8: 3  4 */
        boolean_t                  zp_encrypt:1;         /*     8: 4  4 */
        boolean_t                  zp_byteorder:1;       /*     8: 5  4 */
        boolean_t                  zp_direct_write:1;    /*     8: 6  4 */
        boolean_t                  zp_rewrite:1;         /*     8: 7  4 */

        /* XXX 24 bits hole, try to pack */

        uint32_t                   zp_zpl_smallblk;      /*    12     4 */
        uint8_t                    zp_salt[8];           /*    16     8 */
        uint8_t                    zp_iv[12];            /*    24    12 */
        uint8_t                    zp_mac[16];           /*    36    16 */

        /* size: 52, cachelines: 1, members: 20 */
        /* sum members: 44 */
        /* sum bitfield members: 40 bits, bit holes: 1, sum bit holes: 24 bits */
        /* last cacheline: 52 bytes */
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Code Review Needed Ready for review and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants