* [PATCH 3/3] mm/kmemleak.c: Merge the consecutive scan-areas.
@ 2013-05-14 11:49 majianpeng
2013-05-24 17:06 ` Catalin Marinas
0 siblings, 1 reply; 2+ messages in thread
From: majianpeng @ 2013-05-14 11:49 UTC (permalink / raw)
To: Catalin Marinas; +Cc: linux-mm, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1788 bytes --]
If the scan-areas are adjacent,it can merge in order to reduce memomy.
And using pr_warn instead of pr_warning.
Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
---
mm/kmemleak.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index f0ece93..9590a57 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -746,24 +746,36 @@ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp)
return;
}
- area = kmem_cache_alloc(scan_area_cache, gfp_kmemleak_mask(gfp));
- if (!area) {
- pr_warning("Cannot allocate a scan area\n");
- goto out;
- }
-
spin_lock_irqsave(&object->lock, flags);
if (ptr + size > object->pointer + object->size) {
kmemleak_warn("Scan area larger than object 0x%08lx\n", ptr);
dump_object_info(object);
- kmem_cache_free(scan_area_cache, area);
goto out_unlock;
}
+ hlist_for_each_entry(area, &object->area_list, node) {
+ if (ptr + size == area->start) {
+ area->start = ptr;
+ area->size += size;
+ goto out_unlock;
+ } else if (ptr == area->start + area->size) {
+ area->size += size;
+ goto out_unlock;
+ }
+
+ }
+ spin_unlock_irqrestore(&object->lock, flags);
+
+ area = kmem_cache_alloc(scan_area_cache, gfp_kmemleak_mask(gfp));
+ if (!area) {
+ pr_warn("Cannot allocate a scan area\n");
+ goto out;
+ }
INIT_HLIST_NODE(&area->node);
area->start = ptr;
area->size = size;
+ spin_lock_irqsave(&object->lock, flags);
hlist_add_head(&area->node, &object->area_list);
out_unlock:
spin_unlock_irqrestore(&object->lock, flags);
--
1.8.3.rc1.44.gb387c77
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-mm-kmemleak.c-Merge-the-consecutive-scan-areas.patch --]
[-- Type: text/x-patch; name="0003-mm-kmemleak.c-Merge-the-consecutive-scan-areas.patch", Size: 0 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH 3/3] mm/kmemleak.c: Merge the consecutive scan-areas.
2013-05-14 11:49 [PATCH 3/3] mm/kmemleak.c: Merge the consecutive scan-areas majianpeng
@ 2013-05-24 17:06 ` Catalin Marinas
0 siblings, 0 replies; 2+ messages in thread
From: Catalin Marinas @ 2013-05-24 17:06 UTC (permalink / raw)
To: majianpeng; +Cc: linux-mm, linux-kernel
On Tue, May 14, 2013 at 12:49:51PM +0100, majianpeng wrote:
> If the scan-areas are adjacent,it can merge in order to reduce memomy.
Have you found any significant reduction in the memory size?
What we miss though is removing an area (and I found a use-case for it).
> + hlist_for_each_entry(area, &object->area_list, node) {
> + if (ptr + size == area->start) {
> + area->start = ptr;
> + area->size += size;
> + goto out_unlock;
> + } else if (ptr == area->start + area->size) {
> + area->size += size;
> + goto out_unlock;
I prefer to keep 'goto' only for the error path. You could add a 'bool
merged' and another 'if' block for area allocation.
I'll pick the other too patches.
Thanks.
--
Catalin
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-05-24 17:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-14 11:49 [PATCH 3/3] mm/kmemleak.c: Merge the consecutive scan-areas majianpeng
2013-05-24 17:06 ` Catalin Marinas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox