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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 BFAFCC433DB for ; Thu, 25 Mar 2021 10:22:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 350E061A27 for ; Thu, 25 Mar 2021 10:22:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 350E061A27 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 940326B0074; Thu, 25 Mar 2021 06:22:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EF466B0075; Thu, 25 Mar 2021 06:22:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7697F6B0078; Thu, 25 Mar 2021 06:22:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0209.hostedemail.com [216.40.44.209]) by kanga.kvack.org (Postfix) with ESMTP id 593F76B0074 for ; Thu, 25 Mar 2021 06:22:51 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2E44F183D71E7 for ; Thu, 25 Mar 2021 10:22:50 +0000 (UTC) X-FDA: 77958008100.11.912FA13 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf25.hostedemail.com (Postfix) with ESMTP id 6A3DD60024AF for ; Thu, 25 Mar 2021 10:22:22 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1616667742; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=NUhM+pMq44irMHX7DfDb0Q+0VoT1g5waQrN7iM9goSQ=; b=F97ID0JccJbAI37lYP6SnwfQT6vA2jUoU5aupa5HvrAU5AerC3FqyrVFRbjk1bI6ULJHpM N7a+qeoToCGtnrz1cUUmZiwYoDp51hnQa4WxT1WIGM+a/qedaAmJT8cdtd9aLcI1K0VTSR IvCmVMe9lwOY2Xtz1p2ya0rUKztVezQ= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 313F2AA55; Thu, 25 Mar 2021 10:22:22 +0000 (UTC) Date: Thu, 25 Mar 2021 11:22:20 +0100 From: Michal Hocko To: David Hildenbrand Cc: Mike Kravetz , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Roman Gushchin , Shakeel Butt , Oscar Salvador , Muchun Song , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Andrew Morton Subject: Re: [PATCH 1/8] mm: cma: introduce cma_release_nowait() Message-ID: References: <20210325002835.216118-1-mike.kravetz@oracle.com> <20210325002835.216118-2-mike.kravetz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6A3DD60024AF X-Stat-Signature: g1kn5mrhhsafcawe7uh13sgnfp1xfbrb Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf25; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616667742-36593 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu 25-03-21 10:56:38, David Hildenbrand wrote: > On 25.03.21 01:28, Mike Kravetz wrote: > > From: Roman Gushchin > > > > cma_release() has to lock the cma_lock mutex to clear the cma bitmap. > > It makes it a blocking function, which complicates its usage from > > non-blocking contexts. For instance, hugetlbfs code is temporarily > > dropping the hugetlb_lock spinlock to call cma_release(). > > > > This patch introduces a non-blocking cma_release_nowait(), which > > postpones the cma bitmap clearance. It's done later from a work > > context. The first page in the cma allocation is used to store > > the work struct. Because CMA allocations and de-allocations are > > usually not that frequent, a single global workqueue is used. > > > > To make sure that subsequent cma_alloc() call will pass, cma_alloc() > > flushes the cma_release_wq workqueue. To avoid a performance > > regression in the case when only cma_release() is used, gate it > > by a per-cma area flag, which is set by the first call > > of cma_release_nowait(). > > > > Signed-off-by: Roman Gushchin > > [mike.kravetz@oracle.com: rebased to v5.12-rc3-mmotm-2021-03-17-22-24] > > Signed-off-by: Mike Kravetz > > --- > > > 1. Is there a real reason this is a mutex and not a spin lock? It seems to > only protect the bitmap. Are bitmaps that huge that we spend a significant > amount of time in there? Good question. Looking at the code it doesn't seem that there is any blockable operation or any heavy lifting done under the lock. 7ee793a62fa8 ("cma: Remove potential deadlock situation") has introduced the lock and there was a simple bitmat protection back then. I suspect the patch just followed the cma_mutex lead and used the same type of the lock. cma_mutex used to protect alloc_contig_range which is sleepable. This all suggests that there is no real reason to use a sleepable lock at all and we do not need all this heavy lifting. Thanks! -- Michal Hocko SUSE Labs