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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D175FC433FE for ; Thu, 16 Dec 2021 10:57:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236310AbhLPK5F (ORCPT ); Thu, 16 Dec 2021 05:57:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55139 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbhLPK5E (ORCPT ); Thu, 16 Dec 2021 05:57:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639652223; 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=MC2gvHGYmh9g6Raca53bij6uBB+XqUqBeIAACH6kGiw=; b=K0tlO4kHiCTrYj/Jj6x0sLl4ETeFdI3vXUJztlbQty4xTeoEhL72Xaf0ihSeHarbOnrrMs 9AXHj/JJdb/Jwg3T1lLNuBrkkVUOzCt/g8LhNMM0JDsMkJnsElHeLebqaiwkXqrZssOzRe n5HJVUqyH0HRvt4SeMLywWKJPVLY/Po= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-466-PEDkX0yLPw-1olOYo4HO7w-1; Thu, 16 Dec 2021 05:57:02 -0500 X-MC-Unique: PEDkX0yLPw-1olOYo4HO7w-1 Received: by mail-wr1-f70.google.com with SMTP id j26-20020adfb31a000000b001a2356afd4fso884880wrd.21 for ; Thu, 16 Dec 2021 02:57:02 -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:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=MC2gvHGYmh9g6Raca53bij6uBB+XqUqBeIAACH6kGiw=; b=KSGuw814CXRs5kEjIJbmZHGRHQrtXRvZJlaLCUFbx2xNo4hNQMchYdrakOQbg8ZHU3 Uhk3Z8R7PfmoBhYLUHLLwb/G/TyMEezjoYNS3mAX9B/5U+SUqGGVrn1fTQN+NBzaftRs XpX02dcuvrb0yuD9J8U7mfhhZEgCrYGkXQEVDybs8ACtlwCru8OCEjHWnEjVcUFpjlT0 +AyOErifVc2+kq2SSSs9pTFUwVBxxzlbEoPSCEvisB5b0lnMkcLhyxKDg3EI0RwEen93 nzA+IeTXadaQmMGWrL9qMJaNeT5bUfuYjD2uszKvLnxvHXxNyIIWJGg3kid8iepuAEK3 yl2A== X-Gm-Message-State: AOAM532aBrowwvBQ6ji4jbs4ylNaiMHoheHRul7v9X0ue1e/0TmzVnyJ bOb9jU+DSlrfmren0c4tdfloOeIwapcLQ0UUdbaYvdcbOmCP1w6+XRfgclbu/+eBz8dGCTPCuCY MclNLhG68t7eOtexZrFcTv55/ X-Received: by 2002:a1c:f60a:: with SMTP id w10mr4356541wmc.53.1639652221412; Thu, 16 Dec 2021 02:57:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDhJG49j5IOXlecqEpDnxZnmchZDhLcRCk8gk+wn9LsO6KsDIg1HPa3zDdFSpqHP48eaZL7A== X-Received: by 2002:a1c:f60a:: with SMTP id w10mr4356526wmc.53.1639652221231; Thu, 16 Dec 2021 02:57:01 -0800 (PST) Received: from [192.168.3.132] (p4ff23dcd.dip0.t-ipconnect.de. [79.242.61.205]) by smtp.gmail.com with ESMTPSA id g198sm5057299wme.23.2021.12.16.02.57.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Dec 2021 02:57:00 -0800 (PST) Message-ID: <7d9b7e5f-a6c0-2079-90e7-c02aaeb1f4c0@redhat.com> Date: Thu, 16 Dec 2021 11:56:59 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH 1/2] mm: cma: fix allocation may fail sometimes Content-Language: en-US To: Aisheng Dong , "linux-mm@kvack.org" Cc: "linux-kernel@vger.kernel.org" , "dongas86@gmail.com" , "linux-arm-kernel@lists.infradead.org" , Jason Liu , Leo Li , Abel Vesa , "shawnguo@kernel.org" , dl-linux-imx , "akpm@linux-foundation.org" , "m.szyprowski@samsung.com" , "lecopzer.chen@mediatek.com" , "vbabka@suse.cz" , "stable@vger.kernel.org" , Shijie Qin References: <20211215080242.3034856-1-aisheng.dong@nxp.com> <20211215080242.3034856-2-aisheng.dong@nxp.com> <783f64f5-3a55-6c42-a740-19a12c2c7321@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16.12.21 03:54, Aisheng Dong wrote: >> From: David Hildenbrand >> Sent: Wednesday, December 15, 2021 8:31 PM >> >> On 15.12.21 09:02, Dong Aisheng wrote: >>> We met dma_alloc_coherent() fail sometimes when doing 8 VPU decoder >>> test in parallel on a MX6Q SDB board. >>> >>> 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@3607 >> 6+99@40477+108 >>> @40852+44@41108+20@41196+108@41364+108@41620+ >>> >> 108@42900+108@43156+483@44061+1763@45341+1440@47712+20@49 >> 324+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. >>> >>> 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 pageblock process A try to >>> alloc has already been isolated by the allocation of process B during >>> memory migration. >>> >>> When there're multi process allocating CMA memory in parallel, it's >>> likely that other the remain pageblocks may have also been isolated, >>> then CMA alloc fail finally during the first round of scanning of the >>> whole available CMA bitmap. >> >> I already raised in different context that we should most probably convert that >> -EBUSY to -EAGAIN -- to differentiate an actual migration problem from a >> simple "concurrent allocations that target the same MAX_ORDER -1 range". >> > > Thanks for the info. Is there a patch under review? No, and I was too busy for now to send it out. > BTW i wonder that probably makes no much difference for my patch since we may > prefer retry the next pageblock rather than busy waiting on the same isolated pageblock. Makes sense. BUT as of now we isolate not only a pageblock but a MAX_ORDER -1 page (e.g., 2 pageblocks on x86-64 (!) ). So you'll have the same issue in that case. -- Thanks, David / dhildenb 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 29BD5C433EF for ; Thu, 16 Dec 2021 10:59:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rwq9pW0QMpFk8gdXbh1BY+HRrRM0SxbW1Hofyq3DzPA=; b=tyr05GcoxeX/kR u6cRwNIiExYNiOQUKvD9F7YiWluxfabVZNA36lVSMWbrwadyfwd6F03M/NB/9lwXHakCXr2r5ISwC hG3zbQDkWRRAsqh4qB9zcMiImd/Hvfx+tzThTjXAHmslhB55UD5KzWrk4/8l6JA54LFYz5ovx2y/g uhIih93OlkL4aGUdn0/qxgNKrr5fAw+PKKIqIX8U0rS/r6YWAHiR7RLlNuphgPHXWlPgXmjXXp4WM WJKTe+hIH7GMsgfcIvZdWj/+923MiQgyVuap3SqVZgSxx+qWafrD+UGVcKrAxBeB67zJT6i69ErQm UqovOHHwl+/oDJanYxvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxoRy-004z2k-Pv; Thu, 16 Dec 2021 10:57:28 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxoRc-004ysN-Lm for linux-arm-kernel@lists.infradead.org; Thu, 16 Dec 2021 10:57:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639652223; 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=MC2gvHGYmh9g6Raca53bij6uBB+XqUqBeIAACH6kGiw=; b=K0tlO4kHiCTrYj/Jj6x0sLl4ETeFdI3vXUJztlbQty4xTeoEhL72Xaf0ihSeHarbOnrrMs 9AXHj/JJdb/Jwg3T1lLNuBrkkVUOzCt/g8LhNMM0JDsMkJnsElHeLebqaiwkXqrZssOzRe n5HJVUqyH0HRvt4SeMLywWKJPVLY/Po= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-171-gCfoIlxPNiGh8uqYLcMEOw-1; Thu, 16 Dec 2021 05:57:02 -0500 X-MC-Unique: gCfoIlxPNiGh8uqYLcMEOw-1 Received: by mail-wm1-f72.google.com with SMTP id j20-20020a05600c1c1400b00343ad0c4c40so1126936wms.0 for ; Thu, 16 Dec 2021 02:57:02 -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:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=MC2gvHGYmh9g6Raca53bij6uBB+XqUqBeIAACH6kGiw=; b=TRUccQJim7OuMtifHazylr+tnzH4rSv2jdg4yiZTLAWvlLKxEu9sQYIqKTMltCHx/f 1Ds4xcW3dZrvY9yL2JJqJSSolkhvyiNTkNkARY07Olke9KfOaXMlCTXCTuURwabhF5nE SB9e0jb79nwsdnkw7ZYU0jQ3ZJqtLzSjQAxDDVXkUhi2l6esC4PefYomh6F4O+TivX+Y bHBwjF0hwRUhqTTAPmmZ7KcB+SRCMyhtTx8HKPRb+cILSoIodZkPUBv89KgaXxEZTJ8/ +rtQWmgYS5DzoNpzLiPzdUESQ/nRSWysW/S1TNqsE15eYf/1i9bAsckNqp6+1MVgIBn+ rpOg== X-Gm-Message-State: AOAM5337li7QMzp58cGMFu5H5sJchHyitoYY92qmEqQZ1qDtaJKybRDz 830xyZxVb3YOo63nWCsOE3OPn+wvwblN6iUAGwUlEnk3VNeVk5EEt4w6PrVWySEnme6+mumqphJ Gbv1doHdyYPDjwPmXrbuqRXuGjwsztE2rTlo= X-Received: by 2002:a1c:f60a:: with SMTP id w10mr4356536wmc.53.1639652221411; Thu, 16 Dec 2021 02:57:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDhJG49j5IOXlecqEpDnxZnmchZDhLcRCk8gk+wn9LsO6KsDIg1HPa3zDdFSpqHP48eaZL7A== X-Received: by 2002:a1c:f60a:: with SMTP id w10mr4356526wmc.53.1639652221231; Thu, 16 Dec 2021 02:57:01 -0800 (PST) Received: from [192.168.3.132] (p4ff23dcd.dip0.t-ipconnect.de. [79.242.61.205]) by smtp.gmail.com with ESMTPSA id g198sm5057299wme.23.2021.12.16.02.57.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Dec 2021 02:57:00 -0800 (PST) Message-ID: <7d9b7e5f-a6c0-2079-90e7-c02aaeb1f4c0@redhat.com> Date: Thu, 16 Dec 2021 11:56:59 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH 1/2] mm: cma: fix allocation may fail sometimes To: Aisheng Dong , "linux-mm@kvack.org" Cc: "linux-kernel@vger.kernel.org" , "dongas86@gmail.com" , "linux-arm-kernel@lists.infradead.org" , Jason Liu , Leo Li , Abel Vesa , "shawnguo@kernel.org" , dl-linux-imx , "akpm@linux-foundation.org" , "m.szyprowski@samsung.com" , "lecopzer.chen@mediatek.com" , "vbabka@suse.cz" , "stable@vger.kernel.org" , Shijie Qin References: <20211215080242.3034856-1-aisheng.dong@nxp.com> <20211215080242.3034856-2-aisheng.dong@nxp.com> <783f64f5-3a55-6c42-a740-19a12c2c7321@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211216_025704_844286_A408F5DC X-CRM114-Status: GOOD ( 16.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 16.12.21 03:54, Aisheng Dong wrote: >> From: David Hildenbrand >> Sent: Wednesday, December 15, 2021 8:31 PM >> >> On 15.12.21 09:02, Dong Aisheng wrote: >>> We met dma_alloc_coherent() fail sometimes when doing 8 VPU decoder >>> test in parallel on a MX6Q SDB board. >>> >>> 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@3607 >> 6+99@40477+108 >>> @40852+44@41108+20@41196+108@41364+108@41620+ >>> >> 108@42900+108@43156+483@44061+1763@45341+1440@47712+20@49 >> 324+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. >>> >>> 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 pageblock process A try to >>> alloc has already been isolated by the allocation of process B during >>> memory migration. >>> >>> When there're multi process allocating CMA memory in parallel, it's >>> likely that other the remain pageblocks may have also been isolated, >>> then CMA alloc fail finally during the first round of scanning of the >>> whole available CMA bitmap. >> >> I already raised in different context that we should most probably convert that >> -EBUSY to -EAGAIN -- to differentiate an actual migration problem from a >> simple "concurrent allocations that target the same MAX_ORDER -1 range". >> > > Thanks for the info. Is there a patch under review? No, and I was too busy for now to send it out. > BTW i wonder that probably makes no much difference for my patch since we may > prefer retry the next pageblock rather than busy waiting on the same isolated pageblock. Makes sense. BUT as of now we isolate not only a pageblock but a MAX_ORDER -1 page (e.g., 2 pageblocks on x86-64 (!) ). So you'll have the same issue in that case. -- Thanks, David / dhildenb _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel