From patchwork Fri Feb 5 08:06:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 376892 Delivered-To: patches@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp2008441jah; Fri, 5 Feb 2021 00:06:40 -0800 (PST) X-Received: by 2002:aa7:9585:0:b029:1c5:10ce:ba7f with SMTP id z5-20020aa795850000b02901c510ceba7fmr3531110pfj.79.1612512399873; Fri, 05 Feb 2021 00:06:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612512399; cv=none; d=google.com; s=arc-20160816; b=YfkZsrP+Dmlqgox38AOFbnCpa7a+H/ZcNwJnqPyevcPAoPJWQ00yrLnnIhybqZC5PA 2Jm2x+vxoVIaGQFsfu+9tKEQOs6eusjdY7iUQKVEwv19mCgdGYMRbEAUn/zfLjgKPGTg YOxcnggFu9GzzNfCe2wUq8hHN1sdBumL2EP6cWil/c+R8BK5CDIO0FLHNsIfnhhln6ST hZ9/hg/7WoIuOuBCXMJiMkEJ3IiWW+gdjASY3ipDd1r942sxVHScQkesifIGlRFJTVf8 5vA9OEkjt4wRghcr0GrpgMooaZ/A9pPq7QhKRZTP75sryE84cdrdMf8uyz7o9+8s3RgE sdEg== 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=GOndOP8F+BfXNLjrSX9CtfpObuYsc9aU1JNxbRzKav4=; b=lgi4pW+BoiyWJ71ByEUEEgKwaWVS/qJYdm4Q5uiFMdna7TUl6H9PHg2VCMU6Tqr6cW 0+kE+y1YqgmV1KlbQHAaAq2XbwHIIXfz2QvxUtPzxiItW7m87K6iyPe4ukFd7ohvKkSk 137LwS40m3ZheivRpN7/Lw8CGCsYeFH9tId6x4nnPQPKsnmkt1yXwbcYgDkcfpTQuiLT 3VXON2elN0zFVu+V8FExpSITl3Kj9jifls9xync6ansbrTcGJ+0DB3pVayOvC8mjJTdZ oh7USmHm0pmDmH3wb6qyZd4qDpBzgTx62bnLh80v7XyCNcpr83UljTXfBADC63I+pszs duTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nn+MlC5t; 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 s15sor4187596pfe.24.2021.02.05.00.06.39 for (Google Transport Security); Fri, 05 Feb 2021 00:06:39 -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=Nn+MlC5t; 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=GOndOP8F+BfXNLjrSX9CtfpObuYsc9aU1JNxbRzKav4=; b=Nn+MlC5tKBHafRdbSa7S8DmObCjHIWlNYVXwMR2RRmFpY/1YFN/JejT9MseDX0khO/ Piwh7OqAi92p946kQ+P8IdpWiNbpooftChpefls8Lmv9U8Q7rleVcIwXuOnqu/4BQzC+ goprUTNEMoRlSmp6To1gKsxWw6vM72Yr5P7HEGj5Yi9M5drA9jSPHpz65qDMqWz+R6RX v/NGL7oFcwvXJOVn5S/LHz+ARYcnN5bywATDFLipVqQsms2hfi5V5SGE6jH3LGHk0hhg /aqgi5o6SNZzoeZBdlWnAv3EE3rtQ2IxAYedQIia3hiO+oABFCiB/SacNV9a2foTJouk GRDA== 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=GOndOP8F+BfXNLjrSX9CtfpObuYsc9aU1JNxbRzKav4=; b=O599IuJwCcFCV7pkpwSwhrhKP2vY8uRBQ7TkUOqB9qye4nPqfuJCAIZ6HXrIv9KsV1 9NPpfixKKKzzp7Kxd1XoNjcGLbKWWzqlZCgWQVF9UkYECElETmPaEnEIPpIY3R1zvelI cGcWVjhtJiqIpjT0zNnWQYPf0IHfGgjJcvi9OYWCfnIEg87JWsYzdrTonDs7GBA8yXmh zEctWZg2NbZFebCzrXxTC70G21K5s/Y4gQUp8tBStKmLMFpU45hhiKl9moWIiB5zIp2I PziFcwrFN/hpZGYxHSDJ9jNwoLV11BwbHAji4/KnCTUwcjHXpk+F0FPWVxhXqFN2HXux 4Dxw== X-Gm-Message-State: AOAM532hBc+/BNnPJiX1Tnc2ah8qcESw8JdK4YDGpq9ooQpvc4rZd5L1 IuLQJEPiCu6vk1UJUZRunjvftFal X-Google-Smtp-Source: ABdhPJx+FpGulW/NuF4+mtl7ogJq0jqebiVtB3k4/SZDAmxf9F1Xx8HSTD5aCBfLoqE9Pbnctuk3TQ== X-Received: by 2002:aa7:9538:0:b029:1d6:ccef:72ad with SMTP id c24-20020aa795380000b02901d6ccef72admr3319521pfp.64.1612512399559; Fri, 05 Feb 2021 00:06:39 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 32sm9520070pgq.80.2021.02.05.00.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 00:06:38 -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: [RFC][PATCH v6 7/7] dma-buf: system_heap: Add deferred freeing to the system heap Date: Fri, 5 Feb 2021 08:06:21 +0000 Message-Id: <20210205080621.3102035-8-john.stultz@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210205080621.3102035-1-john.stultz@linaro.org> References: <20210205080621.3102035-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 --- drivers/dma-buf/heaps/Kconfig | 1 + drivers/dma-buf/heaps/system_heap.c | 31 ++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 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 6d39e9f32e36..042244407db5 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 { @@ -308,30 +310,45 @@ static int system_heap_zero_buffer(struct system_heap_buffer *buffer) return ret; } -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); /* Zero the buffer pages before adding back to the pool */ - system_heap_zero_buffer(buffer); + if (reason == DF_NORMAL) + if (system_heap_zero_buffer(buffer)) + reason = DF_UNDER_PRESSURE; // On failure, just 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; + + deferred_free(&buffer->deferred_free, system_heap_buf_free, buffer->len); +} + static const struct dma_buf_ops system_heap_buf_ops = { .attach = system_heap_attach, .detach = system_heap_detach,