On Wed, Nov 29, 2023 at 05:57:11PM -0500, Waiman Long wrote: > On 11/28/23 11:04, Catalin Marinas wrote: > > The problem is looking up the object tree for each per-cpu offset. We > > can make the percpu pointer handling O(1) since freeing is only done by > > the main __percpu pointer, so that's the only one needing a look-up. So > > far the per-cpu pointers are not tracked for leaking, only scanned. > > > > We could just add the per_cpu_ptr(ptr, 0) to the kmemleak > > object_tree_root but when scanning we don't have an inverse function to > > get the __percpu pointer back and calculate the pointers for the other > > CPUs (well, we could with some hacks but they are probably fragile). > > > > What I came up with is a separate object_percpu_tree_root similar to the > > object_phys_tree_root. The only reason for these additional trees is to > > look up the kmemleak metadata when needed (usually freeing). They don't > > contain objects that are tracked for actual leaking, only scanned. A > > briefly tested patch below. I need to go through it again, update some > > comments and write a commit log: [...] > The patch looks reasonable to me. It also has a side effect of reducing the > # of kmemleak objects to track especially for system with large number of > CPUs. Of course, we still need more testing to make sure that it won't break > anything. Thanks for having a look. I'll tidy it up and post today or tomorrow. It can stay in next for a bit before upstreaming to get some exposure (though not sure many test -next with kmemleak enabled). -- Catalin