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_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 397C5C433DB for ; Tue, 30 Mar 2021 08:18:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D4E5B61490 for ; Tue, 30 Mar 2021 08:18:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D4E5B61490 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 6621B6B007D; Tue, 30 Mar 2021 04:18:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6391B6B007E; Tue, 30 Mar 2021 04:18:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DA8E6B0080; Tue, 30 Mar 2021 04:18:43 -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 329656B007D for ; Tue, 30 Mar 2021 04:18:43 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D7A1C180AD81A for ; Tue, 30 Mar 2021 08:18:42 +0000 (UTC) X-FDA: 77975839284.34.9F72607 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf08.hostedemail.com (Postfix) with ESMTP id 2E10E80192E1 for ; Tue, 30 Mar 2021 08:18:36 +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=1617092321; 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=wNw4nGVKh6SriT/z86f2SGzgVHpW0NorEGH4COOxJUo=; b=l8JS67PZkLeSBclyeYuVlbPnE6ocBl1TXDJ8G0G72ngoWy6FLGLhJWgfW8qEalAdsZ3RBN 7hXMQp9JY8kb+azQhsW14wJNiUxZo+CnhlCTEL5DPM3xGjSZOzbuRgDQ13XtZBC8fTxzmR uny1PEiAX5U8jCXzvf3pkWrNedW59ks= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EAB04AEF5; Tue, 30 Mar 2021 08:18:40 +0000 (UTC) Date: Tue, 30 Mar 2021 10:18:39 +0200 From: Michal Hocko To: Muchun Song 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 Subject: Re: [External] Re: [PATCH v2 1/8] mm/cma: change cma mutex to irq safe spinlock Message-ID: References: <20210329232402.575396-1-mike.kravetz@oracle.com> <20210329232402.575396-2-mike.kravetz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 2E10E80192E1 X-Stat-Signature: am1h59x3tcbmi3qba7peet6m49yrzat3 X-Rspamd-Server: rspam02 Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf08; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617092316-172186 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 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 -- Michal Hocko SUSE Labs