From patchwork Sat Jan 23 03:46:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 369444 Delivered-To: patches@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp2054895jam; Fri, 22 Jan 2021 19:47:03 -0800 (PST) X-Received: by 2002:a17:90a:a502:: with SMTP id a2mr9086420pjq.218.1611373622878; Fri, 22 Jan 2021 19:47:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611373622; cv=none; d=google.com; s=arc-20160816; b=xC8k48B0E/IjeYsMFvzj0cwzrIcOkki9ff/Ww45iFarvIQZYZgEwo4yZwxscIZSbqg 9C5pLPGT/Dnr5aAMs119ilklxvAM1Fm2RlICuRazeEm7a6Msz8onevhClBHL7+DO+APr 5xOfCR/hk2f9Zf/+1H1ZADzfUkrrJR7VCNoZ7XLTLZD6I4momNR1joWuloGLLhzYp+KL l0m+4wHfdzMckYctBzWv//GnmtAsRCCUJ1uh22QRLcd680TEX072ftLL3yLvQM0XNcz4 ZCVAsG9HCHDt8Dqg/I8tgGrf4be4a/LOzvVZaI3uvPw1cKQXhiUX2g73c49rqeU0lMVj d6Fw== 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=NeU+sbXmljaYFeP3l6UlIJg8urIJG4eKqAQWq4YMm7Q=; b=iDyASYIDiUNgsUKKBDF8+OJm/JcTXyyZW9y/iH04ioqy762ZuLCol5SOr2MZRlRJMH seP3xWzXjTEV4e2XdVohJf0WVP7HCSAag+F2Fl4KbTcRsJOLwkxOGWTL5SUv4O6VnbuI icanro4z0AZz8m0+D4yrndc/gx/EWJFldhRAqkR2qEdX342IZC0+FwDFjKpIie10HpQs pFVilK2aobx1v1DeFh8v7M+MFixFnZI8kIjhOKb/zIXijYHCpXccMlhuFrYyfWzs+fBi qJxDSQQ4thEYR7biRsoB/zmnTuaroWIZO+KUlhCYt+4v8e6ob7/ycRjL3UsDuxMk1yfO 0EJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WnxuHG+5; 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 z1sor5824294pje.43.2021.01.22.19.47.02 for (Google Transport Security); Fri, 22 Jan 2021 19:47:02 -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=WnxuHG+5; 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=NeU+sbXmljaYFeP3l6UlIJg8urIJG4eKqAQWq4YMm7Q=; b=WnxuHG+58B7ObL97OX1lcKW9Hk6NeIHCjNLj+Ln4wJsoDeIQbBP+2ByXlvfZxdp6xM ZHm3dS++P7X/juDRpoRnVOs0+6P0DE/MLFMnFT+oG23Y2K+iDsKR1IqSXz50WqwNLXrW kc8oy2ktygL6toj6sEVnLbt/YzPbduFQAvMvfJWGL9Y19Os79LYUZkD+vum4PHTIZ9f9 LawLrkgE7NuSJ9/Pmb2fkpeWzn3k2SIDnK1MsF3/sHRAvqXGygs4L1hd7DocUguZpid5 cnYdR20sbtKRuHIyD3eTOjXgWNMHabLZkKYmh20fZBkdsFl6m0tC8YWSw9nyfLchkhQu S8yA== 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=NeU+sbXmljaYFeP3l6UlIJg8urIJG4eKqAQWq4YMm7Q=; b=edx/9di6s19L/FS3vaIdkVjHhFYzcCaupjLu0irL2+9SnUHJ+T32ohE9G2MJn/Zg3k V6YHpLcw7Ik/6sO2EGg1w+vj6ltdPJgEr13yHrYk7qqVF5AAJ7FloUxQH9FHiMedAFNp Gy5hzDhxEg1YLnR+P+rlu/VIYOwc0RMb+1kBWC7T3xtGsNrCiuJOJdzpxrjb1J5qyBzg X9vF9krSf9jF1Q6CmcBy+lqQ2ex1CwMjPghJKHSt/l/NSZLlDyYSUK/gA6+6CLAruSi2 eyfRIZgPdCrg+NhVZ/DyR6V0tGpjVKN22mIQgp+aO86KyLGIpnouUVsaio6LvG2rmxVV mhiw== X-Gm-Message-State: AOAM530oplhLBXS0egr3Vvccyd2hp6b4//b2vO0TdLw9Dz2LXQfmOv4j JxMbWUoidh9tpiz+LIG7DpXqCtqK X-Google-Smtp-Source: ABdhPJxIYWGLWs4iE8DbmMqeyBbwTuBXL43v1z7ZqgX+FHaaaJjZZAx1y0u7UHKgbJEkz+l0gMljOA== X-Received: by 2002:a17:90b:4c0b:: with SMTP id na11mr2604106pjb.45.1611373622594; Fri, 22 Jan 2021 19:47:02 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id q24sm10316702pfs.72.2021.01.22.19.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 19:47:01 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Daniel Vetter , 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 v2 3/3] dma-buf: system_heap: Add deferred freeing to the system heap Date: Sat, 23 Jan 2021 03:46:55 +0000 Message-Id: <20210123034655.102813-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210123034655.102813-1-john.stultz@linaro.org> References: <20210123034655.102813-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: 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(-) -- 2.17.1 diff --git a/drivers/dma-buf/heaps/Kconfig b/drivers/dma-buf/heaps/Kconfig index 748e840e6edd..3f4d7b949301 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 885e30894b77..747fa2250e84 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 { @@ -317,30 +320,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,