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=-12.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 CEA36C433DB for ; Thu, 25 Mar 2021 17:16:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4986261A2B for ; Thu, 25 Mar 2021 17:16:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4986261A2B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6A84E6B006C; Thu, 25 Mar 2021 13:16:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 67F1C6B006E; Thu, 25 Mar 2021 13:16:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FAAC6B0070; Thu, 25 Mar 2021 13:16:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0117.hostedemail.com [216.40.44.117]) by kanga.kvack.org (Postfix) with ESMTP id 358376B006C for ; Thu, 25 Mar 2021 13:16:22 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C0A7D2AEE5 for ; Thu, 25 Mar 2021 17:16:21 +0000 (UTC) X-FDA: 77959050162.39.1B179FF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 1F734E000266 for ; Thu, 25 Mar 2021 17:16:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616692577; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CvfaC95aieRSVkuhdfvCS5wS1U7ACP9oYPxW5/dC0DU=; b=hzXW6Mv9sTMVjpUp890/2k45uZ26DvOQR6zoImwgnWJz7rFDpIvLHZaxUNIuEUl2DPwUhC 8Prmyv4JeD8hsW54ESDPRmV6RtSidLaOhJIWNeyy2rI5tSfxC93Ksp6ZzDRlGlhhWnzyYg eN+94RqD0S7kEz+PFhw/IqysCyshdpY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-150-ksrTlQFjMsaDLsgrOHWiLg-1; Thu, 25 Mar 2021 13:16:12 -0400 X-MC-Unique: ksrTlQFjMsaDLsgrOHWiLg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6DD1D10A5A2F; Thu, 25 Mar 2021 17:15:18 +0000 (UTC) Received: from [10.36.115.72] (ovpn-115-72.ams2.redhat.com [10.36.115.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id E76CB88F0C; Thu, 25 Mar 2021 17:15:12 +0000 (UTC) Subject: Re: [PATCH 1/8] mm: cma: introduce cma_release_nowait() To: Mike Kravetz , Michal Hocko Cc: 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 , Joonsoo Kim References: <20210325002835.216118-1-mike.kravetz@oracle.com> <20210325002835.216118-2-mike.kravetz@oracle.com> <76aaf359-9496-04df-a585-3662d0375749@oracle.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <4bc3c5d8-f1a7-6439-8fee-582364a7c021@redhat.com> Date: Thu, 25 Mar 2021 18:15:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <76aaf359-9496-04df-a585-3662d0375749@oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Stat-Signature: 7wrt7jitwxgyz4p74nzkcgka6h7c1awr X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1F734E000266 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf30; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616692574-410170 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 25.03.21 17:56, Mike Kravetz wrote: > On 3/25/21 3:22 AM, Michal Hocko wrote: >> 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. >> > > When Roman first proposed these patches, I brought up the same issue: > > https://lore.kernel.org/linux-mm/20201022023352.GC300658@carbon.dhcp.thefacebook.com/ > > Previously, Roman proposed replacing the mutex with a spinlock but > Joonsoo was opposed. > > Adding Joonsoo on Cc: > There has to be a good reason not to. And if there is a good reason, lockless clearing might be one feasible alternative. -- Thanks, David / dhildenb