linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Tony Battersby <tonyb@cybernetics.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: iommu@lists.linux-foundation.org, kernel-team@fb.com,
	Matthew Wilcox <willy@infradead.org>,
	Keith Busch <kbusch@kernel.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Tony Lindgren <tony@atomide.com>
Subject: [PATCH v6 09/11] dmapool: cleanup dma_pool_destroy
Date: Tue, 7 Jun 2022 14:45:44 -0400	[thread overview]
Message-ID: <11b7e3cd-c929-654c-1f45-1abe9a6f6a98@cybernetics.com> (raw)
In-Reply-To: <340ff8ef-9ff5-7175-c234-4132bbdfc5f7@cybernetics.com>

pool_free_page() is called only from dma_pool_destroy(), so inline it
and make it less generic since we know that the pool is being destroyed.

Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
---

Changes since v5:
Take the opposite approach and inline pool_free_page() into
dma_pool_destroy() instead of moving the is_page_busy() check into
pool_free_page().

 mm/dmapool.c | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/mm/dmapool.c b/mm/dmapool.c
index c7ec38cb4631..4e075feb038f 100644
--- a/mm/dmapool.c
+++ b/mm/dmapool.c
@@ -241,18 +241,6 @@ static inline bool is_page_busy(struct dma_page *page)
 	return page->in_use != 0;
 }
 
-static void pool_free_page(struct dma_pool *pool, struct dma_page *page)
-{
-	dma_addr_t dma = page->dma;
-
-#ifdef	DMAPOOL_DEBUG
-	memset(page->vaddr, POOL_POISON_FREED, pool->allocation);
-#endif
-	dma_free_coherent(pool->dev, pool->allocation, page->vaddr, dma);
-	list_del(&page->page_list);
-	kfree(page);
-}
-
 /**
  * dma_pool_destroy - destroys a pool of dma memory blocks.
  * @pool: dma pool that will be destroyed
@@ -280,14 +268,22 @@ void dma_pool_destroy(struct dma_pool *pool)
 	mutex_unlock(&pools_reg_lock);
 
 	list_for_each_entry_safe(page, tmp, &pool->page_list, page_list) {
+		void *vaddr = page->vaddr;
+
 		if (is_page_busy(page)) {
 			dev_err(pool->dev, "%s %s, %p busy\n", __func__,
-				pool->name, page->vaddr);
+				pool->name, vaddr);
 			/* leak the still-in-use consistent memory */
-			list_del(&page->page_list);
-			kfree(page);
-		} else
-			pool_free_page(pool, page);
+		} else {
+#ifdef	DMAPOOL_DEBUG
+			memset(vaddr, POOL_POISON_FREED, pool->allocation);
+#endif
+			dma_free_coherent(pool->dev,
+					  pool->allocation,
+					  vaddr,
+					  page->dma);
+		}
+		kfree(page);
 	}
 
 	kfree(pool);
@@ -459,8 +455,7 @@ void dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t dma)
 	*(int *)vaddr = page->offset;
 	page->offset = offset;
 	/*
-	 * Resist a temptation to do
-	 *    if (!is_page_busy(page)) pool_free_page(pool, page);
+	 * Resist a temptation to free unused pages immediately.
 	 * Better have a few empty pages hang around.
 	 */
 	spin_unlock_irqrestore(&pool->lock, flags);
-- 
2.25.1



  parent reply	other threads:[~2022-06-07 18:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07 18:38 [PATCH v6 00/11] mpt3sas and dmapool scalability Tony Battersby
2022-06-07 18:39 ` [PATCH v6 01/11] dmapool: remove checks for dev == NULL Tony Battersby
2022-06-07 18:40 ` [PATCH v6 02/11] dmapool: use sysfs_emit() instead of scnprintf() Tony Battersby
2022-06-07 18:41 ` [PATCH v6 03/11] dmapool: cleanup integer types Tony Battersby
2022-06-07 18:42 ` [PATCH v6 04/11] dmapool: fix boundary comparison Tony Battersby
2022-06-07 18:42 ` [PATCH v6 05/11] dmapool: improve accuracy of debug statistics Tony Battersby
2022-06-07 18:43 ` [PATCH v6 06/11] dmapool: debug: prevent endless loop in case of corruption Tony Battersby
2022-06-07 18:44 ` [PATCH v6 07/11] dmapool: ignore init_on_free when DMAPOOL_DEBUG enabled Tony Battersby
2022-06-07 18:44 ` [PATCH v6 08/11] dmapool: speedup DMAPOOL_DEBUG with init_on_alloc Tony Battersby
2022-06-07 18:45 ` Tony Battersby [this message]
2022-06-07 18:46 ` [PATCH v6 10/11] dmapool: improve scalability of dma_pool_alloc Tony Battersby
2022-06-07 18:46 ` [PATCH v6 11/11] dmapool: improve scalability of dma_pool_free Tony Battersby

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=11b7e3cd-c929-654c-1f45-1abe9a6f6a98@cybernetics.com \
    --to=tonyb@cybernetics.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=kbusch@kernel.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=robin.murphy@arm.com \
    --cc=tony@atomide.com \
    --cc=willy@infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).