mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jaewon Kim <jaewon31.kim@samsung.com>
To: hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com,
	gregkh@linuxfoundation.org, iommu@lists.linux-foundation.org
Cc: akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	jaewon31.kim@gmail.com, Jaewon Kim <jaewon31.kim@samsung.com>
Subject: [RFC PATCH] drivers: base: dma-coherent: find free region without alignment
Date: Tue, 14 Nov 2017 17:42:29 +0900	[thread overview]
Message-ID: <20171114084229.13512-1-jaewon31.kim@samsung.com> (raw)
In-Reply-To: <CGME20171114084234epcas2p44ac00494b49aa798f709c5bbdf92127a@epcas2p4.samsung.com>

dma-coherent uses bitmap API which internally consider align based on the
requested size. Depending on some usage pattern, using align, I think, may
be good for fast search and anti-fragmentation. But with the align, an
allocation may be failed.

This is a example, total size is 30MB, only few memory at front is being
used, and 9MB is being requsted. Then 9MB will be aligned to 16MB. The
first try on offset 0MB will be failed because of others already using. The
second try on offset 16MB will be failed because of ouf of bound.

So if the align is not necessary on dma-coherent, this patch removes the
align policy to allow allocation without increasing the total size.

Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
---
 drivers/base/dma-coherent.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c
index 744f64f43454..b86a96d0cd07 100644
--- a/drivers/base/dma-coherent.c
+++ b/drivers/base/dma-coherent.c
@@ -162,7 +162,7 @@ EXPORT_SYMBOL(dma_mark_declared_memory_occupied);
 static void *__dma_alloc_from_coherent(struct dma_coherent_mem *mem,
 		ssize_t size, dma_addr_t *dma_handle)
 {
-	int order = get_order(size);
+	int nr_page = PAGE_ALIGN(size) >> PAGE_SHIFT;
 	unsigned long flags;
 	int pageno;
 	void *ret;
@@ -172,9 +172,11 @@ static void *__dma_alloc_from_coherent(struct dma_coherent_mem *mem,
 	if (unlikely(size > (mem->size << PAGE_SHIFT)))
 		goto err;
 
-	pageno = bitmap_find_free_region(mem->bitmap, mem->size, order);
-	if (unlikely(pageno < 0))
+	pageno = bitmap_find_next_zero_area(mem->bitmap, mem->size, 0,
+					    nr_page, 0);
+	if (unlikely(pageno >= mem->size)) {
 		goto err;
+	bitmap_set(mem->bitmap, pageno, nr_page);
 
 	/*
 	 * Memory was found in the coherent area.
-- 
2.13.0

       reply	other threads:[~2017-11-14  8:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20171114084234epcas2p44ac00494b49aa798f709c5bbdf92127a@epcas2p4.samsung.com>
2017-11-14  8:42 ` Jaewon Kim [this message]
2017-11-14 11:07   ` Marek Szyprowski
2017-11-15 17:04     ` Jaewon Kim

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=20171114084229.13512-1-jaewon31.kim@samsung.com \
    --to=jaewon31.kim@samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jaewon31.kim@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mhocko@suse.com \
    --cc=robin.murphy@arm.com \
    --cc=vbabka@suse.cz \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®