From patchwork Thu Feb 8 05:07:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 13549315 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B35C0C4828F for ; Thu, 8 Feb 2024 05:07:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D28FC6B0071; Thu, 8 Feb 2024 00:07:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB1B66B0074; Thu, 8 Feb 2024 00:07:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA0836B0075; Thu, 8 Feb 2024 00:07:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A6BA16B0071 for ; Thu, 8 Feb 2024 00:07:21 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5A26CA085D for ; Thu, 8 Feb 2024 05:07:21 +0000 (UTC) X-FDA: 81767453082.20.1A9BDDB Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf04.hostedemail.com (Postfix) with ESMTP id C27DE4000C for ; Thu, 8 Feb 2024 05:07:18 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707368839; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=YKCGpO/cMcn3FMt5PKZwNk8uHiZq+rWry7xE8q++fJM=; b=iSW0VdDg8djlxIoFXtNxMPrDp8R/Ezl3GxaellX57HbkGqISfbohswhnD5uBM33197wyUq kG9DmulBFPiSRwrfe+M0oUxYtF1bZRNbXP2RTqpAHyD/7TUAciGHfAWR3bCkPMrDGHLTlz +zU9LQAUSf8Xhxz0d7Mb+bo5dWgYqjU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707368839; a=rsa-sha256; cv=none; b=uuNd/cSoCeem+VaoZtRPpobmh7Ber8yWU5IVoTpRGWTy9Dbge9WmPUZqpSM7Rn4u0jquwv f/FZpxP6foBdlFpn4lsV7KeJCK/kOnj3y5pr+eF3jEp01B6oRKoSRYd5a/a0EOdNOJCjRN dIdEqrDYM5pZGe9X3G6ncH3SHlA2HzU= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CFCF11FB; Wed, 7 Feb 2024 21:07:59 -0800 (PST) Received: from a077893.arm.com (unknown [10.163.44.57]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3F3CC3F762; Wed, 7 Feb 2024 21:07:11 -0800 (PST) From: Anshuman Khandual To: linux-mm@kvack.org Cc: Anshuman Khandual , Andrew Morton , David Hildenbrand , Mike Rapoport , Mike Kravetz , Minchan Kim , linux-kernel@vger.kernel.org Subject: [RFC] mm/cma: Move cma_mutex into 'struct cma' Date: Thu, 8 Feb 2024 10:37:01 +0530 Message-Id: <20240208050701.1081613-1-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: C27DE4000C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: azfekk545gek8rfhaghoo36obozs5ief X-HE-Tag: 1707368838-351973 X-HE-Meta: U2FsdGVkX1/fN8ezSWhcigY2BDzi8jiWyhikIbEaynNIZ/a4HU04WUcs9x8PNpUDFudbztGhj7EkKjNEDo4+srU/cfTq3aTkN/cymeaSyclsd01rIoQrH584oq5d15klJK6Uh6QKkOsXFzC530ucmB+HLuYfvtcoeFR2xlzw7OqpVXS1I8IVyx7hTQRlX9SLGphR0S7g56Si5TnL0BwYqQIS1y+/+zUoCQDfaCDjozUNqvEKY6TSNyewM6TYXKCGwUON/RtQC3QVhZGwKRaPk6XXoUdhn8QXs9JJ51lbz57eCQ5uhIy3R22oAi9G8gLQK71PqEi7hRVtcJaZlawmCS9OC8DEAGzsHIy8pT05powBdPcZuFmqNffUKBEdoiT7k90iOVsLhYFKcml4VVuAD5Ye2t6/USBnASP+pf+d3Hxkwqew1n3hqXDs29ZUp4W0FmyBSVqCMQCNuj11dSImnshTosH0k7OcPWEfNMoyAwOpBrWblYMj/BsqUmoKZxlZGf7VythYzgb65u4XzcmDJiM7oDTctWNbhAmgmQHUsek8/0VFpzsxFHCVNf1xrUVXsMMpdZQJEjX/gBXdwjYrCbaiGBujT3KNkK1DLRwv4LJtxZgf0kVb6UtB6cGIfGKm29N+emEFIGh2iVwmy2OkY/9c2sqpi2eqWfLSDASvvZF2zfJ9Yp6t4l9exXo5QlUvDyo4PtQbRyRpFZHjAYygHITRSG27Cz3T68ljWyZyVatiPnYle35UqD3DzUm+EiTeQ/Aj2jqfYDOXP8c3gbav8oVCSwt3Td3Bz26W/VEI9txEGqOqsyV4LuZEbrDixIG9e4eHMpXdFJ4b+E+x/EfoWnSVlWasCwIcujoyv84208sNs8LBOzsFk5lpQvqVmB7IWDMoz9ua5djaMaLOqqYt7Og1f8cZuyi9wMHb8WJoSAKNLofw2UBhz6ljgLUIJXNu9G9Zus+cjulvewkPV5N E04RhZ1s HZh44p8DqU14pAbRVLksSe0jrWfS7mJ4OT9TrYS6HkKrZJxH4gInfn30g/tN6Em3sE1P8KdtY9jvk1GJ0iivJTWbQYce9mBll8LCrDD8TmYNK8ZeiGnstfsDRRLUFLoITqQxRtcjBXQjo+FCZUB+4JDEijJ4LhhLVeBhLFEcvo/JGKqXhQvXy1w6mGABMxVBjds8QC4s5n6GbZGqmFnEIMT6D4iPHvL9aAt0+MFKScuSYuQfdl0+/WMslCHPWXZ1mXT1olWQsVd1EK7gq8imQ8gAGotqxHoUdAbUFhmGiR/urAMPeyD0lzyktbMY0JQZ5LY8rRkP0omDfceYc2xLdlGQFmNQvMJWFu9GzkpcW5/fmyOMvYLts4SyPG62w+jAfz8iovZyMqApNoQFod77B0+9dN0Ffp7KnyAF/iNbETfdeRj4= 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: List-Subscribe: List-Unsubscribe: Concurrent cma_alloc() requests might race with each other, inside the same CMA heap area. These races could not happen between two different CMA areas as their pfn ranges will be non overlapping. Let's just reduce the scope of the 'cma_mutex' from being system wide to CMA heap area specific, allowing concurrent cma_alloc() requests in different CMA heap areas. Cc: Andrew Morton Cc: David Hildenbrand Cc: Mike Rapoport Cc: Mike Kravetz Cc: Minchan Kim Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- This patch is slightly tested, although wanted to get some initial feedback on whether the scope of this CMA mutex should be reduced down in principle. mm/cma.c | 6 +++--- mm/cma.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index 4f95266eba1d..d6a52dec1b19 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -33,7 +33,6 @@ struct cma cma_areas[MAX_CMA_AREAS]; unsigned cma_area_count; -static DEFINE_MUTEX(cma_mutex); phys_addr_t cma_get_base(const struct cma *cma) { @@ -111,6 +110,7 @@ static void __init cma_activate_area(struct cma *cma) init_cma_reserved_pageblock(pfn_to_page(pfn)); spin_lock_init(&cma->lock); + mutex_init(&cma->cma_mutex); #ifdef CONFIG_CMA_DEBUGFS INIT_HLIST_HEAD(&cma->mem_head); @@ -460,10 +460,10 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, spin_unlock_irq(&cma->lock); pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit); - mutex_lock(&cma_mutex); + mutex_lock(&cma->cma_mutex); ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, GFP_KERNEL | (no_warn ? __GFP_NOWARN : 0)); - mutex_unlock(&cma_mutex); + mutex_unlock(&cma->cma_mutex); if (ret == 0) { page = pfn_to_page(pfn); break; diff --git a/mm/cma.h b/mm/cma.h index ad61cc6dd439..d84183e1caba 100644 --- a/mm/cma.h +++ b/mm/cma.h @@ -16,6 +16,7 @@ struct cma { unsigned long *bitmap; unsigned int order_per_bit; /* Order of pages represented by one bit */ spinlock_t lock; + struct mutex cma_mutex; #ifdef CONFIG_CMA_DEBUGFS struct hlist_head mem_head; spinlock_t mem_head_lock;