Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3971544imu; Tue, 18 Dec 2018 07:09:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/U1et2j9sUqXZS7DKhV+ltB5k7E+xNIhSZ4TJUTE8ozwhsxbFtTjag/9xdj4DmxsaX9zorW X-Received: by 2002:a62:be0c:: with SMTP id l12mr5826733pff.51.1545145761957; Tue, 18 Dec 2018 07:09:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545145761; cv=none; d=google.com; s=arc-20160816; b=BlUMohCIorSclq8xTsCw51RZ4l8/lY/RgU5oFJ8GBoEIyCb45QgPewVTdF+d+IRe0k tkPuDlherbTUBb9HiaMhJRCG/bR974bLi7zjsGCkGYktbhyO//61X0zaKrAqcgMHv4gj qa1Xi0SnQc9lfA4FVQE+7BGwqhCpr2tnGS0fXg31KXm86H9e+ww1qekn8IulZH6uQby6 qxlfh7QUeZVPjpvSlq1wK6CHkzMFD5Fhx3ETHsniAR2z4FEM5j4NJTiTCkGPgJ7nTqJE uOBYtCo2vRfuNWClRJ4dVq5+WBDewXrh+QVAzoKAJjkSi0ImHjMdn080yW09PeBFMBfw fz1Q== 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=4Xrat00qqu4XbipozqL4HyZlsc7Gi0BsCo9qrof1fSo=; b=1Fu6e+sQF1a1EQ/DbfxHwDj5ZmTO/7JyFBVx6E2TmPxuer3DbOJXAitvoOInzO1nwB T33zVuQ7huAZV/Jc39+o7c7qlF0e0YC2JSPhyU3ECZ3ptesGDGHrSSTXeWPySCRL8yxk pS6vAjRv0TuWAJXqF4HOWyy7YMBspYr5MnKwl5ctH5uFOv6lQ926MEqqpOZalPPoE73b niB2BEC8haNCgVhGeoCom70OO6nMsE/H8TxtDIVxbAqb3U8L3UdnuVMcYvEZneOhmoJ3 Dg9BnIF4O/nq6Q73K6EsTeIqXtWTj8lLIE1srSISnzPXaxnjm24FCAnyKdcAaOfOZYz9 nLgQ== 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 o1si12888352plk.257.2018.12.18.07.09.06; Tue, 18 Dec 2018 07:09:21 -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 S1726790AbeLRPHt (ORCPT + 99 others); Tue, 18 Dec 2018 10:07:49 -0500 Received: from foss.arm.com ([217.140.101.70]:47680 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726426AbeLRPHt (ORCPT ); Tue, 18 Dec 2018 10:07:49 -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 1266080D; Tue, 18 Dec 2018 07:07:49 -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 8AAB83F59C; Tue, 18 Dec 2018 07:07:47 -0800 (PST) Date: Tue, 18 Dec 2018 15:07:45 +0000 From: Catalin Marinas To: He Zhe Cc: Sebastian Andrzej Siewior , tglx@linutronix.de, rostedt@goodmis.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org Subject: Re: [PATCH v2] kmemleak: Turn kmemleak_lock to raw spinlock on RT Message-ID: <20181218150744.GB20197@arrakis.emea.arm.com> References: <1542877459-144382-1-git-send-email-zhe.he@windriver.com> <20181123095314.hervxkxtqoixovro@linutronix.de> <40a63aa5-edb6-4673-b4cc-1bc10e7b3953@windriver.com> <20181130181956.eewrlaabtceekzyu@linutronix.de> <20181205191400.qrhim3m3ak5hcsuh@linutronix.de> <16ac893a-a080-18a5-e636-7b7668d978b0@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <16ac893a-a080-18a5-e636-7b7668d978b0@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 Tue, Dec 18, 2018 at 06:51:41PM +0800, He Zhe wrote: > On 2018/12/6 03:14, Sebastian Andrzej Siewior wrote: > > With raw locks you wouldn't have multiple readers at the same time. > > Maybe you wouldn't have recursion but since you can't have multiple > > readers you would add lock contention where was none (because you could > > have two readers at the same time). > > OK. I understand your concern finally. At the commit log said, I wanted to use raw > rwlock but didn't find the DEFINE helper for it. Thinking it would not be expected to > have great performance, I turn to use raw spinlock instead. And yes, this would > introduce worse performance. Looking through the kmemleak code, I can't really find significant reader contention. The longest holder of this lock (read) is the scan thread which is also protected by a scan_mutex, so can't run concurrently with another scanner (triggered through debugfs). The other read_lock(&kmemleak_lock) user is find_and_get_object() called from a few places. However, all such places normally follow a create_object() call (kmemleak_alloc() and friends) which already performs a write_lock(&kmemleak_lock), so it needs to wait for the scan thread to release the kmemleak_lock. It may be worth running some performance/latency tests during kmemleak scanning (echo scan > /sys/kernel/debug/kmemleak) but at a quick look, I don't think we'd see any difference with a raw_spin_lock_t. With a bit more thinking (though I'll be off until the new year), we could probably get rid of the kmemleak_lock entirely in scan_block() and make lookup_object() and the related rbtree code in kmemleak RCU-safe. -- Catalin