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 BCCA0C433EF for ; Thu, 17 Mar 2022 10:55:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 29F086B0071; Thu, 17 Mar 2022 06:55:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 24EA76B0072; Thu, 17 Mar 2022 06:55:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 117AF8D0001; Thu, 17 Mar 2022 06:55:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0173.hostedemail.com [216.40.44.173]) by kanga.kvack.org (Postfix) with ESMTP id 00A3A6B0071 for ; Thu, 17 Mar 2022 06:55:45 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A51E61827C15D for ; Thu, 17 Mar 2022 10:55:45 +0000 (UTC) X-FDA: 79253572650.31.9C36608 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 6305DC0029 for ; Thu, 17 Mar 2022 10:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647514543; 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=oI5WSIRwZsbGZlVeSYcyiheGQZ2AXv4KqUCkckxJqyo=; b=Pn4h0qj+oypCYgN6Py/YsD4cp9Gbm1JwJcIsBTKJA2dKh1NsPkYW8RN0bPjWiqz4W8cT9I 4jMS7yFsuIZLoRd8Bd45zs80d+bAKOCQ49w+8SIQuCBDZWib9a5ipCfO0aAjEd8krpLt9l TwJnfe9kgYMKadE5DDEIQhETudxeFRA= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-180-tm38G7G-PcOkxwj9DVOhGg-1; Thu, 17 Mar 2022 06:55:42 -0400 X-MC-Unique: tm38G7G-PcOkxwj9DVOhGg-1 Received: by mail-wr1-f72.google.com with SMTP id f18-20020adf9f52000000b00203d86759beso1428482wrg.11 for ; Thu, 17 Mar 2022 03:55:42 -0700 (PDT) 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=oI5WSIRwZsbGZlVeSYcyiheGQZ2AXv4KqUCkckxJqyo=; b=q+pq94r7WRDNdhjkHtVXV0BnSIvGiOBbfzFTiPCFiMExioE1ckIubqDD/YflYHPfY6 p2x1MWI/PucSjfFuzah65rS21JUCvTG23a7oX2Wb9mUAVkwe1PPGw81QqJ5ONEoh7fJb WdFhMWtXJ/cnABNd1D0yvZeQ5WW9mrR8YTVJTgB1/uSSIIoWhxg+L283WGjJA7ii1/gB /tNA9K+jMKmnsX3+urkVBSKVcRE7Po7DzXuBPrGHQk1OrCoKe4MboqTp+kMM08o4c5mj zhNnppmoyKkL1IJmVHI6dapojuirh7inYEd5Qexi+kBT0souBYwp/ZjbpL1uqu5gvJia aa2A== X-Gm-Message-State: AOAM5333UdaT2148H7cH5zt9TF18YByfx/mH6+uhiV28ZiQUM2LiiUNd QqUgcMWOPcg4m4khz1Agsm8N/xPtUC7S9yxqqpjBb3CAYID/lRHcSuPfEzlmrOQuvb1yC3wVTMn 3Rshf1BYF84M= X-Received: by 2002:a5d:59a4:0:b0:203:914f:52fa with SMTP id p4-20020a5d59a4000000b00203914f52famr3417271wrr.257.1647514541654; Thu, 17 Mar 2022 03:55:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysbRU6X3N38sZnHt2a+qYqTxqD7zt/WiAYw+BN78ayQKGmZg2WlK4KxV8gsbHuhc5/z0oc2A== X-Received: by 2002:a5d:59a4:0:b0:203:914f:52fa with SMTP id p4-20020a5d59a4000000b00203914f52famr3417232wrr.257.1647514541257; Thu, 17 Mar 2022 03:55:41 -0700 (PDT) Received: from ?IPV6:2a09:80c0:192:0:20af:34be:985b:b6c8? ([2a09:80c0:192:0:20af:34be:985b:b6c8]) by smtp.gmail.com with ESMTPSA id r2-20020a0560001b8200b00203dffb9598sm3290679wru.86.2022.03.17.03.55.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Mar 2022 03:55:40 -0700 (PDT) Message-ID: <93480fb1-6992-b992-4c93-0046f3b92d7a@redhat.com> Date: Thu, 17 Mar 2022 11:55:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 To: Dong Aisheng , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, dongas86@gmail.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: <20220315144521.3810298-1-aisheng.dong@nxp.com> <20220315144521.3810298-2-aisheng.dong@nxp.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v3 1/2] mm: cma: fix allocation may fail sometimes In-Reply-To: <20220315144521.3810298-2-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-Stat-Signature: 9xgdddsbs5us38wpgmbfjkqiyhbog4eo Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Pn4h0qj+; spf=none (imf28.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-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6305DC0029 X-HE-Tag: 1647514544-493171 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 15.03.22 15:45, Dong Aisheng wrote: > When there're multiple process allocing dma memory in parallel s/allocing/allocating/ > by calling dma_alloc_coherent(), it may fail sometimes as follows: > > Error log: > cma: cma_alloc: linux,cma: alloc failed, req-size: 148 pages, ret: -16 > cma: number of available pages: > 3@125+20@172+12@236+4@380+32@736+17@2287+23@2473+20@36076+99@40477+108@40852+44@41108+20@41196+108@41364+108@41620+ > 108@42900+108@43156+483@44061+1763@45341+1440@47712+20@49324+20@49388+5076@49452+2304@55040+35@58141+20@58220+20@58284+ > 7188@58348+84@66220+7276@66452+227@74525+6371@75549=> 33161 free of 81920 total pages > > When issue happened, we saw there were still 33161 pages (129M) free CMA > memory and a lot available free slots for 148 pages in CMA bitmap that we > want to allocate. > > If dumping memory info, we found that there was also ~342M normal memory, > but only 1352K CMA memory left in buddy system while a lot of pageblocks > were isolated. s/If/When/ > > Memory info log: > Normal free:351096kB min:30000kB low:37500kB high:45000kB reserved_highatomic:0KB > active_anon:98060kB inactive_anon:98948kB active_file:60864kB inactive_file:31776kB > unevictable:0kB writepending:0kB present:1048576kB managed:1018328kB mlocked:0kB > bounce:0kB free_pcp:220kB local_pcp:192kB free_cma:1352kB lowmem_reserve[]: 0 0 0 > Normal: 78*4kB (UECI) 1772*8kB (UMECI) 1335*16kB (UMECI) 360*32kB (UMECI) 65*64kB (UMCI) > 36*128kB (UMECI) 16*256kB (UMCI) 6*512kB (EI) 8*1024kB (UEI) 4*2048kB (MI) 8*4096kB (EI) > 8*8192kB (UI) 3*16384kB (EI) 8*32768kB (M) = 489288kB > > The root cause of this issue is that since commit a4efc174b382 > ("mm/cma.c: remove redundant cma_mutex lock"), CMA supports concurrent > memory allocation. It's possible that the memory range process A trying > to alloc has already been isolated by the allocation of process B during > memory migration. > > The problem here is that the memory range isolated during one allocation > by start_isolate_page_range() could be much bigger than the real size we > want to alloc due to the range is aligned to MAX_ORDER_NR_PAGES. > > Taking an ARMv7 platform with 1G memory as an example, when MAX_ORDER_NR_PAGES > is big (e.g. 32M with max_order 14) and CMA memory is relatively small > (e.g. 128M), there're only 4 MAX_ORDER slot, then it's very easy that > all CMA memory may have already been isolated by other processes when > one trying to allocate memory using dma_alloc_coherent(). > Since current CMA code will only scan one time of whole available CMA > memory, then dma_alloc_coherent() may easy fail due to contention with > other processes. > > This patch introduces a retry mechanism to rescan CMA bitmap for -EBUSY > error in case the target memory range may has been temporarily isolated > by others and released later. But you patch doesn't check for -EBUSY and instead might retry forever, on any allocation error, no? I'd really suggest letting alloc_contig_range() return -EAGAIN in case the isolation failed and handling -EAGAIN only in a special way instead. In addition, we might want to stop once we looped to often I assume. -- Thanks, David / dhildenb