[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230906231354.GX14420@twin.jikos.cz>
Date: Thu, 7 Sep 2023 01:13:54 +0200
From: David Sterba <dsterba@...e.cz>
To: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Kent Overstreet <kent.overstreet@...ux.dev>,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-bcachefs@...r.kernel.org
Subject: Re: [GIT PULL] bcachefs
On Wed, Sep 06, 2023 at 06:55:38PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Wed, Sep 06, 2023 at 01:20:59PM -0700, Linus Torvalds escreveu:
> > On Wed, 6 Sept 2023 at 13:02, Linus Torvalds
> > <torvalds@...ux-foundation.org> wrote:
> > >
> > > And guess what happens when you have (unsigned char)-1? It does *not*
> > > cast back to -1.
> >
> > Side note: again, this may be one of those "it works in practice",
> > because if we have -fshort-enums, I think 'enum
> > btree_node_locked_type' in turn ends up being represented as a 'signed
> > char', because that's the smallest simple type that can fit all those
> > values.
>
> > I don't think gcc ever uses less than that (ie while a six_lock_type
> > could fit in two bits, it's still going to be considered at least a
> > 8-bit value in practice).
>
> There are some cases where people stuff the enum into a bitfield, but
> no, no simple type.
>
> ⬢[acme@...lbox perf-tools-next]$ pahole | grep -w enum | grep :
> enum btrfs_rsv_type type:8; /* 28:16 4 */
> enum btrfs_delayed_item_type type:8; /* 100: 0 4 */
The simple grep might give a skewed view, in the above case there's also
/* Bitfield combined with previous fields */
in the full output, with adjacent bool struct members it's all packed
into one int. I think I've always seen an int for enums, unless it was
explicitly narrowed in the structure (:8) or by __packed attribute in
the enum definition.
> enum kernel_pkey_operation op:8; /* 40: 0 4 */
> enum integrity_status ima_file_status:4; /* 96: 0 4 */
> enum integrity_status ima_mmap_status:4; /* 96: 4 4 */
> enum integrity_status ima_bprm_status:4; /* 96: 8 4 */
> enum integrity_status ima_read_status:4; /* 96:12 4 */
> enum integrity_status ima_creds_status:4; /* 96:16 4 */
> enum integrity_status evm_status:4; /* 96:20 4 */
> enum fs_context_purpose purpose:8; /* 152: 0 4 */
> enum fs_context_phase phase:8; /* 152: 8 4 */
> enum fs_value_type type:8; /* 8: 0 4 */
> enum sgx_page_type type:16; /* 8: 8 4 */
> enum nf_hook_ops_type hook_ops_type:8; /* 24: 8 4 */
> enum resctrl_event_id evtid:8; /* 0:10 4 */
> enum _cache_type type:5; /* 0: 0 4 */
Powered by blists - more mailing lists