Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp994044pxp; Wed, 16 Mar 2022 23:48:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBcpnbh+nOL8dSAtJB7fe1P+Z+WZ/m3id77xFLqopjznqM3MWRM6l8S4zK8AjslUdd/oJm X-Received: by 2002:a17:902:d492:b0:151:86ac:bc7b with SMTP id c18-20020a170902d49200b0015186acbc7bmr3170391plg.52.1647499702057; Wed, 16 Mar 2022 23:48:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647499702; cv=none; d=google.com; s=arc-20160816; b=FhqUvAi23YUcNlvJDCdjTLUEsqztcNGq8wg/UuW40P9iEVTr+rHI60SvK8XDycuKZq kuA5BH/XZrXTHFxPbL8EfW4pk/CZGkodHeCVQzOIgG6dmBaTfj3VmhOtM4ItEtPOerGs pX0lhWNq0XGZ9qWp36pd0K/gYt4GIELkOaMboBo+fFPwlVCcA4pShMBkS2PcOI2lZMzy WUCaUox3yCMQTOSj/9/MaZUOWs3qWL6Fi3nJ7oeLSZPEaXMxByXC28fYQEHExx3SrWMn jfkOKDtqSV//Ba7vDZRS4rvyQRSE8kYg4hOSpYusAIYC8fFa7M33Z6ylUwjUvqupCJsh yReQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=C0askMQ1hJt2Oj+q2xsNyemjufXTyoW9SOcV9G48KFY=; b=QmStzNB0cfylgmir3iEvLx6GE59LiqPRsEEh64MJbARI9lKwUVHEKdDiU01PLQ7X2O FtrCVfk4kuveFQs63jPM2vKIgWmtamcXfCdz9JeXRXexSMbgjrn5PE+/63dGqZ114b+n 6MHKQroqkpvPTomPpIeYnprYM2OYpq9fEPJnRRkpFWMbcp7p2pMoeZZ1SWA+GcWTCGZh F7H18/4t02Gj418tUX9JZLHAgdGt6kwTpwCtr/4sUgdF7MkiXF/THY+klR4x2qE5bt1P M1mh2CkAIImyvnwiJdZY0UtaU2cflpcMN2kVmOpHKrQzQj9AgtRbvFcIbAyUVD9KtX1p d3cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=u7h37YQ6; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id be13-20020a056a001f0d00b004f6c8722cf2si3594288pfb.248.2022.03.16.23.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 23:48:22 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=u7h37YQ6; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F2D31D1CDF; Wed, 16 Mar 2022 22:33:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347462AbiCPVK0 (ORCPT + 99 others); Wed, 16 Mar 2022 17:10:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbiCPVKX (ORCPT ); Wed, 16 Mar 2022 17:10:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC0A0C05; Wed, 16 Mar 2022 14:09:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 42FB4B81D66; Wed, 16 Mar 2022 21:09:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 917E4C340EC; Wed, 16 Mar 2022 21:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1647464946; bh=oWK3VcNvpXGTNhy85nGsEuBb0xLj+hGobYNogj8xemA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=u7h37YQ6uAvKEsqQZ/qS24pnWVadk3WbVxPK1DDYOhSGSuTASwzPaNBR/gUruokiX rGftaV3gnwWPlFCmHHKM2zZ9tWQcC+cAOBryIHekRu2sTKBWaeIqbN5YS6QGRqtasn NphHE2JPraITErtwDaRJOE6rN9QbiIl7banPPseI= Date: Wed, 16 Mar 2022 14:09:04 -0700 From: Andrew Morton To: Dong Aisheng Cc: Dong Aisheng , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, shawnguo@kernel.org, linux-imx@nxp.com, m.szyprowski@samsung.com, lecopzer.chen@mediatek.com, david@redhat.com, vbabka@suse.cz, stable@vger.kernel.org, shijie.qin@nxp.com Subject: Re: [PATCH v3 1/2] mm: cma: fix allocation may fail sometimes Message-Id: <20220316140904.513fe0e8180b4e3fcad24e3b@linux-foundation.org> In-Reply-To: References: <20220315144521.3810298-1-aisheng.dong@nxp.com> <20220315144521.3810298-2-aisheng.dong@nxp.com> <20220315155837.2dcef6eb226ad74e37ca31ca@linux-foundation.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 16 Mar 2022 11:41:37 +0800 Dong Aisheng wrote: > On Wed, Mar 16, 2022 at 6:58 AM Andrew Morton wrote: > > > > On Tue, 15 Mar 2022 22:45:20 +0800 Dong Aisheng wrote: > > > > > --- a/mm/cma.c > > > +++ b/mm/cma.c > > > > > > ... > > > > > > @@ -457,6 +458,16 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, > > > offset); > > > if (bitmap_no >= bitmap_maxno) { > > > spin_unlock_irq(&cma->lock); > > > + pr_debug("%s(): alloc fail, retry loop %d\n", __func__, loop++); > > > + /* > > > + * rescan as others may finish the memory migration > > > + * and quit if no available CMA memory found finally > > > + */ > > > + if (start) { > > > + schedule(); > > > + start = 0; > > > + continue; > > > + } > > > break; > > > > The schedule() is problematic. For a start, we'd normally use > > cond_resched() here, so we avoid calling the more expensive schedule() > > if we know it won't perform any action. > > > > But cond_resched() is problematic if this thread has realtime > > scheduling policy and the process we're waiting on does not. One way > > to address that is to use an unconditional msleep(1), but that's still > > just a hack. > > > > I think we can simply drop schedule() here during the second round of retry > as the estimated delay may not be really needed. That will simply cause a tight loop, so I'm obviously not understanding the proposal.