From patchwork Tue Feb 2 07:41:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 374606 Delivered-To: patches@linaro.org Received: by 2002:a17:906:24d5:0:0:0:0 with SMTP id f21csp18454ejb; Mon, 1 Feb 2021 23:41:59 -0800 (PST) X-Received: by 2002:a17:902:eacb:b029:e1:2de4:72b6 with SMTP id p11-20020a170902eacbb02900e12de472b6mr15998164pld.17.1612251719473; Mon, 01 Feb 2021 23:41:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612251719; cv=none; d=google.com; s=arc-20160816; b=KoNI5Dc9ziI27Q3p2QViuXPjxzf8nr0dvrLHBv0VzlzTfLmaEiDH8FnGsYHVLATyXu aH3FHkeWjNgBfdlsuO5htPu1CDpRnaIHA7d6+U9IzH5TLW8shSj2zu/iM8rF55uGErvb 7MMkdwoMPk9HKn/vJo6879wICd1C24ZBub29W9NriNBxvcRF0s5LVfPPAVYY6anpfJE0 hDqBZzlcnVIoRwHCQ3Ca7mHthL86SKnF/Wrjef8IC0O/BLBwT953nAhUY8tBxG0vd7NH UOB5nqMkSMGDylwj2tvqe4Us27HjhLLeezEHtJBWRkjNeY5SqwOdCpKkdjp0wPet9B0C 31Og== 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=yF9oYLwsZ1KojzzdMIJNFHTIF6r0NLzbmizzA10msek=; b=kB/RUEir3lAeh6WOcGqwn3khXcGz6iJmn5x3GEGCvdCRGRAISL0/ClCaX3Z/cxrzsx zXAaFKIgAsoAuqxE729STwjomomLpgeYL8KZT6JtNml/at5V3pALmOn9/hYhXD3eoMUB tN48GGbqQHLfZnIOPZTKYqouhfO62+wiXS+MSu4CUfKhu0QpxRWWbpg+tNKuHrc7FEya O+EVJNZnQiFATKRdQitoJg1KJtJmtFTyYPFqtSTiT8y5qytrC/suEaGCKtr1f5Scxnhs 1WOznkhmWqH7NusU5pFGFiOPpI73YhM0r/3XDUHB3CoHB94AOnzPfEy0AcD56O+g+Ppc VaMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i2KWwMMW; 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 i8sor960487pjv.34.2021.02.01.23.41.59 for (Google Transport Security); Mon, 01 Feb 2021 23:41:59 -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=i2KWwMMW; 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=yF9oYLwsZ1KojzzdMIJNFHTIF6r0NLzbmizzA10msek=; b=i2KWwMMWbuGF2eiQySUtHobe5uTz4nG5XRV4S2XJ/mHh1GbIX54qDVTDwHLfIR7D2/ qsr7I6lilB8DfLaglk+KKmLYDFcLfD8yf9sj2W2EGPfEvPUZ7cfa9eDsaXiP3KM4vDx+ SeLls8iGFsCugRt525lMp5RI4ICOmGqH04gE2ZE2wyMS0jbFSpBel6/rRX4bXGsw/vCo TPivIwY7fxlczAzpjZCgP1t11aqp+XaYonFc9iv5hvqaG8vsMPQ9cmU+Xm/ArO6Dd0YQ kQEWFQmgKg65gixRyMtqqbzE0BUmJvCNNaoQfdsfgB4YXn19AWuw5/hw/iHwmvrSHBzh 4JOA== 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=pUSAPHj3xnPWbXv6IQ+Ou0dLXkf7CKfgDykmT75n9sUUoJVibxXaqcKxGpueyWy8kC 16OKZ0Oo53zc+L0shbOpRdkhjnSs82MPPPkHyTQQfLo0IGbv5V0pUG2bUdeA9CLTmmuW 9BHWip9fVUA431h+kiIHcjT/+13qZpfvZ5uF8Va5Q6UBp6xS/HYYnd5Najrw5rRHhgr2 JUMIBgQN+9UpxI0r8WAtz/z5RbcFLiINN5uMx/Mjl3aPutfrcX3afTeJjrM2YLu33Ayd Lbcg/yQzTqdgLWBAsW9dNs+u2pEkXkEDJxP8KtO0gjpKIkoV9vMkmN+KRYVAB8ykNxFg IFVg== X-Gm-Message-State: AOAM531FS6uZKtg52AUp1XfWpfKgGBE2sqHQzU4IyDL8Cq1VSk6abO6G ryctJkVyN1MHFVOoJ8MeYjbkgCw/ X-Google-Smtp-Source: ABdhPJxje564VpHOPV+rh4rYf4PQrgkJXTdm+hnKe+ctEVPFgfpIqQ9fOc4EUqeGuKE61UOFwfC2qA== X-Received: by 2002:a17:90a:6549:: with SMTP id f9mr3026149pjs.17.1612251719077; Mon, 01 Feb 2021 23:41:59 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id k9sm9410666pgh.94.2021.02.01.23.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 23:41:58 -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 v4 3/3] dma-buf: system_heap: Add deferred freeing to the system heap Date: Tue, 2 Feb 2021 07:41:51 +0000 Message-Id: <20210202074151.3146795-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210202074151.3146795-1-john.stultz@linaro.org> References: <20210202074151.3146795-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.25.1 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,