Re: [PATCH 2.6.28-rc5 01/11] kmemleak: Add the base support

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Catalin Marinas
Date: Saturday, December 6, 2008 - 4:07 pm

On Thu, 2008-12-04 at 08:55 -0800, Paul E. McKenney wrote:
[...]

You haven't missed it, that's the first time I posted this text.


So, to make sure I understand it correctly, the rcu_read_lock() is
needed to protect between the point where the object pointer was
obtained to the get_object() point. Would it also work if
spin_lock_irqsave(object_list_lock) is used instead of rcu_read_lock()?
The call_rcu() in put_object is bracketed with object_list_lock.

BTW, I'll have a look if I could remove an object from the object_list
in delete_object() rather than waiting until put_object().


object_list holds all the memleak_objects in the system and it is
traversed when preparing the scanning and also when reporting the leaks.

object_tree_root is used to look-up memleak_objects by the allocated
memory block. In the past, this used to be a radix tree (with some
lockdep problems) and later a hash. I now use a prio tree because it
allows pointer ranges.

Kmemleak could probably iterate over the object_tree_root when reporting
but it is more convenient to report the leaks in the order they were
allocated (preserved by object_list) since one leak may trigger many
subsequent reports but they disappear once the first one is solved.


Correct. I'll have to review this again.


It wasn't documented, so pretty hard to guess.


Yes.


OK, I got it now.


I'll document it better and make sure it's clear for me as well.


Yes.


Yes.


I'll try to make the memleak_seq_next() function use rcu_dereference()
and rcu_read_lock(). ATM, the "v" object has use_count >= 1 (from a
previous get_object) and the next pointer is accessed under
object_list_lock, so no modifications to the list (even put_object
acquires this lock when invoking call_rcu). There is still the bug with
not checking the get_object() return.


Yes


The previous objects' use_count are decremented in memleak_seq_next()
just before returning "next", so between seq_start-seq_next and
seq_next-seq_stop, there is only one object with an incremented
use_count. The memleak_seq_next() function may have two such objects for
a small period of time.

I actually added a test for this in memleak_scan() (if DEBUG is defined)
and I've never got any reports. There may be some situations when for
very short periods of time the use_count is > 1 at the beginning of a
scan, usually when one of the memleak_scan_area or memleak_ignore
callbacks are invoked.

I'll revise the locking a bit and re-post the patches this week.

Thanks.

-- 
Catalin

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 2.6.28-rc5 01/11] kmemleak: Add the base support, Catalin Marinas, (Thu Nov 20, 4:30 am)
[PATCH 2.6.28-rc5 04/11] kmemleak: Add modules support, Catalin Marinas, (Thu Nov 20, 4:30 am)
[PATCH 2.6.28-rc5 05/11] kmemleak: Add support for i386, Catalin Marinas, (Thu Nov 20, 4:30 am)
[PATCH 2.6.28-rc5 06/11] kmemleak: Add support for ARM, Catalin Marinas, (Thu Nov 20, 4:31 am)
Re: [PATCH 2.6.28-rc5 01/11] kmemleak: Add the base support, Catalin Marinas, (Fri Nov 21, 5:07 am)
Re: [PATCH 2.6.28-rc5 01/11] kmemleak: Add the base support, Paul E. McKenney, (Wed Dec 3, 11:12 am)
Re: [PATCH 2.6.28-rc5 01/11] kmemleak: Add the base support, Paul E. McKenney, (Thu Dec 4, 9:55 am)
Re: [PATCH 2.6.28-rc5 01/11] kmemleak: Add the base support, Catalin Marinas, (Sat Dec 6, 4:07 pm)
Re: [PATCH 2.6.28-rc5 01/11] kmemleak: Add the base support, Paul E. McKenney, (Sun Dec 7, 4:19 pm)