Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1650606

[PATCH v2 2/3] mm: kmemleak: Factor object reference updating out of scan_block()

From Catalin Marinas <catalin.marinas@arm.com>
Newsgroups linux.kernel
Subject [PATCH v2 2/3] mm: kmemleak: Factor object reference updating out of scan_block()
Date 2017-05-25 17:50 +0200
Message-ID <tL3bs-1AL-29@gated-at.bofh.it> (permalink)
References <tL3br-1AL-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


The scan_block() function updates the number of references (pointers) to
objects, adding them to the gray_list when object->min_count is reached.
The patch factors out this functionality into a separate update_refs()
function.

Cc: Michal Hocko <mhocko@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: "Luis R. Rodriguez" <mcgrof@kernel.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
---
 mm/kmemleak.c | 43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 964b12eba2c1..266482f460c2 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1188,6 +1188,30 @@ static bool update_checksum(struct kmemleak_object *object)
 }
 
 /*
+ * Update an object's references. object->lock must be held by the caller.
+ */
+static void update_refs(struct kmemleak_object *object)
+{
+	if (!color_white(object)) {
+		/* non-orphan, ignored or new */
+		return;
+	}
+
+	/*
+	 * Increase the object's reference count (number of pointers to the
+	 * memory block). If this count reaches the required minimum, the
+	 * object's color will become gray and it will be added to the
+	 * gray_list.
+	 */
+	object->count++;
+	if (color_gray(object)) {
+		/* put_object() called when removing from gray_list */
+		WARN_ON(!get_object(object));
+		list_add_tail(&object->gray_list, &gray_list);
+	}
+}
+
+/*
  * Memory scanning is a long process and it needs to be interruptable. This
  * function checks whether such interrupt condition occurred.
  */
@@ -1259,24 +1283,7 @@ static void scan_block(void *_start, void *_end,
 		 * enclosed by scan_mutex.
 		 */
 		spin_lock_nested(&object->lock, SINGLE_DEPTH_NESTING);
-		if (!color_white(object)) {
-			/* non-orphan, ignored or new */
-			spin_unlock(&object->lock);
-			continue;
-		}
-
-		/*
-		 * Increase the object's reference count (number of pointers
-		 * to the memory block). If this count reaches the required
-		 * minimum, the object's color will become gray and it will be
-		 * added to the gray_list.
-		 */
-		object->count++;
-		if (color_gray(object)) {
-			/* put_object() called when removing from gray_list */
-			WARN_ON(!get_object(object));
-			list_add_tail(&object->gray_list, &gray_list);
-		}
+		update_refs(object);
 		spin_unlock(&object->lock);
 	}
 	read_unlock_irqrestore(&kmemleak_lock, flags);

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 0/3] mm: kmemleak: Improve vmalloc() false positives for thread stack allocation Catalin Marinas <catalin.marinas@arm.com> - 2017-05-25 17:50 +0200
  [PATCH v2 2/3] mm: kmemleak: Factor object reference updating out of scan_block() Catalin Marinas <catalin.marinas@arm.com> - 2017-05-25 17:50 +0200
    Re: [PATCH v2 2/3] mm: kmemleak: Factor object reference updating  out of scan_block() Luis Henriques <lhenriques@suse.com> - 2017-05-26 18:10 +0200
      Re: [PATCH v2 2/3] mm: kmemleak: Factor object reference updating  out of scan_block() Catalin Marinas <catalin.marinas@arm.com> - 2017-05-26 18:30 +0200
        Re: [PATCH v2 2/3] mm: kmemleak: Factor object reference updating  out of scan_block() Catalin Marinas <catalin.marinas@arm.com> - 2017-05-26 18:30 +0200
          Re: [PATCH v2 2/3] mm: kmemleak: Factor object reference updating  out of scan_block() Luis Henriques <lhenriques@suse.com> - 2017-05-26 19:20 +0200

csiph-web