Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4872876pxv; Tue, 29 Jun 2021 18:38:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5jQVjYU3Eht5Sk5S3XTho4w/1wUf5jFebcky+K0wccEZVtAHNHmYORRQIi3IwilUqKbrL X-Received: by 2002:a17:906:1c5b:: with SMTP id l27mr8733617ejg.40.1625017088775; Tue, 29 Jun 2021 18:38:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625017088; cv=none; d=google.com; s=arc-20160816; b=enKYiCkCLFFC7N75+r+1g/Cf1DXCwHD4ViYWkbKHo+e+JBFlz76MjgOxoWHrnKmDbI hv7jo+VKZOp7WNIBh7hfS3BZOGt/QVV0kEpAzC/GNsb+sumGPQe2LFhkhSSho/ElhqNw 2aiXVnhkLFh6xuMtPb/uZVBRf2x8jvDpf9v1tPXoMShnTDZqtYwylaAUfV35k6p4/75z hp/9+B1gFx3C8q+ZAShGkOSf/NVUdkE6DSBgVsXkd1LXiQZb9dxwX8NHm8S42g4xYHZG LwRxly+raX57YoxbJyYBwp9oL4kGd55VrRP8OWLQftOmlZ7HfK+Tc69WEek6AeIBc1kk jGrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DFvfw3znc9/iNgUeu9+epS+fTvKPZKLuhAUaTL0kY/M=; b=XFphOSIAzpF/DpRWr+7ezZ2tEJ4hCxM/OiXlFCGlUVLFxltEioUW1omXW3S52KpW20 wO/9XjQBU8hPjbRh3lMoI8vJk4ywFWD1BZmSj9dFAjgPCVQCHrWtZJXQcZq6968PtGQK fP81IezybJ3lqYXKnhRneWJqXLHjTi6bpntmVhkCg59AULL9cGMvkFZ4oMIPYqRER1oa 1BGdcMyEvBWiSj5m+Ta8hH3u1MiSRgmbb4kn7URUab8rC6R4K60JMmBu/7KBlqhftDlB JBMrlZk4upUZ1HoARd4Tvrs+8AsWHrE17rF5S2Yor7zzTOQ8LW+9gaulcYZDjIalxE3a 5dbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oJpnLzmE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id er20si17518058ejc.101.2021.06.29.18.37.45; Tue, 29 Jun 2021 18:38:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oJpnLzmE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232545AbhF3BhS (ORCPT + 99 others); Tue, 29 Jun 2021 21:37:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232333AbhF3BhK (ORCPT ); Tue, 29 Jun 2021 21:37:10 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08C1EC061767 for ; Tue, 29 Jun 2021 18:34:38 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id n11so724941pjo.1 for ; Tue, 29 Jun 2021 18:34:38 -0700 (PDT) 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=DFvfw3znc9/iNgUeu9+epS+fTvKPZKLuhAUaTL0kY/M=; b=oJpnLzmEuM+/uMBXpQoc4X8AngeoGclUDsnVQ33jUTM2egEVhMJCBUDpXcH6nrLmLx 82TQkoyi4f0rkpVhElAKnsaSTOfD6OmughNSeXmHMm+j4LHIzeDaZawrx4TFdwTvkvrZ 0m6YLmyM3JPKZ8t0/wSpkHfYfoZ4A9e2eiQIAkun3gG80Bv2aYJYlKVh5V2HokFE8Byx TN0BFmtpEVrmCsBlOzxffG4lfxMs3c2pDf5aLQfsmtPizwrjdnpBOK0zpapq/F9k2KvW PYJ4xkQ78400cqdx6qVaZ5sZDY5J2AxtEr6nCwEa+0qA9T50kiR/CxbeBV30DR1XWWdt 6I/Q== 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=DFvfw3znc9/iNgUeu9+epS+fTvKPZKLuhAUaTL0kY/M=; b=UujIubqz8oKJRko0PFatTmqqpRX4eoPswpZgGSH5xj51VK/eZ+E27ojS2mhkayLIun L+igrr8YMEdekKL92nNJlVaz8TMt9Owt90kiopkjjLXNZfP97+JjvpD5rqKkKW7kpCO6 GruLGtKIUwkZqnlqwQnqrp2baTxwkAFOpKHejfE7wzt03LDe90hnBl8URt85GJRMG+HD LTJyoKXYwNaYR5fxa2SX+gqg9Zqx+n+ac0ur1HKxWL8ieckql5lStpvGTnf2VUda5lDt RR1UhHpj+sqCjvcIsFZkQ6ohMhP4QkuF1BEMCyUXFP2l7wMtgGgtZHn8QMU3dCdla77k cLSQ== X-Gm-Message-State: AOAM530yVq3PewKIBKqLqC8mamvfGJ20kBBFwIGfR66X7UbmzkV2ckY0 /0KV/ZUuECjSwkLF8uuSkSb8HIu3WxYaVg== X-Received: by 2002:a17:902:6b84:b029:ee:f966:1911 with SMTP id p4-20020a1709026b84b02900eef9661911mr30460530plk.69.1625016877203; Tue, 29 Jun 2021 18:34:37 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id g8sm20252901pja.14.2021.06.29.18.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 18:34:36 -0700 (PDT) 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=20Eide?= , Robin Murphy , Ezequiel Garcia , Simon Ser , James Jones , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH v9 5/5] dma-buf: system_heap: Add deferred freeing to the system heap Date: Wed, 30 Jun 2021 01:34:21 +0000 Message-Id: <20210630013421.735092-6-john.stultz@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210630013421.735092-1-john.stultz@linaro.org> References: <20210630013421.735092-1-john.stultz@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) 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 85ceca2ed61d..8a0170b0427e 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 void system_heap_free_pages(struct drm_page_pool *pool, struct page *p) __free_pages(p, 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, -- 2.25.1