Re: [PATCH -v2] ext4: enable scoped NOFS when starting a handle in nojournal mode
Andreas Dilger <[email protected]>
| Newsgroups | org.kernel.vger.linux-ext4 |
|---|---|
| Message-ID | <[email protected]> |
On Jul 16, 2026, at 08:48, Theodore Ts'o <[email protected]> wrote: > > The jbd2 layer enables NOFS mode using memalloc_nofs_{save,restore}() > while a handle is active. We need to do the same in nojournal mode so > that it is safe to remove GFP_NOFS flags while a jbd2 handle is > active. > > This will require that we actually allocate a real handle, but with an > h_invalid flag set, so there is a place to put the saved memalloc > context. If you wanted to avoid an allocation for each nojournal handle on 64-bit systems, you could put a magic number in the high 32 bits of the handle pointer (which is unlikely to conflict with real memory addresses), and the PF_* flags in the low 32 bits. While the memory savings would be minimal (32 bytes for minimum kmalloc), it would avoid a potential new allocation failure path for that mode. > diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h > index b68561187e90..7348fdadc810 100644 > --- a/include/linux/jbd2.h > +++ b/include/linux/jbd2.h > @@ -513,6 +513,7 @@ struct jbd2_journal_handle > unsigned int h_sync: 1; > unsigned int h_reserved: 1; > unsigned int h_aborted: 1; > + unsigned int h_invalid: 1; > unsigned int h_type: 8; > unsigned int h_line_no: 16; Not sure if it makes much difference, but should h_line_no be aligned on a 16-bit offset and h_type aligned on an 8-bit offset by adding an "unsigned int h_unused:4" field before h_type, or reorder them so the 1-bit fields are at the end? That would allow the integer fields to be accessed directly rather than also having to shift them. Cheers, Andreas