Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2146665imm; Sat, 2 Jun 2018 19:13:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLwdtnUcd6FSLl8HOvw/4Uh3lmlRuFfplkQL4qZuetdc4tMX7vp4FxDhYMNEKhnCTR4Nlzp X-Received: by 2002:a17:902:7603:: with SMTP id k3-v6mr13262087pll.371.1527992025684; Sat, 02 Jun 2018 19:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527992025; cv=none; d=google.com; s=arc-20160816; b=r0V4GWxKITRVNrG5sjO2nDtY1ClKypDXHhNvmiZ8u4Ho5cSsMq7RQe2H74ZLbS1SkM sK+dqYGNDMEyD9DPuykzl0Uey844IH8TEkiqppavGa+V9E4akUH5slWvJLfiHeVon++f HvvGv8yGFWpjK0UZHUvUXjXALSczSxGqZX/Xed2PVpRgooxyCov0RpivemzLrO+D1px1 Ov/y28i0Th8nrQ3544BLwUB4Cqgt0DKAuLejFUDPmcUHTt1YGjNx0+xIx/FVljP8mjnV bpRUYNH5MKtxWdbdRoJlD0PKkdmcdEE/aIRQ14lV/X1P8pX4lOjwg3Z+YyHsRmylxe/H Ey+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=Z3VcRsyzGKfKFImpMVmhso9Y7737mmLI8wV8QfOQrDA=; b=s4w9gXpO5Q8Z0OIhJJk+o8ZquNkK5Sh66vmKHZU4HAqwL1YoOIx8/3zbfsuzh7YTO9 NAaREzBEFK1Ql6OiGON9ZuySxphAUmzNblK4zVQRYYtn6saULt/rTa3HVk2PwIbFhAHI axWfcT6ZlkkHPXqwBLkPCOgpIfPS1Gc1ccA+i8lHw3M6424fAYcflFUgwlMBdC/ESHXf ck30uHjWtjTs+QTj6f67hq454EoShGn7p3KLGugkc97Jeksku9IfB5lIswOIAlQxmiy2 0kbAepovRiuL71GWlEVQ2tjiPHLPxT9vqnWBAeJ3Fsi2FA+qZwO0Z4Nj+Nz0CwgPWQSo XuQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MKPMf8mH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h21-v6si239892plr.369.2018.06.02.19.13.31; Sat, 02 Jun 2018 19:13:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MKPMf8mH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751235AbeFCCMT (ORCPT + 99 others); Sat, 2 Jun 2018 22:12:19 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:35825 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751193AbeFCCMS (ORCPT ); Sat, 2 Jun 2018 22:12:18 -0400 Received: by mail-oi0-f68.google.com with SMTP id e8-v6so7416591oii.2 for ; Sat, 02 Jun 2018 19:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Z3VcRsyzGKfKFImpMVmhso9Y7737mmLI8wV8QfOQrDA=; b=MKPMf8mHaXWshO7K8SoL4j2OqdqZrFFTuvqOsbwvBZyBx1eb3YRJpqDlFHHm2Mj3vZ R9DOxB2MPudDjMbgiVxWqjgSgtfoHgmV7GAhPmV3rvaWwlW7Tci8zMfcj0BOHlOYbyiL 7XeHEMKv/WIdzQiJePm2Axsxh/yEOTGJ8/e2M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Z3VcRsyzGKfKFImpMVmhso9Y7737mmLI8wV8QfOQrDA=; b=mIESj6Yz0gTVZ8umVAmnjuiRkdardaFrtLWVhq9Y7co+OJe5sHGnLKaGdS3m8XYcrJ DEjAhLBVgKIjeUdXiySkWQRR/6eC6J4aKTC9A3e6M0xxkgT7icudbnpr6v4mwqIJ/gO5 LF4/w9E9AHoC35ZJZIpmiFfnbKLHm30o/3/FCw1fLGkOvaIt7Z0jBOKWDVjoeCI0w+UE yeBkqK4PrPzkDm41yw1sJkRn2EXsBUWvZC+P4c2gh/6sLlbPdakw9df0oCfJhva3dG8X Le/TlnxLk8oZIh30lyx2Zb5Gth5Ze36GUIiY1f7ht7koT10zistNP1xJGDGTRsP2u3KS UNPA== X-Gm-Message-State: APt69E1wMCx0tDkMhvWgUBJovLRELeXr1w6IGeyme9sFAYxL01wKwFJD whkohqSHacsJ8mBErdGnxZVdxfhQKOaeE0RawrDwFA== X-Received: by 2002:aca:c1c6:: with SMTP id r189-v6mr9668021oif.350.1527991937973; Sat, 02 Jun 2018 19:12:17 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:2d44:0:0:0:0:0 with HTTP; Sat, 2 Jun 2018 19:12:17 -0700 (PDT) In-Reply-To: <1d02b2e1-dd1c-af2a-e980-29aef4aa0c00@arm.com> References: <1d02b2e1-dd1c-af2a-e980-29aef4aa0c00@arm.com> From: Baolin Wang Date: Sun, 3 Jun 2018 10:12:17 +0800 Message-ID: Subject: Re: [PATCH 1/2] dma-coherent: Add one parameter to save available coherent memory To: Robin Murphy Cc: hch@lst.de, Marek Szyprowski , Greg KH , iommu@lists.linux-foundation.org, LKML , Arnd Bergmann , Mark Brown Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1 June 2018 at 01:25, Robin Murphy wrote: > On 31/05/18 06:55, Baolin Wang wrote: >> >> It is incorrect to use mem->size to valid if there are enough coherent >> memory to allocate in __dma_alloc_from_coherent(), since some devices >> may mark some occupied coherent memory by >> dma_mark_declared_memory_occupied(). >> >> So we can introduce one 'avail' parameter to save the available device >> coherent memory, to valid if we have enough coherent memory for the device >> to allocate. > > > We already have dma_mem->size stored for other reasons, so there's little > harm in using it for a rough sanity check to short-circuit the odd > allocation which cannot possibly succeed, but adding machinery purely for > the sake an ever-so-slightly more accurate, but still far from exhaustive, > check doesn't really seem worth it. > > Even if size <= dma_mem->avail there's still no guarantee that the > allocation will actually succeed, so what benefit does the explicit > accounting provide? > Yes, it can not guarantee one successful allocation, but it can avoid some redundant bitmap operation and reducing the preempt-disable time if we have not enough memory by checking the actual available coherent memory. By the way, I think we should also add check in dma_mark_declared_memory_occupied() and __dma_mmap_from_coherent(). -- Baolin.wang Best Regards