From patchwork Thu Jan 28 06:21:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 12051941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40AA1C433DB for ; Thu, 28 Jan 2021 06:22:02 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F3DA964DC4 for ; Thu, 28 Jan 2021 06:22:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3DA964DC4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BABD36E8DF; Thu, 28 Jan 2021 06:21:58 +0000 (UTC) Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by gabe.freedesktop.org (Postfix) with ESMTPS id BA2466E8DD for ; Thu, 28 Jan 2021 06:21:56 +0000 (UTC) Received: by mail-pg1-x533.google.com with SMTP id v19so3601478pgj.12 for ; Wed, 27 Jan 2021 22:21:56 -0800 (PST) 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=yF9oYLwsZ1KojzzdMIJNFHTIF6r0NLzbmizzA10msek=; b=hsKEFCeDBPBnnkjBCVVbIShSoY9OmkyTebKHBfnRXysY8Aciy3zWs6gv4DGrah5AUR Kgk8GtE3VPMyZIfJC9GLOdFwr3cweevE95L8zAHI7w4jMh4XLM4INu6IyB+g+HJLBlmF 2VWmU9oDGSV48vRWYea9wgobgBN6PblZwrnvU08P8TWMIYyx2gE9KhZdeMIyUI6XERvf j4dM1keHxZSwBKHwQUvhgDpo6Knar8Q2d9DayeTfN08fkaezIs8XMJVj3etyG/QRb8sf DgbmVmJeCKRP5RLfjnoXiQHvZ6grT/ji6IS60unxI8Gt4+3+IQANaXu07ZV5fCkrWKq1 bLTQ== 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=yF9oYLwsZ1KojzzdMIJNFHTIF6r0NLzbmizzA10msek=; b=i/kFlBDs64TKGIyb/tioNE1G5cc/D8TmGKF6Ms9UFPbsEyAhQtbb6t2Qx3jfscezUw F6jQ7J+tBMT5K0WLVx7Q/0WW7dMxDyqk1bVfibUUnuMfmghaIKJuxFtKpEsVd8xoT7G/ NGzbOBaH2Oi0CeeUAOxbWuqEc3P28SOlbF5ajBc5rRlo0E1e3TrTB2wQ6xHswUtvVXTl k+9spdHHv5DNaCaF1DCk/boKfULVJ0yuun1X43qTeDt+O/hfHLffQxFUOQGQar+D7oBm 2wucJ8vKe8xSAo2VAiCLe8EualK5j3q30Fdr5bCP7VofGfvjyeJtkPDWVRsSnGNrv8RP CC8Q== X-Gm-Message-State: AOAM533t3da7AWGTsFk2ihGKFCITeFlhI+5iwVIlo/1ADNdjt7LdIIne 7DPTB5N4X25YD6S8kmNZ+JVaHQ== X-Google-Smtp-Source: ABdhPJwxi586eEw48AejdKr0BVFHkCaeosEKpbkmcBQcanrMo5ek4fcHdf/tem0eB/as7f/hJ5B26g== X-Received: by 2002:a63:1220:: with SMTP id h32mr15123978pgl.309.1611814916310; Wed, 27 Jan 2021 22:21:56 -0800 (PST) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id s9sm4477765pfd.38.2021.01.27.22.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 22:21:55 -0800 (PST) From: John Stultz To: lkml Subject: [PATCH v3 3/3] dma-buf: system_heap: Add deferred freeing to the system heap Date: Thu, 28 Jan 2021 06:21:47 +0000 Message-Id: <20210128062147.438413-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210128062147.438413-1-john.stultz@linaro.org> References: <20210128062147.438413-1-john.stultz@linaro.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dri-devel@lists.freedesktop.org, Sandeep Patil , Chris Goldsworthy , Ezequiel Garcia , Robin Murphy , James Jones , Liam Mark , Laura Abbott , Hridya Valsaraju , =?utf-8?q?=C3=98rjan_Eide?= , linux-media@vger.kernel.org, Suren Baghdasaryan , Daniel Mentz Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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: 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 | 32 ++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/dma-buf/heaps/Kconfig b/drivers/dma-buf/heaps/Kconfig index 45c7d277448b..2276420ae905 100644 --- a/drivers/dma-buf/heaps/Kconfig +++ b/drivers/dma-buf/heaps/Kconfig @@ -6,6 +6,7 @@ config DMABUF_HEAPS_SYSTEM depends on DMABUF_HEAPS select NET select 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 2addb6d832e0..fe122b5eff10 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -22,6 +22,8 @@ #include #include +#include "deferred-free-helper.h" + static struct dma_heap *sys_heap; struct system_heap_buffer { @@ -32,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 { @@ -301,30 +304,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; + } + page_pool_put_full_page(pools[j], page, false); } - page_pool_put_full_page(pools[j], page, false); } 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,