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.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 8FDB3C433C1 for ; Thu, 25 Mar 2021 09:57:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0B4D561A23 for ; Thu, 25 Mar 2021 09:56:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B4D561A23 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 69D2E6B0070; Thu, 25 Mar 2021 05:56:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64CB06B0071; Thu, 25 Mar 2021 05:56:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4ED466B0072; Thu, 25 Mar 2021 05:56:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id 35EF76B0070 for ; Thu, 25 Mar 2021 05:56:59 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E509282499A8 for ; Thu, 25 Mar 2021 09:56:58 +0000 (UTC) X-FDA: 77957942916.30.2C4ACD5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id C97F4407F8F6 for ; Thu, 25 Mar 2021 09:56:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616666217; 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=8iDzS2rQihbEPN5F5Fal5LzoNiVnY/VTGnse7ANYFHg=; b=RskVjdRwfDQgPuma3ADt6P4Se4TNYWg4Vpby7i4eWrvB4KJe2sVmhtBZWmIRzIjUHRYfKo 7cZ4rvWuP3ciK3XfIjFHhwLPJQw3I209SleDHTy6BiCiLFjcaRJg+V+IcmgG6DyXTKZBQT W3oRoYEeMQed9GmVcIPzEzg1PscVHRw= 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-170-y8ji1gcZPz-bTiDFyxfDjw-1; Thu, 25 Mar 2021 05:56:54 -0400 X-MC-Unique: y8ji1gcZPz-bTiDFyxfDjw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA4571013722; Thu, 25 Mar 2021 09:56:51 +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 949D66787C; Thu, 25 Mar 2021 09:56:39 +0000 (UTC) To: Mike Kravetz , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Roman Gushchin , Michal Hocko , 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 References: <20210325002835.216118-1-mike.kravetz@oracle.com> <20210325002835.216118-2-mike.kravetz@oracle.com> From: David Hildenbrand Organization: Red Hat GmbH Subject: Re: [PATCH 1/8] mm: cma: introduce cma_release_nowait() Message-ID: Date: Thu, 25 Mar 2021 10:56:38 +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: <20210325002835.216118-2-mike.kravetz@oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Stat-Signature: moco7gtrc51w9iq4hqo886g1c51mxqjz X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C97F4407F8F6 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf10; 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: 1616666216-861496 Content-Transfer-Encoding: quoted-printable 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 01:28, Mike Kravetz wrote: > From: Roman Gushchin >=20 > 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(). >=20 > 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. >=20 > 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(). >=20 > 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=20 to only protect the bitmap. Are bitmaps that huge that we spend a=20 significant amount of time in there? Because I also read "Because CMA allocations and de-allocations are usually not that frequent". With a spinlock, you would no longer be sleeping, but obviously you=20 might end up waiting for the lock ;) Not sure if that would help. 2. IIUC, if we would do the clearing completely lockless and use atomic=20 bitmap ops instead, only cma_debug_show_areas() would see slight=20 inconsistencies. As long as the setting code (-> allocation code) holds=20 the lock, I think this should be fine (-> no double allocations). (sorry if that has already been discussed) --=20 Thanks, David / dhildenb