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=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 594AEC433DF for ; Tue, 20 Oct 2020 11:27:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CFBB52223C for ; Tue, 20 Oct 2020 11:27:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RbXIYqLq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CFBB52223C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 559596B005C; Tue, 20 Oct 2020 07:27:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E2A66B0062; Tue, 20 Oct 2020 07:27:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A9506B0068; Tue, 20 Oct 2020 07:27:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0210.hostedemail.com [216.40.44.210]) by kanga.kvack.org (Postfix) with ESMTP id 05C516B005C for ; Tue, 20 Oct 2020 07:27:44 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9763A180AD802 for ; Tue, 20 Oct 2020 11:27:44 +0000 (UTC) X-FDA: 77392078848.18.milk69_0e0cac42723f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 61DF0100A55F2 for ; Tue, 20 Oct 2020 11:27:44 +0000 (UTC) X-HE-Tag: milk69_0e0cac42723f X-Filterd-Recvd-Size: 4497 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Tue, 20 Oct 2020 11:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603193263; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vJlBrtx7b8MuYro3yQ5487UyppQfsd5wQW5QKM9zah0=; b=RbXIYqLqYHue5m62ygjH/C5qFyVInpaX57A6Zc+GSvNhStREfgi6mYi6FX1XqcE7pck+p+ UEfS2Glko3LvDvf/d4/qWNBhUP6kc8mXfDZDRAH3a/RB5zs807rjKXx3aL8CmrE8RDUII7 EbscwI6IjhaqIlYoVj21Sy/76pyy9Yw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-131-S1eb4lJ8M4CZawKTkyqNKA-1; Tue, 20 Oct 2020 07:27:41 -0400 X-MC-Unique: S1eb4lJ8M4CZawKTkyqNKA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EE45A18A076B; Tue, 20 Oct 2020 11:27:39 +0000 (UTC) Received: from [10.36.114.141] (ovpn-114-141.ams2.redhat.com [10.36.114.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id A17515B4A3; Tue, 20 Oct 2020 11:27:38 +0000 (UTC) Subject: Re: [PATCH] mm/cma.c: remove redundant cma_mutex lock To: Lecopzer Chen , linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: matthias.bgg@gmail.com, akpm@linux-foundation.org, yj.chiang@mediatek.com References: <20201020102241.3729-1-lecopzer.chen@mediatek.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <458cdc24-f637-ef4b-19de-513ceab14f23@redhat.com> Date: Tue, 20 Oct 2020 13:27:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 In-Reply-To: <20201020102241.3729-1-lecopzer.chen@mediatek.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 20.10.20 12:22, Lecopzer Chen wrote: > 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 the 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. > > Signed-off-by: Lecopzer Chen > --- > mm/cma.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/mm/cma.c b/mm/cma.c > index 7f415d7cda9f..3692a34e2353 100644 > --- a/mm/cma.c > +++ b/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, size_t count, unsigned int align, > 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; > I guess this is fine. In case there is a race we return with -EBUSY - which is suboptimal (as it could just be a temporary issue if the other user backs off), but should be good enough for now. Acked-by: David Hildenbrand -- Thanks, David / dhildenb