From patchwork Thu Mar 4 23:20:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 393461 Delivered-To: patches@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp386131jai; Thu, 4 Mar 2021 15:20:23 -0800 (PST) X-Received: by 2002:a17:90a:3489:: with SMTP id p9mr7381904pjb.68.1614900023402; Thu, 04 Mar 2021 15:20:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614900023; cv=none; d=google.com; s=arc-20160816; b=meWdH8f1yT3r+FGWWWhW+7yKWPp3t9wjvt2frDkjyEBihL++yxrkcISmI7AU5hc8wZ HQRX9ZYSBDCn80hEXdJjrDPIq72ZgWxBH0/lxjiP7qgsrvaxMCtKg+oFs2fYPsv7j7Aa 7Q0YKRqK1RUwn+++4DTGON0nlCrTORG2FrvlRmpf6HR3B5XcZEEsZsOEzUC8nibApPMb 5ssedC3d6aUV7YeLH3pxQM3IiZVVoQ0wXqzkUHjTz1AxjcW0hVqABw9xHdW2SInXWkMu /2QXMzRTf1gw+EShvCWcXGWCi63LZdB1gZqdrLDpWapWUHzEwisL3yO8DsUN8Z3wsld2 0uEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=1viYL6LhK+5nIQ13ju++XlarHcY6osyk1cCjbOPG1F0=; b=f/oJcXCDX6niqLr4K6FXNZgWIiX8LIzfMkQhECfCzvbpFdlQKBlrz6TTCS58YQRLrj x9XZ+dxR65UvdduiqxsBa6Sj6FadImxNkLZsnWXK1DKUTa++d2V94pfRG5H954BSfLlm CzmHhMfsjN9eVEJdgyrDAHtNyNelHw47PmTNIZmjJQKeofJY+GbR1e6bRv/1F1aa6FHo tq0XAgKr0NHvq43otn9bmRAQNfif1QYPMpzKVfIdNPfsdH0T1R+c1C0Kdskplc12KIuF keVPg4P9SN3hxoFuQr49LJ13NW9w1pr5+r2SvZBlQvT9Y+AEizqqr5SRporaDhe9x7xS Lfzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KcWKRMcT; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id n8sor391032pfq.2.2021.03.04.15.20.23 for (Google Transport Security); Thu, 04 Mar 2021 15:20:23 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KcWKRMcT; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1viYL6LhK+5nIQ13ju++XlarHcY6osyk1cCjbOPG1F0=; b=KcWKRMcTqPHZF1q05Ce0JCzTme39nwPKHDDiT/YIqKCsscOzC9PyUbaxoEvglXFwrK 1w32NYPCKD9OTcIgZBeCWhzZDLKez5Sl3ufwPZjZCA9VnxgZhu0jIuSF7RZQwDPMX1lw Z5a47mYCKuV+OVShTvu9KWHrGgTAPKj4pQIvMwsZNm24ziWIXPihJMDYtexedzbB1N5u nyE1nYLI9TW/aaWhK7GA7d3xngcaHhqA/h6acr3mB5GPKA7G2GqQUQQXj+4luvgel37m P4UBL+C8Ll6L9gUFrsn3ZL/qjxkKcuBQ2s/cwt2cj3mDi8uyuMqv3qGrJM83UhMY0Tty Fa4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1viYL6LhK+5nIQ13ju++XlarHcY6osyk1cCjbOPG1F0=; b=ehhIY9JOrFCPJ2INfUyO/P6BOdrpJ1l5nlbzI3nTqTZecKpGr08QKI5bNo4GGru+n3 JQr7XseCTy8yABNW41hoh7fyhSx2xpnC66sHv8CH5V7af/MeKCriPGfDRBbFt5KPi6yb UttjBLROCslgtbw36zaJLQDXRUYhSm9OmbhgaJMhqfPrio0e/v6T8ySBB94tK+lwA0mS sHnzQiWrniOb4ZiupklK0d99yIqNrPSm1jvdzkpP6imfOiuZ9hQkNfQFhLqLX0haELfa dFyO+72hYlom4b95yc1odSYrwkERImANjM+B7qXxtF6sn2DaJMs93J42zN55M2fMEDwc mhxw== X-Gm-Message-State: AOAM533ps1rBj90eaZRpoF8fqUzSScgGVydXV0d1UFflNsUsHXEvig+L Vdogbyy1E1czO8oHXAqwKC7dkuPF X-Google-Smtp-Source: ABdhPJw2jFY8Rq+iS4tDrmeKtrXjB9IUAoh4ZkSvegh37qen93VKtQdaq2WlbCBS2hJuKS1jzQ4vsA== X-Received: by 2002:aa7:8d05:0:b029:1ec:b460:f21d with SMTP id j5-20020aa78d050000b02901ecb460f21dmr6027582pfe.29.1614900023086; Thu, 04 Mar 2021 15:20:23 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id u66sm429290pfc.72.2021.03.04.15.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 15:20:22 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Daniel Vetter , Christian Koenig , Sumit Semwal , Liam Mark , Chris Goldsworthy , Laura Abbott , Brian Starkey , Hridya Valsaraju , Suren Baghdasaryan , Sandeep Patil , Daniel Mentz , =?utf-8?q?=C3=98rjan_Eide?= , Robin Murphy , Ezequiel Garcia , Simon Ser , James Jones , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH v8 5/5] dma-buf: system_heap: Add deferred freeing to the system heap Date: Thu, 4 Mar 2021 23:20:11 +0000 Message-Id: <20210304232011.1479036-6-john.stultz@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210304232011.1479036-1-john.stultz@linaro.org> References: <20210304232011.1479036-1-john.stultz@linaro.org> MIME-Version: 1.0 Utilize the deferred free helper library in the system heap. This provides a nice performance bump and puts the system heap performance on par with ION. Cc: Daniel Vetter Cc: Christian Koenig Cc: Sumit Semwal Cc: Liam Mark Cc: Chris Goldsworthy Cc: Laura Abbott Cc: Brian Starkey Cc: Hridya Valsaraju Cc: Suren Baghdasaryan Cc: Sandeep Patil Cc: Daniel Mentz Cc: Ørjan Eide Cc: Robin Murphy Cc: Ezequiel Garcia Cc: Simon Ser Cc: James Jones Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Signed-off-by: John Stultz --- v2: * Rework deferred-free api to use reason enum as suggested by Suren Baghdasaryan * Rework for deferred-free api change to use nr_pages rather than size as suggsted by Suren Baghdasaryan v8: * Reworked to drop buffer zeroing logic, as the drm_page_pool now handles that. --- drivers/dma-buf/heaps/Kconfig | 1 + drivers/dma-buf/heaps/system_heap.c | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) -- 2.25.1 diff --git a/drivers/dma-buf/heaps/Kconfig b/drivers/dma-buf/heaps/Kconfig index 7e28934e0def..10632ccfb4a5 100644 --- a/drivers/dma-buf/heaps/Kconfig +++ b/drivers/dma-buf/heaps/Kconfig @@ -5,6 +5,7 @@ config DMABUF_HEAPS_SYSTEM bool "DMA-BUF System Heap" depends on DMABUF_HEAPS select DRM_PAGE_POOL + select DMABUF_HEAPS_DEFERRED_FREE help Choose this option to enable the system dmabuf heap. The system heap is backed by pages from the buddy allocator. If in doubt, say Y. diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index 006271881d85..c753c82fd9f1 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -22,6 +22,7 @@ #include #include +#include "deferred-free-helper.h" static struct dma_heap *sys_heap; @@ -33,6 +34,7 @@ struct system_heap_buffer { struct sg_table sg_table; int vmap_cnt; void *vaddr; + struct deferred_freelist_item deferred_free; }; struct dma_heap_attachment { @@ -290,27 +292,41 @@ static unsigned long system_heap_free_pages(struct drm_page_pool *pool, struct p return 1 << pool->order; } -static void system_heap_dma_buf_release(struct dma_buf *dmabuf) +static void system_heap_buf_free(struct deferred_freelist_item *item, + enum df_reason reason) { - struct system_heap_buffer *buffer = dmabuf->priv; + struct system_heap_buffer *buffer; struct sg_table *table; struct scatterlist *sg; int i, j; + buffer = container_of(item, struct system_heap_buffer, deferred_free); table = &buffer->sg_table; for_each_sg(table->sgl, sg, table->nents, i) { struct page *page = sg_page(sg); - for (j = 0; j < NUM_ORDERS; j++) { - if (compound_order(page) == orders[j]) - break; + if (reason == DF_UNDER_PRESSURE) { + __free_pages(page, compound_order(page)); + } else { + for (j = 0; j < NUM_ORDERS; j++) { + if (compound_order(page) == orders[j]) + break; + } + drm_page_pool_add(&pools[j], page); } - drm_page_pool_add(&pools[j], page); } sg_free_table(table); kfree(buffer); } +static void system_heap_dma_buf_release(struct dma_buf *dmabuf) +{ + struct system_heap_buffer *buffer = dmabuf->priv; + int npages = PAGE_ALIGN(buffer->len) / PAGE_SIZE; + + deferred_free(&buffer->deferred_free, system_heap_buf_free, npages); +} + static const struct dma_buf_ops system_heap_buf_ops = { .attach = system_heap_attach, .detach = system_heap_detach,