Skip to contentSkip to conversation

mm/kmemleak.c: Merge the consecutive scan-areas.

PATCH In review majianpeng 2 participants 2 messages May 14, 2013 – May 24, 2013

Subsystems (2)
lore
Share & tools
lore

majianpeng

author
#0 lore raw

PATCH 3/3 mm/kmemleak.c: Merge the consecutive scan-areas.

If the scan-areas are adjacent,it can merge in order to reduce memomy. And using pr_warn instead of pr_warning.

---
 mm/kmemleak.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
mm/kmemleak.c +19 -7
index f0ece93..9590a57 100644
@@ -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);
Signature · 1 line
1.8.3.rc1.44.gb387c77
maintainer
#1 lore raw
Quoted 1 line · majianpeng

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).

mm/kmemleak.c static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp) · line 762

Quoted 8 lines
mm/kmemleak.c +8 -0
+    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.

Signature · 7 lines
Catalin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>