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=-8.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 97916C433C1 for ; Thu, 25 Mar 2021 20:12:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2901C61A2B for ; Thu, 25 Mar 2021 20:12:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2901C61A2B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 65B456B006C; Thu, 25 Mar 2021 16:12:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60B266B006E; Thu, 25 Mar 2021 16:12:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4844B6B0070; Thu, 25 Mar 2021 16:12:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id 2817F6B006C for ; Thu, 25 Mar 2021 16:12:57 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DE7E1180AD81D for ; Thu, 25 Mar 2021 20:12:56 +0000 (UTC) X-FDA: 77959495152.30.A24AA62 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf28.hostedemail.com (Postfix) with ESMTP id CCD2B2000253 for ; Thu, 25 Mar 2021 20:12:55 +0000 (UTC) Received: by mail-pg1-f181.google.com with SMTP id l76so2929597pga.6 for ; Thu, 25 Mar 2021 13:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=oKCCJvFAhyXitm2ivJmoGad7JQ14zbFEvHLYcmjzujI=; b=Wal6MNfKxDi8FAcS76nifM2uKxeApjUPR6pWBvMdiVwjENJ41KMHuiuBFSD68Kmsw9 Lj6aeh5bHVzjXrKYdh9GN1E7DYqrLpMbFN1uWSjgjJcQO31d2CqzRn7VCrDuQmvRJq5i ghv9+NKQw3gSb5VzPnb/wS2syQWGS9UA1m8l9bIRQwdx0L+mDejM52xy2/1a1zUgHQ5w T8Za1iMNlpdEB1QMt8LOvKaKvCJ9EGTHwARD+iyvYFOkmdhhyeGoEjuiQFERdgJ9DSXg 2YXTUduQqMJCfgkJkzxBISnilOSBCSMM5bjvQAPbkVHrgkS32OEc9h5xpBGeOlvVcTdw iRyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=oKCCJvFAhyXitm2ivJmoGad7JQ14zbFEvHLYcmjzujI=; b=sTdwOIUWvo7KenA7HsGVhU5GHCI3PwS/y3c9BxDyEQhHR+mzdAVC72UKH8IFIxQNHU 0UfIvTYaovoX9rykWNUICV8hSOIu2LTAVqVgBy2upGuKUcwVnS+HaVaeuC4rJLB8HA5X M4a0M/jPI/+epjuoWpzwhje3eqru6rQm6v6EsOgY66Iydj84a1Md6sdzDWOEcybA2n90 XDu/I57SGmDfv+zg2oUYGAnvisriGu6SO9JxjWkH2LnQ7rH2pUEt8+Ai2X651QhOMFrN op1drM+pGn09NSGQpx066RszhNYs2YBwG2ZrYPbXm5h8q8weZhGZTtZQHWbol9VfeWLZ uncw== X-Gm-Message-State: AOAM532xsdC2+VGhIgAkqHcMawwqZZYxmyXAyP6cl31egCZ4C2aeie1t tXiDew2U5ky+ows9ZDsGE6g= X-Google-Smtp-Source: ABdhPJxpPtICV9qH7Mky40gHzeB9G0a1Pe1w3UI8+/0GeVw7mcKrL6dozLNBYQNgTSj/eg1Zn1KqDw== X-Received: by 2002:a63:ce03:: with SMTP id y3mr8974310pgf.414.1616703175343; Thu, 25 Mar 2021 13:12:55 -0700 (PDT) Received: from google.com ([2620:15c:211:201:4c1e:8d39:76c4:59d7]) by smtp.gmail.com with ESMTPSA id b84sm6519072pfb.162.2021.03.25.13.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 13:12:54 -0700 (PDT) Date: Thu, 25 Mar 2021 13:12:51 -0700 From: Minchan Kim To: David Hildenbrand Cc: Mike Kravetz , Michal Hocko , 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 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> <76aaf359-9496-04df-a585-3662d0375749@oracle.com> <4bc3c5d8-f1a7-6439-8fee-582364a7c021@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4bc3c5d8-f1a7-6439-8fee-582364a7c021@redhat.com> X-Stat-Signature: ozbtf6pqm3cqdirwds6d9dukackhxpto X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: CCD2B2000253 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=mail-pg1-f181.google.com; client-ip=209.85.215.181 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616703175-517259 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, Mar 25, 2021 at 06:15:11PM +0100, David Hildenbrand wrote: > 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. I also don't think nowait variant is good idea. If the scanning of bitmap is *really* significant, it might be signal that we need to introduce different technique or data structure not bitmap rather than a new API variant.