From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 919C9C5517A for ; Fri, 23 Oct 2020 20:53:42 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1BEB820FC3 for ; Fri, 23 Oct 2020 20:53:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="kvqPjaUA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1BEB820FC3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0B07A6E828; Fri, 23 Oct 2020 20:53:41 +0000 (UTC) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by gabe.freedesktop.org (Postfix) with ESMTPS id C85576E828; Fri, 23 Oct 2020 20:53:39 +0000 (UTC) Received: from paulmck-ThinkPad-P72.home (50-39-104-11.bvtn.or.frontiernet.net [50.39.104.11]) (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 693F1208E4; Fri, 23 Oct 2020 20:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603486419; bh=ojQX8v4FWHWriM/9vutOQ7P1tVXDPKF1/x3d5VeoJaw=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=kvqPjaUAbhgOA7v9m5hPwFhSot+9JpnZXoeCrdsm06tmZk3i0PrkuY3l00nQhXTO7 mME/ZUGMaFJ8HfKVhEI2MvB8tG0mJXu0Oz9Lq5QXxDSvD9OeEOp7qTfPlU5UBnvfap tnFzhsUdlh/9ZNLst1GWoxnofysl3fTu/WbsWfz4= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 03E563520D11; Fri, 23 Oct 2020 13:53:39 -0700 (PDT) Date: Fri, 23 Oct 2020 13:53:38 -0700 From: "Paul E. McKenney" To: Daniel Vetter Subject: Re: [PATCH 04/65] mm: Extract might_alloc() debug check Message-ID: <20201023205338.GQ3249@paulmck-ThinkPad-P72> References: <20201021163242.1458885-1-daniel.vetter@ffwll.ch> <20201023122216.2373294-1-daniel.vetter@ffwll.ch> <20201023122216.2373294-4-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201023122216.2373294-4-daniel.vetter@ffwll.ch> User-Agent: Mutt/1.9.4 (2018-02-28) X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: paulmck@kernel.org Cc: Peter Zijlstra , Sebastian Andrzej Siewior , Dave Chinner , DRI Development , linux-mm@kvack.org, Daniel Vetter , Christoph Lameter , Michel Lespinasse , Ingo Molnar , Pekka Enberg , David Rientjes , Waiman Long , Intel Graphics Development , Qian Cai , Thomas Gleixner , Joonsoo Kim , Vlastimil Babka , Randy Dunlap , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Mathieu Desnoyers , Andrew Morton Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Fri, Oct 23, 2020 at 02:21:15PM +0200, Daniel Vetter wrote: > Extracted from slab.h, which seems to have the most complete version > including the correct might_sleep() check. Roll it out to slob.c. > > Motivated by a discussion with Paul about possibly changing call_rcu > behaviour to allocate memory, but only roughly every 500th call. > > There are a lot fewer places in the kernel that care about whether > allocating memory is allowed or not (due to deadlocks with reclaim > code) than places that care whether sleeping is allowed. But debugging > these also tends to be a lot harder, so nice descriptive checks could > come in handy. I might have some use eventually for annotations in > drivers/gpu. > > Note that unlike fs_reclaim_acquire/release gfpflags_allow_blocking > does not consult the PF_MEMALLOC flags. But there is no flag > equivalent for GFP_NOWAIT, hence this check can't go wrong due to > memalloc_no*_save/restore contexts. > > Cc: Paul E. McKenney > Cc: Christoph Lameter > Cc: Pekka Enberg > Cc: David Rientjes > Cc: Joonsoo Kim > Cc: Andrew Morton > Cc: Peter Zijlstra > Cc: Ingo Molnar > Cc: Vlastimil Babka > Cc: Mathieu Desnoyers > Cc: Sebastian Andrzej Siewior > Cc: Michel Lespinasse > Cc: Daniel Vetter > Cc: Waiman Long > Cc: Thomas Gleixner > Cc: Randy Dunlap > Cc: linux-mm@kvack.org > Cc: linux-fsdevel@vger.kernel.org > Cc: Dave Chinner > Cc: Qian Cai > Cc: linux-xfs@vger.kernel.org > Signed-off-by: Daniel Vetter Nice!!! Acked-by: Paul E. McKenney > --- > include/linux/sched/mm.h | 16 ++++++++++++++++ > mm/slab.h | 5 +---- > mm/slob.c | 6 ++---- > 3 files changed, 19 insertions(+), 8 deletions(-) > > diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h > index f889e332912f..2b0037abac0b 100644 > --- a/include/linux/sched/mm.h > +++ b/include/linux/sched/mm.h > @@ -205,6 +205,22 @@ static inline void fs_reclaim_acquire(gfp_t gfp_mask) { } > static inline void fs_reclaim_release(gfp_t gfp_mask) { } > #endif > > +/** > + * might_alloc - Marks possible allocation sites > + * @gfp_mask: gfp_t flags that would be use to allocate > + * > + * Similar to might_sleep() and other annotations this can be used in functions > + * that might allocate, but often dont. Compiles to nothing without > + * CONFIG_LOCKDEP. Includes a conditional might_sleep() if @gfp allows blocking. > + */ > +static inline void might_alloc(gfp_t gfp_mask) > +{ > + fs_reclaim_acquire(gfp_mask); > + fs_reclaim_release(gfp_mask); > + > + might_sleep_if(gfpflags_allow_blocking(gfp_mask)); > +} > + > /** > * memalloc_noio_save - Marks implicit GFP_NOIO allocation scope. > * > diff --git a/mm/slab.h b/mm/slab.h > index 6cc323f1313a..fedd789b2270 100644 > --- a/mm/slab.h > +++ b/mm/slab.h > @@ -492,10 +492,7 @@ static inline struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s, > { > flags &= gfp_allowed_mask; > > - fs_reclaim_acquire(flags); > - fs_reclaim_release(flags); > - > - might_sleep_if(gfpflags_allow_blocking(flags)); > + might_alloc(flags); > > if (should_failslab(s, flags)) > return NULL; > diff --git a/mm/slob.c b/mm/slob.c > index 7cc9805c8091..8d4bfa46247f 100644 > --- a/mm/slob.c > +++ b/mm/slob.c > @@ -474,8 +474,7 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller) > > gfp &= gfp_allowed_mask; > > - fs_reclaim_acquire(gfp); > - fs_reclaim_release(gfp); > + might_alloc(gfp); > > if (size < PAGE_SIZE - minalign) { > int align = minalign; > @@ -597,8 +596,7 @@ static void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node) > > flags &= gfp_allowed_mask; > > - fs_reclaim_acquire(flags); > - fs_reclaim_release(flags); > + might_alloc(flags); > > if (c->size < PAGE_SIZE) { > b = slob_alloc(c->size, flags, c->align, node, 0); > -- > 2.28.0 > _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel