On Wed, Nov 13, 2024 at 4:23 PM Liam R. Howlett <Liam.Howlett@xxxxxxxxxx> wrote: > * Matthew Wilcox <willy@xxxxxxxxxxxxx> [241113 08:57]: > > On Wed, Nov 13, 2024 at 07:38:02AM -0500, Liam R. Howlett wrote: > > > > Hi, I was wondering if we actually need the detached flag. Couldn't > > > > "detached" simply mean vma->vm_mm == NULL and we save 4 bytes? Do we ever > > > > need a vma that's detached but still has a mm pointer? I'd hope the places > > > > that set detached to false have the mm pointer around so it's not inconvenient. > > > > > > I think the gate vmas ruin this plan. > > > > But the gate VMAs aren't to be found in the VMA tree. Used to be that > > was because the VMA tree was the injective RB tree and so VMAs could > > only be in one tree at a time. We could change that now! > > \o/ > > > > > Anyway, we could use (void *)1 instead of NULL to indicate a "detached" > > VMA if we need to distinguish between a detached VMA and a gate VMA. > > I was thinking a pointer to itself vma->vm_mm = vma, then a check for > this, instead of null like we do today. Sidenote: Something like NULL or (void*)1 is fine with me but please don't do pointer-to-itself - we shouldn't unnecessarily store a pointer to an object of one type in a pointer field of an incompatible type, that increases the risk of creating type confusion issues (both in the memory corruption sense and in the Spectre sense). I know MM already has several places where similar stuff can happen (in particular page->mapping), but here it seems like unnecessary risk to me.