From patchwork Thu Jun 12 03:21:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 4339401 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 286A3BEEAA for ; Thu, 12 Jun 2014 03:21:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3123220303 for ; Thu, 12 Jun 2014 03:21:32 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A61E200DF for ; Thu, 12 Jun 2014 03:21:31 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WuvXv-0001jd-95; Thu, 12 Jun 2014 03:19:23 +0000 Received: from lgeamrelo01.lge.com ([156.147.1.125]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WuvWo-00018s-1b for linux-arm-kernel@lists.infradead.org; Thu, 12 Jun 2014 03:18:18 +0000 Received: from unknown (HELO js1304-P5Q-DELUXE.LGE.NET) (10.177.220.145) by 156.147.1.125 with ESMTP; 12 Jun 2014 12:17:50 +0900 X-Original-SENDERIP: 10.177.220.145 X-Original-MAILFROM: iamjoonsoo.kim@lge.com From: Joonsoo Kim To: Andrew Morton , "Aneesh Kumar K.V" , Marek Szyprowski , Michal Nazarewicz Subject: [PATCH v2 10/10] mm, cma: use spinlock instead of mutex Date: Thu, 12 Jun 2014 12:21:47 +0900 Message-Id: <1402543307-29800-11-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1402543307-29800-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1402543307-29800-1-git-send-email-iamjoonsoo.kim@lge.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140611_201814_513136_0576E290 X-CRM114-Status: GOOD ( 10.97 ) X-Spam-Score: -0.7 (/) Cc: Russell King - ARM Linux , kvm@vger.kernel.org, linux-mm@kvack.org, Gleb Natapov , Greg Kroah-Hartman , Alexander Graf , kvm-ppc@vger.kernel.org, linux-kernel@vger.kernel.org, Minchan Kim , Paul Mackerras , Benjamin Herrenschmidt , Paolo Bonzini , Joonsoo Kim , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, we should take the mutex for manipulating bitmap. This job may be really simple and short so we don't need to sleep if contended. So I change it to spinlock. Signed-off-by: Joonsoo Kim diff --git a/mm/cma.c b/mm/cma.c index 22a5b23..3085e8c 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,7 @@ struct cma { unsigned long count; unsigned long *bitmap; int order_per_bit; /* Order of pages represented by one bit */ - struct mutex lock; + spinlock_t lock; }; /* @@ -72,9 +73,9 @@ static void clear_cma_bitmap(struct cma *cma, unsigned long pfn, int count) bitmapno = (pfn - cma->base_pfn) >> cma->order_per_bit; nr_bits = cma_bitmap_pages_to_bits(cma, count); - mutex_lock(&cma->lock); + spin_lock(&cma->lock); bitmap_clear(cma->bitmap, bitmapno, nr_bits); - mutex_unlock(&cma->lock); + spin_unlock(&cma->lock); } static int __init cma_activate_area(struct cma *cma) @@ -112,7 +113,7 @@ static int __init cma_activate_area(struct cma *cma) init_cma_reserved_pageblock(pfn_to_page(base_pfn)); } while (--i); - mutex_init(&cma->lock); + spin_lock_init(&cma->lock); return 0; err: @@ -261,11 +262,11 @@ struct page *cma_alloc(struct cma *cma, int count, unsigned int align) nr_bits = cma_bitmap_pages_to_bits(cma, count); for (;;) { - mutex_lock(&cma->lock); + spin_lock(&cma->lock); bitmapno = bitmap_find_next_zero_area(cma->bitmap, bitmap_maxno, start, nr_bits, mask); if (bitmapno >= bitmap_maxno) { - mutex_unlock(&cma->lock); + spin_unlock(&cma->lock); break; } bitmap_set(cma->bitmap, bitmapno, nr_bits); @@ -274,7 +275,7 @@ struct page *cma_alloc(struct cma *cma, int count, unsigned int align) * our exclusive use. If the migration fails we will take the * lock again and unmark it. */ - mutex_unlock(&cma->lock); + spin_unlock(&cma->lock); pfn = cma->base_pfn + (bitmapno << cma->order_per_bit); mutex_lock(&cma_mutex);