Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp937897ybj; Thu, 7 May 2020 10:56:47 -0700 (PDT) X-Google-Smtp-Source: APiQypIyplESkZs9Izf/+Uy7IQAaJBn0LAhZUyQYiP/kzcBjARnahTEy+KBYrqX1FPidruT9QC0V X-Received: by 2002:a17:906:9453:: with SMTP id z19mr2841143ejx.276.1588874207531; Thu, 07 May 2020 10:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588874207; cv=none; d=google.com; s=arc-20160816; b=uPvV5k2X8ciY51o2RvPOLybA8HUdgNSQCDiYyYBtUpYka3ZCN7KOQReXWDsFsf2TRG tqxd4QRZp5/saiaoxtKn4v0PD+2sjgVvOGuGOGgGeDrORq5vdYrmhxxUwBLSlylAnTYT TJCmUVRuiQERGvoGmJZnILCa0jSxjEe8Tks80IcsHRxJrqanNQvz6qM+BiG4qlfKQeZ9 VR4m+gN0eTa+q9+6+hgFjtiPTQEoRUV+k2Qyhb8Ctu1r23Oh3+vAdbJa1jz9eXtn4K16 PFIeNOCiYWkr03Yj0YBTrH+bpC0xW/pTUbwJaPNEXUB0AzDJfVp694iIuJ2EbCX5MeD3 yltg== 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:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=WPcKoa3TJ1rZ9qzAS6Fg4Gc3MOGA5sY3/f6Z99zC6uk=; b=ci62xtxeC29wAYR6ShkAtmmZXPboBqSHvOSQybMJdTQsK783mweBYkMJQ44Jd6+13M 5CWNrsXAGjiJdOmqgxL5zahZWs5a4PV0y8ouFPfkJru07WDYqbQzlbf24KIOx6lJuCks 7mB13G4QXRSPYGAzwS9ANun72rIR/EexPtTeCGdKl9cD6GHy6VWHtX7cz4jl3DEGvq1l Yq7GpuBNrsPN63DZJeubHdq8tRBIuguiAec4oG5FE/99U7YBLfwcej809rVqTaD7PhtP 40VWMvAPSlnexPYqt9y7yJF/vRsWoS7TWP+TcFwUCND453ytijweyQxb97iEqBDFZGXV tx5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pKD8QCZK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dg6si1171487edb.15.2020.05.07.10.56.22; Thu, 07 May 2020 10:56:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pKD8QCZK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728049AbgEGRy2 (ORCPT + 99 others); Thu, 7 May 2020 13:54:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:44704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726320AbgEGRy1 (ORCPT ); Thu, 7 May 2020 13:54:27 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5B1D52145D; Thu, 7 May 2020 17:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588874067; bh=QJaiSjCjLbAWFDcmuf/Pneq2du1jY9r042RVJds1hO0=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=pKD8QCZKdNeR4cgjo9ugXAKZQS8MIUuvWNTGi+44zq2pg862dujYCMPY35hu47AYD O6+hmKJ8TYF7QejWc8yOJ8ND9UfRKhg0yxPYnkEFAzRiYc86ZGk0CbtsKRZqwxRTJR +DLTSFziy5UChxjljtQe1VYZCq/s9RWAKawRIo20= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 4493C35231BF; Thu, 7 May 2020 10:54:27 -0700 (PDT) Date: Thu, 7 May 2020 10:54:27 -0700 From: "Paul E. McKenney" To: Catalin Marinas Cc: Qian Cai , Linux-MM , LKML Subject: Re: Kmemleak infrastructure improvement for task_struct leaks and call_rcu() Message-ID: <20200507175427.GT2869@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <45D2D811-C3B0-442B-9744-415B4AC5CCDB@lca.pw> <20200506174019.GA2869@paulmck-ThinkPad-P72> <20200507171418.GC3180@gaia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200507171418.GC3180@gaia> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 07, 2020 at 06:14:19PM +0100, Catalin Marinas wrote: > On Wed, May 06, 2020 at 10:40:19AM -0700, Paul E. McKenney wrote: > > On Wed, May 06, 2020 at 12:22:37PM -0400, Qian Cai wrote: > > > == call_rcu() leaks == > > > Another issue that might be relevant is that it seems sometimes, > > > kmemleak will give a lot of false positives (hundreds) because the > > > memory was supposed to be freed by call_rcu() (for example, in > > > dst_release()) but for some reasons, it takes a long time probably > > > waiting for grace periods or some kind of RCU self-stall, but the > > > memory had already became an orphan. I am not sure how we are going > > > to resolve this properly until we have to figure out why call_rcu() > > > is taking so long to finish? > > > > I know nothing about kmemleak, but I won't let that stop me from making > > random suggestions... > > > > One approach is to do an rcu_barrier() inside kmemleak just before > > printing leaked blocks, and check to see if any are still leaked after > > the rcu_barrier(). > > The main issue is that kmemleak doesn't stop the world when scanning > (which can take over a minute, depending on your hardware), so we get > lots of transient pointer misses. There are some heuristics but > obviously they don't always work. > > With RCU, objects are queued for RCU freeing later and chained via > rcu_head.next (IIUC). Under load, this list can be pretty volatile and > if this happen during kmemleak scanning, it's sufficient to lose track > of a next pointer and the rest of the list would be reported as a leak. > > I think rcu_barrier() just before the starting the kmemleak scanning may > help if it reduces the number of objects queued. It might, especially if the call_rcu() rate is lower after the rcu_barrier() than it was beforehand. Which might well be the case when a large cleanup activity ended just before rcu_barrier() was invoked. > Now, I wonder whether kmemleak itself can break this RCU chain. The > kmemleak metadata is allocated on a slab alloc callback. The freeing, > however, is done using call_rcu() because originally calling back into > the slab freeing from kmemleak_free() didn't go well. Since the > kmemleak_object structure is not tracked by kmemleak, I wonder whether > its rcu_head would break this directed pointer reference graph. It is true that kmemleak could decide that being passed to call_rcu() as being freed. However, it would need to know the rcu_head offset. And there are (or were) a few places that pass linked structures to call_rcu(), and kmemleak would presumably need to mark them all free at that point. Or maybe accept the much lower false-positive rate from not marking them. > Let's try the rcu_barrier() first and I'll think about the metadata case > over the weekend. Looking forward to hearing how it goes! Thanx, Paul