All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linaro.org>
To: Robin Murphy <robin.murphy@arm.com>
Cc: hch@lst.de, Marek Szyprowski <m.szyprowski@samsung.com>,
	Greg KH <gregkh@linuxfoundation.org>,
	iommu@lists.linux-foundation.org,
	LKML <linux-kernel@vger.kernel.org>,
	Arnd Bergmann <arnd@arndb.de>, Mark Brown <broonie@kernel.org>
Subject: Re: [PATCH 1/2] dma-coherent: Add one parameter to save available coherent memory
Date: Sun, 3 Jun 2018 10:12:17 +0800	[thread overview]
Message-ID: <CAMz4kuLHigZJhk8E53v8k8DR59EARvC6CdkQ0+oAwTRjYKu=cw@mail.gmail.com> (raw)
In-Reply-To: <1d02b2e1-dd1c-af2a-e980-29aef4aa0c00@arm.com>

On 1 June 2018 at 01:25, Robin Murphy <robin.murphy@arm.com> 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

WARNING: multiple messages have this Message-ID (diff)
From: Baolin Wang <baolin.wang-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
To: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
Cc: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>,
	Greg KH
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
	LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	hch-jcswGhMUV9g@public.gmane.org
Subject: Re: [PATCH 1/2] dma-coherent: Add one parameter to save available coherent memory
Date: Sun, 3 Jun 2018 10:12:17 +0800	[thread overview]
Message-ID: <CAMz4kuLHigZJhk8E53v8k8DR59EARvC6CdkQ0+oAwTRjYKu=cw@mail.gmail.com> (raw)
In-Reply-To: <1d02b2e1-dd1c-af2a-e980-29aef4aa0c00-5wv7dgnIgG8@public.gmane.org>

On 1 June 2018 at 01:25, Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org> 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

  reply	other threads:[~2018-06-03  2:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-31  5:55 [PATCH 1/2] dma-coherent: Add one parameter to save available coherent memory Baolin Wang
2018-05-31  5:55 ` [PATCH 2/2] dma-coherent: Change the bitmap APIs Baolin Wang
2018-05-31 17:38   ` Robin Murphy
2018-05-31 17:38     ` Robin Murphy
2018-06-03  2:11     ` Baolin Wang
2018-06-03  2:11       ` Baolin Wang
2018-05-31 17:25 ` [PATCH 1/2] dma-coherent: Add one parameter to save available coherent memory Robin Murphy
2018-06-03  2:12   ` Baolin Wang [this message]
2018-06-03  2:12     ` Baolin Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMz4kuLHigZJhk8E53v8k8DR59EARvC6CdkQ0+oAwTRjYKu=cw@mail.gmail.com' \
    --to=baolin.wang@linaro.org \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=robin.murphy@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.