Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp68420pxp; Wed, 16 Mar 2022 00:06:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIk7649J+xYJQfoBAmJ7Q4FsuTDSrP/hM9lRm5kLeZl1tzvXcxOGYDt0hw/3Hhg/nB+kGv X-Received: by 2002:a17:907:216f:b0:6ce:d85f:35cf with SMTP id rl15-20020a170907216f00b006ced85f35cfmr25686580ejb.517.1647414408537; Wed, 16 Mar 2022 00:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647414408; cv=none; d=google.com; s=arc-20160816; b=VcAvk3LvXKkC+DYhUrsHe3/cDEywxReY8VNN8yObHzYEKTN/7+2Thw247rJcyw2NvF URBbUAPUamT7XV1TJQBqcl2uJnxsnqxVkfB1WteRew8/q2yfyiyE7drW5KVuXiLk4rZT +vAAzxA08g/RHXWAZCVfEu4nopQsqYf4uilWWI67Sot7i0WqOhq4DikX7fy8fGbIvOfE t786elqKa9LSq6nzh1NgMVFZuFJgRyx+3j+eMWpUl16PpF7+IaVDm/yQro8hT5L+YriM /pBr+eIVLAwKxOUx8bcNr0XT458mos6KZ8SbKPWCKpTfRMl680NfzpKE6OQz/p9OLFzZ HcYQ== 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=MR15zX/jImFuFVEEZ72W+CdDNqZmShdsQAmnsdopABc=; b=FCdsbx6u5812FW+aq4IDu/7DmimlIN5KBTMClYxdQ4TuEswSWwr9rNcscDVakeJSWQ jqoEE4HwMMrmBx0K+hnBufHQoEEYEPC4Ke0HBixiw5LYpHoRC9BYxThxR+TyRJbLYwNK AU6UEJ91xQhBjqJoMtzBrqGOHx5WAlA4MvnFNG0XPM+8fNU+NYZgaUdqcCxUcR0eilbv 2+bI4dyHTL8II84aBPTmMwvntnZL/8cRXx3pxSKZDWZkFFqImKO+U5SceIeIy95zmarS HeeUEwuAytQVRJ2xnEslSXbHdeWEmVsG/sTbq7f/9yBgYU/wFIZho+2Q+4FCNWYuMsj6 DFUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=GYvfeIOR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020a056402271000b00418549c0009si802656edd.376.2022.03.16.00.06.21; Wed, 16 Mar 2022 00:06:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=GYvfeIOR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241375AbiCOW7y (ORCPT + 99 others); Tue, 15 Mar 2022 18:59:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352433AbiCOW7w (ORCPT ); Tue, 15 Mar 2022 18:59:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED89A4C418; Tue, 15 Mar 2022 15:58:39 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 8A985614A4; Tue, 15 Mar 2022 22:58:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DEF8C340E8; Tue, 15 Mar 2022 22:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1647385119; bh=nAaYL5YjCg97b7NBxM3k75M3xEa2Xha1to1xC1/Cx0E=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=GYvfeIORbleDqEAFiLNYtWqvdjKjkaNBDGOq6DzMhVo9mDsIVxLE4o3mgIC5tUR6E 5yojWb/x1d0ZA5xiCcuGAzNq2Yx3k0eQt+i2ocKA3Yv1Kx0P0Njjwos8KdjTEnoh6c /9zvEUx+SFWPDb9NyMOFImyK9MMjtyRD16u0mxTQ= Date: Tue, 15 Mar 2022 15:58:37 -0700 From: Andrew Morton To: Dong Aisheng Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, dongas86@gmail.com, 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: <20220315155837.2dcef6eb226ad74e37ca31ca@linux-foundation.org> In-Reply-To: <20220315144521.3810298-2-aisheng.dong@nxp.com> References: <20220315144521.3810298-1-aisheng.dong@nxp.com> <20220315144521.3810298-2-aisheng.dong@nxp.com> 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=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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. A much cleaner solution is to use appropriate locking so that various threads run this code in order, without messing each other up. And it looks like the way to do that is to simply revert the commit which caused this regression, a4efc174b382 ("mm/cma.c: remove redundant cma_mutex lock")?