Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4191584pxf; Tue, 30 Mar 2021 01:20:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpJN4M2WQGAByUI3OsdwlHGiR6hqLBmMSRruEdvFvlqQNm7oTFpHd5NgXlMfzU8D3f5Gva X-Received: by 2002:a05:6402:4395:: with SMTP id o21mr31825949edc.22.1617092446590; Tue, 30 Mar 2021 01:20:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617092446; cv=none; d=google.com; s=arc-20160816; b=rsAkZKMQQU5AbaGipffm34yl8YwINihFIcTnUCxfIPPppLXKbAYNjTzkMSVcFKRYes g2oQU15XrDXqLFdWTD9Oo+fL2j4GJQ0o3ZEh7KdaGFKjT22hLa42nY36nQmGP3Y8OMAh xxFnOseDwjBYFeg9Ym/Y9ZptUwqu1x8tjQb3QBiEZpQds72rW7/SpJvS3aNzVQmI6xgt 3zFhIf7EPR6cW1VSq2xRugoclYKgH24aIooLE4xru4/ootuXKgHool1GtZ51mvQ88iAZ QldSkkgVi6JMiaKjbSMgntFj2I/7Y4NUmKMBWxm88YuYsH1Z5qUj3iRb0wyKwKwh2utf IHBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wNw4nGVKh6SriT/z86f2SGzgVHpW0NorEGH4COOxJUo=; b=AmceAdzd7weJfipIb6aX+xUWmtatECxX4gDW/f6EfBPWVRs7Qz1/03gKgPcF3HIx+j HIN4vpRRQGi+jKEZVTOxIvwzx2SgaVFzG+SdgKgRYjB/aX2/fjL2Dw/NUqcTI4rRi1Nf MyzSGPvqGMW6j6lY1V22FIjLXGBr/+Tw3g7AceNsTbq5ugILneNC6BRo367NGQq8hzIN Cx/RaXCSPRLFbT3xLV8OOabZl/IAq6cAQsYkUS57G8HtxRdsbKqjA7ljVmhzj10uCZNv ZtVfBbPSNA1QTFgaZls1grIwjtJkfSPWFBPHAm4EKPLnK4EQhrDU8GOBkG0cNL7S9RmL Wd1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=l8JS67PZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u12si16050602eda.90.2021.03.30.01.20.09; Tue, 30 Mar 2021 01:20:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=l8JS67PZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230415AbhC3ISy (ORCPT + 99 others); Tue, 30 Mar 2021 04:18:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:42298 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231359AbhC3ISm (ORCPT ); Tue, 30 Mar 2021 04:18:42 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1617092321; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wNw4nGVKh6SriT/z86f2SGzgVHpW0NorEGH4COOxJUo=; b=l8JS67PZkLeSBclyeYuVlbPnE6ocBl1TXDJ8G0G72ngoWy6FLGLhJWgfW8qEalAdsZ3RBN 7hXMQp9JY8kb+azQhsW14wJNiUxZo+CnhlCTEL5DPM3xGjSZOzbuRgDQ13XtZBC8fTxzmR uny1PEiAX5U8jCXzvf3pkWrNedW59ks= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EAB04AEF5; Tue, 30 Mar 2021 08:18:40 +0000 (UTC) Date: Tue, 30 Mar 2021 10:18:39 +0200 From: Michal Hocko To: Muchun Song Cc: Mike Kravetz , Linux Memory Management List , LKML , Roman Gushchin , Shakeel Butt , Oscar Salvador , David Hildenbrand , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Joonsoo Kim , Barry Song , Will Deacon , Andrew Morton Subject: Re: [External] Re: [PATCH v2 1/8] mm/cma: change cma mutex to irq safe spinlock Message-ID: References: <20210329232402.575396-1-mike.kravetz@oracle.com> <20210329232402.575396-2-mike.kravetz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 30-03-21 16:08:36, Muchun Song wrote: > On Tue, Mar 30, 2021 at 4:01 PM Michal Hocko wrote: > > > > On Mon 29-03-21 16:23:55, Mike Kravetz wrote: > > > Ideally, cma_release could be called from any context. However, that is > > > not possible because a mutex is used to protect the per-area bitmap. > > > Change the bitmap to an irq safe spinlock. > > > > I would phrase the changelog slightly differerent > > " > > cma_release is currently a sleepable operatation because the bitmap > > manipulation is protected by cma->lock mutex. Hugetlb code which relies > > on cma_release for CMA backed (giga) hugetlb pages, however, needs to be > > irq safe. > > > > The lock doesn't protect any sleepable operation so it can be changed to > > a (irq aware) spin lock. The bitmap processing should be quite fast in > > typical case but if cma sizes grow to TB then we will likely need to > > replace the lock by a more optimized bitmap implementation. > > " > > > > it seems that you are overusing irqsave variants even from context which > > are never called from the IRQ context so they do not need storing flags. > > > > [...] > > > @@ -391,8 +391,9 @@ static void cma_debug_show_areas(struct cma *cma) > > > unsigned long start = 0; > > > unsigned long nr_part, nr_total = 0; > > > unsigned long nbits = cma_bitmap_maxno(cma); > > > + unsigned long flags; > > > > > > - mutex_lock(&cma->lock); > > > + spin_lock_irqsave(&cma->lock, flags); > > > > spin_lock_irq should be sufficient. This is only called from the > > allocation context and that is never called from IRQ context. > > This makes me think more. I think that spin_lock should be > sufficient. Right? Nope. Think of the following scenario spin_lock(cma->lock); put_page __free_huge_page cma_release spin_lock_irqsave() DEADLOCK -- Michal Hocko SUSE Labs