Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1004497imu; Fri, 4 Jan 2019 11:06:49 -0800 (PST) X-Google-Smtp-Source: AFSGD/VFvVFOlCIKbNvYlA9yP0rQU2iP6cT93stA+Km90G/MdIKoSuyisQZ+bNbCyX8BLPvYdJJh X-Received: by 2002:a62:fb07:: with SMTP id x7mr53145749pfm.71.1546628809931; Fri, 04 Jan 2019 11:06:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546628809; cv=none; d=google.com; s=arc-20160816; b=H9z/W7AvyT4JNLlnvtaEyM9tJs/yb1HPls/BrZBQ2RTaYCsVQq+WnmiPkOg0UKlisL e8Mkrb648W2mhyNwJxGeBfcRDkwLPUchgJBf1fBlUz8S7S6iLZ/vnxCWix4QmQV3QtVd tmoqNYrgj2Nu9r0NLNb+l2DVUfB1n2/6qOQsWxxzYfuJ6Pbi6kWTj8SUWtCQHyOoay9i aeAIHN1SWea1y1zoy5ApPYqJG4pOrhnF3hM+q3ILyY+AA33tGC7d+BZxoxDcgT4S+vmM MMABM8hYDw7BwmZuAsI3KdPfTV2YCXSJlgdNF+qA5K0WgGcR0YOeEEA62U6zn6pBMpSC t76w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=iWqHoVxui5ijzJCNUyEJ9XMnhF1JYg3g8qK06aQNFKc=; b=PKidFbB8MAjPJuMwYI7xH9plZl0Xqz5/YvGkwWTG6/u01u4dLkuLIW9VjvFOaYT1X7 bXiHCMiiuSv4twlMb7/RPqVd/axVb8gqhZzUpMuE6iX+ZadbHMJystXhCon0IYiXlRL8 94LFktL2ik4y6eytWhLBXfrPqT8L+nGSXCFRNvhValCw9dBIxf1tpCUYYRcd+DzpzpgE xTSn0bzUVeP/2T2V/N/7Znnk1lwqxAJqeGpahGfFwjKb195wICEoU0e9FLRPS7WMX88o 6nf98wPN9tLWUZhuAoVuz6L8KlZjBIBeFwNwZVd9JjeBNsw/W7mrRi6QYfP+dFsZljRF i8ZA== 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 72si53273967pla.218.2019.01.04.11.06.35; Fri, 04 Jan 2019 11:06:49 -0800 (PST) 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 S1727179AbfADShU (ORCPT + 99 others); Fri, 4 Jan 2019 13:37:20 -0500 Received: from foss.arm.com ([217.140.101.70]:48672 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726036AbfADShT (ORCPT ); Fri, 4 Jan 2019 13:37:19 -0500 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 8069315AD; Fri, 4 Jan 2019 10:37:19 -0800 (PST) Received: from arrakis.emea.arm.com (arrakis.cambridge.arm.com [10.1.196.113]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 91BCD3F5D4; Fri, 4 Jan 2019 10:37:18 -0800 (PST) Date: Fri, 4 Jan 2019 18:37:16 +0000 From: Catalin Marinas To: zhe.he@windriver.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: kmemleak: Turn kmemleak_lock to spin lock and RCU primitives Message-ID: <20190104183715.GC187360@arrakis.emea.arm.com> References: <1546612153-451172-1-git-send-email-zhe.he@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1546612153-451172-1-git-send-email-zhe.he@windriver.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 04, 2019 at 10:29:13PM +0800, zhe.he@windriver.com wrote: > It's not necessary to keep consistency between readers and writers of > kmemleak_lock. RCU is more proper for this case. And in order to gain better > performance, we turn the reader locks to RCU read locks and writer locks to > normal spin locks. This won't work. > @@ -515,9 +515,7 @@ static struct kmemleak_object *find_and_get_object(unsigned long ptr, int alias) > struct kmemleak_object *object; > > rcu_read_lock(); > - read_lock_irqsave(&kmemleak_lock, flags); > object = lookup_object(ptr, alias); > - read_unlock_irqrestore(&kmemleak_lock, flags); The comment on lookup_object() states that the kmemleak_lock must be held. That's because we don't have an RCU-like mechanism for removing removing objects from the object_tree_root: > > /* check whether the object is still available */ > if (object && !get_object(object)) > @@ -537,13 +535,13 @@ static struct kmemleak_object *find_and_remove_object(unsigned long ptr, int ali > unsigned long flags; > struct kmemleak_object *object; > > - write_lock_irqsave(&kmemleak_lock, flags); > + spin_lock_irqsave(&kmemleak_lock, flags); > object = lookup_object(ptr, alias); > if (object) { > rb_erase(&object->rb_node, &object_tree_root); > list_del_rcu(&object->object_list); > } > - write_unlock_irqrestore(&kmemleak_lock, flags); > + spin_unlock_irqrestore(&kmemleak_lock, flags); So here, while list removal is RCU-safe, rb_erase() is not. If you have time to implement an rb_erase_rcu(), than we could reduce the locking in kmemleak. -- Catalin