linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* a case for a destructor for slub: mm_struct
@ 2025-03-12 10:33 Mateusz Guzik
  2025-03-13  8:59 ` Harry Yoo
  0 siblings, 1 reply; 11+ messages in thread
From: Mateusz Guzik @ 2025-03-12 10:33 UTC (permalink / raw)
  To: Vlastimil Babka, Hyeonggon Yoo; +Cc: linux-mm, Dennis Zhou

I'm looking for someone(tm) willing to implement a destructor for slub.

Currently SLUB only supports a constructor, a callback to use when
first creating an object, but there is no matching callback for
getting rid of it.

The pair would come in handy when a frequently allocated and freed
object performs the same expensive work each time.

The specific usage I have in mind is mm_struct -- it gets allocated on
both each fork and exec and suffers global serialization several
times.

The primary thing I'm looking to handle this way is cid and percpu
counter allocation, both going to down to the percpu allocator which
only has a global lock. The problem is exacerbated as it happens
back-to-back, so that's 4 acquires per lifetime cycle (alloc and
free).

There is other expensive work which can also be modified this way.

I recognize something like this would pose a tradeoff in terms of
memory usage, but I don't believe it's a big deal. If you have a
mm_struct hanging out, you are going to need to have the percpu memory
up for grabs to make any use of it anyway. Granted, there may be
spurious mm_struct's hanging out and eating pcpu resources. Something
can be added to reclaim those by the pcpu allocator.

So that's it for making the case, as for the APIs, I think it would be
best if both dtor and ctor accepted a batch of objects to operate on,
but that's a lot of extra churn due to pre-existing ctor users.

ACHTUNG: I think this particular usage would still want some buy in
from the mm folk and at least Dennis (the percpu allocator
maintainer), but one has to start somewhere. There were 2 different
patchsets posted to move rss counters away from the current pcpu
scheme, but both had different tradeoffs and ultimately died off.

Should someone(tm) commit to sorting this out, I'll handle the percpu
thing. There are some other tweaks warranted here (e.g., depessimizing
the rss counter validation loop at exit).

So what do you think?

In order to bench yourself,  you can grab code from here:
http://apollo.backplane.com/DFlyMisc/doexec.c

$ cc -static -O2 -o static-doexec doexec.c
$ ./static-doexec $(nproc)

I check spinlock problems with: bpftrace -e
'kprobe:__pv_queued_spin_lock_slowpath { @[kstack()] = count(); }'
-- 
Mateusz Guzik <mjguzik gmail.com>


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-03-17  9:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-12 10:33 a case for a destructor for slub: mm_struct Mateusz Guzik
2025-03-13  8:59 ` Harry Yoo
2025-03-13 11:23   ` Mateusz Guzik
2025-03-13 11:25     ` Mateusz Guzik
2025-03-14  8:27     ` Harry Yoo
2025-03-14  8:34       ` Harry Yoo
2025-03-14 12:32       ` Mateusz Guzik
2025-03-17  5:42         ` Harry Yoo
2025-03-17  9:02           ` Vlastimil Babka
2025-03-17  9:17             ` Mateusz Guzik
2025-03-17  9:23           ` Mateusz Guzik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox