Memory allocation profiling
Subsystems (55)
Kent Overstreet
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
In reply to Michal HockoQuoted 8 lines · Michal Hocko
Quoted 3 lines · Kent Overstreet
If we want this report to be 100% reliable, then yes the preallocated buffer makes sense - but I don't think 100% makes sense here; I think we can accept ~99% and give back that 4k.
Think about that from the memory reserves consumers. The atomic reserve is a scarse resource and now you want to use it for debugging purposes for which you could have preallocated.
_Memory_ is a finite resource that we shouldn't be using unnecessarily.
We don't need this for the entire time we're under memory pressure; just the short duration it takes to generate the report, then it's back available for other users.
You would have us dedicate 4k, from system bootup, that can never be used by other users.
Again: this makes no sense. The whole point of having watermarks and shared reserves is so that every codepath doesn't have to have its own dedicated, private reserve, so that we can make better use of a shared finite resource.
Steven Rostedt
reviewerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
In reply to Kent OverstreetQuoted 9 lines · On Thu, 15 Feb 2024 15:33:30 -0500 Kent Overstreet <[email protected]>…
Quoted 6 lines
Well, I think without
__GFP_NOWARNit will cause a warning and thus recursion into__show_mem(), potentially infinite? Which is of course trivial to fix, but I'd myself rather sacrifice a bit of memory to get this potentially very useful output, if I enabled the profiling. The necessary memory overhead ofpage_extandslabobj_extmakes the printing buffer overhead negligible in comparison?
__GFP_NOWARNis a good point, we should have that.
Quoted 7 lines
But - and correct me if I'm wrong here - doesn't an OOM kick in well before
GFP_ATOMIC4k allocations are failing? I'd expect the system to be well and truly hosed at that point.If we want this report to be 100% reliable, then yes the preallocated buffer makes sense - but I don't think 100% makes sense here; I think we can accept ~99% and give back that 4k.
I just compiled v6.8-rc4 vanilla (with a fedora localmodconfig build) and saved it off (vmlinux.orig), then I compiled with the following:
Applied the patches but did not enable anything: vmlinux.memtag-off
Enabled MEM_ALLOC_PROFILING: vmlinux.memtag
Enabled MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT: vmlinux.memtag-default-on
Enabled MEM_ALLOC_PROFILING_DEBUG: vmlinux.memtag-debug
And here's what I got:
text data bss dec hex filename 29161847 18352730 5619716 53134293 32ac3d5 vmlinux.orig 29162286 18382638 5595140 53140064 32ada60 vmlinux.memtag-off (+5771) 29230868 18887662 5275652 53394182 32ebb06 vmlinux.memtag (+259889) 29230746 18887662 5275652 53394060 32eba8c vmlinux.memtag-default-on (+259767) dropped? 29276214 18946374 5177348 53399936 32ed180 vmlinux.memtag-debug (+265643)
Just adding the patches increases the size by 5k. But the rest shows an increase of 259k, and you are worried about 4k (and possibly less?)???
-- Steve
Steven Rostedt
reviewerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 6 lines · On Thu, 15 Feb 2024 18:07:42 -0500 Steven Rostedt <[email protected]> wrote:
text data bss dec hex filename 29161847 18352730 5619716 53134293 32ac3d5 vmlinux.orig 29162286 18382638 5595140 53140064 32ada60 vmlinux.memtag-off (+5771) 29230868 18887662 5275652 53394182 32ebb06 vmlinux.memtag (+259889) 29230746 18887662 5275652 53394060 32eba8c vmlinux.memtag-default-on (+259767) dropped? 29276214 18946374 5177348 53399936 32ed180 vmlinux.memtag-debug (+265643)
If you plan on running this in production, and this increases the size of the text by 68k, have you measured the I$ pressure that this may induce? That is, what is the full overhead of having this enabled, as it could cause more instruction cache misses?
I wonder if there has been measurements of it off. That is, having this configured in but default off still increases the text size by 68k. That can't be good on the instruction cache.
-- Steve
Steven Rostedt
reviewerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 10 lines · On Thu, 15 Feb 2024 18:16:48 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 6 lines · On Thu, 15 Feb 2024 18:07:42 -0500 Steven Rostedt <[email protected]> wrote:
text data bss dec hex filename 29161847 18352730 5619716 53134293 32ac3d5 vmlinux.orig 29162286 18382638 5595140 53140064 32ada60 vmlinux.memtag-off (+5771) 29230868 18887662 5275652 53394182 32ebb06 vmlinux.memtag (+259889) 29230746 18887662 5275652 53394060 32eba8c vmlinux.memtag-default-on (+259767) dropped? 29276214 18946374 5177348 53399936 32ed180 vmlinux.memtag-debug (+265643)
Quoted 9 lines
If you plan on running this in production, and this increases the size of the text by 68k, have you measured the I$ pressure that this may induce? That is, what is the full overhead of having this enabled, as it could cause more instruction cache misses?
I wonder if there has been measurements of it off. That is, having this configured in but default off still increases the text size by 68k. That can't be good on the instruction cache.
I should have read the cover letter ;-) (someone pointed me to that on IRC):
Quoted 7 lines
Performance overhead:
To evaluate performance we implemented an in-kernel test executing multiple get_free_page/free_page and kmalloc/kfree calls with allocation sizes growing from 8 to 240 bytes with CPU frequency set to max and CPU affinity set to a specific CPU to minimize the noise. Below are results from running the test on Ubuntu 22.04.2 LTS with 6.8.0-rc1 kernel on 56 core Intel Xeon:
These are micro benchmarks, were any larger benchmarks taken? As microbenchmarks do not always show I$ issues (because the benchmark itself will warm up the cache). The cache issue could slow down tasks at a bigger picture, as it can cause more cache misses.
Running other benchmarks under perf and recording the cache misses between the different configs would be a good picture to show.
Quoted 13 lines
kmalloc pgalloc (1 baseline) 6.764s 16.902s (2 default disabled) 6.793s (+0.43%) 17.007s (+0.62%) (3 default enabled) 7.197s (+6.40%) 23.666s (+40.02%) (4 runtime enabled) 7.405s (+9.48%) 23.901s (+41.41%) (5 memcg) 13.388s (+97.94%) 48.460s (+186.71%)Memory overhead:
Kernel size:
Quoted 6 lines
text data bss dec diff
(1) 26515311 18890222 17018880 62424413 (2) 26524728 19423818 16740352 62688898 264485 (3) 26524724 19423818 16740352 62688894 264481 (4) 26524728 19423818 16740352 62688898 264485 (5) 26541782 18964374 16957440 62463596 39183
Similar to my builds.
Quoted 8 lines
Memory consumption on a 56 core Intel CPU with 125GB of memory:
Code tags: 192 kB PageExts: 262144 kB (256MB) SlabExts: 9876 kB (9.6MB) PcpuExts: 512 kB (0.5MB)Total overhead is 0.2% of total memory.
All this, and we are still worried about 4k for useful debugging :-/
-- Steve
Kent Overstreet
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 1 line · Steven Rostedt
All this, and we are still worried about 4k for useful debugging :-/
Every additional 4k still needs justification. And whether we burn a reserve on this will have no observable effect on user output in remotely normal situations; if this allocation ever fails, we've already been in an OOM situation for awhile and we've already printed out this report many times, with less memory pressure where the allocation would have succeeded.
Suren Baghdasaryan
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 3 lines · Kent Overstreet
Quoted 1 line · Steven Rostedt
All this, and we are still worried about 4k for useful debugging :-/
I was planning to refactor this function to print one record at a time with a smaller buffer but after discussing with Kent, he has plans to reuse this function and having the report in one buffer is needed for that.
Quoted 6 lines
Every additional 4k still needs justification. And whether we burn a reserve on this will have no observable effect on user output in remotely normal situations; if this allocation ever fails, we've already been in an OOM situation for awhile and we've already printed out this report many times, with less memory pressure where the allocation would have succeeded.
I'm not sure this claim will always be true, specifically in the case of low-end devices with relatively low amounts of reserves and in the presence of a possible quick memory usage spike. We should also consider a case when panic_on_oom is set. All we get is one OOM report, so we get only one chance to capture this report. In any case, I don't yet have data to prove or disprove this claim but it will be interesting to test it with data from the field once the feature is deployed.
For now I think with Vlastimil's __GFP_NOWARN suggestion the code becomes safe and the only risk is to lose this report. If we get cases with reports missing this data, we can easily change to reserved memory.
Michal Hocko
reviewerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
On Mon 19-02-24 09:17:36, Suren Baghdasaryan wrote:
[...]
Quoted 4 lines
For now I think with Vlastimil's
__GFP_NOWARNsuggestion the code becomes safe and the only risk is to lose this report. If we get cases with reports missing this data, we can easily change to reserved memory.
This is not just about missing part of the oom report. This is annoying but not earth shattering. Eating into very small reserves (that might be the only usable memory while the system is struggling in OOM situation) could cause functional problems that would be non trivial to test for. All that for debugging purposes is just lame. If you want to reuse the code for a different purpose then abstract it and allocate the buffer when you can afford that and use preallocated on when in OOM situation.
We have always went extra mile to avoid potentially disruptive operations from the oom handling code and I do not see any good reason to diverge from that principle.
Signature · 2 lines
Michal Hocko SUSE Labs
Kent Overstreet
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 15 lines · Michal Hocko
On Mon 19-02-24 09:17:36, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
For now I think with Vlastimil's
__GFP_NOWARNsuggestion the code becomes safe and the only risk is to lose this report. If we get cases with reports missing this data, we can easily change to reserved memory.This is not just about missing part of the oom report. This is annoying but not earth shattering. Eating into very small reserves (that might be the only usable memory while the system is struggling in OOM situation) could cause functional problems that would be non trivial to test for. All that for debugging purposes is just lame. If you want to reuse the code for a different purpose then abstract it and allocate the buffer when you can afford that and use preallocated on when in OOM situation.
Quoted 3 lines
We have always went extra mile to avoid potentially disruptive operations from the oom handling code and I do not see any good reason to diverge from that principle.
Michal, I gave you the logic between dedicated reserves and system reserves. Please stop repeating these vague what-ifs.
Michal Hocko
reviewerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 16 lines · Kent Overstreet
Quoted 15 lines · Michal Hocko
On Mon 19-02-24 09:17:36, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
For now I think with Vlastimil's
__GFP_NOWARNsuggestion the code becomes safe and the only risk is to lose this report. If we get cases with reports missing this data, we can easily change to reserved memory.This is not just about missing part of the oom report. This is annoying but not earth shattering. Eating into very small reserves (that might be the only usable memory while the system is struggling in OOM situation) could cause functional problems that would be non trivial to test for. All that for debugging purposes is just lame. If you want to reuse the code for a different purpose then abstract it and allocate the buffer when you can afford that and use preallocated on when in OOM situation.
Quoted 6 lines
Quoted 3 lines
We have always went extra mile to avoid potentially disruptive operations from the oom handling code and I do not see any good reason to diverge from that principle.
Michal, I gave you the logic between dedicated reserves and system reserves. Please stop repeating these vague what-ifs.
Your argument makes little sense and it seems that it is impossible to explain that to you. I gave up on discussing this further with you.
Consider NAK to any additional allocation from oom path unless you can give very _solid_ arguments this is absolutely necessary. "It's gona be fine and work most of the time" is not a solid argument.
Signature · 2 lines
Michal Hocko SUSE Labs
Kent Overstreet
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 21 lines · Michal Hocko
Quoted 20 lines · Kent Overstreet
Quoted 18 lines · Michal Hocko
On Mon 19-02-24 09:17:36, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
For now I think with Vlastimil's
__GFP_NOWARNsuggestion the code becomes safe and the only risk is to lose this report. If we get cases with reports missing this data, we can easily change to reserved memory.This is not just about missing part of the oom report. This is annoying but not earth shattering. Eating into very small reserves (that might be the only usable memory while the system is struggling in OOM situation) could cause functional problems that would be non trivial to test for. All that for debugging purposes is just lame. If you want to reuse the code for a different purpose then abstract it and allocate the buffer when you can afford that and use preallocated on when in OOM situation.
We have always went extra mile to avoid potentially disruptive operations from the oom handling code and I do not see any good reason to diverge from that principle.
Quoted 5 lines
Quoted 2 lines
Michal, I gave you the logic between dedicated reserves and system reserves. Please stop repeating these vague what-ifs.
Your argument makes little sense and it seems that it is impossible to explain that to you. I gave up on discussing this further with you.
It was your choice to not engage with the technical discussion. And if you're not going to engage, repeating the same arguments that I already responded to 10 or 20 emails later is a pretty dishonest way to argue.
You've been doing this kind of grandstanding throughout the entire discussion across every revision of the patchset.
Knock it off.
Re: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
In reply to Suren BaghdasaryanQuoted 10 lines · Suren Baghdasaryan
Quoted 3 lines · Kent Overstreet
Quoted 1 line · Steven Rostedt
All this, and we are still worried about 4k for useful debugging :-/
I was planning to refactor this function to print one record at a time with a smaller buffer but after discussing with Kent, he has plans to reuse this function and having the report in one buffer is needed for that.
We are printing to console, AFAICS all the code involved uses plain printk() I think it would be way easier to have a function using printk() for this use case than the seq_buf which is more suitable for /proc and friends. Then all concerns about buffers would be gone. It wouldn't be that much of a code duplication?
Quoted 9 lines
Quoted 6 lines
Every additional 4k still needs justification. And whether we burn a reserve on this will have no observable effect on user output in remotely normal situations; if this allocation ever fails, we've already been in an OOM situation for awhile and we've already printed out this report many times, with less memory pressure where the allocation would have succeeded.
I'm not sure this claim will always be true, specifically in the case of low-end devices with relatively low amounts of reserves and in the
That's right, GFP_ATOMIC failures can easily happen without prior OOMs. Consider a system where userspace allocations fill the memory as they usually do, up to high watermark. Then a burst of packets is received and handled by GFP_ATOMIC allocations that deplete the reserves and can't cause OOMs (OOM is when we fail to reclaim anything, but we are allocating from a context that can't reclaim), so the very first report would be an GFP_ATOMIC failure and now it can't allocate that buffer for printing.
I'm sure more such scenarios exist, Cc: Tetsuo who I recall was an expert on this topic.
Quoted 11 lines
presence of a possible quick memory usage spike. We should also consider a case when
panic_on_oomis set. All we get is one OOM report, so we get only one chance to capture this report. In any case, I don't yet have data to prove or disprove this claim but it will be interesting to test it with data from the field once the feature is deployed.For now I think with Vlastimil's
__GFP_NOWARNsuggestion the code becomes safe and the only risk is to lose this report. If we get cases with reports missing this data, we can easily change to reserved memory.
Suren Baghdasaryan
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 13 lines · Vlastimil Babka
Quoted 10 lines · Suren Baghdasaryan
Quoted 3 lines · Kent Overstreet
Quoted 1 line · Steven Rostedt
All this, and we are still worried about 4k for useful debugging :-/
I was planning to refactor this function to print one record at a time with a smaller buffer but after discussing with Kent, he has plans to reuse this function and having the report in one buffer is needed for that.
Quoted 5 lines
We are printing to console, AFAICS all the code involved uses plain
printk()I think it would be way easier to have a function usingprintk()for this use case than theseq_bufwhich is more suitable for /proc and friends. Then all concerns about buffers would be gone. It wouldn't be that much of a code duplication?
Ok, after discussing this with Kent, I'll change this patch to provide a function returning N top consumers (the array and N will be provided by the caller) and then we can print one record at a time with much less memory needed. That should address reusability concerns, will use memory more efficiently and will allow for more flexibility (more/less than 10 records if needed).
Thanks for the feedback, everyone!
Quoted 34 lines
Quoted 10 lines
Quoted 7 lines
Every additional 4k still needs justification. And whether we burn a reserve on this will have no observable effect on user output in remotely normal situations; if this allocation ever fails, we've already been in an OOM situation for awhile and we've already printed out this report many times, with less memory pressure where the allocation would have succeeded.
I'm not sure this claim will always be true, specifically in the case of low-end devices with relatively low amounts of reserves and in the
That's right,
GFP_ATOMICfailures can easily happen without prior OOMs. Consider a system where userspace allocations fill the memory as they usually do, up to high watermark. Then a burst of packets is received and handled byGFP_ATOMICallocations that deplete the reserves and can't cause OOMs (OOM is when we fail to reclaim anything, but we are allocating from a context that can't reclaim), so the very first report would be anGFP_ATOMICfailure and now it can't allocate that buffer for printing.I'm sure more such scenarios exist, Cc: Tetsuo who I recall was an expert on this topic.
Quoted 11 lines
presence of a possible quick memory usage spike. We should also consider a case when
panic_on_oomis set. All we get is one OOM report, so we get only one chance to capture this report. In any case, I don't yet have data to prove or disprove this claim but it will be interesting to test it with data from the field once the feature is deployed.For now I think with Vlastimil's
__GFP_NOWARNsuggestion the code becomes safe and the only risk is to lose this report. If we get cases with reports missing this data, we can easily change to reserved memory.
Re: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
In reply to Vlastimil BabkaQuoted 2 lines · Vlastimil Babka
I'm sure more such scenarios exist, Cc: Tetsuo who I recall was an expert on this topic.
"[PATCH v3 10/35] lib: code tagging framework" says that codetag_lock_module_list() calls down_read() (i.e. sleeping operation), and
"[PATCH v3 31/35] lib: add memory allocations report in show_mem()" says that __show_mem() calls alloc_tags_show_mem_report() after kmalloc(GFP_ATOMIC) (i.e. non-sleeping operation) but alloc_tags_show_mem_report() calls down_read() via codetag_lock_module_list() !?
If __show_mem() might be called from atomic context (e.g. kmalloc(GFP_ATOMIC)), this will be a sleep in atomic bug.
If __show_mem() might be called while semaphore is held for write, this will be a read-lock after write-lock deadlock bug.
Not the matter of whether to allocate buffer statically or dynamically. Please don't hold a lock when trying to report memory usage.
Suren Baghdasaryan
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 12 lines · Tetsuo Handa
Quoted 2 lines · Vlastimil Babka
I'm sure more such scenarios exist, Cc: Tetsuo who I recall was an expert on this topic.
"[PATCH v3 10/35] lib: code tagging framework" says that
codetag_lock_module_list()callsdown_read()(i.e. sleeping operation), and
"[PATCH v3 31/35] lib: add memory allocations report inshow_mem()" says that__show_mem()callsalloc_tags_show_mem_report()afterkmalloc(GFP_ATOMIC)(i.e. non-sleeping operation) butalloc_tags_show_mem_report()callsdown_read()viacodetag_lock_module_list()!?
Quoted 7 lines
If
__show_mem()might be called from atomic context (e.g.kmalloc(GFP_ATOMIC)), this will be a sleep in atomic bug.
If__show_mem()might be called while semaphore is held for write, this will be a read-lock after write-lock deadlock bug.Not the matter of whether to allocate buffer statically or dynamically. Please don't hold a lock when trying to report memory usage.
Thanks for catching this, Tetsuo! Yes, we take the read-lock here to ensure that the list of modules is stable. I'm thinking I can replace the down_read() with down_read_trylock() and if we fail (there is a race with module load/unload) we will skip generating this report. The probability of racing with module load/unload while in OOM state I think is quite low, so skipping this report should not cause much information loss.
Quoted 2 lines
Re: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
In reply to Steven RostedtQuoted 2 lines · Steven Rostedt
Just adding the patches increases the size by 5k. But the rest shows an increase of 259k, and you are worried about 4k (and possibly less?)???
Doesn't the new page_ext thingy add a pointer per 'struct page', or ~0.2% of RAM, or ~32MB on a 16GB laptop? I, too, am confused why 4k is even remotely an issue.
Kent Overstreet
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 7 lines · Dave Hansen
Quoted 2 lines · Steven Rostedt
Just adding the patches increases the size by 5k. But the rest shows an increase of 259k, and you are worried about 4k (and possibly less?)???
Doesn't the new
page_extthingy add a pointer per 'struct page', or ~0.2% of RAM, or ~32MB on a 16GB laptop? I, too, am confused why 4k is even remotely an issue.
page_ext adds a separate per-page array; it itself does not add a pointer to strugt page, it's an array lookup that uses the page pfn.
We do add a pointer to page_ext, and that's (for now) unavoidable overhead - but we'll be looking at referencing code tags by index, and if that works out we'll be able to kill the page_ext dependency and just store the alloc tag index in page bits.
Kent Overstreet
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
In reply to Steven RostedtQuoted 37 lines · Steven Rostedt
Quoted 9 lines · On Thu, 15 Feb 2024 15:33:30 -0500 Kent Overstreet <[email protected]>…
Quoted 6 lines
Well, I think without
__GFP_NOWARNit will cause a warning and thus recursion into__show_mem(), potentially infinite? Which is of course trivial to fix, but I'd myself rather sacrifice a bit of memory to get this potentially very useful output, if I enabled the profiling. The necessary memory overhead ofpage_extandslabobj_extmakes the printing buffer overhead negligible in comparison?
__GFP_NOWARNis a good point, we should have that.Quoted 7 lines
But - and correct me if I'm wrong here - doesn't an OOM kick in well before
GFP_ATOMIC4k allocations are failing? I'd expect the system to be well and truly hosed at that point.If we want this report to be 100% reliable, then yes the preallocated buffer makes sense - but I don't think 100% makes sense here; I think we can accept ~99% and give back that 4k.
I just compiled v6.8-rc4 vanilla (with a fedora localmodconfig build) and saved it off (vmlinux.orig), then I compiled with the following:
Applied the patches but did not enable anything: vmlinux.memtag-off
EnabledMEM_ALLOC_PROFILING: vmlinux.memtag
EnabledMEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT: vmlinux.memtag-default-on
EnabledMEM_ALLOC_PROFILING_DEBUG: vmlinux.memtag-debugAnd here's what I got:
text data bss dec hex filename 29161847 18352730 5619716 53134293 32ac3d5 vmlinux.orig 29162286 18382638 5595140 53140064 32ada60 vmlinux.memtag-off (+5771) 29230868 18887662 5275652 53394182 32ebb06 vmlinux.memtag (+259889) 29230746 18887662 5275652 53394060 32eba8c vmlinux.memtag-default-on (+259767) dropped? 29276214 18946374 5177348 53399936 32ed180 vmlinux.memtag-debug (+265643)
Quoted 2 lines
Just adding the patches increases the size by 5k. But the rest shows an increase of 259k, and you are worried about 4k (and possibly less?)???
Most of that is data (505024), not text (68582, or 66k).
The data is mostly the alloc tags themselves (one per allocation callsite, and you compiled the entire kernel), so that's expected.
Of the text, a lot of that is going to be slowpath stuff - module load and unload hooks, formatt and printing the output, other assorted bits.
Then there's Allocation and deallocating obj extensions vectors - not slowpath but not super fast path, not every allocation.
The fastpath instruction count overhead is pretty small
- actually doing the accounting - the core of slub.c, page_alloc.c, percpu.c
- setting/restoring the alloc tag: this is overhead we add to every allocation callsite, so it's the most relevant - but it's just a few instructions.
So that's the breakdown. Definitely not zero overhead, but that fixed memory overhead (and additionally, the percpu counters) is the price we pay for very low runtime CPU overhead.
Steven Rostedt
reviewerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 2 lines · On Thu, 15 Feb 2024 18:51:41 -0500 Kent Overstreet <[email protected]>…
Most of that is data (505024), not text (68582, or 66k).
And the 4K extra would have been data too.
Quoted 16 lines
The data is mostly the alloc tags themselves (one per allocation callsite, and you compiled the entire kernel), so that's expected.
Of the text, a lot of that is going to be slowpath stuff - module load and unload hooks, formatt and printing the output, other assorted bits.
Then there's Allocation and deallocating obj extensions vectors - not slowpath but not super fast path, not every allocation.
The fastpath instruction count overhead is pretty small
- actually doing the accounting - the core ofslub.c,page_alloc.c,percpu.c
- setting/restoring the alloc tag: this is overhead we add to every allocation callsite, so it's the most relevant - but it's just a few instructions.
Quoted 3 lines
So that's the breakdown. Definitely not zero overhead, but that fixed memory overhead (and additionally, the percpu counters) is the price we pay for very low runtime CPU overhead.
But where are the benchmarks that are not micro-benchmarks. How much overhead does this cause to those? Is it in the noise, or is it noticeable?
-- Steve
Kent Overstreet
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 7 lines · Steven Rostedt
Quoted 2 lines · On Thu, 15 Feb 2024 18:51:41 -0500 Kent Overstreet <[email protected]>…
Most of that is data (505024), not text (68582, or 66k).
And the 4K extra would have been data too.
"It's not that much" isn't an argument for being wasteful.
Quoted 16 lines
Quoted 16 lines
The data is mostly the alloc tags themselves (one per allocation callsite, and you compiled the entire kernel), so that's expected.
Of the text, a lot of that is going to be slowpath stuff - module load and unload hooks, formatt and printing the output, other assorted bits.
Then there's Allocation and deallocating obj extensions vectors - not slowpath but not super fast path, not every allocation.
The fastpath instruction count overhead is pretty small
- actually doing the accounting - the core ofslub.c,page_alloc.c,percpu.c
- setting/restoring the alloc tag: this is overhead we add to every allocation callsite, so it's the most relevant - but it's just a few instructions.
Quoted 6 lines
Quoted 3 lines
So that's the breakdown. Definitely not zero overhead, but that fixed memory overhead (and additionally, the percpu counters) is the price we pay for very low runtime CPU overhead.
But where are the benchmarks that are not micro-benchmarks. How much overhead does this cause to those? Is it in the noise, or is it noticeable?
Microbenchmarks are how we magnify the effect of a change like this to the most we'll ever see. Barring cache effects, it'll be in the noise.
Cache effects are a concern here because we're now touching task_struct in the allocation fast path; that is where the "compiled-in-but-turned-off" overhead comes from, because we can't add static keys for that code without doubling the amount of icache footprint, and I don't think that would be a great tradeoff.
So: if your code has fastpath allocations where the hot part of task_struct isn't in cache, then this will be noticeable overhead to you, otherwise it won't be.
Steven Rostedt
reviewerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 12 lines · On Thu, 15 Feb 2024 19:32:38 -0500 Kent Overstreet <[email protected]>…
Quoted 2 lines
But where are the benchmarks that are not micro-benchmarks. How much overhead does this cause to those? Is it in the noise, or is it noticeable?
Microbenchmarks are how we magnify the effect of a change like this to the most we'll ever see. Barring cache effects, it'll be in the noise.
Cache effects are a concern here because we're now touching
task_structin the allocation fast path; that is where the "compiled-in-but-turned-off" overhead comes from, because we can't add static keys for that code without doubling the amount of icache footprint, and I don't think that would be a great tradeoff.
Quoted 3 lines
So: if your code has fastpath allocations where the hot part of
task_structisn't in cache, then this will be noticeable overhead to you, otherwise it won't be.
All nice, but where are the benchmarks? This looks like it will have an affect on cache and you can talk all you want about how it will not be an issue, but without real world benchmarks, it's meaningless. Numbers talk.
-- Steve
Kent Overstreet
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 15 lines · Steven Rostedt
Quoted 12 lines · On Thu, 15 Feb 2024 19:32:38 -0500 Kent Overstreet <[email protected]>…
Quoted 2 lines
But where are the benchmarks that are not micro-benchmarks. How much overhead does this cause to those? Is it in the noise, or is it noticeable?
Microbenchmarks are how we magnify the effect of a change like this to the most we'll ever see. Barring cache effects, it'll be in the noise.
Cache effects are a concern here because we're now touching
task_structin the allocation fast path; that is where the "compiled-in-but-turned-off" overhead comes from, because we can't add static keys for that code without doubling the amount of icache footprint, and I don't think that would be a great tradeoff.
Quoted 7 lines
Quoted 3 lines
So: if your code has fastpath allocations where the hot part of
task_structisn't in cache, then this will be noticeable overhead to you, otherwise it won't be.All nice, but where are the benchmarks? This looks like it will have an affect on cache and you can talk all you want about how it will not be an issue, but without real world benchmarks, it's meaningless. Numbers talk.
Steve, you're being demanding. We provided sufficient benchmarks to show the overhead is low enough for production, and then I gave you a detailed breakdown of where our overhead is and where it'll show up. I think that's reasonable.
Steven Rostedt
reviewerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 8 lines · On Thu, 15 Feb 2024 19:50:24 -0500 Kent Overstreet <[email protected]>…
Quoted 3 lines
All nice, but where are the benchmarks? This looks like it will have an affect on cache and you can talk all you want about how it will not be an issue, but without real world benchmarks, it's meaningless. Numbers talk.
Steve, you're being demanding. We provided sufficient benchmarks to show the overhead is low enough for production, and then I gave you a detailed breakdown of where our overhead is and where it'll show up. I think that's reasonable.
It's not unreasonable or demanding to ask for benchmarks. You showed only micro-benchmarks that do not show how cache misses may affect the system. Honestly, it sounds like you did run other benchmarks and didn't like the results and are fighting to not have to produce them. Really, how hard is it? There's lots of benchmarks you can run, like hackbench, stress-ng, dbench. Why is this so difficult for you?
-- Steve
Kent Overstreet
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 12 lines · Steven Rostedt
Quoted 8 lines · On Thu, 15 Feb 2024 19:50:24 -0500 Kent Overstreet <[email protected]>…
Quoted 3 lines
All nice, but where are the benchmarks? This looks like it will have an affect on cache and you can talk all you want about how it will not be an issue, but without real world benchmarks, it's meaningless. Numbers talk.
Steve, you're being demanding. We provided sufficient benchmarks to show the overhead is low enough for production, and then I gave you a detailed breakdown of where our overhead is and where it'll show up. I think that's reasonable.
Quoted 6 lines
It's not unreasonable or demanding to ask for benchmarks. You showed only micro-benchmarks that do not show how cache misses may affect the system. Honestly, it sounds like you did run other benchmarks and didn't like the results and are fighting to not have to produce them. Really, how hard is it? There's lots of benchmarks you can run, like hackbench, stress-ng, dbench. Why is this so difficult for you?
Woah, this is verging into paranoid conspiracy territory.
No, we haven't done other benchmarks, and if we had we'd be sharing them. And if I had more time to spend on performance of this patchset that's not where I'd be spending it; the next thing I'd be looking at would be assembly output of the hooking code and seeing if I could shave that down.
But I already put a ton of work into shaving cycles on this patchset, I'm happy with the results, and I have other responsibilities and other things I need to be working on.
Suren Baghdasaryan
maintainerRe: [PATCH v3 31/35] lib: add memory allocations report in show_mem()
Quoted 14 lines · Kent Overstreet
Quoted 12 lines · Steven Rostedt
Quoted 8 lines · On Thu, 15 Feb 2024 19:50:24 -0500 Kent Overstreet <[email protected]>…
Quoted 3 lines
All nice, but where are the benchmarks? This looks like it will have an affect on cache and you can talk all you want about how it will not be an issue, but without real world benchmarks, it's meaningless. Numbers talk.
Steve, you're being demanding. We provided sufficient benchmarks to show the overhead is low enough for production, and then I gave you a detailed breakdown of where our overhead is and where it'll show up. I think that's reasonable.
Quoted 6 lines
Quoted 6 lines
It's not unreasonable or demanding to ask for benchmarks. You showed only micro-benchmarks that do not show how cache misses may affect the system. Honestly, it sounds like you did run other benchmarks and didn't like the results and are fighting to not have to produce them. Really, how hard is it? There's lots of benchmarks you can run, like hackbench, stress-ng, dbench. Why is this so difficult for you?
I'll run these benchmarks and will include the numbers in the next cover letter.
Quoted 12 lines
Woah, this is verging into paranoid conspiracy territory.
No, we haven't done other benchmarks, and if we had we'd be sharing them. And if I had more time to spend on performance of this patchset that's not where I'd be spending it; the next thing I'd be looking at would be assembly output of the hooking code and seeing if I could shave that down.
But I already put a ton of work into shaving cycles on this patchset, I'm happy with the results, and I have other responsibilities and other things I need to be working on.
Suren Baghdasaryan
maintainerPATCH v3 32/35 codetag: debug: skip objext checking when it's for objext itself
In reply to Suren Baghdasaryanobjext objects are created with __GFP_NO_OBJ_EXT flag and therefore have no corresponding objext themselves (otherwise we would get an infinite recursion). When freeing these objects their codetag will be empty and when CONFIG_MEM_ALLOC_PROFILING_DEBUG is enabled this will lead to false warnings. Introduce CODETAG_EMPTY special codetag value to mark allocations which intentionally lack codetag to avoid these warnings. Set objext codetags to CODETAG_EMPTY before freeing to indicate that the codetag is expected to be empty.
--- include/linux/alloc_tag.h | 26 ++++++++++++++++++++++++++ mm/slab.h | 25 +++++++++++++++++++++++++ mm/slab_common.c | 1 + mm/slub.c | 8 ++++++++ 4 files changed, 60 insertions(+)
include/linux/alloc_tag.h +26 -0
@@ -77,6 +77,27 @@ static inline struct alloc_tag_counters alloc_tag_read(struct alloc_tag *tag)return v; } +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG + +#define CODETAG_EMPTY (void *)1 + +static inline bool is_codetag_empty (union codetag_ref *ref) +{ +return ref->ct ==CODETAG_EMPTY ; +} + +static inline void set_codetag_empty (union codetag_ref *ref) +{ +if (ref) + ref->ct =CODETAG_EMPTY ; +} + +#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ + +static inline bool is_codetag_empty (union codetag_ref *ref) {return false; } + +#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ +static inline void __alloc_tag_sub (union codetag_ref *ref,size_t bytes) {struct alloc_tag *tag;
@@ -87,6 +108,11 @@ static inline void __alloc_tag_sub(union codetag_ref *ref, size_t bytes)if (!ref || !ref->ct)return ; +if (is_codetag_empty (ref)) { + ref->ct =NULL ; +return ; + } + tag =ct_to_alloc_tag (ref->ct);this_cpu_sub (tag->counters->bytes, bytes);
mm/slab.h +25 -0
@@ -567,6 +567,31 @@ static inline struct slabobj_ext *slab_obj_exts(struct slab *slab)int alloc_slab_obj_exts (struct slab *slab,struct kmem_cache *s,gfp_t gfp,bool new_slab); + +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG + +static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) +{ +struct slabobj_ext *slab_exts; +struct slab *obj_exts_slab; + + obj_exts_slab =virt_to_slab (obj_exts); + slab_exts =slab_obj_exts (obj_exts_slab); +if (slab_exts) { +unsigned int offs =obj_to_index (obj_exts_slab->slab_cache, + obj_exts_slab, obj_exts); +/* codetag should be NULL */ +WARN_ON (slab_exts[offs].ref.ct); +set_codetag_empty (&slab_exts[offs].ref); + } +} + +#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ + +static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) {} + +#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ +static inline bool need_slab_obj_ext (void ) {#ifdef CONFIG_MEM_ALLOC_PROFILING
mm/slab_common.c +1 -0
@@ -242,6 +242,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,* assign slabobj_exts in parallel. In this case the existing * objcg vector should be reused. */ +mark_objexts_empty (vec);kfree (vec);return 0 ; }
mm/slub.c +8 -0
@@ -1890,6 +1890,14 @@ static inline void free_slab_obj_exts(struct slab *slab)if (!obj_exts)return ; +/* +* obj_exts was created with __GFP_NO_OBJ_EXT flag, therefore its +* corresponding extension will be NULL. alloc_tag_sub() will throw a +* warning if slab has extensions but the extension of an object is +* NULL, therefore replace NULL with CODETAG_EMPTY to indicate that +* the extension for obj_exts is expected to be NULL. +*/ +mark_objexts_empty (obj_exts);kfree (obj_exts); slab->obj_exts =0 ; }
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
Re: [PATCH v3 32/35] codetag: debug: skip objext checking when it's for objext itself
Quoted 19 lines · Suren Baghdasaryan
objext objects are created with
__GFP_NO_OBJ_EXTflag and therefore have no corresponding objext themselves (otherwise we would get an infinite recursion). When freeing these objects their codetag will be empty and whenCONFIG_MEM_ALLOC_PROFILING_DEBUGis enabled this will lead to false warnings. IntroduceCODETAG_EMPTYspecial codetag value to mark allocations which intentionally lack codetag to avoid these warnings. Set objext codetags toCODETAG_EMPTYbefore freeing to indicate that the codetag is expected to be empty.Signed-off-by Suren Baghdasaryan <[email protected]>--- include/linux/alloc_tag.h | 26 ++++++++++++++++++++++++++ mm/slab.h | 25 +++++++++++++++++++++++++ mm/slab_common.c | 1 + mm/slub.c | 8 ++++++++ 4 files changed, 60 insertions(+)include/linux/alloc_tag.h +0
-0
...
Quoted 22 lines
index
c4bd0d5348cb..cf332a839bf4100644mm/slab.h +15
-0@@ -567,6 +567,31 @@ static inline struct slabobj_ext *slab_obj_exts(struct slab *slab)int alloc_slab_obj_exts (struct slab *slab,struct kmem_cache *s,gfp_t gfp,bool new_slab); + +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG + +static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) +{ +struct slabobj_ext *slab_exts; +struct slab *obj_exts_slab; + + obj_exts_slab =virt_to_slab (obj_exts); + slab_exts =slab_obj_exts (obj_exts_slab); +if (slab_exts) { +unsigned int offs =obj_to_index (obj_exts_slab->slab_cache, + obj_exts_slab, obj_exts); +/* codetag should be NULL */ +WARN_ON (slab_exts[offs].ref.ct);
mm/slab.h static inline struct slabobj_ext *slab_obj_exts(struct slab *slab) · line 594
Quoted 10 lines
mm/slab.h +10
-0+ set_codetag_empty(&slab_exts[offs].ref); + } +} + +#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ + +static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) {} + +#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ +
I assume with alloc_slab_obj_exts() moved to slub.c, mark_objexts_empty() could move there too.
Quoted 34 lines
mm/slab.h +0
-0static inline bool need_slab_obj_ext (void ) {#ifdef CONFIG_MEM_ALLOC_PROFILING mm/slab_common.c +1
-0@@ -242,6 +242,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,* assign slabobj_exts in parallel. In this case the existing * objcg vector should be reused. */ +mark_objexts_empty (vec);kfree (vec);return 0 ; }mm/slub.c +8
-0@@ -1890,6 +1890,14 @@ static inline void free_slab_obj_exts(struct slab *slab)if (!obj_exts)return ; +/* +* obj_exts was created with __GFP_NO_OBJ_EXT flag, therefore its +* corresponding extension will be NULL. alloc_tag_sub() will throw a +* warning if slab has extensions but the extension of an object is +* NULL, therefore replace NULL with CODETAG_EMPTY to indicate that +* the extension for obj_exts is expected to be NULL. +*/ +mark_objexts_empty (obj_exts);kfree (obj_exts); slab->obj_exts =0 ; }
Suren Baghdasaryan
maintainerRe: [PATCH v3 32/35] codetag: debug: skip objext checking when it's for objext itself
Quoted 51 lines · Vlastimil Babka
Quoted 19 lines · Suren Baghdasaryan
objext objects are created with
__GFP_NO_OBJ_EXTflag and therefore have no corresponding objext themselves (otherwise we would get an infinite recursion). When freeing these objects their codetag will be empty and whenCONFIG_MEM_ALLOC_PROFILING_DEBUGis enabled this will lead to false warnings. IntroduceCODETAG_EMPTYspecial codetag value to mark allocations which intentionally lack codetag to avoid these warnings. Set objext codetags toCODETAG_EMPTYbefore freeing to indicate that the codetag is expected to be empty.Signed-off-by Suren Baghdasaryan <[email protected]>--- include/linux/alloc_tag.h | 26 ++++++++++++++++++++++++++ mm/slab.h | 25 +++++++++++++++++++++++++ mm/slab_common.c | 1 + mm/slub.c | 8 ++++++++ 4 files changed, 60 insertions(+)include/linux/alloc_tag.h +0
-0...
Quoted 27 lines
index
c4bd0d5348cb..cf332a839bf4100644mm/slab.h +20
-0@@ -567,6 +567,31 @@ static inline struct slabobj_ext *slab_obj_exts(struct slab *slab)int alloc_slab_obj_exts (struct slab *slab,struct kmem_cache *s,gfp_t gfp,bool new_slab); + +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG + +static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) +{ +struct slabobj_ext *slab_exts; +struct slab *obj_exts_slab; + + obj_exts_slab =virt_to_slab (obj_exts); + slab_exts =slab_obj_exts (obj_exts_slab); +if (slab_exts) { +unsigned int offs =obj_to_index (obj_exts_slab->slab_cache, + obj_exts_slab, obj_exts); +/* codetag should be NULL */ +WARN_ON (slab_exts[offs].ref.ct); +set_codetag_empty (&slab_exts[offs].ref); + } +} + +#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */
Quoted 8 lines
mm/slab.h static inline struct slabobj_ext *slab_obj_exts(struct slab *slab) · line 594
Quoted 5 lines
mm/slab.h +5
-0+ +static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) {} + +#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ +I assume with
alloc_slab_obj_exts()moved toslub.c,mark_objexts_empty()could move there too.
No, I think mark_objexts_empty() belongs here. This patch introduced the function and uses it. Makes sense to me to keep it all together.
Quoted 36 lines
Quoted 35 lines
mm/slab.h +0
-0static inline bool need_slab_obj_ext (void ) {#ifdef CONFIG_MEM_ALLOC_PROFILING mm/slab_common.c +1
-0@@ -242,6 +242,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,* assign slabobj_exts in parallel. In this case the existing * objcg vector should be reused. */ +mark_objexts_empty (vec);kfree (vec);return 0 ; }mm/slub.c +8
-0@@ -1890,6 +1890,14 @@ static inline void free_slab_obj_exts(struct slab *slab)if (!obj_exts)return ; +/* +* obj_exts was created with __GFP_NO_OBJ_EXT flag, therefore its +* corresponding extension will be NULL. alloc_tag_sub() will throw a +* warning if slab has extensions but the extension of an object is +* NULL, therefore replace NULL with CODETAG_EMPTY to indicate that +* the extension for obj_exts is expected to be NULL. +*/ +mark_objexts_empty (obj_exts);kfree (obj_exts); slab->obj_exts =0 ; }
Re: [PATCH v3 32/35] codetag: debug: skip objext checking when it's for objext itself
Quoted 61 lines · Suren Baghdasaryan
Quoted 51 lines · Vlastimil Babka
Quoted 19 lines · Suren Baghdasaryan
objext objects are created with
__GFP_NO_OBJ_EXTflag and therefore have no corresponding objext themselves (otherwise we would get an infinite recursion). When freeing these objects their codetag will be empty and whenCONFIG_MEM_ALLOC_PROFILING_DEBUGis enabled this will lead to false warnings. IntroduceCODETAG_EMPTYspecial codetag value to mark allocations which intentionally lack codetag to avoid these warnings. Set objext codetags toCODETAG_EMPTYbefore freeing to indicate that the codetag is expected to be empty.Signed-off-by Suren Baghdasaryan <[email protected]>--- include/linux/alloc_tag.h | 26 ++++++++++++++++++++++++++ mm/slab.h | 25 +++++++++++++++++++++++++ mm/slab_common.c | 1 + mm/slub.c | 8 ++++++++ 4 files changed, 60 insertions(+)include/linux/alloc_tag.h +0
-0...
Quoted 27 lines
index
c4bd0d5348cb..cf332a839bf4100644mm/slab.h +20
-0@@ -567,6 +567,31 @@ static inline struct slabobj_ext *slab_obj_exts(struct slab *slab)int alloc_slab_obj_exts (struct slab *slab,struct kmem_cache *s,gfp_t gfp,bool new_slab); + +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG + +static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) +{ +struct slabobj_ext *slab_exts; +struct slab *obj_exts_slab; + + obj_exts_slab =virt_to_slab (obj_exts); + slab_exts =slab_obj_exts (obj_exts_slab); +if (slab_exts) { +unsigned int offs =obj_to_index (obj_exts_slab->slab_cache, + obj_exts_slab, obj_exts); +/* codetag should be NULL */ +WARN_ON (slab_exts[offs].ref.ct); +set_codetag_empty (&slab_exts[offs].ref); + } +} + +#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ Quoted 8 lines
mm/slab.h static inline struct slabobj_ext *slab_obj_exts(struct slab *slab) · line 594
Quoted 5 lines
mm/slab.h +5
-0+ +static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) {} + +#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ +I assume with
alloc_slab_obj_exts()moved toslub.c,mark_objexts_empty()could move there too.
Quoted 2 lines
No, I think
mark_objexts_empty()belongs here. This patch introduced the function and uses it. Makes sense to me to keep it all together.
Hi,
here I didn't mean moving between patches, but files. alloc_slab_obj_exts() in slub.c means all callers of mark_objexts_empty() are in slub.c so it doesn't need to be in slab.h
Also same thing with mark_failed_objexts_alloc() and handle_failed_objexts_alloc() in patch 34/35.
Suren Baghdasaryan
maintainerRe: [PATCH v3 32/35] codetag: debug: skip objext checking when it's for objext itself
Quoted 63 lines · Vlastimil Babka
Quoted 61 lines · Suren Baghdasaryan
Quoted 59 lines · Vlastimil Babka
Quoted 19 lines · Suren Baghdasaryan
objext objects are created with
__GFP_NO_OBJ_EXTflag and therefore have no corresponding objext themselves (otherwise we would get an infinite recursion). When freeing these objects their codetag will be empty and whenCONFIG_MEM_ALLOC_PROFILING_DEBUGis enabled this will lead to false warnings. IntroduceCODETAG_EMPTYspecial codetag value to mark allocations which intentionally lack codetag to avoid these warnings. Set objext codetags toCODETAG_EMPTYbefore freeing to indicate that the codetag is expected to be empty.Signed-off-by Suren Baghdasaryan <[email protected]>--- include/linux/alloc_tag.h | 26 ++++++++++++++++++++++++++ mm/slab.h | 25 +++++++++++++++++++++++++ mm/slab_common.c | 1 + mm/slub.c | 8 ++++++++ 4 files changed, 60 insertions(+)include/linux/alloc_tag.h +0
-0...
Quoted 22 lines
index
c4bd0d5348cb..cf332a839bf4100644mm/slab.h +15
-0@@ -567,6 +567,31 @@ static inline struct slabobj_ext *slab_obj_exts(struct slab *slab)int alloc_slab_obj_exts (struct slab *slab,struct kmem_cache *s,gfp_t gfp,bool new_slab); + +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG + +static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) +{ +struct slabobj_ext *slab_exts; +struct slab *obj_exts_slab; + + obj_exts_slab =virt_to_slab (obj_exts); + slab_exts =slab_obj_exts (obj_exts_slab); +if (slab_exts) { +unsigned int offs =obj_to_index (obj_exts_slab->slab_cache, + obj_exts_slab, obj_exts); +/* codetag should be NULL */ +WARN_ON (slab_exts[offs].ref.ct);mm/slab.h static inline struct slabobj_ext *slab_obj_exts(struct slab *slab) · line 594
Quoted 10 lines
mm/slab.h +10
-0+ set_codetag_empty(&slab_exts[offs].ref); + } +} + +#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ + +static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) {} + +#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ +I assume with
alloc_slab_obj_exts()moved toslub.c,mark_objexts_empty()could move there too.
Quoted 8 lines
Quoted 2 lines
No, I think
mark_objexts_empty()belongs here. This patch introduced the function and uses it. Makes sense to me to keep it all together.Hi,
here I didn't mean moving between patches, but files.
alloc_slab_obj_exts()inslub.cmeans all callers ofmark_objexts_empty()are inslub.cso it doesn't need to be inslab.h
Ah, I see. I misunderstood your comment. Yes, after slab/slob cleanup this makes sense.
Quoted 3 lines
Also same thing with
mark_failed_objexts_alloc()andhandle_failed_objexts_alloc()in patch 34/35.
Ack. Thanks!
Quoted 1 line
Suren Baghdasaryan
maintainerPATCH v3 33/35 codetag: debug: mark codetags for reserved pages as empty
In reply to Suren BaghdasaryanTo avoid debug warnings while freeing reserved pages which were not allocated with usual allocators, mark their codetags as empty before freeing.
--- include/linux/alloc_tag.h | 2 ++ include/linux/mm.h | 8 ++++++++ include/linux/pgalloc_tag.h | 2 ++ mm/mm_init.c | 9 +++++++++ 4 files changed, 21 insertions(+)
include/linux/alloc_tag.h +2 -0
@@ -95,6 +95,7 @@ static inline void set_codetag_empty(union codetag_ref *ref)#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ static inline bool is_codetag_empty (union codetag_ref *ref) {return false; } +static inline void set_codetag_empty (union codetag_ref *ref) {}#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */
@@ -155,6 +156,7 @@ static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) {}static inline void alloc_tag_sub_noalloc (union codetag_ref *ref,size_t bytes) {}static inline void alloc_tag_add (union codetag_ref *ref,struct alloc_tag *tag,size_t bytes) {} +static inline void set_codetag_empty (union codetag_ref *ref) {}#endif
include/linux/mm.h +8 -0
@@ -5,6 +5,7 @@#include <linux/errno.h> #include <linux/mmdebug.h> #include <linux/gfp.h> +#include <linux/pgalloc_tag.h> #include <linux/bug.h> #include <linux/list.h> #include <linux/mmzone.h>
@@ -3112,6 +3113,13 @@ extern void reserve_bootmem_region(phys_addr_t start,/* Free the reserved page into the buddy system, so it gets managed. */ static inline void free_reserved_page (struct page *page) { +union codetag_ref *ref; + + ref =get_page_tag_ref (page); +if (ref) { +set_codetag_empty (ref); +put_page_tag_ref (ref); + }ClearPageReserved (page);init_page_count (page);__free_page (page);
include/linux/pgalloc_tag.h +2 -0
@@ -93,6 +93,8 @@ static inline void pgalloc_tag_split(struct page *page, unsigned int nr)#else /* CONFIG_MEM_ALLOC_PROFILING */ +static inline union codetag_ref *get_page_tag_ref (struct page *page) {return NULL ; } +static inline void put_page_tag_ref (union codetag_ref *ref) {}static inline void pgalloc_tag_add (struct page *page,struct task_struct *task,unsigned int order) {}static inline void pgalloc_tag_sub (struct page *page,unsigned int order) {}
mm/mm_init.c +9 -0
@@ -2566,6 +2566,7 @@ void __init set_dma_reserve(unsigned long new_dma_reserve)void __init memblock_free_pages (struct page *page,unsigned long pfn,unsigned int order) { +union codetag_ref *ref;if (IS_ENABLED (CONFIG_DEFERRED_STRUCT_PAGE_INIT )) {int nid =early_pfn_to_nid (pfn);
@@ -2578,6 +2579,14 @@ void __init memblock_free_pages(struct page *page, unsigned long pfn,/* KMSAN will take care of these pages. */ return ; } + +/* pages were reserved and not allocated */ + ref =get_page_tag_ref (page); +if (ref) { +set_codetag_empty (ref); +put_page_tag_ref (ref); + } +__free_pages_core (page, order); }
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
Re: [PATCH v3 33/35] codetag: debug: mark codetags for reserved pages as empty
Quoted 3 lines · Suren Baghdasaryan
To avoid debug warnings while freeing reserved pages which were not allocated with usual allocators, mark their codetags as empty before freeing.
How do these get their codetags to begin with? Regardless:
Signature · 1 line
Kees Cook
Suren Baghdasaryan
maintainerRe: [PATCH v3 33/35] codetag: debug: mark codetags for reserved pages as empty
Quoted 7 lines · Kees Cook
Quoted 3 lines · Suren Baghdasaryan
To avoid debug warnings while freeing reserved pages which were not allocated with usual allocators, mark their codetags as empty before freeing.
How do these get their codetags to begin with?
The space for the codetag reference is inside the page_ext and that reference is set to NULL. So, unless we set the reference as empty (set it to CODETAG_EMPTY), the free routine will detect that we are freeing an allocation that has never been accounted for and will issue a warning. To prevent this warning we use this CODETAG_EMPTY to denote that this codetag reference is expected to be empty because it was not allocated in a usual way.
Quoted 6 lines
Regardless:
Reviewed-by Kees Cook <[email protected]>--
Kees Cook
Suren Baghdasaryan
maintainerPATCH v3 34/35 codetag: debug: introduce OBJEXTS_ALLOC_FAIL to mark failed slab_ext allocations
In reply to Suren BaghdasaryanIf slabobj_ext vector allocation for a slab object fails and later on it succeeds for another object in the same slab, the slabobj_ext for the original object will be NULL and will be flagged in case when CONFIG_MEM_ALLOC_PROFILING_DEBUG is enabled.
Mark failed slabobj_ext vector allocations using a new objext_flags flag stored in the lower bits of slab->obj_exts. When new allocation succeeds it marks all tag references in the same slabobj_ext vector as empty to avoid warnings implemented by CONFIG_MEM_ALLOC_PROFILING_DEBUG checks.
--- include/linux/memcontrol.h | 4 +++- mm/slab.h | 25 +++++++++++++++++++++++++ mm/slab_common.c | 22 +++++++++++++++------- 3 files changed, 43 insertions(+), 8 deletions(-)
include/linux/memcontrol.h +3 -1
@@ -365,8 +365,10 @@ enum page_memcg_data_flags {#endif /* CONFIG_MEMCG */ enum objext_flags { +/* slabobj_ext vector failed to allocate */ +OBJEXTS_ALLOC_FAIL = __FIRST_OBJEXT_FLAG,/* the next bit after the last actual flag */ - __NR_OBJEXTS_FLAGS = __FIRST_OBJEXT_FLAG, + __NR_OBJEXTS_FLAGS = (__FIRST_OBJEXT_FLAG <<1 ), };#define OBJEXTS_FLAGS_MASK (__NR_OBJEXTS_FLAGS - 1)
mm/slab.h +25 -0
@@ -586,9 +586,34 @@ static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) } } +static inline void mark_failed_objexts_alloc (struct slab *slab) +{ + slab->obj_exts =OBJEXTS_ALLOC_FAIL ; +} + +static inline void handle_failed_objexts_alloc (unsigned long obj_exts, +struct slabobj_ext *vec,unsigned int objects) +{ +/* +* If vector previously failed to allocate then we have live +* objects with no tag reference. Mark all references in this +* vector as empty to avoid warnings later on. +*/ +if (obj_exts &OBJEXTS_ALLOC_FAIL ) { +unsigned int i; + +for (i =0 ; i < objects; i++) +set_codetag_empty (&vec[i].ref); + } +} + +#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) {} +static inline void mark_failed_objexts_alloc (struct slab *slab) {} +static inline void handle_failed_objexts_alloc (unsigned long obj_exts, +struct slabobj_ext *vec,unsigned int objects) {}#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */
mm/slab_common.c +15 -7
@@ -214,29 +214,37 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp_t gfp, bool new_slab) {unsigned int objects =objs_per_slab (s, slab); -unsigned long obj_exts; -void *vec; +unsigned long new_exts; +unsigned long old_exts; +struct slabobj_ext *vec; gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab)); -if (!vec) +if (!vec) { +/* Mark vectors which failed to allocate */ +if (new_slab) +mark_failed_objexts_alloc (slab); +return -ENOMEM ; + } - obj_exts = (unsigned long )vec; + new_exts = (unsigned long )vec;#ifdef CONFIG_MEMCG - obj_exts |=MEMCG_DATA_OBJEXTS ; + new_exts |=MEMCG_DATA_OBJEXTS ;#endif + old_exts = slab->obj_exts; +handle_failed_objexts_alloc (old_exts, vec, objects);if (new_slab) {/* * If the slab is brand new and nobody can yet access its * obj_exts, no synchronization is required and obj_exts can * be simply assigned. */ - slab->obj_exts = obj_exts; - }else if (cmpxchg (&slab->obj_exts,0 , obj_exts)) { + slab->obj_exts = new_exts; + }else if (cmpxchg (&slab->obj_exts, old_exts, new_exts) != old_exts) {/* * If the slab is already in use, somebody can allocate and * assign slabobj_exts in parallel. In this case the existing
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
Re: [PATCH v3 34/35] codetag: debug: introduce OBJEXTS_ALLOC_FAIL to mark failed slab_ext allocations
Quoted 37 lines · Suren Baghdasaryan
If
slabobj_extvector allocation for a slab object fails and later on it succeeds for another object in the same slab, theslabobj_extfor the original object will be NULL and will be flagged in case whenCONFIG_MEM_ALLOC_PROFILING_DEBUGis enabled.
Mark failedslabobj_extvector allocations using a newobjext_flagsflag stored in the lower bits ofslab->obj_exts. When new allocation succeeds it marks all tag references in the sameslabobj_extvector as empty to avoid warnings implemented byCONFIG_MEM_ALLOC_PROFILING_DEBUGchecks.Signed-off-by Suren Baghdasaryan <[email protected]>--- include/linux/memcontrol.h | 4 +++- mm/slab.h | 25 +++++++++++++++++++++++++ mm/slab_common.c | 22 +++++++++++++++------- 3 files changed, 43 insertions(+), 8 deletions(-)include/linux/memcontrol.h +3
-1@@ -365,8 +365,10 @@ enum page_memcg_data_flags {#endif /* CONFIG_MEMCG */ enum objext_flags { +/* slabobj_ext vector failed to allocate */ +OBJEXTS_ALLOC_FAIL = __FIRST_OBJEXT_FLAG,/* the next bit after the last actual flag */ - __NR_OBJEXTS_FLAGS = __FIRST_OBJEXT_FLAG, + __NR_OBJEXTS_FLAGS = (__FIRST_OBJEXT_FLAG <<1 ), };#define OBJEXTS_FLAGS_MASK (__NR_OBJEXTS_FLAGS - 1)mm/slab.h +0
-0
mm/slab.h static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) · line 591
Quoted 6 lines
mm/slab.h +3
-0@@ -586,9 +586,34 @@ static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) } } +static inline void mark_failed_objexts_alloc (struct slab *slab) +{ + slab->obj_exts =OBJEXTS_ALLOC_FAIL ;
Uh, does this mean slab->obj_exts is suddenly non-NULL? Is everything that accesses obj_exts expecting this?
-Kees
Quoted 80 lines
mm/slab.h +22
-0+} + +static inline void handle_failed_objexts_alloc (unsigned long obj_exts, +struct slabobj_ext *vec,unsigned int objects) +{ +/* +* If vector previously failed to allocate then we have live +* objects with no tag reference. Mark all references in this +* vector as empty to avoid warnings later on. +*/ +if (obj_exts &OBJEXTS_ALLOC_FAIL ) { +unsigned int i; + +for (i =0 ; i < objects; i++) +set_codetag_empty (&vec[i].ref); + } +} + +#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) {} +static inline void mark_failed_objexts_alloc (struct slab *slab) {} +static inline void handle_failed_objexts_alloc (unsigned long obj_exts, +struct slabobj_ext *vec,unsigned int objects) {}#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ mm/slab_common.c +15
-7@@ -214,29 +214,37 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp_t gfp, bool new_slab) {unsigned int objects =objs_per_slab (s, slab); -unsigned long obj_exts; -void *vec; +unsigned long new_exts; +unsigned long old_exts; +struct slabobj_ext *vec; gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab)); -if (!vec) +if (!vec) { +/* Mark vectors which failed to allocate */ +if (new_slab) +mark_failed_objexts_alloc (slab); +return -ENOMEM ; + } - obj_exts = (unsigned long )vec; + new_exts = (unsigned long )vec;#ifdef CONFIG_MEMCG - obj_exts |=MEMCG_DATA_OBJEXTS ; + new_exts |=MEMCG_DATA_OBJEXTS ;#endif + old_exts = slab->obj_exts; +handle_failed_objexts_alloc (old_exts, vec, objects);if (new_slab) {/* * If the slab is brand new and nobody can yet access its * obj_exts, no synchronization is required and obj_exts can * be simply assigned. */ - slab->obj_exts = obj_exts; - }else if (cmpxchg (&slab->obj_exts,0 , obj_exts)) { + slab->obj_exts = new_exts; + }else if (cmpxchg (&slab->obj_exts, old_exts, new_exts) != old_exts) {/* * If the slab is already in use, somebody can allocate and * assign slabobj_exts in parallel. In this case the existing Signature · 1 line
2.43.0.687.g38aa6559b0-goog
Signature · 1 line
Kees Cook
Suren Baghdasaryan
maintainerRe: [PATCH v3 34/35] codetag: debug: introduce OBJEXTS_ALLOC_FAIL to mark failed slab_ext allocations
Quoted 42 lines · Kees Cook
Quoted 40 lines · Suren Baghdasaryan
If
slabobj_extvector allocation for a slab object fails and later on it succeeds for another object in the same slab, theslabobj_extfor the original object will be NULL and will be flagged in case whenCONFIG_MEM_ALLOC_PROFILING_DEBUGis enabled.
Mark failedslabobj_extvector allocations using a newobjext_flagsflag stored in the lower bits ofslab->obj_exts. When new allocation succeeds it marks all tag references in the sameslabobj_extvector as empty to avoid warnings implemented byCONFIG_MEM_ALLOC_PROFILING_DEBUGchecks.Signed-off-by Suren Baghdasaryan <[email protected]>--- include/linux/memcontrol.h | 4 +++- mm/slab.h | 25 +++++++++++++++++++++++++ mm/slab_common.c | 22 +++++++++++++++------- 3 files changed, 43 insertions(+), 8 deletions(-)include/linux/memcontrol.h +3
-1@@ -365,8 +365,10 @@ enum page_memcg_data_flags {#endif /* CONFIG_MEMCG */ enum objext_flags { +/* slabobj_ext vector failed to allocate */ +OBJEXTS_ALLOC_FAIL = __FIRST_OBJEXT_FLAG,/* the next bit after the last actual flag */ - __NR_OBJEXTS_FLAGS = __FIRST_OBJEXT_FLAG, + __NR_OBJEXTS_FLAGS = (__FIRST_OBJEXT_FLAG <<1 ), };#define OBJEXTS_FLAGS_MASK (__NR_OBJEXTS_FLAGS - 1)mm/slab.h +0
-0@@ -586,9 +586,34 @@ static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) } }
Quoted 6 lines
mm/slab.h static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) · line 591
Quoted 3 lines
mm/slab.h +3
-0+static inline void mark_failed_objexts_alloc (struct slab *slab) +{ + slab->obj_exts =OBJEXTS_ALLOC_FAIL ;Uh, does this mean
slab->obj_extsis suddenly non-NULL? Is everything that accessesobj_extsexpecting this?
Hi Kees,
Thank you for the reviews!
Yes, I believe everything that accesses slab->obj_exts directly (currently alloc_slab_obj_exts() and free_slab_obj_exts()) handle this special non-NULL case. kfence_init_pool() initialized slab->obj_exts directly, but since it's setting it and not accessing it, it does not need to handle OBJEXTS_ALLOC_FAIL. All other slab->obj_exts users use slab_obj_exts() which applies OBJEXTS_FLAGS_MASK and masks out any special bits.
Thanks,
Suren.
Quoted 86 lines
-Kees
Quoted 78 lines
mm/slab.h +22
-0+} + +static inline void handle_failed_objexts_alloc (unsigned long obj_exts, +struct slabobj_ext *vec,unsigned int objects) +{ +/* +* If vector previously failed to allocate then we have live +* objects with no tag reference. Mark all references in this +* vector as empty to avoid warnings later on. +*/ +if (obj_exts &OBJEXTS_ALLOC_FAIL ) { +unsigned int i; + +for (i =0 ; i < objects; i++) +set_codetag_empty (&vec[i].ref); + } +} + +#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ static inline void mark_objexts_empty (struct slabobj_ext *obj_exts) {} +static inline void mark_failed_objexts_alloc (struct slab *slab) {} +static inline void handle_failed_objexts_alloc (unsigned long obj_exts, +struct slabobj_ext *vec,unsigned int objects) {}#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ mm/slab_common.c +15
-8@@ -214,29 +214,37 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp_t gfp, bool new_slab) {unsigned int objects =objs_per_slab (s, slab); -unsigned long obj_exts; -void *vec; +unsigned long new_exts; +unsigned long old_exts; +struct slabobj_ext *vec; gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab)); -if (!vec) +if (!vec) { +/* Mark vectors which failed to allocate */ +if (new_slab) +mark_failed_objexts_alloc (slab); +return -ENOMEM ; + } - obj_exts = (unsigned long )vec; + new_exts = (unsigned long )vec;#ifdef CONFIG_MEMCG - obj_exts |=MEMCG_DATA_OBJEXTS ; + new_exts |=MEMCG_DATA_OBJEXTS ;#endif + old_exts = slab->obj_exts; +handle_failed_objexts_alloc (old_exts, vec, objects);if (new_slab) {/* * If the slab is brand new and nobody can yet access its * obj_exts, no synchronization is required and obj_exts can * be simply assigned. */ - slab->obj_exts = obj_exts; - }else if (cmpxchg (&slab->obj_exts,0 , obj_exts)) { + slab->obj_exts = new_exts; + }else if (cmpxchg (&slab->obj_exts, old_exts, new_exts) != old_exts) {/* * If the slab is already in use, somebody can allocate and * assign slabobj_exts in parallel. In this case the existing -- Quoted 2 lines
2.43.0.687.g38aa6559b0-goog
--
Kees Cook
Suren Baghdasaryan
maintainerPATCH v3 35/35 MAINTAINERS: Add entries for code tagging and memory allocation profiling
In reply to Suren BaghdasaryanFrom: Kent Overstreet <[email protected]>
The new code & libraries added are being maintained - mark them as such.
--- MAINTAINERS | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
MAINTAINERS +16 -0
@@ -5210,6 +5210,13 @@ S: Supported F: Documentation/process/code-of-conduct-interpretation.rst F: Documentation/process/code-of-conduct.rst +CODE TAGGING +M: Suren Baghdasaryan <[email protected]> +M: Kent Overstreet <[email protected]> +S: Maintained +F: include/linux/codetag.h +F: lib/codetag.c + COMEDI DRIVERS M: Ian Abbott <[email protected]> M: H Hartley Sweeten <[email protected]>
@@ -14056,6 +14063,15 @@ F: mm/memblock.c F: mm/mm_init.c F: tools/testing/memblock/ +MEMORY ALLOCATION PROFILING +M: Suren Baghdasaryan <[email protected]> +M: Kent Overstreet <[email protected]> +S: Maintained +F: include/linux/alloc_tag.h +F: include/linux/codetag_ctx.h +F: lib/alloc_tag.c +F: lib/pgalloc_tag.c + MEMORY CONTROLLER DRIVERS M: Krzysztof Kozlowski <[email protected]> L: [email protected]
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
Re: [PATCH v3 35/35] MAINTAINERS: Add entries for code tagging and memory allocation profiling
Quoted 30 lines · Suren Baghdasaryan
From: Kent Overstreet <[email protected]>
The new code & libraries added are being maintained - mark them as such.
Signed-off-by Kent Overstreet <[email protected]>Signed-off-by Suren Baghdasaryan <[email protected]>--- MAINTAINERS | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)MAINTAINERS +7
-0@@ -5210,6 +5210,13 @@ S: Supported F: Documentation/process/code-of-conduct-interpretation.rst F: Documentation/process/code-of-conduct.rst +CODE TAGGING +M: Suren Baghdasaryan <[email protected]> +M: Kent Overstreet <[email protected]> +S: Maintained +F: include/linux/codetag.h +F: lib/codetag.c + COMEDI DRIVERS M: Ian Abbott <[email protected]> M: H Hartley Sweeten <[email protected]>@@ -14056,6 +14063,15 @@ F: mm/memblock.c F: mm/mm_init.c
MAINTAINERS F: mm/memblock.c · line 14073
Quoted 10 lines
MAINTAINERS +8
-0F: tools/testing/memblock/ +MEMORY ALLOCATION PROFILING +M: Suren Baghdasaryan <[email protected]> +M: Kent Overstreet <[email protected]> +S: Maintained +F: include/linux/alloc_tag.h +F: include/linux/codetag_ctx.h +F: lib/alloc_tag.c +F: lib/pgalloc_tag.c
Any mailing list to aim at? linux-mm maybe?
Regardless:
Quoted 7 lines
MAINTAINERS +1
-0+ MEMORY CONTROLLER DRIVERS M: Krzysztof Kozlowski <[email protected]> L: [email protected]Signature · 1 line
2.43.0.687.g38aa6559b0-goog
Signature · 1 line
Kees Cook
Suren Baghdasaryan
maintainerRe: [PATCH v3 35/35] MAINTAINERS: Add entries for code tagging and memory allocation profiling
Quoted 34 lines · Kees Cook
Quoted 32 lines · Suren Baghdasaryan
From: Kent Overstreet <[email protected]>
The new code & libraries added are being maintained - mark them as such.
Signed-off-by Kent Overstreet <[email protected]>Signed-off-by Suren Baghdasaryan <[email protected]>--- MAINTAINERS | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)MAINTAINERS +7
-0@@ -5210,6 +5210,13 @@ S: Supported F: Documentation/process/code-of-conduct-interpretation.rst F: Documentation/process/code-of-conduct.rst +CODE TAGGING +M: Suren Baghdasaryan <[email protected]> +M: Kent Overstreet <[email protected]> +S: Maintained +F: include/linux/codetag.h +F: lib/codetag.c + COMEDI DRIVERS M: Ian Abbott <[email protected]> M: H Hartley Sweeten <[email protected]>@@ -14056,6 +14063,15 @@ F: mm/memblock.c F: mm/mm_init.c F: tools/testing/memblock/
Quoted 10 lines
MAINTAINERS F: mm/memblock.c · line 14073
Quoted 8 lines
MAINTAINERS +8
-0+MEMORY ALLOCATION PROFILING +M: Suren Baghdasaryan <[email protected]> +M: Kent Overstreet <[email protected]> +S: Maintained +F: include/linux/alloc_tag.h +F: include/linux/codetag_ctx.h +F: lib/alloc_tag.c +F: lib/pgalloc_tag.cAny mailing list to aim at? linux-mm maybe?
Good point. Will add. Thanks!
Quoted 16 lines
Regardless:
Reviewed-by Kees Cook <[email protected]>Quoted 7 lines
MAINTAINERS +1
-1+ MEMORY CONTROLLER DRIVERS M: Krzysztof Kozlowski <[email protected]> L: [email protected] --2.43.0.687.g38aa6559b0-goog
--
Kees Cook
Quoted 13 lines · Suren Baghdasaryan
Memory allocation, v3 and final:
Overview:
Low overhead [1] per-callsite memory allocation profiling. Not just for debug kernels, overhead low enough to be deployed in production.We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
Example output:
Quoted 11 lines
root@moria-kvm:~# sort -h /proc/allocinfo|tail
3.11MiB 2850 fs/ext4/super.c:1408 module:ext4 func:ext4_alloc_inode
3.52MiB 225 kernel/fork.c:356 module:fork func:alloc_thread_stack_node
3.75MiB 960 mm/page_ext.c:270 module:page_ext func:alloc_page_ext
4.00MiB 2 mm/khugepaged.c:893 module:khugepaged func:hpage_collapse_alloc_folio
10.5MiB 168 block/blk-mq.c:3421 module:blk_mq func:blk_mq_alloc_rqs
14.0MiB 3594 include/linux/gfp.h:295 module:filemap func:folio_alloc_noprof
26.8MiB 6856 include/linux/gfp.h:295 module:memory func:folio_alloc_noprof
64.5MiB 98315 fs/xfs/xfs_rmap_item.c:147 module:xfs func:xfs_rui_init
98.7MiB 25264 include/linux/gfp.h:295 module:readahead func:folio_alloc_noprof
125MiB 7357 mm/slub.c:2201 module:slub func:alloc_slab_pageThis kind of memory profiling would be an incredible asset in cloud environments.
Over the past year, we've encountered several kernel memory overhead issues. Two particularly severe cases involved excessively large IOMMU page tables (20GB per machine) and IOVA magazines (up to 8GB). Considering thousands of machines were affected, the cumulative memory waste was huge.
While we eventually resolved these issues with custom kernel profiling hacks (some based on this series) and kdump analysis, comprehensive memory profiling would have significantly accelerated the diagnostic process, pinpointing the precise source of the allocations.
Quoted 2 lines · Suren Baghdasaryan
Low overhead [1] per-callsite memory allocation profiling. Not just for debug kernels, overhead low enough to be deployed in production.
What's the plan for things like devm_kmalloc() and similar relatively simple wrappers? I was thinking it would be possible to reimplement at least devm_kmalloc() with size and flags changing helper a while back:
https://lore.kernel.org/all/202309111428.6F36672F57@keescook/
I suspect it could be possible to adapt the alloc_hooks wrapper in this series similarly:
#define alloc_hooks_prep(_do_alloc, _do_prepare, _do_finish, \
ctx, size, flags) \
({ \
typeof(_do_alloc) _res; \
DEFINE_ALLOC_TAG(_alloc_tag, _old); \
ssize_t _size = (size); \
size_t _usable = _size; \
gfp_t _flags = (flags); \
\
_res = _do_prepare(ctx, &_size, &_flags); \
if (!IS_ERR_OR_NULL(_res) \
_res = _do_alloc(_size, _flags); \
if (!IS_ERR_OR_NULL(_res) \
_res = _do_finish(ctx, _usable, _size, _flags, _res); \
_res; \
})#define devm_kmalloc(dev, size, flags) \ alloc_hooks_prep(kmalloc, devm_alloc_prep, devm_alloc_finish, \ dev, size, flags)
And devm_alloc_prep() and devm_alloc_finish() adapted from the URL above.
And _do_finish instances could be marked with __realloc_size(2)
-Kees
Signature · 1 line
Kees Cook
Suren Baghdasaryan
maintainerQuoted 31 lines · Kees Cook
Quoted 2 lines · Suren Baghdasaryan
Low overhead [1] per-callsite memory allocation profiling. Not just for debug kernels, overhead low enough to be deployed in production.
What's the plan for things like
devm_kmalloc()and similar relatively simple wrappers? I was thinking it would be possible to reimplement at leastdevm_kmalloc()with size and flags changing helper a while back:https://lore.kernel.org/all/202309111428.6F36672F57@keescook/
I suspect it could be possible to adapt the
alloc_hookswrapper in this series similarly:#define alloc_hooks_prep(_do_alloc, _do_prepare, _do_finish, \ ctx, size, flags) \ ({ \ typeof(_do_alloc) _res; \ DEFINE_ALLOC_TAG(_alloc_tag, _old); \ ssize_t _size = (size); \ size_t _usable = _size; \ gfp_t _flags = (flags); \ \ _res = _do_prepare(ctx, &_size, &_flags); \ if (!IS_ERR_OR_NULL(_res) \ _res = _do_alloc(_size, _flags); \ if (!IS_ERR_OR_NULL(_res) \ _res = _do_finish(ctx, _usable, _size, _flags, _res); \ _res; \ })
Quoted 8 lines
#define
devm_kmalloc(dev, size, flags)\
alloc_hooks_prep(kmalloc,devm_alloc_prep,devm_alloc_finish, \
dev, size, flags)And
devm_alloc_prep()anddevm_alloc_finish()adapted from the URL above.And
_do_finishinstances could be marked with__realloc_size(2)
devm_kmalloc() is definitely a great candidate to account separately. Looks like it's currently using alloc_dr()->kmalloc_node_track_caller(), so this series will account the internal kmalloc_node_track_caller() allocation. We can easily apply alloc_hook to devm_kmalloc() and friends and replace the kmalloc_node_track_caller() call inside alloc_dr() with kmalloc_node_track_caller_noprof(). That will move accounting directly to devm_kmalloc().
Quoted 5 lines
-Kees
--
Kees Cook
Michal Hocko
reviewerOn Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]
Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation _as long as_ there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.
Quoted 1 line
81 files changed, 2126 insertions(+), 695 deletions(-)
Signature · 2 lines
Michal Hocko SUSE Labs
Suren Baghdasaryan
maintainerQuoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Thanks,
Suren.
Quoted 5 lines
Quoted 2 lines
81 files changed, 2126 insertions(+), 695 deletions(-)--
Michal Hocko
SUSE Labs
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.
Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
Signature · 3 lines
Cheers, David / dhildenb
Kent Overstreet
maintainerQuoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
Quoted 36 lines · Kent Overstreet
Quoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
Quoted 8 lines
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
Signature · 3 lines
Cheers, David / dhildenb
Kent Overstreet
maintainerQuoted 42 lines · David Hildenbrand
Quoted 41 lines · Kent Overstreet
Quoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Quoted 7 lines
Quoted 3 lines
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
A meeting wouldn't be out of the question, _if_ there is an agenda, but:
What's that coffeee mug say? I just survived another meeting that could've been an email? What exactly is the outcome we're looking for?
Is there info that people are looking for? I think we summed things up pretty well in the cover letter; if there are specifics that people want to discuss, that's why we emailed the series out.
There's people in this thread who've used this patchset in production and diagnosed real issues (gigabytes of memory gone missing, I heard the other day); I'm personally looking for them to chime in on this thread (Johannes, Pasha).
If it's just grumbling about "maintenance overhead" we need to get past
- well, people are going to have to accept that we can't deliver features without writing code, and I'm confident that the hooking in particular is about as clean as it's going to get, _regardless_ of toolchain support; and moreover it addresses what's been historically a pretty gaping hole in our ability to profile and understand the code we write.
Quoted 25 lines · Kent Overstreet
Quoted 24 lines · David Hildenbrand
Quoted 23 lines · Kent Overstreet
Quoted 22 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 19 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
You want to stall this effort for *three months* to schedule a meeting?
I would love to have better profiling of memory allocations inside XFS so that we can answer questions like "What's going on with these allocation stalls?" or "What memory is getting used, and where?" more quickly than we can now.
Right now I get to stare at tracepoints and printk crap until my eyes bleed, and maybe dchinner comes to my rescue and figures out what's going on sooner than I do. More often we just never figure it out because only the customer can reproduce the problem, the reams of data produced by ftrace is unmanageable, and BPF isn't always available.
I'm not thrilled by the large increase in macro crap in the allocation paths, but I don't know of a better way to instrument things. Our attempts to use _RET_IP in XFS to instrument its code paths have never worked quite right w.r.t. inlined functions and whatnot.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
From my outsider's perspective, nine months have gone by since the last LSF. Who has come up with a cleaner/better/faster way to do what Suren and Kent have done? Were those code changes integrated into this patchset? Or why not?
Most of what I saw in 2023 involved compiler changes (great; now I have to wait until RHEL 11/Debian 14 to use it) and/or still utilize fugly macros.
Recalling all the way back to suggestions made in 2022, who wrote the prototype for doing this via ftrace? Or BPF? How well did that go for counting allocation events and the like? I saw Tejun saying something about how they use BPF aggressively inside Meta, but that was about it.
Were any of those solutions significantly better than what's in front of us here?
I get it, a giant patch forcing everyone to know the difference between alloc_foo and alloc_foo_noperf offends my (yours?) stylistic sensibilities. On the other side, making analysis easier during customer escalations means we kernel people get data, answers, and solutions sooner instead of watching all our time get eaten up on L4 support and backporting hell.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
Quoted 8 lines
Quoted 3 lines
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
A meeting wouldn't be out of the question, _if_ there is an agenda, but:
What's that coffeee mug say? I just survived another meeting that could've been an email?
I congratulate you on your memory of my kitchen mug. Yes, that's what it says.
Quoted 11 lines
What exactly is the outcome we're looking for?
Is there info that people are looking for? I think we summed things up pretty well in the cover letter; if there are specifics that people want to discuss, that's why we emailed the series out.
There's people in this thread who've used this patchset in production and diagnosed real issues (gigabytes of memory gone missing, I heard the other day); I'm personally looking for them to chime in on this thread (Johannes, Pasha).
Quoted 7 lines
If it's just grumbling about "maintenance overhead" we need to get past
- well, people are going to have to accept that we can't deliver features without writing code, and I'm confident that the hooking in particular is about as clean as it's going to get, _regardless_ of toolchain support; and moreover it addresses what's been historically a pretty gaping hole in our ability to profile and understand the code we write.
Are you and Suren willing to pay whatever maintenance overhead there is?
--D
Kent Overstreet
maintainerQuoted 121 lines · Darrick J. Wong
Quoted 25 lines · Kent Overstreet
Quoted 24 lines · David Hildenbrand
Quoted 23 lines · Kent Overstreet
Quoted 22 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 19 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
You want to stall this effort for *three months* to schedule a meeting?
I would love to have better profiling of memory allocations inside XFS so that we can answer questions like "What's going on with these allocation stalls?" or "What memory is getting used, and where?" more quickly than we can now.
Right now I get to stare at tracepoints and printk crap until my eyes bleed, and maybe dchinner comes to my rescue and figures out what's going on sooner than I do. More often we just never figure it out because only the customer can reproduce the problem, the reams of data produced by ftrace is unmanageable, and BPF isn't always available.
I'm not thrilled by the large increase in macro crap in the allocation paths, but I don't know of a better way to instrument things. Our attempts to use
_RET_IPin XFS to instrument its code paths have never worked quite right w.r.t. inlined functions and whatnot.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
From my outsider's perspective, nine months have gone by since the last LSF. Who has come up with a cleaner/better/faster way to do what Suren and Kent have done? Were those code changes integrated into this patchset? Or why not?
Most of what I saw in 2023 involved compiler changes (great; now I have to wait until RHEL 11/Debian 14 to use it) and/or still utilize fugly macros.
Recalling all the way back to suggestions made in 2022, who wrote the prototype for doing this via ftrace? Or BPF? How well did that go for counting allocation events and the like? I saw Tejun saying something about how they use BPF aggressively inside Meta, but that was about it.
Were any of those solutions significantly better than what's in front of us here?
I get it, a giant patch forcing everyone to know the difference between
alloc_fooandalloc_foo_noperfoffends my (yours?) stylistic sensibilities. On the other side, making analysis easier during customer escalations means we kernel people get data, answers, and solutions sooner instead of watching all our time get eaten up on L4 support and backporting hell.Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
Quoted 8 lines
Quoted 3 lines
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
A meeting wouldn't be out of the question, _if_ there is an agenda, but:
What's that coffeee mug say? I just survived another meeting that could've been an email?
I congratulate you on your memory of my kitchen mug. Yes, that's what it says.
Quoted 11 lines
What exactly is the outcome we're looking for?
Is there info that people are looking for? I think we summed things up pretty well in the cover letter; if there are specifics that people want to discuss, that's why we emailed the series out.
There's people in this thread who've used this patchset in production and diagnosed real issues (gigabytes of memory gone missing, I heard the other day); I'm personally looking for them to chime in on this thread (Johannes, Pasha).
Quoted 7 lines
If it's just grumbling about "maintenance overhead" we need to get past
- well, people are going to have to accept that we can't deliver features without writing code, and I'm confident that the hooking in particular is about as clean as it's going to get, _regardless_ of toolchain support; and moreover it addresses what's been historically a pretty gaping hole in our ability to profile and understand the code we write.
Quoted 1 line
Are you and Suren willing to pay whatever maintenance overhead there is?
I'm still wondering what this supposed "maintenance overhead" is going to be...
As I use this patch series I occasionally notice places where a bunch of memory is being accounted to one line of code, and it would better be accounted to a caller - but then it's just a couple lines of code to fix that. You switch that callsite to the _noprof() version of whatever allocation it's doing, then add an alloc_hooks() wrapper at the place you do want it accounted.
That doesn't really feel like overhead to me, just the normal tweaking your tools to get the most out of them.
I will continue to do that for the code I'm looking at, yes.
If other people are doing that too, it'll be because they're also using memory allocation profiling and finding it valuable.
I did notice earlier that we're still lacking documentation in the Documentation/ directory; the workflow for "how you shift accounting to the right spot" is something that should go in there.
Suren Baghdasaryan
maintainerQuoted 43 lines · David Hildenbrand
Quoted 41 lines · Kent Overstreet
Quoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Quoted 7 lines
Quoted 3 lines
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
There will be a maintenance burden even with the cleanest proposed approach. We worked hard to make the patchset as clean as possible and if benefits still don't outweigh the maintenance cost then we should probably stop trying. At LSF/MM I would rather discuss functonal issues/requirements/improvements than alternative approaches to instrument allocators.
I'm happy to arrange a separate meeting with MM folks if that would help to progress on the cost/benefit decision.
Quoted 9 lines
--
Cheers,David / dhildenb
--
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
Quoted 48 lines · Suren Baghdasaryan
Quoted 47 lines · David Hildenbrand
Quoted 44 lines · Kent Overstreet
Quoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
Quoted 6 lines
Quoted 3 lines
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
There will be a maintenance burden even with the cleanest proposed approach.
Yes.
Quoted 3 lines
We worked hard to make the patchset as clean as possible and if benefits still don't outweigh the maintenance cost then we should probably stop trying.
Indeed.
Quoted 5 lines
At LSF/MM I would rather discuss functonal issues/requirements/improvements than alternative approaches to instrument allocators.
I'm happy to arrange a separate meeting with MM folks if that would help to progress on the cost/benefit decision.
Note that I am only proposing ways forward.
If you think you can easily achieve what Michal requested without all that, good.
My past experience was that LSF/MM / bi-weekly MM meetings were extremely helpful to reach consensus.
Signature · 3 lines
Cheers, David / dhildenb
Kent Overstreet
maintainerQuoted 69 lines · David Hildenbrand
Quoted 48 lines · Suren Baghdasaryan
Quoted 47 lines · David Hildenbrand
Quoted 44 lines · Kent Overstreet
Quoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
Quoted 6 lines
Quoted 3 lines
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
There will be a maintenance burden even with the cleanest proposed approach.
Yes.
Quoted 3 lines
We worked hard to make the patchset as clean as possible and if benefits still don't outweigh the maintenance cost then we should probably stop trying.
Indeed.
Quoted 5 lines
At LSF/MM I would rather discuss functonal issues/requirements/improvements than alternative approaches to instrument allocators.
I'm happy to arrange a separate meeting with MM folks if that would help to progress on the cost/benefit decision.
Quoted 4 lines
Note that I am only proposing ways forward.
If you think you can easily achieve what Michal requested without all that, good.
He requested something?
Quoted 70 lines · Kent Overstreet
Quoted 69 lines · David Hildenbrand
Quoted 48 lines · Suren Baghdasaryan
Quoted 47 lines · David Hildenbrand
Quoted 44 lines · Kent Overstreet
Quoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
Quoted 6 lines
Quoted 3 lines
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
There will be a maintenance burden even with the cleanest proposed approach.
Yes.
Quoted 3 lines
We worked hard to make the patchset as clean as possible and if benefits still don't outweigh the maintenance cost then we should probably stop trying.
Indeed.
Quoted 5 lines
At LSF/MM I would rather discuss functonal issues/requirements/improvements than alternative approaches to instrument allocators.
I'm happy to arrange a separate meeting with MM folks if that would help to progress on the cost/benefit decision.
Quoted 7 lines
Quoted 4 lines
Note that I am only proposing ways forward.
If you think you can easily achieve what Michal requested without all that, good.
He requested something?
This won't get merged without acks from MM people.
Signature · 3 lines
Cheers, David / dhildenb
Suren Baghdasaryan
maintainerQuoted 71 lines · Kent Overstreet
Quoted 69 lines · David Hildenbrand
Quoted 48 lines · Suren Baghdasaryan
Quoted 47 lines · David Hildenbrand
Quoted 44 lines · Kent Overstreet
Quoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
Quoted 6 lines
Quoted 3 lines
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
There will be a maintenance burden even with the cleanest proposed approach.
Yes.
Quoted 3 lines
We worked hard to make the patchset as clean as possible and if benefits still don't outweigh the maintenance cost then we should probably stop trying.
Indeed.
Quoted 5 lines
At LSF/MM I would rather discuss functonal issues/requirements/improvements than alternative approaches to instrument allocators.
I'm happy to arrange a separate meeting with MM folks if that would help to progress on the cost/benefit decision.
Quoted 6 lines
Quoted 4 lines
Note that I am only proposing ways forward.
If you think you can easily achieve what Michal requested without all that, good.
He requested something?
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
Quoted 78 lines · Suren Baghdasaryan
Quoted 76 lines · Kent Overstreet
Quoted 73 lines · David Hildenbrand
Quoted 48 lines · Suren Baghdasaryan
Quoted 47 lines · David Hildenbrand
Quoted 44 lines · Kent Overstreet
Quoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
Quoted 6 lines
Quoted 3 lines
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
There will be a maintenance burden even with the cleanest proposed approach.
Yes.
Quoted 3 lines
We worked hard to make the patchset as clean as possible and if benefits still don't outweigh the maintenance cost then we should probably stop trying.
Indeed.
Quoted 5 lines
At LSF/MM I would rather discuss functonal issues/requirements/improvements than alternative approaches to instrument allocators.
I'm happy to arrange a separate meeting with MM folks if that would help to progress on the cost/benefit decision.Note that I am only proposing ways forward.
If you think you can easily achieve what Michal requested without all that, good.
Quoted 7 lines
Quoted 1 line
He requested something?
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
I was talking about this: "I can live with all the downsides of the proposed implementationas long as there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers".
I certainly cannot be motivated at this point to review and ack this, unfortunately too much negative energy around here.
Signature · 3 lines
Cheers, David / dhildenb
Kent Overstreet
maintainerQuoted 87 lines · David Hildenbrand
Quoted 78 lines · Suren Baghdasaryan
Quoted 76 lines · Kent Overstreet
Quoted 73 lines · David Hildenbrand
Quoted 48 lines · Suren Baghdasaryan
Quoted 47 lines · David Hildenbrand
Quoted 44 lines · Kent Overstreet
Quoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
Quoted 6 lines
Quoted 3 lines
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
There will be a maintenance burden even with the cleanest proposed approach.
Yes.
Quoted 3 lines
We worked hard to make the patchset as clean as possible and if benefits still don't outweigh the maintenance cost then we should probably stop trying.
Indeed.
Quoted 5 lines
At LSF/MM I would rather discuss functonal issues/requirements/improvements than alternative approaches to instrument allocators.
I'm happy to arrange a separate meeting with MM folks if that would help to progress on the cost/benefit decision.Note that I am only proposing ways forward.
If you think you can easily achieve what Michal requested without all that, good.
Quoted 7 lines
Quoted 1 line
He requested something?
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
Quoted 7 lines
I was talking about this: "I can live with all the downsides of the proposed implementationas long as there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers".
I certainly cannot be motivated at this point to review and ack this, unfortunately too much negative energy around here.
David, this kind of reaction is exactly why I was telling Andrew I was going to submit this as a direct pull request to Linus.
This is an important feature; if we can't stay focused ot the technical and get it done that's what I'll do.
Quoted 93 lines · Kent Overstreet
Quoted 92 lines · David Hildenbrand
Quoted 78 lines · Suren Baghdasaryan
Quoted 76 lines · Kent Overstreet
Quoted 73 lines · David Hildenbrand
Quoted 48 lines · Suren Baghdasaryan
Quoted 47 lines · David Hildenbrand
Quoted 44 lines · Kent Overstreet
Quoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
Quoted 6 lines
Quoted 3 lines
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
There will be a maintenance burden even with the cleanest proposed approach.
Yes.
Quoted 3 lines
We worked hard to make the patchset as clean as possible and if benefits still don't outweigh the maintenance cost then we should probably stop trying.
Indeed.
Quoted 5 lines
At LSF/MM I would rather discuss functonal issues/requirements/improvements than alternative approaches to instrument allocators.
I'm happy to arrange a separate meeting with MM folks if that would help to progress on the cost/benefit decision.Note that I am only proposing ways forward.
If you think you can easily achieve what Michal requested without all that, good.
Quoted 7 lines
Quoted 1 line
He requested something?
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
I was talking about this: "I can live with all the downsides of the proposed implementationas long as there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers".
Quoted 8 lines
Quoted 2 lines
I certainly cannot be motivated at this point to review and ack this, unfortunately too much negative energy around here.
David, this kind of reaction is exactly why I was telling Andrew I was going to submit this as a direct pull request to Linus.
This is an important feature; if we can't stay focused ot the technical and get it done that's what I'll do.
Kent, I started this with "Would it make sense" in an attempt to help Suren and you to finally make progress with this, one way or the other. I know that there were ways in the past to get the MM community to agree on such things.
I tried to be helpful, finding ways *not having to* bypass the MM community to get MM stuff merged.
The reply I got is mostly negative energy.
So you don't need my help here, understood.
But I will fight against any attempts to bypass the MM community.
Signature · 3 lines
Cheers, David / dhildenb
Suren Baghdasaryan
maintainerQuoted 109 lines · David Hildenbrand
Quoted 93 lines · Kent Overstreet
Quoted 92 lines · David Hildenbrand
Quoted 78 lines · Suren Baghdasaryan
Quoted 76 lines · Kent Overstreet
Quoted 73 lines · David Hildenbrand
Quoted 48 lines · Suren Baghdasaryan
Quoted 47 lines · David Hildenbrand
Quoted 44 lines · Kent Overstreet
Quoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 12 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]Quoted 4 lines
We're aiming to get this in the next merge window, for 6.9. The feedback
we've gotten has been that even out of tree this patchset has already
been useful, and there's a significant amount of other work gated on the
code tagging functionality included in this patchset [2].I suspect it will not come as a surprise that I really dislike the implementation proposed here. I will not repeat my arguments, I have done so on several occasions already.
Quoted 7 lines
Anyway, I didn't go as far as to nak it even though I _strongly_ believe this debugging feature will add a maintenance overhead for a very long time. I can live with all the downsides of the proposed implementation
_aslongas_there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers so aiming into the next merge window is more than little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
Quoted 6 lines
Quoted 3 lines
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
There will be a maintenance burden even with the cleanest proposed approach.
Yes.
Quoted 3 lines
We worked hard to make the patchset as clean as possible and if benefits still don't outweigh the maintenance cost then we should probably stop trying.
Indeed.
Quoted 5 lines
At LSF/MM I would rather discuss functonal issues/requirements/improvements than alternative approaches to instrument allocators.
I'm happy to arrange a separate meeting with MM folks if that would help to progress on the cost/benefit decision.Note that I am only proposing ways forward.
If you think you can easily achieve what Michal requested without all that, good.
Quoted 7 lines
Quoted 1 line
He requested something?
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
I was talking about this: "I can live with all the downsides of the proposed implementationas long as there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers".
Quoted 8 lines
Quoted 2 lines
I certainly cannot be motivated at this point to review and ack this, unfortunately too much negative energy around here.
David, this kind of reaction is exactly why I was telling Andrew I was going to submit this as a direct pull request to Linus.
This is an important feature; if we can't stay focused ot the technical and get it done that's what I'll do.
Kent, I started this with "Would it make sense" in an attempt to help Suren and you to finally make progress with this, one way or the other. I know that there were ways in the past to get the MM community to agree on such things.
Quoted 8 lines
I tried to be helpful, finding ways *not having to* bypass the MM community to get MM stuff merged.
The reply I got is mostly negative energy.
So you don't need my help here, understood.
But I will fight against any attempts to bypass the MM community.
Well, I'm definitely not trying to bypass the MM community, that's why this patchset is posted. Not sure why people can't voice their opinion on the benefit/cost balance of the patchset over the email... But if a meeting would be more productive I'm happy to set it up.
Quoted 6 lines
--
Cheers,David / dhildenb
Quoted 5 lines
Quoted 5 lines
I tried to be helpful, finding ways *not having to* bypass the MM community to get MM stuff merged.
The reply I got is mostly negative energy.
Quoted 8 lines
Quoted 3 lines
So you don't need my help here, understood.
But I will fight against any attempts to bypass the MM community.
Well, I'm definitely not trying to bypass the MM community, that's why this patchset is posted. Not sure why people can't voice their opinion on the benefit/cost balance of the patchset over the email... But if a meeting would be more productive I'm happy to set it up.
Discussing these concerns during the next available MM Alignment session makes sense. At a minimum, Suren and Kent can present their reasons for believing the current approach is superior to the previously proposed alternatives.
However, delaying the discussion and feature merge until after LSF/MM seems unnecessary. As I mentioned earlier in this thread, we've already leveraged the concepts within this feature to debug unexplained memory overhead, saving us many terabytes of memory. This was just the initial benefit; we haven't even explored its full potential to track every allocation path.
Pasha
Kent Overstreet
maintainerQuoted 14 lines · Pasha Tatashin
Quoted 5 lines
Quoted 5 lines
I tried to be helpful, finding ways *not having to* bypass the MM community to get MM stuff merged.
The reply I got is mostly negative energy.
Quoted 8 lines
Quoted 3 lines
So you don't need my help here, understood.
But I will fight against any attempts to bypass the MM community.
Well, I'm definitely not trying to bypass the MM community, that's why this patchset is posted. Not sure why people can't voice their opinion on the benefit/cost balance of the patchset over the email... But if a meeting would be more productive I'm happy to set it up.
Quoted 4 lines
Discussing these concerns during the next available MM Alignment session makes sense. At a minimum, Suren and Kent can present their reasons for believing the current approach is superior to the previously proposed alternatives.
Hang on though: I believe we did so adequately within this thread. Both in the cover letter, and I further outlined exactly what the hooks need to do, and cited the exact code.
Nobody seems to be complaining about the specifics, so I'm not sure what would be on the agenda?
Quoted 115 lines · Suren Baghdasaryan
Quoted 114 lines · David Hildenbrand
Quoted 93 lines · Kent Overstreet
Quoted 92 lines · David Hildenbrand
Quoted 78 lines · Suren Baghdasaryan
Quoted 76 lines · Kent Overstreet
Quoted 73 lines · David Hildenbrand
Quoted 48 lines · Suren Baghdasaryan
Quoted 47 lines · David Hildenbrand
Quoted 44 lines · Kent Overstreet
Quoted 27 lines · David Hildenbrand
Quoted 21 lines · Suren Baghdasaryan
Quoted 19 lines · Michal Hocko
On Mon 12-02-24 13:38:46, Suren Baghdasaryan wrote:
[...]
We're aiming to get this in the next merge window, for 6.9. The feedback
we've gotten has been that even out of tree this patchset has already
been useful, and there's a significant amount of other work gated on the
code tagging functionality included in this patchset [2].I suspect it will not come as a surprise that I really dislike the
implementation proposed here. I will not repeat my arguments, I have
done so on several occasions already.Anyway, I didn't go as far as to nak it even though I _strongly_ believe
this debugging feature will add a maintenance overhead for a very long
time. I can live with all the downsides of the proposed implementation
_as long as_ there is a wider agreement from the MM community as this is
where the maintenance cost will be payed. So far I have not seen (m)any
acks by MM developers so aiming into the next merge window is more than
little rushed.Quoted 4 lines
We tried other previously proposed approaches and all have their downsides without making maintenance much easier. Your position is understandable and I think it's fair. Let's see if others see more benefit than cost here.
Quoted 7 lines
Would it make sense to discuss that at LSF/MM once again, especially covering why proposed alternatives did not work out? LSF/MM is not "too far" away (May).
I recall that the last LSF/MM session on this topic was a bit unfortunate (IMHO not as productive as it could have been). Maybe we can finally reach a consensus on this.
I'd rather not delay for more bikeshedding. Before agreeing to LSF I'd need to see a serious proposl - what we had at the last LSF was people jumping in with half baked alternative proposals that very much hadn't been thought through, and I see no need to repeat that.
Like I mentioned, there's other work gated on this patchset; if people want to hold this up for more discussion they better be putting forth something to discuss.
Quoted 6 lines
Quoted 3 lines
I'm thinking of ways on how to achieve Michal's request: "as long as there is a wider agreement from the MM community". If we can achieve that without LSF, great! (a bi-weekly MM meeting might also be an option)
There will be a maintenance burden even with the cleanest proposed approach.
Yes.
Quoted 3 lines
We worked hard to make the patchset as clean as possible and if benefits still don't outweigh the maintenance cost then we should probably stop trying.
Indeed.
Quoted 5 lines
At LSF/MM I would rather discuss functonal issues/requirements/improvements than alternative approaches to instrument allocators.
I'm happy to arrange a separate meeting with MM folks if that would help to progress on the cost/benefit decision.Note that I am only proposing ways forward.
If you think you can easily achieve what Michal requested without all that, good.
Quoted 7 lines
Quoted 1 line
He requested something?
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
I was talking about this: "I can live with all the downsides of the proposed implementationas long as there is a wider agreement from the MM community as this is where the maintenance cost will be payed. So far I have not seen (m)any acks by MM developers".
Quoted 8 lines
Quoted 2 lines
I certainly cannot be motivated at this point to review and ack this, unfortunately too much negative energy around here.
David, this kind of reaction is exactly why I was telling Andrew I was going to submit this as a direct pull request to Linus.
This is an important feature; if we can't stay focused ot the technical and get it done that's what I'll do.
Kent, I started this with "Would it make sense" in an attempt to help Suren and you to finally make progress with this, one way or the other. I know that there were ways in the past to get the MM community to agree on such things.
I tried to be helpful, finding ways *not having to* bypass the MM community to get MM stuff merged.
The reply I got is mostly negative energy.
Quoted 8 lines
Quoted 3 lines
So you don't need my help here, understood.
But I will fight against any attempts to bypass the MM community.
Well, I'm definitely not trying to bypass the MM community, that's why this patchset is posted. Not sure why people can't voice their opinion on the benefit/cost balance of the patchset over the email... But if a meeting would be more productive I'm happy to set it up.
If you can get the acks without any additional meetings, great. The replies from Pasha and Johannes are encouraging, let's hope core memory-allocator people will voice their opinion here.
If you come to the conclusion that another meeting would help getting maintainers's attention and sorting out some of the remaining concerns, feel free to schedule a meeting with Dave R. I suspect only the slot next week is already taken. In the past, we also had "special" meetings just for things to make progress faster.
If you're looking for ideas on what the agenda of such a meeting could look like, I'll happily discuss that with you off-list.
v2 was more than 3 months ago. If it's really about minor details here, waiting another 3 months for LSF/MM is indeed not reasonable.
Myself, I'll be happy not having to sit through another LSF/MM session of that kind. The level of drama is exceptional and I'm hoping it won't be the new norm in the MM space.
Good luck!
Signature · 3 lines
Cheers, David / dhildenb
Kent Overstreet
maintainerQuoted 9 lines · Suren Baghdasaryan
Quoted 7 lines · Kent Overstreet
Quoted 4 lines · David Hildenbrand
Quoted 1 line · Suren Baghdasaryan
On Tue, Feb 13, 2024 at 2:17 PM David Hildenbrand <[email protected]> wrote:
If you think you can easily achieve what Michal requested without all that, good.
Quoted 6 lines
Quoted 1 line
He requested something?
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
Hang on, let's look at the actual code.
This is what instrumenting an allocation function looks like:
#define krealloc_array(...) alloc_hooks(krealloc_array_noprof(__VA_ARGS__))
IOW, we have to:
- rename krealloc_array to krealloc_array_noprof
- replace krealloc_array with a one wrapper macro call
Is this really all we're getting worked up over?
The renaming we need regardless, because the thing that makes this approach efficient enough to run in production is that we account at _one_ point in the callstack, we don't save entire backtraces.
And thus we need to explicitly annotate which one that is; which means we need _noprof() versions of functions for when the accounting is done by an outer wraper (e.g. mempool).
And, as I keep saying: that alloc_hooks() macro will also get us _per callsite fault injection points_, and we really need that because - if you guys have been paying attention to other threads - whenever moving more stuff to PF_MEMALLOC_* flags comes up (including adding PF_MEMALLOC_NORECLAIM), the issue of small allocations not failing and not being testable keeps coming up.
Quoted 37 lines · Kent Overstreet
Quoted 9 lines · Suren Baghdasaryan
Quoted 7 lines · Kent Overstreet
Quoted 4 lines · David Hildenbrand
Quoted 1 line · Suren Baghdasaryan
On Tue, Feb 13, 2024 at 2:17 PM David Hildenbrand <[email protected]> wrote:
If you think you can easily achieve what Michal requested without all that, good.
Quoted 6 lines
Quoted 1 line
He requested something?
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
Hang on, let's look at the actual code.
This is what instrumenting an allocation function looks like:
#define
krealloc_array(...)alloc_hooks(krealloc_array_noprof(__VA_ARGS__))IOW, we have to:
- renamekrealloc_arraytokrealloc_array_noprof
- replacekrealloc_arraywith a one wrapper macro callIs this really all we're getting worked up over?
The renaming we need regardless, because the thing that makes this approach efficient enough to run in production is that we account at _one_ point in the callstack, we don't save entire backtraces.
And thus we need to explicitly annotate which one that is; which means we need
_noprof()versions of functions for when the accounting is done by an outer wraper (e.g. mempool).
Quoted 6 lines
And, as I keep saying: that
alloc_hooks()macro will also get us_percallsite fault injectionpoints_, and we really need that because - if you guys have been paying attention to other threads - whenever moving more stuff to PF_MEMALLOC_* flags comes up (including addingPF_MEMALLOC_NORECLAIM), the issue of small allocations not failing and not being testable keeps coming up.
How exactly do you envision the fault injection to help here? The proposals are about scoping via a process flag, and the process may then call just about anything under that scope. So if our tool is per callsite fault injection points, how do we know which callsites to enable to focus the fault injection on the particular scope?
Kent Overstreet
maintainerQuoted 8 lines · Vlastimil Babka
Quoted 6 lines · Kent Overstreet
And, as I keep saying: that
alloc_hooks()macro will also get us_percallsite fault injectionpoints_, and we really need that because - if you guys have been paying attention to other threads - whenever moving more stuff to PF_MEMALLOC_* flags comes up (including addingPF_MEMALLOC_NORECLAIM), the issue of small allocations not failing and not being testable keeps coming up.
Quoted 5 lines
How exactly do you envision the fault injection to help here? The proposals are about scoping via a process flag, and the process may then call just about anything under that scope. So if our tool is per callsite fault injection points, how do we know which callsites to enable to focus the fault injection on the particular scope?
So the question with fault injection is - how do we integrate it into our existing tests?
We need fault injection that we can integrate into our existing tests because that's the only way to get the code coverage we need - writing new tests that cover all the error paths isn't going to happen, and wouldn't work as well anyways.
But the trouble with injecting memory allocation failures is that they'll result in errors bubbling up to userspace, and in unpredictable ways.
We _definitely_ cannot enable random memory allocation faults for the entire kernel at runttme - or rather we _could_, and that would actually be great to do as a side project; but that's not something we can do in our existing automated tests because the results will be completely unpredictable. If we did that the goal would be to just make sure the kernel doesn't explode - but what we actually want is for our automated pass/fail tests to still pass; we need to constrain what will fail.
So we need at a minumum to be able to only enable memory allocation failures for the code we're interested in testing (file/module) - enabling memory allocation failures in some other random subsystem we're not developing or looking at isn't what we want.
Beyond that, it's very much subsystem dependent. For bcachefs, my main strategy has been to flip on random (1%) memory allocation failures after the filesystem has mounted. During startup, we do a ton of allocations (I cover those with separate tests), but after startup we should be able to run normally in the precence of allocation failures without ever returning an error to userspace - so that's what I'm trying to test.
Matthew Wilcox
maintainerQuoted 8 lines · Kent Overstreet
This is what instrumenting an allocation function looks like:
#define
krealloc_array(...)alloc_hooks(krealloc_array_noprof(__VA_ARGS__))IOW, we have to:
- renamekrealloc_arraytokrealloc_array_noprof
- replacekrealloc_arraywith a one wrapper macro call
Quoted 5 lines
Is this really all we're getting worked up over?
The renaming we need regardless, because the thing that makes this approach efficient enough to run in production is that we account at _one_ point in the callstack, we don't save entire backtraces.
I'm probably going to regret getting involved in this thread, but since Suren already decided to put me on the cc ...
There might be a way to do it without renaming. We have a bit of the linker script called SCHED_TEXT which lets us implement in_sched_functions(). ie we could have the equivalent of
include/linux/sched/debug.h:#define __sched __section(".sched.text")
perhaps #define __memalloc __section(".memalloc.text") which would do all the necessary magic to know where the backtrace should stop.
Kent Overstreet
maintainerQuoted 22 lines · Matthew Wilcox
Quoted 8 lines · Kent Overstreet
This is what instrumenting an allocation function looks like:
#define
krealloc_array(...)alloc_hooks(krealloc_array_noprof(__VA_ARGS__))IOW, we have to:
- renamekrealloc_arraytokrealloc_array_noprof
- replacekrealloc_arraywith a one wrapper macro callQuoted 5 lines
Is this really all we're getting worked up over?
The renaming we need regardless, because the thing that makes this approach efficient enough to run in production is that we account at _one_ point in the callstack, we don't save entire backtraces.
I'm probably going to regret getting involved in this thread, but since Suren already decided to put me on the cc ...
There might be a way to do it without renaming. We have a bit of the linker script called
SCHED_TEXTwhich lets us implementin_sched_functions(). ie we could have the equivalent of
Quoted 5 lines
include/linux/sched/debug.h:#define
__sched__section(".sched.text")perhaps #define
__memalloc__section(".memalloc.text")which would do all the necessary magic to know where the backtrace should stop.
Could we please try to get through the cover letter before proposing alternatives? I already explained there why we need the renaming.
In addition, you can't create the per-callsite codetag with linker magic; you nede the macro for that.
Instead of citing myself again, I'm just going to post what I was working on last night for the documentation directory:
.. SPDX-License-Identifier: GPL-2.0
===========================
MEMORY ALLOCATION PROFILING
===========================
Low overhead (suitable for production) accounting of all memory allocations, tracked by file and line number.
Usage:
kconfig options:
- CONFIG_MEM_ALLOC_PROFILING
- CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT
- CONFIG_MEM_ALLOC_PROFILING_DEBUG
adds warnings for allocations that weren't accounted because of a missing annotation
sysctl:
/proc/sys/vm/mem_profiling
Runtime info:
/proc/allocinfo
Example output:
root@moria-kvm:~# sort -h /proc/allocinfo|tail
3.11MiB 2850 fs/ext4/super.c:1408 module:ext4 func:ext4_alloc_inode
3.52MiB 225 kernel/fork.c:356 module:fork func:alloc_thread_stack_node
3.75MiB 960 mm/page_ext.c:270 module:page_ext func:alloc_page_ext
4.00MiB 2 mm/khugepaged.c:893 module:khugepaged func:hpage_collapse_alloc_folio
10.5MiB 168 block/blk-mq.c:3421 module:blk_mq func:blk_mq_alloc_rqs
14.0MiB 3594 include/linux/gfp.h:295 module:filemap func:folio_alloc_noprof
26.8MiB 6856 include/linux/gfp.h:295 module:memory func:folio_alloc_noprof
64.5MiB 98315 fs/xfs/xfs_rmap_item.c:147 module:xfs func:xfs_rui_init
98.7MiB 25264 include/linux/gfp.h:295 module:readahead func:folio_alloc_noprof
125MiB 7357 mm/slub.c:2201 module:slub func:alloc_slab_pageTheory of operation:
Memory allocation profiling builds off of code tagging, which is a library for declaring static structs (that typcially describe a file and line number in some way, hence code tagging) and then finding and operating on them at runtime
- i.e. iterating over them to print them in debugfs/procfs.
To add accounting for an allocation call, we replace it with a macro invocation, alloc_hooks(), that
- declares a code tag
- stashes a pointer to it in task_struct
- calls the real allocation function
- and finally, restores the task_struct alloc tag pointer to its previous value.
This allows for alloc_hooks() calls to be nested, with the most recent one taking effect. This is important for allocations internal to the mm/ code that do not properly belong to the outer allocation context and should be counted
separately: for example, slab object extension vectors, or when the slab allocates pages from the page allocator.
Thus, proper usage requires determining which function in an allocation call stack should be tagged. There are many helper functions that essentially wrap e.g. kmalloc() and do a little more work, then are called in multiple places; we'll generally want the accounting to happen in the callers of these helpers, not in the helpers themselves.
To fix up a given helper, for example foo(), do the following:
- switch its allocation call to the _noprof() version, e.g. kmalloc_noprof()
- rename it to foo_noprof()
- define a macro version of foo() like so:
#define foo(...) alloc_hooks(foo_noprof(__VA_ARGS__))
Michal Hocko
reviewerQuoted 4 lines · Suren Baghdasaryan
Quoted 2 lines · Kent Overstreet
On Tue, Feb 13, 2024 at 11:48:41PM +0100, David Hildenbrand wrote:
[...]
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
If you think you can easily achieve what Michal requested without all that, good.
He requested something?
Yes, a cleaner instrumentation.
Nope, not really. You have indicated you want to target this version for the _next_ merge window without any acks, really. If you want to go forward with this then you should gain a support from the MM community at least. Why? Because the whole macro layering is adding maintenance cost for MM people.
I have expressed why I absolutely hate the additional macro layer. We have been through similar layers of macros in other areas (not to mention page allocator interface itself) and it has _always_ turned out a bad idea long term. I do not see why this case should be any different.
The whole kernel is moving to a dynamic tracing realm and now we are going to build a statically macro based tracing infrastructure which will need tweaking anytime real memory consumers are one layer up the existing macro infrastructure (do not forget quite a lot of allocations are in library functions) and/or we need to modify the allocator API in some way. Call me unimpressed!
Now, I fully recognize that the solution doesn't really have to be perfect in order to be useful. Hence I never NAKed it even though I really _dislike_ the approach. I have expected you will grow the community support over time if this is indeed the only feasible approach but that is not reflected in the series posted here. If you find a support I will not stand in the way.
Quoted 4 lines
Unfortunately the cleanest one is not
possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
I am pretty sure you have invested a non-trivial time into evaluating other ways, yet your cover letter is rather modest about any details:
: - looked at alternate hooking methods.
: There were suggestions on alternate methods (compiler attribute, : trampolines), but they wouldn't have made the patchset any cleaner : (we still need to have different function versions for accounting vs. no : accounting to control at which point in a call chain the accounting : happens), and they would have added a dependency on toolchain : support.
First immediate question would be: What about page_owner? I do remember the runtime overhead being discussed but I do not really remember any actual numbers outside of artificial workloads. Has this been investigated? Is our stack unwinder the problem? Etc.
Also what are the biggest obstacles to efficiently track allocations via our tracing infrastructure? Has this been investigated? What were conclusions?
Signature · 2 lines
Michal Hocko SUSE Labs
Andrew Morton
maintainerQuoted 9 lines · On Tue, 13 Feb 2024 14:59:11 -0800 Suren Baghdasaryan <[email protected]> wrote:
Quoted 4 lines
Quoted 2 lines
If you think you can easily achieve what Michal requested without all that, good.
He requested something?
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
Can we please be told much more about this compiler feature? Description of what it is, what it does, how it will affect this kernel feature, etc.
Who is developing it and when can we expect it to become available?
Will we be able to migrate to it without back-compatibility concerns? (I think "you need quite recent gcc for memory profiling" is reasonable).
Because: if the maintainability issues which Michel describes will be significantly addressed with the gcc support then we're kinda reviewing the wrong patchset. Yes, it may be a maintenance burden initially, but at some (yet to be revealed) time in the future, this will be addressed with the gcc support?
Suren Baghdasaryan
maintainerQuoted 8 lines · Andrew Morton
Quoted 5 lines · On Tue, 13 Feb 2024 14:59:11 -0800 Suren Baghdasaryan <[email protected]> wrote:
Quoted 4 lines
Quoted 2 lines
If you think you can easily achieve what Michal requested without all that, good.
He requested something?
Quoted 8 lines
Quoted 4 lines
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
Can we please be told much more about this compiler feature? Description of what it is, what it does, how it will affect this kernel feature, etc.
Sure. The compiler support will be in a form of a new __attribute__, simplified example:
// generate data for the wrapper
static void _alloc_tag()
{
static struct alloc_tag _alloc_tag __section ("alloc_tags")
= { .ct = CODE_TAG_INIT, .counter = 0 };
}static inline int
wrapper (const char *name, int x, int (*callee) (const char *, int),
struct alloc_tag *callsite_data)
{
callsite_data->counter++;
printf ("Call #%d from %s:%d (%s)\n", callsite_data->counter,
callsite_data->ct.filename, callsite_data->ct.lineno,
callsite_data->ct.function); int ret = callee (name, x);
printf ("Returned: %d\n", ret);
return ret;
}
__attribute__((annotate("callsite_wrapped_by", wrapper, _alloc_tag))) int foo(const char* name, int x);
int foo(const char* name, int x) {
printf ("Hello %s, %d!\n", name, x);
return x;
}
Which we will be able to attach to a function without changing its name and preserving the namespace (it applies only to functions with that name, not everything else).
Note that we will still need _noprof versions of the allocators.
Quoted 2 lines
Who is developing it and when can we expect it to become available?
Aleksei Vetrov (google) with the help of Nick Desaulniers (google). Both are CC'ed on this email.
After several iterations Aleksei has a POC which we are evaluating
(https://github.com/llvm/llvm-project/compare/main...noxwell:llvm-project:callsite-wrapper-tree-transform).
Once it's in good shape we are going to engage with CLANG and GCC community to get it upstreamed. When it will become available and when the distributions will pick it up is anybody's guess. Upstreaming is usually a lengthy process.
Quoted 4 lines
Will we be able to migrate to it without back-compatibility concerns? (I think "you need quite recent gcc for memory profiling" is reasonable).
The migration should be quite straight-forward, replacing the macros with functions with that attribute.
Quoted 7 lines
Because: if the maintainability issues which Michel describes will be significantly addressed with the gcc support then we're kinda reviewing the wrong patchset. Yes, it may be a maintenance burden initially, but at some (yet to be revealed) time in the future, this will be addressed with the gcc support?
That's what I'm aiming for. I just don't want this placed on hold until the compiler support is widely available, which might take years.
Quoted 1 line
Kent Overstreet
maintainerQuoted 24 lines · Andrew Morton
Quoted 9 lines · On Tue, 13 Feb 2024 14:59:11 -0800 Suren Baghdasaryan <[email protected]> wrote:
Quoted 4 lines
Quoted 2 lines
If you think you can easily achieve what Michal requested without all that, good.
He requested something?
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
Can we please be told much more about this compiler feature? Description of what it is, what it does, how it will affect this kernel feature, etc.
Who is developing it and when can we expect it to become available?
Will we be able to migrate to it without back-compatibility concerns? (I think "you need quite recent gcc for memory profiling" is reasonable).
Quoted 5 lines
Because: if the maintainability issues which Michel describes will be significantly addressed with the gcc support then we're kinda reviewing the wrong patchset. Yes, it may be a maintenance burden initially, but at some (yet to be revealed) time in the future, this will be addressed with the gcc support?
Even if we had compiler magic, after considering it more I don't think the patchset would be improved by it - I would still prefer to stick with the macro approach.
There's also a lot of unresolved questions about whether the compiler approach would even end being what we need; we need macro expansion to happen in the caller of the allocation function, and that's another level of hooking that I don't think the compiler people are even considering yet, since cpp runs before the main part of the compiler; if C macros worked and were implemented more like Rust macros I'm sure it could be done - in fact, I think this could all be done in Rust _without_ any new compiler support - but in C, this is a lot to ask.
Let's look at the instrumentation again. There's two steps:
- Renaming the original function to _noprof
- Adding a hooked version of the original function.
We need to do the renaming regardless of what approach we take in order to correctly handle allocations that happen inside the context of an existing alloc tag hook but should not be accounted to the outer context; we do that by selecting the alloc_foo() or alloc_foo_noprof() version as appropriate.
It's important to get this right; consider slab object extension vectors or the slab allocator allocating pages from the page allocator.
Second step, adding a hooked version of the original function. We do that with
#define alloc_foo(...) alloc_hooks(alloc_foo_noprof(__VA_ARGS__))
That's pretty clean, if you ask me. The only way to make it more succint be if it were possible for a C macro to define a new macro, then it could be just
alloc_fn(alloc_foo);
But honestly, the former is probably preferable anyways from a ctags/cscope POV.
Suren Baghdasaryan
maintainerQuoted 32 lines · Kent Overstreet
Quoted 24 lines · Andrew Morton
Quoted 9 lines · On Tue, 13 Feb 2024 14:59:11 -0800 Suren Baghdasaryan <[email protected]> wrote:
Quoted 4 lines
Quoted 2 lines
If you think you can easily achieve what Michal requested without all that, good.
He requested something?
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
Can we please be told much more about this compiler feature? Description of what it is, what it does, how it will affect this kernel feature, etc.
Who is developing it and when can we expect it to become available?
Will we be able to migrate to it without back-compatibility concerns? (I think "you need quite recent gcc for memory profiling" is reasonable).
Quoted 5 lines
Because: if the maintainability issues which Michel describes will be significantly addressed with the gcc support then we're kinda reviewing the wrong patchset. Yes, it may be a maintenance burden initially, but at some (yet to be revealed) time in the future, this will be addressed with the gcc support?
Quoted 7 lines
Even if we had compiler magic, after considering it more I don't think the patchset would be improved by it - I would still prefer to stick with the macro approach.
There's also a lot of unresolved questions about whether the compiler approach would even end being what we need; we need macro expansion to happen in the caller of the allocation function
For the record, that's what this attribute will be doing. So it should cover our usecase.
Quoted 33 lines
, and that's another
level of hooking that I don't think the compiler people are even considering yet, since cpp runs before the main part of the compiler; if C macros worked and were implemented more like Rust macros I'm sure it could be done - in fact, I think this could all be done in Rust _without_ any new compiler support - but in C, this is a lot to ask.Let's look at the instrumentation again. There's two steps:
- Renaming the original function to
_noprof
- Adding a hooked version of the original function.We need to do the renaming regardless of what approach we take in order to correctly handle allocations that happen inside the context of an existing alloc tag hook but should not be accounted to the outer context; we do that by selecting the
alloc_foo()oralloc_foo_noprof()version as appropriate.It's important to get this right; consider slab object extension vectors or the slab allocator allocating pages from the page allocator.
Second step, adding a hooked version of the original function. We do that with
#define
alloc_foo(...)alloc_hooks(alloc_foo_noprof(__VA_ARGS__))That's pretty clean, if you ask me. The only way to make it more succint be if it were possible for a C macro to define a new macro, then it could be just
alloc_fn(alloc_foo);But honestly, the former is probably preferable anyways from a ctags/cscope POV.
Kent Overstreet
maintainerQuoted 38 lines · Suren Baghdasaryan
Quoted 36 lines · Kent Overstreet
Quoted 24 lines · Andrew Morton
Quoted 9 lines · On Tue, 13 Feb 2024 14:59:11 -0800 Suren Baghdasaryan <[email protected]> wrote:
Quoted 4 lines
Quoted 2 lines
If you think you can easily achieve what Michal requested without all that, good.
He requested something?
Yes, a cleaner instrumentation. Unfortunately the cleanest one is not possible until the compiler feature is developed and deployed. And it still would require changes to the headers, so don't think it's worth delaying the feature for years.
Can we please be told much more about this compiler feature? Description of what it is, what it does, how it will affect this kernel feature, etc.
Who is developing it and when can we expect it to become available?
Will we be able to migrate to it without back-compatibility concerns? (I think "you need quite recent gcc for memory profiling" is reasonable).
Quoted 5 lines
Because: if the maintainability issues which Michel describes will be significantly addressed with the gcc support then we're kinda reviewing the wrong patchset. Yes, it may be a maintenance burden initially, but at some (yet to be revealed) time in the future, this will be addressed with the gcc support?
Even if we had compiler magic, after considering it more I don't think the patchset would be improved by it - I would still prefer to stick with the macro approach.
Quoted 6 lines
Quoted 3 lines
There's also a lot of unresolved questions about whether the compiler approach would even end being what we need; we need macro expansion to happen in the caller of the allocation function
For the record, that's what this attribute will be doing. So it should cover our usecase.
That wasn't clear in the meeting we had the other day; all that was discussed there was the attribute syntax, as I recall.
So say that does work out (and I don't think that's a given; if I were a compiler person I don't think I'd be interested in this strange half macro, half inline function beast); all that has accomplished is to get rid of the need for the renaming - the _noprof() versions of functions.
So then how do you distinguish where in the callstack the accounting happens?
If you say "it happens at the outermost wrapper", then what happens is
- Extra overhead for all the inner wrapper invocations, where they have to now check "actually, we already have an alloc tag, don't do anything". That's a cost, and given how much time we spent shaving cycles and branches during development it's not one we want.
- Inner allocations that shouldn't be accounted to the outer context are now a major problem, because they silently will be accounted there and never noticed.
With our approach, inner allocations are by default (i.e. when we haven't switched them to the _noprof() variant) accounted to their own alloc tag; that way, when we're reading the /proc/allocinfo output, we can examine them and check if they should be collapsed to the outer context. With this approach they won't be seen.
So no, we still don't want the compiler approach.
Johannes Weiner
maintainerI'll do a more throrough code review, but before the discussion gets too sidetracked, I wanted to add my POV on the overall merit of the direction that is being proposed here.
I have backported and used this code for debugging production issues before. Logging into a random host with an unfamiliar workload and being able to get a reliable, comprehensive list of kernel memory consumers is one of the coolest things I have seen in a long time. This is a huge improvement to sysadmin quality of life.
It's also a huge improvement for MM developers. We're the first points of contact for memory regressions that can be caused by pretty much any driver or subsystem in the kernel.
I encourage anybody who is undecided on whether this is worth doing to build a kernel with these patches applied and run it on their own machine. I think you'll be surprised what you'll find - and how myopic and uninformative /proc/meminfo feels in comparison to this. Did you know there is a lot more to modern filesystems than the VFS objects we are currently tracking? :)
Then imagine what this looks like on a production host running a complex mix of filesystems, enterprise networking, bpf programs, gpus and accelerators etc.
Backporting the code to a slightly older production kernel wasn't too difficult. The instrumentation layering is explicit, clean, and fairly centralized, so resolving minor conflicts around the _noprof renames and the wrappers was pretty straight-forward.
When we talk about maintenance cost, a fair shake would be to weigh it against the cost and reliability of our current method: evaluating consumers in the kernel on a case-by-case basis and annotating the alloc/free sites by hand; then quibbling with the MM community about whether that consumer is indeed significant enough to warrant an entry in /proc/meminfo, and what the catchiest name for the stat would be.
I think we can agree that this is vastly less scalable and more burdensome than central annotations around a handful of mostly static allocator entry points. Especially considering the rate of change in the kernel as a whole, and that not everybody will think of the comprehensive MM picture when writing a random driver. And I think that's generous - we don't even have the network stack in meminfo.
So I think what we do now isn't working. In the Meta fleet, at any given time the p50 for unaccounted kernel memory is several gigabytes per host. The p99 is between 15% and 30% of total memory. That's a looot of opaque resource usage we have to accept on faith.
For hunting down regressions, all it takes is one untracked consumer in the kernel to really throw a wrench into things. It's difficult to find in the noise with tracing, and if it's not growing after an initial allocation spike, you're pretty much out of luck finding it at all. Raise your hand if you've written a drgn script to walk pfns and try to guess consumers from the state of struct page :)
I agree we should discuss how the annotations are implemented on a technical basis, but my take is that we need something like this.
In a codebase of our size, I don't think the allocator should be handing out memory without some basic implied tracking of where it's going. It's a liability for production environments, and it can hide bad memory management decisions in drivers and other subsystems for a very long time.
Michal Hocko
reviewerOn Wed 14-02-24 01:20:20, Johannes Weiner wrote:
[...]
Quoted 2 lines
I agree we should discuss how the annotations are implemented on a technical basis, but my take is that we need something like this.
I do not think there is any disagreement on usefulness of a better memory allocation tracking. At least for me the primary problem is the implementation. At LFSMM last year we have heard that existing tracing infrastructure hasn't really been explored much. Cover letter doesn't really talk much about those alternatives so it is really hard to evaluate whether the proposed solution is indeed our best way to approach this.
Quoted 5 lines
In a codebase of our size, I don't think the allocator should be handing out memory without some basic implied tracking of where it's going. It's a liability for production environments, and it can hide bad memory management decisions in drivers and other subsystems for a very long time.
Fully agreed! It is quite common to see oom reports with a large portion of memory unaccounted and this really presents additional cost on the debugging side.
Signature · 2 lines
Michal Hocko SUSE Labs
Kent Overstreet
maintainerQuoted 5 lines · Michal Hocko
On Wed 14-02-24 01:20:20, Johannes Weiner wrote:
[...]Quoted 2 lines
I agree we should discuss how the annotations are implemented on a technical basis, but my take is that we need something like this.
Quoted 7 lines
I do not think there is any disagreement on usefulness of a better memory allocation tracking. At least for me the primary problem is the implementation. At LFSMM last year we have heard that existing tracing infrastructure hasn't really been explored much. Cover letter doesn't really talk much about those alternatives so it is really hard to evaluate whether the proposed solution is indeed our best way to approach this.
Michal, we covered this before.
To do this with tracing you'd have to build up data structures separately, in userspace, that would mirror the allocator's data structures; you would have to track every single allocation so that you could match up the free event to the place it was allocated.
Even if it could be built, which I doubt, it'd be completely non viable because the performance would be terrible.
Like I said, we covered all this before; if you're going to spend so much time on these threads you really should be making a better attempt at keeping up with what's been talked about.
Michal Hocko
reviewerQuoted 14 lines · Kent Overstreet
Quoted 5 lines · Michal Hocko
On Wed 14-02-24 01:20:20, Johannes Weiner wrote:
[...]Quoted 2 lines
I agree we should discuss how the annotations are implemented on a technical basis, but my take is that we need something like this.
Quoted 7 lines
I do not think there is any disagreement on usefulness of a better memory allocation tracking. At least for me the primary problem is the implementation. At LFSMM last year we have heard that existing tracing infrastructure hasn't really been explored much. Cover letter doesn't really talk much about those alternatives so it is really hard to evaluate whether the proposed solution is indeed our best way to approach this.
Quoted 1 line
Michal, we covered this before.
It is a good practice to summarize previous discussions in the cover letter. Especially when there are different approaches discussed over a longer time period or when the topic is controversial.
I do not see anything like that here. Neither for the existing tracing infrastructure, page owner nor performance concerns discussed before etc. Look, I do not want to nit pick or insist on formalisms but having those data points layed out would make any further discussion much more smooth.
Signature · 2 lines
Michal Hocko SUSE Labs
Kent Overstreet
maintainerQuoted 21 lines · Michal Hocko
Quoted 14 lines · Kent Overstreet
Quoted 5 lines · Michal Hocko
On Wed 14-02-24 01:20:20, Johannes Weiner wrote:
[...]Quoted 2 lines
I agree we should discuss how the annotations are implemented on a technical basis, but my take is that we need something like this.
Quoted 7 lines
I do not think there is any disagreement on usefulness of a better memory allocation tracking. At least for me the primary problem is the implementation. At LFSMM last year we have heard that existing tracing infrastructure hasn't really been explored much. Cover letter doesn't really talk much about those alternatives so it is really hard to evaluate whether the proposed solution is indeed our best way to approach this.
Quoted 1 line
Michal, we covered this before.
It is a good practice to summarize previous discussions in the cover letter. Especially when there are different approaches discussed over a longer time period or when the topic is controversial.
Quoted 5 lines
I do not see anything like that here. Neither for the existing tracing infrastructure, page owner nor performance concerns discussed before etc. Look, I do not want to nit pick or insist on formalisms but having those data points layed out would make any further discussion much more smooth.
You don't want to nitpick???
Look, you've been consistently sidestepping the technical discussion; it seems all you want to talk about is process or "your nack".
If we're going to have a technical discussion, it's incumbent upon all of us to /keep the focus on the technical/; that is everyone's responsibility.
I'm not going to write a 20 page cover letter and recap every dead end that was proposed. That would be a lot of useless crap for eveyone to wade through. I'm going to summarize the important stuff, and keep the focus on what we're doing and documenting it. If you want to take part in a discussion, it's your responsibility to be reading with comprehension and finding useful things to say.
You gotta stop with this this derailing garbage.
Michal Hocko
reviewerOn Wed 14-02-24 11:17:20, Kent Overstreet wrote:
[...]
Quoted 1 line
You gotta stop with this this derailing garbage.
It is always pleasure talking to you Kent, but let me give you advice (free of charge of course). Let Suren talk, chances for civilized and productive discussion are much higher!
I do not have much more to add to the discussion. My point stays, find a support of the MM community if you want to proceed with this work.
Signature · 2 lines
Michal Hocko SUSE Labs
Suren Baghdasaryan
maintainerQuoted 8 lines · Michal Hocko
On Wed 14-02-24 11:17:20, Kent Overstreet wrote:
[...]Quoted 1 line
You gotta stop with this this derailing garbage.
It is always pleasure talking to you Kent, but let me give you advice (free of charge of course). Let Suren talk, chances for civilized and productive discussion are much higher!
Every time I wake up to a new drama... Sorry I won't follow up on this one not to feed the fire.
Quoted 6 lines
I do not have much more to add to the discussion. My point stays, find a support of the MM community if you want to proceed with this work. --
Michal Hocko
SUSE Labs
Quoted 1 line · Suren Baghdasaryan
Memory allocation, v3 and final:
Would be nice to have --base added to cover letter. The very first patch can't be applied on today's Linux Next.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Suren Baghdasaryan
maintainerQuoted 6 lines · Andy Shevchenko
Quoted 1 line · Suren Baghdasaryan
Memory allocation, v3 and final:
Would be nice to have --base added to cover letter. The very first patch can't be applied on today's Linux Next.
Sorry about that. It as based on Linus` ToT at the time of posting (7521f258ea30 Merge tag 'mm-hotfixes-stable-2024-02-10-11-16' ofgit://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm). I also applied it to mm-unstable with only one trivial merge conflict in one of the patches.
Quoted 7 lines
--
With Best Regards,
Andy Shevchenko
Quoted 63 lines · Suren Baghdasaryan
Memory allocation, v3 and final:
Overview:
Low overhead [1] per-callsite memory allocation profiling. Not just for debug kernels, overhead low enough to be deployed in production.We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
Example output:
root@moria-kvm:~# sort -h /proc/allocinfo|tail 3.11MiB 2850 fs/ext4/super.c:1408 module:ext4 func:ext4_alloc_inode 3.52MiB 225 kernel/fork.c:356 module:fork func:alloc_thread_stack_node 3.75MiB 960 mm/page_ext.c:270 module:page_ext func:alloc_page_ext 4.00MiB 2 mm/khugepaged.c:893 module:khugepaged func:hpage_collapse_alloc_folio 10.5MiB 168 block/blk-mq.c:3421 module:blk_mq func:blk_mq_alloc_rqs 14.0MiB 3594 include/linux/gfp.h:295 module:filemap func:folio_alloc_noprof 26.8MiB 6856 include/linux/gfp.h:295 module:memory func:folio_alloc_noprof 64.5MiB 98315 fs/xfs/xfs_rmap_item.c:147 module:xfs func:xfs_rui_init 98.7MiB 25264 include/linux/gfp.h:295 module:readahead func:folio_alloc_noprof 125MiB 7357 mm/slub.c:2201 module:slub func:alloc_slab_pageSince v2:
- tglx noticed a circular header dependency betweensched.handpercpu.h; a bunch of header cleanups were merged into 6.8 to ameliorate this [3].- a number of improvements, moving
alloc_hooks()annotations to the correct place for better tracking (mempool), and bugfixes.- looked at alternate hooking methods.
There were suggestions on alternate methods (compiler attribute, trampolines), but they wouldn't have made the patchset any cleaner (we still need to have different function versions for accounting vs. no accounting to control at which point in a call chain the accounting happens), and they would have added a dependency on toolchain support.Usage:
kconfig options:
-CONFIG_MEM_ALLOC_PROFILING
-CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT
-CONFIG_MEM_ALLOC_PROFILING_DEBUG
adds warnings for allocations that weren't accounted because of a missing annotationsysctl:
/proc/sys/vm/mem_profilingRuntime info:
/proc/allocinfoNotes:
[1]: Overhead
To measure the overhead we are comparing the following configurations:
(1) Baseline withCONFIG_MEMCG_KMEM=n
(2) Disabled by default (CONFIG_MEM_ALLOC_PROFILING=y&&CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=n)
(3) Enabled by default (CONFIG_MEM_ALLOC_PROFILING=y&&CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=y)
(4) Enabled at runtime (CONFIG_MEM_ALLOC_PROFILING=y&&
Quoted 3 lines
CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=n && /proc/sys/vm/mem_profiling=1)(5) Baseline with
CONFIG_MEMCG_KMEM=y&& allocating with__GFP_ACCOUNT
Thanks for the work on this patchset and it is quite useful. A clarification question on the data:
I assume Config (2), (3) and (4) has CONFIG_MEMCG_KMEM=n, right? If so do you have similar data for config (2), (3) and (4) but with CONFIG_MEMCG_KMEM=y for comparison with (5)?
Tim
Quoted 15 lines
Performance overhead:
To evaluate performance we implemented an in-kernel test executing multiple get_free_page/free_page and kmalloc/kfree calls with allocation sizes growing from 8 to 240 bytes with CPU frequency set to max and CPU affinity set to a specific CPU to minimize the noise. Below are results from running the test on Ubuntu 22.04.2 LTS with 6.8.0-rc1 kernel on 56 core Intel Xeon:kmalloc pgalloc (1 baseline) 6.764s 16.902s (2 default disabled) 6.793s (+0.43%) 17.007s (+0.62%) (3 default enabled) 7.197s (+6.40%) 23.666s (+40.02%) (4 runtime enabled) 7.405s (+9.48%) 23.901s (+41.41%) (5 memcg) 13.388s (+97.94%) 48.460s (+186.71%)
Suren Baghdasaryan
maintainerQuoted 69 lines · Tim Chen
Quoted 63 lines · Suren Baghdasaryan
Memory allocation, v3 and final:
Overview:
Low overhead [1] per-callsite memory allocation profiling. Not just for debug kernels, overhead low enough to be deployed in production.We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
Example output:
root@moria-kvm:~# sort -h /proc/allocinfo|tail 3.11MiB 2850 fs/ext4/super.c:1408 module:ext4 func:ext4_alloc_inode 3.52MiB 225 kernel/fork.c:356 module:fork func:alloc_thread_stack_node 3.75MiB 960 mm/page_ext.c:270 module:page_ext func:alloc_page_ext 4.00MiB 2 mm/khugepaged.c:893 module:khugepaged func:hpage_collapse_alloc_folio 10.5MiB 168 block/blk-mq.c:3421 module:blk_mq func:blk_mq_alloc_rqs 14.0MiB 3594 include/linux/gfp.h:295 module:filemap func:folio_alloc_noprof 26.8MiB 6856 include/linux/gfp.h:295 module:memory func:folio_alloc_noprof 64.5MiB 98315 fs/xfs/xfs_rmap_item.c:147 module:xfs func:xfs_rui_init 98.7MiB 25264 include/linux/gfp.h:295 module:readahead func:folio_alloc_noprof 125MiB 7357 mm/slub.c:2201 module:slub func:alloc_slab_pageSince v2:
- tglx noticed a circular header dependency betweensched.handpercpu.h; a bunch of header cleanups were merged into 6.8 to ameliorate this [3].- a number of improvements, moving
alloc_hooks()annotations to the correct place for better tracking (mempool), and bugfixes.- looked at alternate hooking methods.
There were suggestions on alternate methods (compiler attribute, trampolines), but they wouldn't have made the patchset any cleaner (we still need to have different function versions for accounting vs. no accounting to control at which point in a call chain the accounting happens), and they would have added a dependency on toolchain support.Usage:
kconfig options:
-CONFIG_MEM_ALLOC_PROFILING
-CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT
-CONFIG_MEM_ALLOC_PROFILING_DEBUG
adds warnings for allocations that weren't accounted because of a missing annotationsysctl:
/proc/sys/vm/mem_profilingRuntime info:
/proc/allocinfoNotes:
[1]: Overhead
To measure the overhead we are comparing the following configurations:
(1) Baseline withCONFIG_MEMCG_KMEM=n
(2) Disabled by default (CONFIG_MEM_ALLOC_PROFILING=y&&CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=n)
(3) Enabled by default (CONFIG_MEM_ALLOC_PROFILING=y&&CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=y)
(4) Enabled at runtime (CONFIG_MEM_ALLOC_PROFILING=y&&Quoted 3 lines
CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=n && /proc/sys/vm/mem_profiling=1)(5) Baseline with
CONFIG_MEMCG_KMEM=y&& allocating with__GFP_ACCOUNT
Quoted 4 lines
Thanks for the work on this patchset and it is quite useful. A clarification question on the data:
I assume Config (2), (3) and (4) has
CONFIG_MEMCG_KMEM=n, right?
Yes, correct.
Quoted 2 lines
If so do you have similar data for config (2), (3) and (4) but with
CONFIG_MEMCG_KMEM=yfor comparison with (5)?
I have data for these additional configs (didn't think there were that important):
(6) Disabled by default (CONFIG_MEM_ALLOC_PROFILING=y && CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=n) && CONFIG_MEMCG_KMEM=y
(7) Enabled by default (CONFIG_MEM_ALLOC_PROFILING=y && CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=y) && CONFIG_MEMCG_KMEM=y
Quoted 17 lines
Tim
Quoted 14 lines
Performance overhead:
To evaluate performance we implemented an in-kernel test executing multiple get_free_page/free_page and kmalloc/kfree calls with allocation sizes growing from 8 to 240 bytes with CPU frequency set to max and CPU affinity set to a specific CPU to minimize the noise. Below are results from running the test on Ubuntu 22.04.2 LTS with 6.8.0-rc1 kernel on 56 core Intel Xeon:kmalloc pgalloc (1 baseline) 6.764s 16.902s (2 default disabled) 6.793s (+0.43%) 17.007s (+0.62%) (3 default enabled) 7.197s (+6.40%) 23.666s (+40.02%) (4 runtime enabled) 7.405s (+9.48%) 23.901s (+41.41%) (5 memcg) 13.388s (+97.94%) 48.460s (+186.71%)
(6 default disabled+memcg) 13.332s (+97.10%) 48.105s (+184.61%)
(7 default enabled+memcg) 13.446s (+98.78%) 54.963s (+225.18%)
(6) shows a bit better performance than (5) but it's probably noise. I would expect them to be roughly the same. Hope this helps.
Quoted 3 lines
Quoted 1 line
Quoted 15 lines
Quoted 8 lines
Quoted 8 lines
Performance overhead:
To evaluate performance we implemented an in-kernel test executing multiple get_free_page/free_page and kmalloc/kfree calls with allocation sizes growing from 8 to 240 bytes with CPU frequency set to max and CPU affinity set to a specific CPU to minimize the noise. Below are results from running the test on Ubuntu 22.04.2 LTS with 6.8.0-rc1 kernel on 56 core Intel Xeon:Quoted 6 lines
Quoted 6 lines
kmalloc pgalloc (1 baseline) 6.764s 16.902s (2 default disabled) 6.793s (+0.43%) 17.007s (+0.62%) (3 default enabled) 7.197s (+6.40%) 23.666s (+40.02%) (4 runtime enabled) 7.405s (+9.48%) 23.901s (+41.41%) (5 memcg) 13.388s (+97.94%) 48.460s (+186.71%)
Quoted 2 lines
(6 default disabled+memcg) 13.332s (+97.10%) 48.105s (+184.61%)
(7 default enabled+memcg) 13.446s (+98.78%) 54.963s (+225.18%)
I think these numbers are very interesting for folks that already use memcg. Specifically, the difference between 6 & 7, which seems to be ~0.85% and ~14.25%. IIUC, this means that the extra overhead is relatively much lower if someone is already using memcgs.
Quoted 7 lines
(6) shows a bit better performance than (5) but it's probably noise. I would expect them to be roughly the same. Hope this helps.
Quoted 3 lines
Quoted 1 line
Suren Baghdasaryan
maintainerQuoted 16 lines · Yosry Ahmed
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Performance overhead:
To evaluate performance we implemented an in-kernel test executing multiple get_free_page/free_page and kmalloc/kfree calls with allocation sizes growing from 8 to 240 bytes with CPU frequency set to max and CPU affinity set to a specific CPU to minimize the noise. Below are results from running the test on Ubuntu 22.04.2 LTS with 6.8.0-rc1 kernel on 56 core Intel Xeon:kmalloc pgalloc (1 baseline) 6.764s 16.902s (2 default disabled) 6.793s (+0.43%) 17.007s (+0.62%) (3 default enabled) 7.197s (+6.40%) 23.666s (+40.02%) (4 runtime enabled) 7.405s (+9.48%) 23.901s (+41.41%) (5 memcg) 13.388s (+97.94%) 48.460s (+186.71%)
Quoted 7 lines
Quoted 2 lines
(6 default disabled+memcg) 13.332s (+97.10%) 48.105s (+184.61%)
(7 default enabled+memcg) 13.446s (+98.78%) 54.963s (+225.18%)I think these numbers are very interesting for folks that already use memcg. Specifically, the difference between 6 & 7, which seems to be ~0.85% and ~14.25%. IIUC, this means that the extra overhead is relatively much lower if someone is already using memcgs.
Well, yes, percentage-wise it's much lower. If you look at the absolute difference between 6 & 7 vs 2 & 3, it's quite close.
Quoted 8 lines
Quoted 8 lines
(6) shows a bit better performance than (5) but it's probably noise. I would expect them to be roughly the same. Hope this helps.
Quoted 3 lines
Quoted 1 line
Quoted 20 lines · Suren Baghdasaryan
Quoted 19 lines · Yosry Ahmed
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
Performance overhead:
To evaluate performance we implemented an in-kernel test executing multiple get_free_page/free_page and kmalloc/kfree calls with allocation sizes growing from 8 to 240 bytes with CPU frequency set to max and CPU affinity set to a specific CPU to minimize the noise. Below are results from running the test on Ubuntu 22.04.2 LTS with 6.8.0-rc1 kernel on 56 core Intel Xeon:Quoted 6 lines
Quoted 6 lines
kmalloc pgalloc (1 baseline) 6.764s 16.902s (2 default disabled) 6.793s (+0.43%) 17.007s (+0.62%) (3 default enabled) 7.197s (+6.40%) 23.666s (+40.02%) (4 runtime enabled) 7.405s (+9.48%) 23.901s (+41.41%) (5 memcg) 13.388s (+97.94%) 48.460s (+186.71%)(6 default disabled+memcg) 13.332s (+97.10%) 48.105s (+184.61%)
(7 default enabled+memcg) 13.446s (+98.78%) 54.963s (+225.18%)
Quoted 14 lines
Quoted 4 lines
I think these numbers are very interesting for folks that already use memcg. Specifically, the difference between 6 & 7, which seems to be ~0.85% and ~14.25%. IIUC, this means that the extra overhead is relatively much lower if someone is already using memcgs.
Well, yes, percentage-wise it's much lower. If you look at the absolute difference between 6 & 7 vs 2 & 3, it's quite close.
Quoted 6 lines
Quoted 6 lines
(6) shows a bit better performance than (5) but it's probably noise. I would expect them to be roughly the same. Hope this helps.
Quoted 1 line
Thanks for the data. It does show that turning on memcg does not cost extra overhead percentage wise.
Tim
Quoted 10 lines · Suren Baghdasaryan
Memory allocation, v3 and final:
Overview:
Low overhead [1] per-callsite memory allocation profiling. Not just for debug kernels, overhead low enough to be deployed in production.We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
I wonder if it wouldn't be too much trouble to write at least a brief overview document under Documentation/ describing what this is all about? Even as follow-up. People seeing the patch series have the benefit of the cover letter and the commit messages, but that's hardly documentation.
We have all these great frameworks and tools but their discoverability to kernel developers isn't always all that great.
BR,
Jani.
Signature · 1 line
Jani Nikula, Intel
Kent Overstreet
maintainerQuoted 12 lines · Jani Nikula
Quoted 10 lines · Suren Baghdasaryan
Memory allocation, v3 and final:
Overview:
Low overhead [1] per-callsite memory allocation profiling. Not just for debug kernels, overhead low enough to be deployed in production.We're aiming to get this in the next merge window, for 6.9. The feedback we've gotten has been that even out of tree this patchset has already been useful, and there's a significant amount of other work gated on the code tagging functionality included in this patchset [2].
Quoted 8 lines
I wonder if it wouldn't be too much trouble to write at least a brief overview document under
Documentation/describing what this is all about? Even as follow-up. People seeing the patch series have the benefit of the cover letter and the commit messages, but that's hardly documentation.We have all these great frameworks and tools but their discoverability to kernel developers isn't always all that great.
commit f589b48789de4b8f77bfc70b9f3ab2013c01eaf2
Author: Kent Overstreet <[email protected]> Date: Wed Feb 14 01:13:04 2024 -0500
memprofiling: Documentation
Documentation/mm/allocation-profiling.rst new file +68 -0
@@ -0,0 +1,68 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=========================== +MEMORY ALLOCATION PROFILING +=========================== + +Low overhead (suitable for production) accounting of all memory allocations, +tracked by file and line number. + +Usage: +kconfig options: + - CONFIG_MEM_ALLOC_PROFILING + - CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT + - CONFIG_MEM_ALLOC_PROFILING_DEBUG + adds warnings for allocations that weren't accounted because of a + missing annotation + +sysctl: + /proc/sys/vm/mem_profiling + +Runtime info: + /proc/allocinfo + +Example output: + root@moria-kvm:~# sort -h /proc/allocinfo|tail + 3.11MiB 2850 fs/ext4/super.c:1408 module:ext4 func:ext4_alloc_inode + 3.52MiB 225 kernel/fork.c:356 module:fork func:alloc_thread_stack_node + 3.75MiB 960 mm/page_ext.c:270 module:page_ext func:alloc_page_ext + 4.00MiB 2 mm/khugepaged.c:893 module:khugepaged func:hpage_collapse_alloc_folio + 10.5MiB 168 block/blk-mq.c:3421 module:blk_mq func:blk_mq_alloc_rqs + 14.0MiB 3594 include/linux/gfp.h:295 module:filemap func:folio_alloc_noprof + 26.8MiB 6856 include/linux/gfp.h:295 module:memory func:folio_alloc_noprof + 64.5MiB 98315 fs/xfs/xfs_rmap_item.c:147 module:xfs func:xfs_rui_init + 98.7MiB 25264 include/linux/gfp.h:295 module:readahead func:folio_alloc_noprof + 125MiB 7357 mm/slub.c:2201 module:slub func:alloc_slab_page + + +Theory of operation: + +Memory allocation profiling builds off of code tagging, which is a library for +declaring static structs (that typcially describe a file and line number in +some way, hence code tagging) and then finding and operating on them at runtime +- i.e. iterating over them to print them in debugfs/procfs. + +To add accounting for an allocation call, we replace it with a macro +invocation, alloc_hooks(), that + - declares a code tag + - stashes a pointer to it in task_struct + - calls the real allocation function + - and finally, restores the task_struct alloc tag pointer to its previous value. + +This allows for alloc_hooks() calls to be nested, with the most recent one +taking effect. This is important for allocations internal to the mm/ code that +do not properly belong to the outer allocation context and should be counted +separately: for example, slab object extension vectors, or when the slab +allocates pages from the page allocator. + +Thus, proper usage requires determining which function in an allocation call +stack should be tagged. There are many helper functions that essentially wrap +e.g. kmalloc() and do a little more work, then are called in multiple places; +we'll generally want the accounting to happen in the callers of these helpers, +not in the helpers themselves. + +To fix up a given helper, for example foo(), do the following: + - switch its allocation call to the _noprof() version, e.g. kmalloc_noprof() + - rename it to foo_noprof() + - define a macro version of foo() like so: + #define foo(...) alloc_hooks(foo_noprof(__VA_ARGS__))
Quoted 10 lines · Kent Overstreet
Quoted 8 lines · Jani Nikula
I wonder if it wouldn't be too much trouble to write at least a brief overview document under
Documentation/describing what this is all about? Even as follow-up. People seeing the patch series have the benefit of the cover letter and the commit messages, but that's hardly documentation.We have all these great frameworks and tools but their discoverability to kernel developers isn't always all that great.
Quoted 7 lines
commit
f589b48789de4b8f77bfc70b9f3ab2013c01eaf2Author: Kent Overstreet <[email protected]> Date: Wed Feb 14 01:13:04 2024 -0500memprofiling: Documentation
Signed-off-by Kent Overstreet <[email protected]>
Thanks! Wasn't part of this series and I wasn't aware it existed.
BR,
Jani.
Signature · 1 line
Jani Nikula, Intel