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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05D5EC433EF for ; Wed, 16 Mar 2022 03:47:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 52D638D0002; Tue, 15 Mar 2022 23:47:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DBCA8D0001; Tue, 15 Mar 2022 23:47:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A38C8D0002; Tue, 15 Mar 2022 23:47:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id 285FC8D0001 for ; Tue, 15 Mar 2022 23:47:54 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id CCF799BBBB for ; Wed, 16 Mar 2022 03:47:53 +0000 (UTC) X-FDA: 79248865626.30.7ACEEEF Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) by imf29.hostedemail.com (Postfix) with ESMTP id 6556812000D for ; Wed, 16 Mar 2022 03:47:53 +0000 (UTC) Received: by mail-oi1-f177.google.com with SMTP id v75so1388145oie.1 for ; Tue, 15 Mar 2022 20:47:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PEfk5ZCw1gvfQthm7kb0RoxLz3zm47ykuGeSs5jnx6I=; b=HSG7GO50mp8W5FgZV9MsYIWpa+Z2WfR1etjogsmIf9wpK6wV3CL8Zew6wa2q6DrHdK ju8tVEdB9pALkQysQlXU5JTAhFJ623UBIzmacZ5EcA9yCWHch0RyLKilZcCdKiXphn8D lvSfmKeLIJhffkMCc+G2cGJ1972MUYAY0Mx3fWwtK0ultcytt6NYE8MEdvtE9kEK5CoA jVfndsNoSXrEnIJx6IRPzLBXciPhgcEJBLZKsxgejm80CmZcRoIILj0UY3lX9LOk9x6t +t5UQoke0OnhySOY/GMeGokZd+FGPp/NpbyAPVn+EiY46pYPpqAjFpyiHDtwPMBvRWTX kEDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PEfk5ZCw1gvfQthm7kb0RoxLz3zm47ykuGeSs5jnx6I=; b=UhWnm05AXL729SKbCX2GfNFufWUg/c4yCqkyW/L58qFuzSvC1Hl5SzKtf9Sq/0Ggo5 zkrKZ+ie5ys8iC8nSYu7lTmX3FioYkmjRvGn1HmRDxfQCxYkg5bs8Qyi31Bgz4hlUSJT ttkNLCOrdxDwLTpJaQ5wCp1Ny+8hvgTnQppqCw8cYVDSF0w2jcD1VR1Q6hL4XD9W5FiX RgSjTCYpTYfqw5Bws7xOAkhSQii1TZ7FaHIfPvlmPsDZowxqrsQ0hiJ3PImfKA9bPtao 9mastKYk4V1JP/e+KCrKW/sVyX8fI7W74DJsQJlA1MvOcVZe/nga33NbjMSTXv6teoKY rfnQ== X-Gm-Message-State: AOAM530zyA+O0L2h6W5y5Au9RwFz3yqVZyPyC390tFe1crrVxj+YSi36 XnPUk/wFwmykAzMBYn0kcEcd3JeyEVAm9g9N2Gg= X-Google-Smtp-Source: ABdhPJzg99M9AK63teBKEJsFUyLwWfNV90oI6GfdhY6zqxkW0xn2DFGNkG68nRcBD+T3EcpCWZ2ZTqYw79g5GaSHJts= X-Received: by 2002:a05:6808:118e:b0:2d4:6fe7:6bd7 with SMTP id j14-20020a056808118e00b002d46fe76bd7mr3250272oil.146.1647402472671; Tue, 15 Mar 2022 20:47:52 -0700 (PDT) MIME-Version: 1.0 References: <20220315144521.3810298-1-aisheng.dong@nxp.com> <20220315144521.3810298-2-aisheng.dong@nxp.com> <20220315155837.2dcef6eb226ad74e37ca31ca@linux-foundation.org> In-Reply-To: <20220315155837.2dcef6eb226ad74e37ca31ca@linux-foundation.org> From: Dong Aisheng Date: Wed, 16 Mar 2022 11:41:37 +0800 Message-ID: Subject: Re: [PATCH v3 1/2] mm: cma: fix allocation may fail sometimes To: Andrew Morton 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 Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 6556812000D X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=HSG7GO50; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of dongas86@gmail.com designates 209.85.167.177 as permitted sender) smtp.mailfrom=dongas86@gmail.com X-Stat-Signature: gfhnxh5ftqco4x4rhot1zdfkapzepk6x X-Rspamd-Server: rspam04 X-HE-Tag: 1647402473-793410 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 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. Do you think that's ok? > 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")? Yes, agree it could be a backup solution if not better ideas. Regards Aisheng