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 08A27C433F5 for ; Tue, 25 Jan 2022 16:33:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B1616B00A2; Tue, 25 Jan 2022 11:33:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 960776B00A3; Tue, 25 Jan 2022 11:33:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 801E06B00A4; Tue, 25 Jan 2022 11:33:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay031.a.hostedemail.com [64.99.140.31]) by kanga.kvack.org (Postfix) with ESMTP id 6FC726B00A2 for ; Tue, 25 Jan 2022 11:33:55 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 3E4D3608C3 for ; Tue, 25 Jan 2022 16:33:55 +0000 (UTC) X-FDA: 79069356030.01.697EB92 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id B34F680004 for ; Tue, 25 Jan 2022 16:33:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643128434; 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=KfgMJjJLkuse5GtAchEf6Kwh02fgOfErvUbiicxCd3s=; b=EMrl4AgE0al7JhPL7jsWr/d1fvkOFOIkLpI548UFt29YvPuy4/PSISUnDI9AW0uBZj90X4 8jt3oBMUmnR4MzfMNDNFI87q7wM3pIVgEIYqio/DSJx7lElEpmF9Kcc6DNeAFyGCdH2JYA VOKpltLWChoBobe2h+mUb8xfMOlt3KM= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-480-sxdaaE4INqy6m0SvunlsmA-1; Tue, 25 Jan 2022 11:33:52 -0500 X-MC-Unique: sxdaaE4INqy6m0SvunlsmA-1 Received: by mail-ej1-f72.google.com with SMTP id p16-20020a170906785000b006b5d9c3d47fso3646775ejm.21 for ; Tue, 25 Jan 2022 08:33:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=KfgMJjJLkuse5GtAchEf6Kwh02fgOfErvUbiicxCd3s=; b=NafIOEPZMWkpCkD3b0KU/Ko6J5WHK6kfVh7SwBS8teOb1ilBbonLTYxKcTHezOJLYR UOCbPodBp/32/xdnuiSsxviNWqpNe6COcY85qISsl/Wi0mMUwDxiDz2EXu2aB37RKV40 Toyd8Ce45dlhFMqlyoPwVsgSaIfuSCSLCiUk4USNy27U87rqLI5KVp9iG5YF4glMbLdp mHBedcTD5mlAPxVu3XlG80OuNn2f8dYhED+f/6MLX0ow5N6xrClfWZyDtZ3UhQfoH6sJ RQisrJNoVTe8oJBDEeS9mK0BrUiNupPyEBhevXLTKnUeBeONybpMha2i+UsMIf07RAFP Y4eg== X-Gm-Message-State: AOAM5330Yi+/1Cg/8HHw6dO2qEkI+vaVQ2u2FZk22Ihf4oB0w71ymUnI /R+sQlYbH5DQkZC6Sa6GcNmIAbRxk1pppCaCVIb9m+VQ8lpwh/UQkLWq6/ncd7lZFo+448Dhpv4 RtwDG/wRFTRM= X-Received: by 2002:a17:907:3e98:: with SMTP id hs24mr5686297ejc.615.1643128431456; Tue, 25 Jan 2022 08:33:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyeyf5mAQBARaflP79k/1usfZgp11GmPqAXlH9bD84k9hx/lc6ZGcZS3QYF6aaWGyAbIL/opw== X-Received: by 2002:a17:907:3e98:: with SMTP id hs24mr5686263ejc.615.1643128431147; Tue, 25 Jan 2022 08:33:51 -0800 (PST) Received: from ?IPV6:2003:cb:c70f:8000:9797:8f:1ed9:7596? (p200300cbc70f80009797008f1ed97596.dip0.t-ipconnect.de. [2003:cb:c70f:8000:9797:8f:1ed9:7596]) by smtp.gmail.com with ESMTPSA id n25sm4995831ejx.92.2022.01.25.08.33.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Jan 2022 08:33:50 -0800 (PST) Message-ID: <517e1ea1-f826-228b-16a0-da1dc76017cc@redhat.com> Date: Tue, 25 Jan 2022 17:33:49 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 To: Dong Aisheng , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, dongas86@gmail.com, jason.hui.liu@nxp.com, leoyang.li@nxp.com, abel.vesa@nxp.com, shawnguo@kernel.org, linux-imx@nxp.com, akpm@linux-foundation.org, m.szyprowski@samsung.com, lecopzer.chen@mediatek.com, vbabka@suse.cz, stable@vger.kernel.org, shijie.qin@nxp.com References: <20220112131552.3329380-1-aisheng.dong@nxp.com> <20220112131552.3329380-3-aisheng.dong@nxp.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2 2/2] mm: cma: try next MAX_ORDER_NR_PAGES during retry In-Reply-To: <20220112131552.3329380-3-aisheng.dong@nxp.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B34F680004 X-Stat-Signature: zytkcuztuz1obkac4hd6jguaq735hxo7 X-Rspam-User: nil Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EMrl4AgE; spf=none (imf30.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1643128434-278740 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 12.01.22 14:15, Dong Aisheng wrote: > On an ARMv7 platform with 32M pageblock(MAX_ORDER 14), we observed a Did you actually intend to talk about pageblocks here (and below)? I assume you have to be clearer here that you talk about the maximum allocation granularity, which is usually bigger than actual pageblock size. > huge number of repeat retries of CMA allocation (1k+) during booting > when allocating one page for each of 3 mmc instance probe. > > This is caused by CMA now supports cocurrent allocation since commit > a4efc174b382 ("mm/cma.c: remove redundant cma_mutex lock"). > The pageblock or (MAX_ORDER -1) from which we are trying to allocate > memory may have already been acquired and isolated by others. > Current cma_alloc() will then retry the next area by the step of > bitmap_no + mask + 1 which are very likely within the same isolated range > and fail again. So when the pageblock or MAX_ORDER is big (e.g. 8192), > keep retrying in a small step become meaningless because it will be known > to fail at a huge number of times due to the pageblock has been isolated > by others, especially when allocating only one or two pages. > > Instread of looping in the same pageblock and wasting CPU mips a lot, > especially for big pageblock system (e.g. 16M or 32M), > we try the next MAX_ORDER_NR_PAGES directly. > > Doing this way can greatly mitigate the situtation. > > Below is the original error log during booting: > [ 2.004804] cma: cma_alloc(cma (ptrval), count 1, align 0) > [ 2.010318] cma: cma_alloc(cma (ptrval), count 1, align 0) > [ 2.010776] cma: cma_alloc(): memory range at (ptrval) is busy, retrying > [ 2.010785] cma: cma_alloc(): memory range at (ptrval) is busy, retrying > [ 2.010793] cma: cma_alloc(): memory range at (ptrval) is busy, retrying > [ 2.010800] cma: cma_alloc(): memory range at (ptrval) is busy, retrying > [ 2.010807] cma: cma_alloc(): memory range at (ptrval) is busy, retrying > [ 2.010814] cma: cma_alloc(): memory range at (ptrval) is busy, retrying > .... (+1K retries) > > After fix, the 1200+ reties can be reduced to 0. > Another test running 8 VPU decoder in parallel shows that 1500+ retries > dropped to ~145. > > IOW this patch can improve the CMA allocation speed a lot when there're > enough CMA memory by reducing retries significantly. > > Cc: Andrew Morton > Cc: Marek Szyprowski > Cc: Lecopzer Chen > Cc: David Hildenbrand > Cc: Vlastimil Babka > CC: stable@vger.kernel.org # 5.11+ > Fixes: a4efc174b382 ("mm/cma.c: remove redundant cma_mutex lock") > Signed-off-by: Dong Aisheng > --- > v1->v2: > * change to align with MAX_ORDER_NR_PAGES instead of pageblock_nr_pages > --- > mm/cma.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/mm/cma.c b/mm/cma.c > index 1c13a729d274..1251f65e2364 100644 > --- a/mm/cma.c > +++ b/mm/cma.c > @@ -500,7 +500,9 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, > trace_cma_alloc_busy_retry(cma->name, pfn, pfn_to_page(pfn), > count, align); > /* try again with a bit different memory target */ > - start = bitmap_no + mask + 1; > + start = ALIGN(bitmap_no + mask + 1, > + MAX_ORDER_NR_PAGES >> cma->order_per_bit); Mind giving the reader a hint in the code why we went for MAX_ORDER_NR_PAGES? What would happen if the CMA granularity is bigger than MAX_ORDER_NR_PAGES? I'd assume no harm done, as we'd try aligning to 0. -- Thanks, David / dhildenb