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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,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 C956AC433B4 for ; Tue, 6 Apr 2021 09:36:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 60F9B613C2 for ; Tue, 6 Apr 2021 09:36:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60F9B613C2 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 C01346B007E; Tue, 6 Apr 2021 05:36:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B9E546B0080; Tue, 6 Apr 2021 05:36:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A17526B0081; Tue, 6 Apr 2021 05:36:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0150.hostedemail.com [216.40.44.150]) by kanga.kvack.org (Postfix) with ESMTP id 81B756B007E for ; Tue, 6 Apr 2021 05:36:02 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 347D7363D for ; Tue, 6 Apr 2021 09:36:02 +0000 (UTC) X-FDA: 78001435764.20.6351738 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf30.hostedemail.com (Postfix) with ESMTP id 9A43AE000113 for ; Tue, 6 Apr 2021 09:35:56 +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=1617701760; 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=SRwipLY+b1q1Ng3CPB27+Kz4klgfyfup2vzIC/VRkiQ=; b=Qr1DCsawXUipVa6pi5VbIAfveKswpPD63XOD8j/eDIdjWVfzTG3YcnfWXPXf2qxAXqV8HC 0VSdcnA3csvhK0Vq8Dg+u0gsK2lEaw96h6e03RHjSo8SklLubVtazN610qcIYbLD4ESvLP Pgyhl+1Rcs8eliP9H7RXCdKSj7pHi64= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 99584B12E; Tue, 6 Apr 2021 09:35:59 +0000 (UTC) Date: Tue, 6 Apr 2021 11:35:56 +0200 From: Michal Hocko To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Roman Gushchin , Shakeel Butt , Oscar Salvador , David Hildenbrand , Muchun Song , 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: [PATCH v4 1/8] mm/cma: change cma mutex to irq safe spinlock Message-ID: References: <20210405230043.182734-1-mike.kravetz@oracle.com> <20210405230043.182734-2-mike.kravetz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210405230043.182734-2-mike.kravetz@oracle.com> X-Stat-Signature: 3dtd7paijeectw4e8x4j56kiwapz6bmb X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9A43AE000113 Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf30; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617701756-876198 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 Mon 05-04-21 16:00:36, Mike Kravetz wrote: > 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. > > Signed-off-by: Mike Kravetz I belive I have acked the previous version already. Anyway Acked-by: Michal Hocko > --- > mm/cma.c | 18 +++++++++--------- > mm/cma.h | 2 +- > mm/cma_debug.c | 8 ++++---- > 3 files changed, 14 insertions(+), 14 deletions(-) > > diff --git a/mm/cma.c b/mm/cma.c > index f3bca4178c7f..995e15480937 100644 > --- a/mm/cma.c > +++ b/mm/cma.c > @@ -24,7 +24,6 @@ > #include > #include > #include > -#include > #include > #include > #include > @@ -83,13 +82,14 @@ static void cma_clear_bitmap(struct cma *cma, unsigned long pfn, > unsigned long count) > { > unsigned long bitmap_no, bitmap_count; > + unsigned long flags; > > bitmap_no = (pfn - cma->base_pfn) >> cma->order_per_bit; > bitmap_count = cma_bitmap_pages_to_bits(cma, count); > > - mutex_lock(&cma->lock); > + spin_lock_irqsave(&cma->lock, flags); > bitmap_clear(cma->bitmap, bitmap_no, bitmap_count); > - mutex_unlock(&cma->lock); > + spin_unlock_irqrestore(&cma->lock, flags); > } > > static void __init cma_activate_area(struct cma *cma) > @@ -118,7 +118,7 @@ static void __init cma_activate_area(struct cma *cma) > pfn += pageblock_nr_pages) > init_cma_reserved_pageblock(pfn_to_page(pfn)); > > - mutex_init(&cma->lock); > + spin_lock_init(&cma->lock); > > #ifdef CONFIG_CMA_DEBUGFS > INIT_HLIST_HEAD(&cma->mem_head); > @@ -392,7 +392,7 @@ static void cma_debug_show_areas(struct cma *cma) > unsigned long nr_part, nr_total = 0; > unsigned long nbits = cma_bitmap_maxno(cma); > > - mutex_lock(&cma->lock); > + spin_lock_irq(&cma->lock); > pr_info("number of available pages: "); > for (;;) { > next_zero_bit = find_next_zero_bit(cma->bitmap, nbits, start); > @@ -407,7 +407,7 @@ static void cma_debug_show_areas(struct cma *cma) > start = next_zero_bit + nr_zero; > } > pr_cont("=> %lu free of %lu total pages\n", nr_total, cma->count); > - mutex_unlock(&cma->lock); > + spin_unlock_irq(&cma->lock); > } > #else > static inline void cma_debug_show_areas(struct cma *cma) { } > @@ -454,12 +454,12 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, > goto out; > > for (;;) { > - mutex_lock(&cma->lock); > + spin_lock_irq(&cma->lock); > bitmap_no = bitmap_find_next_zero_area_off(cma->bitmap, > bitmap_maxno, start, bitmap_count, mask, > offset); > if (bitmap_no >= bitmap_maxno) { > - mutex_unlock(&cma->lock); > + spin_unlock_irq(&cma->lock); > break; > } > bitmap_set(cma->bitmap, bitmap_no, bitmap_count); > @@ -468,7 +468,7 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, > * our exclusive use. If the migration fails we will take the > * lock again and unmark it. > */ > - mutex_unlock(&cma->lock); > + spin_unlock_irq(&cma->lock); > > pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit); > ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, > diff --git a/mm/cma.h b/mm/cma.h > index 68ffad4e430d..2c775877eae2 100644 > --- a/mm/cma.h > +++ b/mm/cma.h > @@ -15,7 +15,7 @@ struct cma { > unsigned long count; > unsigned long *bitmap; > unsigned int order_per_bit; /* Order of pages represented by one bit */ > - struct mutex lock; > + spinlock_t lock; > #ifdef CONFIG_CMA_DEBUGFS > struct hlist_head mem_head; > spinlock_t mem_head_lock; > diff --git a/mm/cma_debug.c b/mm/cma_debug.c > index d5bf8aa34fdc..2e7704955f4f 100644 > --- a/mm/cma_debug.c > +++ b/mm/cma_debug.c > @@ -36,10 +36,10 @@ static int cma_used_get(void *data, u64 *val) > struct cma *cma = data; > unsigned long used; > > - mutex_lock(&cma->lock); > + spin_lock_irq(&cma->lock); > /* pages counter is smaller than sizeof(int) */ > used = bitmap_weight(cma->bitmap, (int)cma_bitmap_maxno(cma)); > - mutex_unlock(&cma->lock); > + spin_unlock_irq(&cma->lock); > *val = (u64)used << cma->order_per_bit; > > return 0; > @@ -53,7 +53,7 @@ static int cma_maxchunk_get(void *data, u64 *val) > unsigned long start, end = 0; > unsigned long bitmap_maxno = cma_bitmap_maxno(cma); > > - mutex_lock(&cma->lock); > + spin_lock_irq(&cma->lock); > for (;;) { > start = find_next_zero_bit(cma->bitmap, bitmap_maxno, end); > if (start >= bitmap_maxno) > @@ -61,7 +61,7 @@ static int cma_maxchunk_get(void *data, u64 *val) > end = find_next_bit(cma->bitmap, bitmap_maxno, start); > maxchunk = max(end - start, maxchunk); > } > - mutex_unlock(&cma->lock); > + spin_unlock_irq(&cma->lock); > *val = (u64)maxchunk << cma->order_per_bit; > > return 0; > -- > 2.30.2 > -- Michal Hocko SUSE Labs