From patchwork Tue Dec 15 03:13:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11973945 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.7 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,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 AFD50C2BB48 for ; Tue, 15 Dec 2020 03:13:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 638AD223C8 for ; Tue, 15 Dec 2020 03:13:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 638AD223C8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F2CC28D0071; Mon, 14 Dec 2020 22:13:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E8B208D001C; Mon, 14 Dec 2020 22:13:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D78F38D0071; Mon, 14 Dec 2020 22:13:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0115.hostedemail.com [216.40.44.115]) by kanga.kvack.org (Postfix) with ESMTP id BC61E8D001C for ; Mon, 14 Dec 2020 22:13:25 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7F869181AEF30 for ; Tue, 15 Dec 2020 03:13:25 +0000 (UTC) X-FDA: 77594045970.14.door54_63030ca27420 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 6128F18229837 for ; Tue, 15 Dec 2020 03:13:25 +0000 (UTC) X-HE-Tag: door54_63030ca27420 X-Filterd-Recvd-Size: 3219 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Dec 2020 03:13:24 +0000 (UTC) Date: Mon, 14 Dec 2020 19:13:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1608002004; bh=C8wUdiZt8+oc4sOw6lbo03WHf8sF1zlF678hzJL3YLk=; h=From:To:Subject:In-Reply-To:From; b=IYLhXT1cly60mpzp5lwxM+fbXvW7MgsjSxM0Ces4L4T/pPzPkoKTl8RQwtxtaCjO3 grgdffTEMHIIYNOM7XGsdGnN+ZtZyTWn5WvsXuj5aMbIloeXZ9tFkDmUX2XcBwZMaU v+1N7ZGatlZ/ye8nxMq/eMxCmJF2/xXhq9XKUCA0= From: Andrew Morton To: akpm@linux-foundation.org, david@redhat.com, lecopzer.chen@mediatek.com, linux-mm@kvack.org, matthias.bgg@gmail.com, mm-commits@vger.kernel.org, torvalds@linux-foundation.org, vbabka@suse.cz, yj.chiang@mediatek.com Subject: [patch 172/200] mm/cma.c: remove redundant cma_mutex lock Message-ID: <20201215031323.-4QcJQxbF%akpm@linux-foundation.org> In-Reply-To: <20201214190237.a17b70ae14f129e2dca3d204@linux-foundation.org> User-Agent: s-nail v14.8.16 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: From: Lecopzer Chen Subject: mm/cma.c: remove redundant cma_mutex lock The cma_mutex which protects alloc_contig_range() was first appeared in commit 7ee793a62fa8c ("cma: Remove potential deadlock situation"), at that time, there is no guarantee the behavior of concurrency inside alloc_contig_range(). After commit 2c7452a075d4db2dc ("mm/page_isolation.c: make start_isolate_page_range() fail if already isolated") > However, two subsystems (CMA and gigantic > huge pages for example) could attempt operations on the same range. If > this happens, one thread may 'undo' the work another thread is doing. > This can result in pageblocks being incorrectly left marked as > MIGRATE_ISOLATE and therefore not available for page allocation. The concurrency inside alloc_contig_range() was clarified. Now we can find that hugepage and virtio call alloc_contig_range() without any lock, thus cma_mutex is "redundant" in cma_alloc() now. Link: https://lkml.kernel.org/r/20201020102241.3729-1-lecopzer.chen@mediatek.com Signed-off-by: Lecopzer Chen Acked-by: David Hildenbrand Acked-by: Vlastimil Babka Cc: Matthias Brugger Cc: YJ Chiang Signed-off-by: Andrew Morton --- mm/cma.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- a/mm/cma.c~mm-cmac-remove-redundant-cma_mutex-lock +++ a/mm/cma.c @@ -38,7 +38,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) { @@ -454,10 +453,9 @@ struct page *cma_alloc(struct cma *cma, mutex_unlock(&cma->lock); pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit); - mutex_lock(&cma_mutex); ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, GFP_KERNEL | (no_warn ? __GFP_NOWARN : 0)); - mutex_unlock(&cma_mutex); + if (ret == 0) { page = pfn_to_page(pfn); break;