On Wed, Jan 19, 2022 at 1:58 AM Guangming.Cao guangming.cao@mediatek.com wrote:
On Fri, 2022-01-14 at 17:17 -0800, John Stultz wrote:
If the max value is per-heap, why not enforce that value in the per-heap allocation function?
Moving the check to the heap alloc to me seems simpler to me than adding complexity to the infrastructure to add a heap max_size callback. Is there some other use for the callback that you envision?
If you think max the value is per-heap, why not add an optional callback for dma-heap to solve this issue(prevent consuming too much time for a doomed to fail allocation), if the dma-heap doesn't have a special size check, just use the default value(totalram) in dma-heap framework to do the size check.
As the totalram default isn't correct for all heaps (or necessarily even most heaps), so those heaps would need to implement the callback.
I'm just not sure adding complexity to the framework to address this is useful. Instead of an additional check in the allocation function, heap implementers will need to assess if the default logic in a framework is correct, and then possibly implement the callback.
Yes, for linux dma-heaps, only system-heap needs it, so adding it in system heap is the simplest. However, there are many vendor dma-heaps like system-heap which won't be uploaded to linux codebase, and maybe have same limitation, all these heaps need to add the same limitation.
My worry is that without seeing these vendor heaps, this is a bit of a theoretical concern. We don't have the data on how common this is. I very much hope that vendors can start submitting their heaps upstream (along with drivers that benefit from the heaps). Then we can really assess what makes the most sense for the community maintained code.
I just think it's boring. However, If you think discussing these absent cases based on current linux code is meaningless, I also agree to it.
So, as a rule, the upstream kernel doesn't create/maintain logic to accommodate out of tree code.
Now, I agree there is the potential for some duplication in the checks in the allocation logic, but until it affects the upstream kernel, community maintainers can't really make an appropriate evaluation.
As a contra-example, if the allocation is some extreme hotpath, adding an extra un-inlinable function pointer traversal for the size callback may actually have a negative impact. This isn't likely but again, if we cannot demonstrate it one way or the other against the upstream tree, we can't figure out what the best solution might be.
So, to summarize, if you still think adding it in system_heap.c is better, I also agree and I will update the patch to add it in system_heap.c
I think this is the best solution for now. As this is not part of an userland ABI, we can always change it in the future once we see the need.
thanks -john