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_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 5EDB6C433DB for ; Tue, 30 Mar 2021 08:22:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A989161983 for ; Tue, 30 Mar 2021 08:22:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A989161983 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 23D566B007D; Tue, 30 Mar 2021 04:22:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1EFAC6B007E; Tue, 30 Mar 2021 04:22:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 068166B0080; Tue, 30 Mar 2021 04:22:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id DB24D6B007D for ; Tue, 30 Mar 2021 04:22:25 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A2E7D181AEF3C for ; Tue, 30 Mar 2021 08:22:25 +0000 (UTC) X-FDA: 77975848650.23.EB541F1 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf11.hostedemail.com (Postfix) with ESMTP id 261362000250 for ; Tue, 30 Mar 2021 08:22:17 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id f3so1975903pgv.0 for ; Tue, 30 Mar 2021 01:22:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WmJ21fc08wsM4/Y/mftNY0QYOCA3T7/Fy8IF01quWa8=; b=NfcIqc8VdHrkD+lX9suAICo1FeGZMq3e27Xkf+RaCaoQZ9CaMjV2lY8ksfyQg4VHPV qMyeMaGerEb/O7jf6LatoAgKpGStyGsPnpT2y3gYYWuSykwT4PfcOBXq3L2/+izLA6ia 32wgxSe/yZF/0UGWaD39wJohfqc8wG5Pnj1sSEYLOpnLbOYVR7fLKmFdL0j86LWrJLBW X8ntKkJ3F+j2bTdYwgguPd75b+EbT6R4TlldDx/IFb1zcPzw8LIotPPV7JhZEaCGT0nE qYKyy+X08vJaaHLi2XW+SD2GDonOK2tpXvr+rsTepyphsxQRmqVk1wcFW1qQPplqrfNM WzQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WmJ21fc08wsM4/Y/mftNY0QYOCA3T7/Fy8IF01quWa8=; b=GukjgsrqnekB1QaHsRb8L7qFHR96c60Z/PJUCFwEN61bY5iRGI0UcvL4vcyjh08BsX hF/5ujecb9IG2pCwK+WjH0ZQqiQrdIZkOFLOmWqbXfJtJATG1G2cdBsNQvOoiQK0cj73 zoX05/lpn7eYO6ozv7ueaSSaUp4XTujd0+h39rq/41IvDgYxuH9mcnxsHGe9LcxzvLCO 3QK/Hscxlhx3ipHw75N6rfT5IfVYtzWpiKLlUaOhEe6BaSoFwd1O8EEBth7r6qpnrG7B RLg7hQIlaaivgDr/Y8J2uHrGTF+13c1cfQPYblvUc+MEA5lgJpeI53Df1ccLlXaRr1xS FJxg== X-Gm-Message-State: AOAM532FtD/gG5kO2cFLHEq5ea9cAQ6d8eJZsG35ws1cmaD5iKgVz2aU 6th66Jq6xqpdzDaPKw1YnTasyiiz+9cSsEzHExC3jA== X-Google-Smtp-Source: ABdhPJyEYtkzl2Pc0ZLvbiKG2dJH0aZ2VdnUWyan/CC1FU6krgOdjR6GEt/fVzUEUN/ZZfNluPSw9rEEQ3dNiNmlLFA= X-Received: by 2002:aa7:9e5b:0:b029:1f1:5ba4:57a2 with SMTP id z27-20020aa79e5b0000b02901f15ba457a2mr28836298pfq.59.1617092541436; Tue, 30 Mar 2021 01:22:21 -0700 (PDT) MIME-Version: 1.0 References: <20210329232402.575396-1-mike.kravetz@oracle.com> <20210329232402.575396-2-mike.kravetz@oracle.com> In-Reply-To: From: Muchun Song Date: Tue, 30 Mar 2021 16:21:45 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v2 1/8] mm/cma: change cma mutex to irq safe spinlock To: Michal Hocko Cc: Mike Kravetz , Linux Memory Management List , LKML , Roman Gushchin , Shakeel Butt , Oscar Salvador , David Hildenbrand , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Joonsoo Kim , Barry Song , Will Deacon , Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 261362000250 X-Stat-Signature: imcpkyor7ynchg3jng3wzzfggjbfntg1 Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf11; identity=mailfrom; envelope-from=""; helo=mail-pg1-f176.google.com; client-ip=209.85.215.176 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617092537-758040 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 Tue, Mar 30, 2021 at 4:18 PM Michal Hocko wrote: > > On Tue 30-03-21 16:08:36, Muchun Song wrote: > > On Tue, Mar 30, 2021 at 4:01 PM Michal Hocko wrote: > > > > > > On Mon 29-03-21 16:23:55, Mike Kravetz wrote: > > > > Ideally, cma_release could be called from any context. However, that is > > > > not possible because a mutex is used to protect the per-area bitmap. > > > > Change the bitmap to an irq safe spinlock. > > > > > > I would phrase the changelog slightly differerent > > > " > > > cma_release is currently a sleepable operatation because the bitmap > > > manipulation is protected by cma->lock mutex. Hugetlb code which relies > > > on cma_release for CMA backed (giga) hugetlb pages, however, needs to be > > > irq safe. > > > > > > The lock doesn't protect any sleepable operation so it can be changed to > > > a (irq aware) spin lock. The bitmap processing should be quite fast in > > > typical case but if cma sizes grow to TB then we will likely need to > > > replace the lock by a more optimized bitmap implementation. > > > " > > > > > > it seems that you are overusing irqsave variants even from context which > > > are never called from the IRQ context so they do not need storing flags. > > > > > > [...] > > > > @@ -391,8 +391,9 @@ static void cma_debug_show_areas(struct cma *cma) > > > > unsigned long start = 0; > > > > unsigned long nr_part, nr_total = 0; > > > > unsigned long nbits = cma_bitmap_maxno(cma); > > > > + unsigned long flags; > > > > > > > > - mutex_lock(&cma->lock); > > > > + spin_lock_irqsave(&cma->lock, flags); > > > > > > spin_lock_irq should be sufficient. This is only called from the > > > allocation context and that is never called from IRQ context. > > > > This makes me think more. I think that spin_lock should be > > sufficient. Right? > > Nope. Think of the following scenario > spin_lock(cma->lock); > > put_page > __free_huge_page > cma_release > spin_lock_irqsave() DEADLOCK Got it. Thanks. > -- > Michal Hocko > SUSE Labs