From patchwork Thu May 25 15:42:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 100518 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp824307qge; Thu, 25 May 2017 08:42:59 -0700 (PDT) X-Received: by 10.98.93.217 with SMTP id n86mr45954111pfj.113.1495726978794; Thu, 25 May 2017 08:42:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495726978; cv=none; d=google.com; s=arc-20160816; b=vmGMYshz+aeDEWHSYq4h/s7GTtB42o0SKb2Ya2omZvV17MoX5PKotjU9BSua9Bt9h6 ReAR3E9DobqLAebkiTir1bTztJb764xSdTb+xjCsCp3w/ns3oN9XaeGRZrdLGPLSA1aZ Ae4Xjv3Q41YCFUrcc+P0a17g0053iXwOHmWcqT3NlCmuPN6ElQzQXMrL9WvKIGdu/t/7 I4F+6tPOne5rymqiQvOvJ+ZbF22dOcK3N5OjBTxTyxCygu/ylVmdJ6kKd2pfL1me80Gt mcjvd7FFOCPbaRCy5EFyluGW8EbnnOyf/h4/3rA2Iek9jv87NROPyiy9UzyOspNTmSS7 nHAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=AJL3dchf55zUdzNawMtX5SfQ0r5h5QNx+Y9paII/36M=; b=EQmwoqOTkKyrteoFYyZGMGGc3Jtz1ytWl3xXDLRzM4Fedn8lZMN7IjMBKbZHflNxLT g4w8sUVsPaIZcbHb7+fRtdBi6gZ+ilBbIUp3HQEnd7NIjcoPjtIxR+1GiFIaXWXTWmk9 HcAIRSxJe0RK6B7I7dfOMIcE94SEUI8kqo63f2p/M9qC2wL0YtuLN0gaR9gt+nwGMbsy bPBuTBfEpb6+H9rfSDeQpIbUrzrbdRm9/ZuTcZjIpwRSoqJNhSIXEx2O9C9SCPNfZ0Ny OS3LNJ+PhJPcPftTAKOl5o0G3x34xd8xj/zqtd4YzaQly29VG1An1CkYeyT5dE/ZEL9x aGGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m23si6536710pli.111.2017.05.25.08.42.58; Thu, 25 May 2017 08:42:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S942452AbdEYPms (ORCPT + 25 others); Thu, 25 May 2017 11:42:48 -0400 Received: from foss.arm.com ([217.140.101.70]:51358 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S942385AbdEYPm2 (ORCPT ); Thu, 25 May 2017 11:42:28 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 33C14344; Thu, 25 May 2017 08:42:28 -0700 (PDT) Received: from e104818-lin.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EF9943F41F; Thu, 25 May 2017 08:42:26 -0700 (PDT) From: Catalin Marinas To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Michal Hocko , Andy Lutomirski , "Luis R. Rodriguez" , Andrew Morton Subject: [PATCH v2 2/3] mm: kmemleak: Factor object reference updating out of scan_block() Date: Thu, 25 May 2017 16:42:16 +0100 Message-Id: <1495726937-23557-3-git-send-email-catalin.marinas@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1495726937-23557-1-git-send-email-catalin.marinas@arm.com> References: <1495726937-23557-1-git-send-email-catalin.marinas@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Andy Lutomirski Cc: "Luis R. Rodriguez" Signed-off-by: Catalin Marinas --- 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);