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: 4339231 Return-Path: X-Original-To: patchwork-kvm@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 ED300BEEAA for ; Thu, 12 Jun 2014 03:19:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3014E20303 for ; Thu, 12 Jun 2014 03:19:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2AE6E2022A for ; Thu, 12 Jun 2014 03:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755939AbaFLDSv (ORCPT ); Wed, 11 Jun 2014 23:18:51 -0400 Received: from lgeamrelo01.lge.com ([156.147.1.125]:55657 "EHLO lgeamrelo01.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755683AbaFLDRw (ORCPT ); Wed, 11 Jun 2014 23:17:52 -0400 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 Cc: Minchan Kim , Russell King - ARM Linux , Greg Kroah-Hartman , Paolo Bonzini , Gleb Natapov , Alexander Graf , Benjamin Herrenschmidt , Paul Mackerras , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Joonsoo Kim 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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);