[ Al, I hope your email works now ] On Sat, 23 Mar 2024 at 19:27, Al Viro <viro@xxxxxxxxxxxxxxxxxx> wrote: > > We can have the same file occuring in many slots of many descriptor tables, > obviously. So it would have to be a flag (in ->f_mode?) set by it, for > "someone's already charged for it", or you'll end up with really insane > crap on each fork(), dup(), etc. Nope. That flag already exists in the slab code itself with this patch. The kmem_cache_charge() thing itself just sets the "I'm charged" bit in the slab header, and you're done. Any subsequent fd_install (with dup, or fork or whatever) simply is irrelevant. In fact, dup and fork and friends won't need to worry about this, because they only work on files that have already been installed, so they know the file is already accounted. So it's only the initial open() case that needs to do the kmem_cache_charge() as it does the fd_install. > But there's also MAP_ANON with its setup_shmem_file(), with the resulting > file not going into descriptor tables at all, and that's not a rare thing. Just making alloc_file_pseudo() do a SLAB_ACOUNT should take care of all the normal case. For once, the core allocator is not exposed very much, so we can literally just look at "who does alloc_file*()" and it turns out it's all pretty well abstracted out. So I think it's mainly the three cases of 'alloc_empty_file()' that would be affected and need to check that they actually do the fd_install() (or release it). Everything else should either not account at all (if they know they are doing temporary kernel things), or always account (eg alloc_file_pseudo()). Linus