Generic page pool & deferred freeing for system dmabuf heap
Subsystems (6)
v6 cover Generic page pool & deferred freeing for system dmabuf heap
This series is starting to get long, so I figured I'd add a short cover letter for context.
The point of this series is trying to add both deferred-freeing logic as well as a page pool to the DMA-BUF system heap.
This is desired, as the combination of deferred freeing along with the page pool allows us to offload page-zeroing out of the allocation hot path. This was done originally with ION and this patch series allows the DMA-BUF system heap to match ION's system heap allocation performance in a simple microbenchmark [1] (ION re-added to the kernel for comparision, running on an x86 vm image):
./dmabuf-heap-bench -i 0 1 system
Testing dmabuf system vs ion heaptype 0 (flags: 0x1)
---------------------------------------------
dmabuf heap: alloc 4096 bytes 5000 times in 86572223 ns 17314 ns/call ion heap: alloc 4096 bytes 5000 times in 97442526 ns 19488 ns/call dmabuf heap: alloc 1048576 bytes 5000 times in 196635057 ns 39327 ns/call ion heap: alloc 1048576 bytes 5000 times in 357323629 ns 71464 ns/call dmabuf heap: alloc 8388608 bytes 5000 times in 3165445534 ns 633089 ns/call ion heap: alloc 8388608 bytes 5000 times in 3699591271 ns 739918 ns/call dmabuf heap: alloc 33554432 bytes 5000 times in 13327402517 ns 2665480 ns/call ion heap: alloc 33554432 bytes 5000 times in 15292352796 ns 3058470 ns/call
Daniel didn't like earlier attempts to re-use the network page-pool code to achieve this, and suggested the ttm_pool be used instead. This required pulling the fairly tightly knit ttm_pool logic apart, but after many failed attmempts I think I found a workable abstraction to split out shared logic.
So this series contains a new generic drm_page_pool helper library, converts the ttm_pool to use it, and then adds the dmabuf deferred freeing and adds support to the dmabuf system heap to use both deferred freeing and the new drm_page_pool.
Input would be greatly appreciated. Testing as well, as I don't have any development hardware that utilizes the ttm pool.
thanks
-john
John Stultz (7):
drm: Add a sharable drm page-pool implementation
drm: ttm_pool: Rename the ttm_pool_dma structure to ttm_pool_page_dat
drm: ttm_pool: Rework ttm_pool_free_page to allow us to use it as a
function pointer
drm: ttm_pool: Rework ttm_pool to use drm_page_pool
dma-buf: heaps: Add deferred-free-helper library code
dma-buf: system_heap: Add drm pagepool support to system heap
dma-buf: system_heap: Add deferred freeing to the system heap
drivers/dma-buf/heaps/Kconfig | 5 + drivers/dma-buf/heaps/Makefile | 1 + drivers/dma-buf/heaps/deferred-free-helper.c | 145 ++++++++++ drivers/dma-buf/heaps/deferred-free-helper.h | 55 ++++ drivers/dma-buf/heaps/system_heap.c | 77 ++++- drivers/gpu/drm/Kconfig | 5 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/page_pool.c | 220 +++++++++++++++ drivers/gpu/drm/ttm/ttm_pool.c | 278 ++++++------------- include/drm/page_pool.h | 54 ++++ include/drm/ttm/ttm_pool.h | 23 +- 11 files changed, 639 insertions(+), 225 deletions(-) create mode 100644 drivers/dma-buf/heaps/deferred-free-helper.c create mode 100644 drivers/dma-buf/heaps/deferred-free-helper.h create mode 100644 drivers/gpu/drm/page_pool.c create mode 100644 include/drm/page_pool.h
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH v6 1/7 drm: Add a sharable drm page-pool implementation
This adds a shrinker controlled page pool, closely following the ttm_pool logic, which is abstracted out a bit so it can be used by other non-ttm drivers.
--- drivers/gpu/drm/Kconfig | 4 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/page_pool.c | 220 ++++++++++++++++++++++++++++++++++++ include/drm/page_pool.h | 54 +++++++++ 4 files changed, 279 insertions(+) create mode 100644 drivers/gpu/drm/page_pool.c create mode 100644 include/drm/page_pool.h
drivers/gpu/drm/Kconfig +4 -0
@@ -174,6 +174,10 @@ config DRM_DP_CEC Note: not all adapters support this feature, and even for those that do support this they often do not hook up the CEC pin. +config DRM_PAGE_POOL + bool + depends on DRM + config DRM_TTM tristate depends on DRM && MMU
drivers/gpu/drm/Makefile +1 -0
@@ -32,6 +32,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o drm-$(CONFIG_PCI) += drm_pci.o drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o +drm-$(CONFIG_DRM_PAGE_POOL) += page_pool.o drm_vram_helper-y := drm_gem_vram_helper.o obj-$(CONFIG_DRM_VRAM_HELPER) += drm_vram_helper.o
drivers/gpu/drm/page_pool.c new file +220 -0
220 lines not on this page · raw message
include/drm/page_pool.h new file +54 -0
54 lines not on this page · raw message
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Am 05.02.21 um 09:06 schrieb John Stultz:
Quoted 65 lines
This adds a shrinker controlled page pool, closely following the
ttm_poollogic, which is abstracted out a bit so it can be used by other non-ttm drivers.Cc Daniel Vetter <[email protected]>Cc Christian Koenig <[email protected]>Cc Sumit Semwal <[email protected]>Cc Liam Mark <[email protected]>Cc Chris Goldsworthy <[email protected]>Cc Laura Abbott <[email protected]>Cc Brian Starkey <[email protected]>Cc Hridya Valsaraju <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Sandeep Patil <[email protected]>Cc Daniel Mentz <[email protected]>Cc Ørjan Eide <[email protected]>Cc Robin Murphy <[email protected]>Cc Ezequiel Garcia <[email protected]>Cc Simon Ser <[email protected]>Cc James Jones <[email protected]>Signed-off-by John Stultz <[email protected]>--- drivers/gpu/drm/Kconfig | 4 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/page_pool.c | 220 ++++++++++++++++++++++++++++++++++++ include/drm/page_pool.h | 54 +++++++++ 4 files changed, 279 insertions(+)create mode 100644
drivers/gpu/drm/page_pool.c
create mode 100644include/drm/page_pool.hdrivers/gpu/drm/Kconfig +4
-0@@ -174,6 +174,10 @@ config DRM_DP_CEC Note: not all adapters support this feature, and even for those that do support this they often do not hook up the CEC pin. +config DRM_PAGE_POOL + bool + depends on DRM + config DRM_TTM tristate depends on DRM && MMUdrivers/gpu/drm/Makefile +1
-0@@ -32,6 +32,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o drm-$(CONFIG_PCI) += drm_pci.o drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o +drm-$(CONFIG_DRM_PAGE_POOL) += page_pool.o drm_vram_helper-y := drm_gem_vram_helper.o obj-$(CONFIG_DRM_VRAM_HELPER) += drm_vram_helper.odrivers/gpu/drm/page_pool.c new file +0
-0
drivers/gpu/drm/page_pool.c line 1
Quoted 1 line
drivers/gpu/drm/page_pool.c new file +1
-0@@ -0,0 +1,220 @@ +// SPDX-License-Identifier: GPL-2.0
Please use a BSD/MIT compatible license if you want to copy this from the TTM code.
Quoted 39 lines
drivers/gpu/drm/page_pool.c new file +39
-0+/* +* DRM page pool system +* +* Copyright (C) 2020 Linaro Ltd. +* +* Based on the ION page pool code +* Copyright (C) 2011 Google, Inc. +* As well as the ttm_pool code +* Copyright (C) 2020 Advanced Micro Devices, Inc. +*/ + +#include <linux/freezer.h> +#include <linux/list.h> +#include <linux/slab.h> +#include <linux/swap.h> +#include <linux/sched/signal.h> +#include <drm/page_pool.h> + +static LIST_HEAD (pool_list); +static DEFINE_MUTEX (pool_list_lock); +static atomic_long_t total_pages; +static unsigned long page_pool_max; +MODULE_PARM_DESC (page_pool_max,"Number of pages in the WC/UC/DMA pool" ); +module_param (page_pool_max, ulong,0644 ); + +void drm_page_pool_set_max (unsigned long max) +{ +/* only write once */ +if (!page_pool_max) + page_pool_max = max; +} + +unsigned long drm_page_pool_get_max (void ) +{ +return page_pool_max; +} + +unsigned long drm_page_pool_get_total (void ) +{
drivers/gpu/drm/page_pool.c line 50
Quoted 10 lines
drivers/gpu/drm/page_pool.c new file +10
-0+return atomic_long_read (&total_pages); +} + +int drm_page_pool_get_size (struct drm_page_pool *pool) +{ +int ret; + +spin_lock (&pool->lock); + ret = pool->count; +spin_unlock (&pool->lock);
Maybe use an atomic for the count instead?
Quoted 11 lines
drivers/gpu/drm/page_pool.c new file +11
-0+return ret; +} + +static inline unsigned int drm_page_pool_free_pages (struct drm_page_pool *pool, +struct page *page) +{ +return pool->free (page, pool->order); +} + +static int drm_page_pool_shrink_one (void ); +
drivers/gpu/drm/page_pool.c line 71
Quoted 10 lines
drivers/gpu/drm/page_pool.c new file +10
-0+void drm_page_pool_add (struct drm_page_pool *pool,struct page *page) +{ +spin_lock (&pool->lock); +list_add_tail (&page->lru, &pool->items); + pool->count++; +atomic_long_add (1 << pool->order, &total_pages); +spin_unlock (&pool->lock); + +mod_node_page_state (page_pgdat (page),NR_KERNEL_MISC_RECLAIMABLE , +1 << pool->order);
Hui what? What should that be good for?
drivers/gpu/drm/page_pool.c line 84
Quoted 13 lines
drivers/gpu/drm/page_pool.c new file +13
-0+ +/* make sure we don't grow too large */ +while (page_pool_max &&atomic_long_read (&total_pages) > page_pool_max) +drm_page_pool_shrink_one (); +} +EXPORT_SYMBOL_GPL (drm_page_pool_add); + +static struct page *drm_page_pool_remove (struct drm_page_pool *pool) +{ +struct page *page; + +if (!pool->count) +return NULL ;
Better use list_first_entry_or_null instead of checking the count.
This way you can also pull the lock into the function.
Quoted 22 lines
drivers/gpu/drm/page_pool.c new file +22
-0+ + page = list_first_entry(&pool->items, struct page, lru); + pool->count--; +atomic_long_sub (1 << pool->order, &total_pages); + +list_del (&page->lru); +mod_node_page_state (page_pgdat (page),NR_KERNEL_MISC_RECLAIMABLE , + -(1 << pool->order)); +return page; +} + +struct page *drm_page_pool_fetch (struct drm_page_pool *pool) +{ +struct page *page =NULL ; + +if (!pool) { +WARN_ON (!pool); +return NULL ; + } + +spin_lock (&pool->lock); + page =drm_page_pool_remove (pool);
drivers/gpu/drm/page_pool.c line 116
Quoted 10 lines
drivers/gpu/drm/page_pool.c new file +10
-0+spin_unlock (&pool->lock); + +return page; +} +EXPORT_SYMBOL_GPL (drm_page_pool_fetch); + +struct drm_page_pool *drm_page_pool_create (unsigned int order, +int (*free_page)(struct page *p,unsigned int order)) +{ +struct drm_page_pool *pool =kmalloc (sizeof (*pool),GFP_KERNEL );
Why not making this an embedded object? We should not see much dynamic pool creation.
Quoted 20 lines
drivers/gpu/drm/page_pool.c new file +20
-0+ +if (!pool) +return NULL ; + + pool->count =0 ; +INIT_LIST_HEAD (&pool->items); + pool->order = order; + pool->free = free_page; +spin_lock_init (&pool->lock); +INIT_LIST_HEAD (&pool->list); + +mutex_lock (&pool_list_lock); +list_add (&pool->list, &pool_list); +mutex_unlock (&pool_list_lock); + +return pool; +} +EXPORT_SYMBOL_GPL (drm_page_pool_create); + +void drm_page_pool_destroy (struct drm_page_pool *pool)
drivers/gpu/drm/page_pool.c line 146
Quoted 10 lines
drivers/gpu/drm/page_pool.c new file +10
-0+{ +struct page *page; + +/* Remove us from the pool list */ +mutex_lock (&pool_list_lock); +list_del (&pool->list); +mutex_unlock (&pool_list_lock); + +/* Free any remaining pages in the pool */ +spin_lock (&pool->lock);
Locking should be unnecessary when the pool is destroyed anyway.
Quoted 19 lines
drivers/gpu/drm/page_pool.c new file +19
-0+while (pool->count) { + page =drm_page_pool_remove (pool); +spin_unlock (&pool->lock); +drm_page_pool_free_pages (pool, page); +spin_lock (&pool->lock); + } +spin_unlock (&pool->lock); + +kfree (pool); +} +EXPORT_SYMBOL_GPL (drm_page_pool_destroy); + +static int drm_page_pool_shrink_one (void ) +{ +struct drm_page_pool *pool; +struct page *page; +int nr_freed =0 ; + +mutex_lock (&pool_list_lock);
drivers/gpu/drm/page_pool.c line 175
Quoted 10 lines
drivers/gpu/drm/page_pool.c new file +10
-0+ pool =list_first_entry (&pool_list,typeof (*pool), list); + +spin_lock (&pool->lock); + page =drm_page_pool_remove (pool); +spin_unlock (&pool->lock); + +if (page) + nr_freed =drm_page_pool_free_pages (pool, page); + +list_move_tail (&pool->list, &pool_list);
Better to move this up, directly after the list_first_entry().
Quoted 95 lines
drivers/gpu/drm/page_pool.c new file +45
-0+mutex_unlock (&pool_list_lock); + +return nr_freed; +} + +static unsigned long drm_page_pool_shrink_count (struct shrinker *shrinker, +struct shrink_control *sc) +{ +unsigned long count =atomic_long_read (&total_pages); + +return count ? count :SHRINK_EMPTY ; +} + +static unsigned long drm_page_pool_shrink_scan (struct shrinker *shrinker, +struct shrink_control *sc) +{ +int to_scan = sc->nr_to_scan; +int nr_total =0 ; + +if (to_scan ==0 ) +return 0 ; + +do { +int nr_freed =drm_page_pool_shrink_one (); + + to_scan -= nr_freed; + nr_total += nr_freed; + }while (to_scan >=0 &&atomic_long_read (&total_pages)); + +return nr_total; +} + +static struct shrinker pool_shrinker = { + .count_objects = drm_page_pool_shrink_count, + .scan_objects = drm_page_pool_shrink_scan, + .seeks =1 , + .batch =0 , +}; + +int drm_page_pool_init_shrinker (void ) +{ +return register_shrinker (&pool_shrinker); +} +module_init (drm_page_pool_init_shrinker); +MODULE_LICENSE ("GPL v2" );include/drm/page_pool.h new file +44
-0@@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* +* Copyright 2020 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Authors: Christian König +*/ + +#ifndef _DRM_PAGE_POOL_H_ +#define _DRM_PAGE_POOL_H_ + +#include <linux/mmzone.h> +#include <linux/llist.h> +#include <linux/spinlock.h> + +struct drm_page_pool { +int count; +struct list_head items; + +int order; +int (*free)(struct page *p,unsigned int order); + +spinlock_t lock; +struct list_head list; +}; + +void drm_page_pool_set_max (unsigned long max);
include/drm/page_pool.h line 54
Quoted 10 lines
include/drm/page_pool.h new file +10
-0+unsigned long drm_page_pool_get_max (void ); +unsigned long drm_page_pool_get_total (void ); +int drm_page_pool_get_size (struct drm_page_pool *pool); +struct page *drm_page_pool_fetch (struct drm_page_pool *pool); +void drm_page_pool_add (struct drm_page_pool *pool,struct page *page); +struct drm_page_pool *drm_page_pool_create (unsigned int order, +int (*free_page)(struct page *p,unsigned int order)); +void drm_page_pool_destroy (struct drm_page_pool *pool); + +#endif
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Quoted 11 lines · Christian König
Am 05.02.21 um 09:06 schrieb John Stultz:
drivers/gpu/drm/page_pool.c line 1
Quoted 7 lines
drivers/gpu/drm/page_pool.c new file +1
-0@@ -0,0 +1,220 @@ +// SPDX-License-Identifier: GPL-2.0 Please use a BSD/MIT compatible license if you want to copy this from the TTM code.
Hrm. This may be problematic, as it's not just TTM code, but some of the TTM logic integrated into a page-pool implementation I wrote based on logic from the ION code (which was GPL-2.0 before it was dropped). So I don't think I can just make it MIT. Any extra context on the need for MIT, or suggestions on how to best resolve this?
Quoted 10 lines
drivers/gpu/drm/page_pool.c line 50
Quoted 7 lines
drivers/gpu/drm/page_pool.c new file +7
-0+int drm_page_pool_get_size (struct drm_page_pool *pool) +{ +int ret; + +spin_lock (&pool->lock); + ret = pool->count; +spin_unlock (&pool->lock);Maybe use an atomic for the count instead?
I can do that, but am curious as to the benefit? We are mostly using count where we already have to take the pool->lock anyway, and this drm_page_pool_get_size() is only used for debugfs output so far, so I don't expect it to be a hot path.
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/page_pool.c new file +4
-0+void drm_page_pool_add (struct drm_page_pool *pool,struct page *page) +{ +spin_lock (&pool->lock); +list_add_tail (&page->lru, &pool->items);
Quoted 8 lines
drivers/gpu/drm/page_pool.c line 71
Quoted 6 lines
drivers/gpu/drm/page_pool.c new file +6
-0+ pool->count++; +atomic_long_add (1 << pool->order, &total_pages); +spin_unlock (&pool->lock); + +mod_node_page_state (page_pgdat (page),NR_KERNEL_MISC_RECLAIMABLE , +1 << pool->order);Hui what? What should that be good for?
This is a carryover from the ION page pool implementation:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/staging/android/ion/ion_page_pool.c?h=v5.10#n28
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Quoted 10 lines
drivers/gpu/drm/page_pool.c line 84
Quoted 6 lines
drivers/gpu/drm/page_pool.c new file +6
-0+static struct page *drm_page_pool_remove (struct drm_page_pool *pool) +{ +struct page *page; + +if (!pool->count) +return NULL ;Better use
list_first_entry_or_nullinstead of checking the count.This way you can also pull the lock into the function.
Yea, that cleans a number of things up nicely. Thank you!
Quoted 7 lines
drivers/gpu/drm/page_pool.c line 116
Quoted 4 lines
drivers/gpu/drm/page_pool.c new file +4
-0+struct drm_page_pool *drm_page_pool_create (unsigned int order, +int (*free_page)(struct page *p,unsigned int order)) +{ +struct drm_page_pool *pool =kmalloc (sizeof (*pool),GFP_KERNEL );Why not making this an embedded object? We should not see much dynamic pool creation.
Yea, it felt cleaner at the time this way, but I think I will need to switch to an embedded object in order to resolve the memory usage issue you pointed out with growing the ttm_pool_dma, so thank you for the suggestion!
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/page_pool.c new file +5
-0+void drm_page_pool_destroy (struct drm_page_pool *pool) +{ +struct page *page; + +/* Remove us from the pool list */
Quoted 8 lines
drivers/gpu/drm/page_pool.c line 146
Quoted 6 lines
drivers/gpu/drm/page_pool.c new file +6
-0+mutex_lock (&pool_list_lock); +list_del (&pool->list); +mutex_unlock (&pool_list_lock); + +/* Free any remaining pages in the pool */ +spin_lock (&pool->lock);Locking should be unnecessary when the pool is destroyed anyway.
I guess if we've already pruned ourself from the pool list, then your right, we can't race with the shrinker and it's maybe not necessary. But it also seems easier to consistently follow the locking rules in a very unlikely path rather than leaning on subtlety. Either way, I think this becomes moot if I make the improvements you suggest to drm_page_pool_remove().
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/page_pool.c new file +11
-0+static int drm_page_pool_shrink_one (void ) +{ +struct drm_page_pool *pool; +struct page *page; +int nr_freed =0 ; + +mutex_lock (&pool_list_lock); + pool =list_first_entry (&pool_list,typeof (*pool), list); + +spin_lock (&pool->lock); + page =drm_page_pool_remove (pool);
Quoted 8 lines
drivers/gpu/drm/page_pool.c line 175
Quoted 6 lines
drivers/gpu/drm/page_pool.c new file +6
-0+spin_unlock (&pool->lock); + +if (page) + nr_freed =drm_page_pool_free_pages (pool, page); + +list_move_tail (&pool->list, &pool_list);Better to move this up, directly after the
list_first_entry().
Sounds good!
Thanks so much for your review and feedback! I'll try to get some of the easy suggestions integrated, and will have to figure out what to do about the re-licensing request.
thanks
-john
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Quoted 51 lines · John Stultz
Quoted 11 lines · Christian König
Am 05.02.21 um 09:06 schrieb John Stultz:
drivers/gpu/drm/page_pool.c line 1
Quoted 7 lines
drivers/gpu/drm/page_pool.c new file +1
-0@@ -0,0 +1,220 @@ +// SPDX-License-Identifier: GPL-2.0 Please use a BSD/MIT compatible license if you want to copy this from the TTM code.
Hrm. This may be problematic, as it's not just TTM code, but some of the TTM logic integrated into a page-pool implementation I wrote based on logic from the ION code (which was GPL-2.0 before it was dropped). So I don't think I can just make it MIT. Any extra context on the need for MIT, or suggestions on how to best resolve this?
Quoted 10 lines
drivers/gpu/drm/page_pool.c line 50
Quoted 7 lines
drivers/gpu/drm/page_pool.c new file +7
-0+int drm_page_pool_get_size (struct drm_page_pool *pool) +{ +int ret; + +spin_lock (&pool->lock); + ret = pool->count; +spin_unlock (&pool->lock);Maybe use an atomic for the count instead?
I can do that, but am curious as to the benefit? We are mostly using count where we already have to take the
pool->lockanyway, and thisdrm_page_pool_get_size()is only used for debugfs output so far, so I don't expect it to be a hot path.Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/page_pool.c new file +4
-0+void drm_page_pool_add (struct drm_page_pool *pool,struct page *page) +{ +spin_lock (&pool->lock); +list_add_tail (&page->lru, &pool->items);Quoted 8 lines
drivers/gpu/drm/page_pool.c line 71
Quoted 6 lines
drivers/gpu/drm/page_pool.c new file +6
-0+ pool->count++; +atomic_long_add (1 << pool->order, &total_pages); +spin_unlock (&pool->lock); + +mod_node_page_state (page_pgdat (page),NR_KERNEL_MISC_RECLAIMABLE , +1 << pool->order);Hui what? What should that be good for?
Quoted 8 lines
This is a carryover from the ION page pool implementation:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/staging/android/ion/ion_page_pool.c?h=v5.10#n28My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Yep, ION pools were accounted for as reclaimable kernel memory because they could be dropped when the system is under memory pressure.
Quoted 71 lines
Quoted 11 lines
drivers/gpu/drm/page_pool.c line 84
Quoted 8 lines
drivers/gpu/drm/page_pool.c new file +6
-0+static struct page *drm_page_pool_remove (struct drm_page_pool *pool) +{ +struct page *page; + +if (!pool->count) +return NULL ;Better use
list_first_entry_or_nullinstead of checking the count.Quoted 1 line
This way you can also pull the lock into the function.
Yea, that cleans a number of things up nicely. Thank you!
Quoted 7 lines
drivers/gpu/drm/page_pool.c line 116
Quoted 4 lines
drivers/gpu/drm/page_pool.c new file +4
-0+struct drm_page_pool *drm_page_pool_create (unsigned int order, +int (*free_page)(struct page *p,unsigned int order)) +{ +struct drm_page_pool *pool =kmalloc (sizeof (*pool),GFP_KERNEL );Why not making this an embedded object? We should not see much dynamic pool creation.
Yea, it felt cleaner at the time this way, but I think I will need to switch to an embedded object in order to resolve the memory usage issue you pointed out with growing the
ttm_pool_dma, so thank you for the suggestion!Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/page_pool.c new file +5
-0+void drm_page_pool_destroy (struct drm_page_pool *pool) +{ +struct page *page; + +/* Remove us from the pool list */ Quoted 8 lines
drivers/gpu/drm/page_pool.c line 146
Quoted 6 lines
drivers/gpu/drm/page_pool.c new file +6
-0+mutex_lock (&pool_list_lock); +list_del (&pool->list); +mutex_unlock (&pool_list_lock); + +/* Free any remaining pages in the pool */ +spin_lock (&pool->lock);Locking should be unnecessary when the pool is destroyed anyway.
I guess if we've already pruned ourself from the pool list, then your right, we can't race with the shrinker and it's maybe not necessary. But it also seems easier to consistently follow the locking rules in a very unlikely path rather than leaning on subtlety. Either way, I think this becomes moot if I make the improvements you suggest to
drm_page_pool_remove().Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/page_pool.c new file +11
-0+static int drm_page_pool_shrink_one (void ) +{ +struct drm_page_pool *pool; +struct page *page; +int nr_freed =0 ; + +mutex_lock (&pool_list_lock); + pool =list_first_entry (&pool_list,typeof (*pool), list); + +spin_lock (&pool->lock); + page =drm_page_pool_remove (pool);Quoted 8 lines
drivers/gpu/drm/page_pool.c line 175
Quoted 6 lines
drivers/gpu/drm/page_pool.c new file +6
-0+spin_unlock (&pool->lock); + +if (page) + nr_freed =drm_page_pool_free_pages (pool, page); + +list_move_tail (&pool->list, &pool_list);Better to move this up, directly after the
list_first_entry().
Quoted 8 lines
Sounds good!
Thanks so much for your review and feedback! I'll try to get some of the easy suggestions integrated, and will have to figure out what to do about the re-licensing request.
thanks
-john
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
In reply to John StultzAm 05.02.21 um 21:46 schrieb John Stultz:
Quoted 12 lines
Quoted 10 lines · Christian König
Am 05.02.21 um 09:06 schrieb John Stultz:
drivers/gpu/drm/page_pool.c line 1
Quoted 7 lines
drivers/gpu/drm/page_pool.c new file +1
-0@@ -0,0 +1,220 @@ +// SPDX-License-Identifier: GPL-2.0 Please use a BSD/MIT compatible license if you want to copy this from the TTM code.
Quoted 5 lines
Hrm. This may be problematic, as it's not just TTM code, but some of the TTM logic integrated into a page-pool implementation I wrote based on logic from the ION code (which was GPL-2.0 before it was dropped). So I don't think I can just make it MIT. Any extra context on the need for MIT, or suggestions on how to best resolve this?
Most of the DRM/TTM code is also license able under the BSD/MIT style license since we want to enable the BSD guys to port it over as well.
What stuff do you need from the ION code that you can't just code yourself? As far as I have seen this is like 99% code from the TTM pool.
Christian.
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/page_pool.c line 50
Quoted 8 lines
drivers/gpu/drm/page_pool.c new file +7
-0+int drm_page_pool_get_size (struct drm_page_pool *pool) +{ +int ret; + +spin_lock (&pool->lock); + ret = pool->count; +spin_unlock (&pool->lock);Maybe use an atomic for the count instead?
Quoted 4 lines
I can do that, but am curious as to the benefit? We are mostly using count where we already have to take the
pool->lockanyway, and thisdrm_page_pool_get_size()is only used for debugfs output so far, so I don't expect it to be a hot path.
Yeah, it's not really important. IIRC I even walked over the linked list to count how many pages we had.
Christian.
Quoted 84 lines
Quoted 13 lines
drivers/gpu/drm/page_pool.c line 71
Quoted 12 lines
drivers/gpu/drm/page_pool.c new file +10
-0+void drm_page_pool_add (struct drm_page_pool *pool,struct page *page) +{ +spin_lock (&pool->lock); +list_add_tail (&page->lru, &pool->items); + pool->count++; +atomic_long_add (1 << pool->order, &total_pages); +spin_unlock (&pool->lock); + +mod_node_page_state (page_pgdat (page),NR_KERNEL_MISC_RECLAIMABLE , +1 << pool->order);Hui what? What should that be good for?
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Quoted 9 lines
drivers/gpu/drm/page_pool.c line 84
Quoted 6 lines
drivers/gpu/drm/page_pool.c new file +6
-0+static struct page *drm_page_pool_remove (struct drm_page_pool *pool) +{ +struct page *page; + +if (!pool->count) +return NULL ;Better use
list_first_entry_or_nullinstead of checking the count.This way you can also pull the lock into the function.
Yea, that cleans a number of things up nicely. Thank you!
Quoted 6 lines
drivers/gpu/drm/page_pool.c line 116
Quoted 4 lines
drivers/gpu/drm/page_pool.c new file +4
-0+struct drm_page_pool *drm_page_pool_create (unsigned int order, +int (*free_page)(struct page *p,unsigned int order)) +{ +struct drm_page_pool *pool =kmalloc (sizeof (*pool),GFP_KERNEL );Why not making this an embedded object? We should not see much dynamic pool creation.
Yea, it felt cleaner at the time this way, but I think I will need to switch to an embedded object in order to resolve the memory usage issue you pointed out with growing the
ttm_pool_dma, so thank you for the suggestion!Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/page_pool.c new file +4
-0+void drm_page_pool_destroy (struct drm_page_pool *pool) +{ +struct page *page; +Quoted 8 lines
drivers/gpu/drm/page_pool.c line 146
Quoted 7 lines
drivers/gpu/drm/page_pool.c new file +7
-0+/* Remove us from the pool list */ +mutex_lock (&pool_list_lock); +list_del (&pool->list); +mutex_unlock (&pool_list_lock); + +/* Free any remaining pages in the pool */ +spin_lock (&pool->lock);Locking should be unnecessary when the pool is destroyed anyway.
I guess if we've already pruned ourself from the pool list, then your right, we can't race with the shrinker and it's maybe not necessary. But it also seems easier to consistently follow the locking rules in a very unlikely path rather than leaning on subtlety. Either way, I think this becomes moot if I make the improvements you suggest to
drm_page_pool_remove().Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/page_pool.c new file +10
-0+static int drm_page_pool_shrink_one (void ) +{ +struct drm_page_pool *pool; +struct page *page; +int nr_freed =0 ; + +mutex_lock (&pool_list_lock); + pool =list_first_entry (&pool_list,typeof (*pool), list); + +spin_lock (&pool->lock);Quoted 8 lines
drivers/gpu/drm/page_pool.c line 175
Quoted 7 lines
drivers/gpu/drm/page_pool.c new file +7
-0+ page =drm_page_pool_remove (pool); +spin_unlock (&pool->lock); + +if (page) + nr_freed =drm_page_pool_free_pages (pool, page); + +list_move_tail (&pool->list, &pool_list);Better to move this up, directly after the
list_first_entry().
Quoted 8 lines
Sounds good!
Thanks so much for your review and feedback! I'll try to get some of the easy suggestions integrated, and will have to figure out what to do about the re-licensing request.
thanks
-john
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/page_pool.c new file +4
-0+void drm_page_pool_add (struct drm_page_pool *pool,struct page *page) +{ + spin_lock(&pool->lock); + list_add_tail(&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
+ pool->count++;
+atomic_long_add(1 << pool->order, &total_pages); +spin_unlock(&pool->lock);
+
+ mod_node_page_state(page_pgdat(page),NR_KERNEL_MISC_RECLAIMABLE,
+ 1 <<pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Quoted 25 lines · Christian König
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/page_pool.c new file +4
-0+void drm_page_pool_add (struct drm_page_pool *pool,struct page *page) +{ +spin_lock (&pool->lock); +list_add_tail (&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/page_pool.c new file +5
-0+ pool->count++; +atomic_long_add (1 << pool->order, &total_pages); +spin_unlock (&pool->lock); + + mod_node_page_state(page_pgdat(page),
NR_KERNEL_MISC_RECLAIMABLE,
+ 1 <<pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Quoted 6 lines
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
IIRC the original motivation for counting ION pooled pages as reclaimable was to include them into /proc/meminfo's MemAvailable calculations. NR_KERNEL_MISC_RECLAIMABLE defined as "reclaimable non-slab kernel pages" seems like a good place to account for them but I might be wrong.
Quoted 5 lines
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Am 09.02.21 um 18:33 schrieb Suren Baghdasaryan:
Quoted 28 lines · Christian König
Quoted 27 lines
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/page_pool.c new file +4
-0+void drm_page_pool_add (struct drm_page_pool *pool,struct page *page) +{ +spin_lock (&pool->lock); +list_add_tail (&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/page_pool.c new file +5
-0+ pool->count++; +atomic_long_add (1 << pool->order, &total_pages); +spin_unlock (&pool->lock); + + mod_node_page_state(page_pgdat(page),
NR_KERNEL_MISC_RECLAIMABLE,
+ 1 <<pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Quoted 7 lines
Quoted 2 lines
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
IIRC the original motivation for counting ION pooled pages as reclaimable was to include them into /proc/meminfo's MemAvailable calculations.
NR_KERNEL_MISC_RECLAIMABLEdefined as "reclaimable non-slab kernel pages" seems like a good place to account for them but I might be wrong.
Yeah, that's what I see here as well. But exactly that is utterly nonsense.
Those pages are not "free" in the sense that get_free_page could return them directly.
Regards,
Christian.
Quoted 5 lines
Quoted 5 lines
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Quoted 40 lines · Christian König
Am 09.02.21 um 18:33 schrieb Suren Baghdasaryan:
Quoted 28 lines · Christian König
Quoted 27 lines
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+void drm_page_pool_add(struct drm_page_pool *pool, struct page *page) +{ + spin_lock(&pool->lock); + list_add_tail(&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
(quoted diff) +5
-0+ pool->count++; + atomic_long_add(1 << pool->order, &total_pages); + spin_unlock(&pool->lock); + + mod_node_page_state(page_pgdat(page),
NR_KERNEL_MISC_RECLAIMABLE,
+ 1 <<pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Quoted 7 lines
Quoted 2 lines
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
IIRC the original motivation for counting ION pooled pages as reclaimable was to include them into /proc/meminfo's MemAvailable calculations.
NR_KERNEL_MISC_RECLAIMABLEdefined as "reclaimable non-slab kernel pages" seems like a good place to account for them but I might be wrong.
Quoted 4 lines
Yeah, that's what I see here as well. But exactly that is utterly nonsense.
Those pages are not "free" in the sense that
get_free_pagecould return them directly.
Any ideas where these pages would fit better? We do want to know that under memory pressure these pages can be made available (which is I think what MemAvailable means).
Quoted 10 lines
Regards,
Christian.Quoted 5 lines
Quoted 5 lines
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
In reply to Christian KönigQuoted 40 lines · Christian König
Am 09.02.21 um 18:33 schrieb Suren Baghdasaryan:
Quoted 28 lines · Christian König
Quoted 27 lines
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+void drm_page_pool_add(struct drm_page_pool *pool, struct page *page) +{ + spin_lock(&pool->lock); + list_add_tail(&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
(quoted diff) +5
-0+ pool->count++; + atomic_long_add(1 << pool->order, &total_pages); + spin_unlock(&pool->lock); + + mod_node_page_state(page_pgdat(page),
NR_KERNEL_MISC_RECLAIMABLE,
+ 1 <<pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Quoted 7 lines
Quoted 2 lines
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
IIRC the original motivation for counting ION pooled pages as reclaimable was to include them into /proc/meminfo's MemAvailable calculations.
NR_KERNEL_MISC_RECLAIMABLEdefined as "reclaimable non-slab kernel pages" seems like a good place to account for them but I might be wrong.
Quoted 4 lines
Yeah, that's what I see here as well. But exactly that is utterly nonsense.
Those pages are not "free" in the sense that
get_free_pagecould return them directly.
Well on Android that is kinda true, because Android has it's oom-killer (way back it was just a shrinker callback, not sure how it works now), which just shot down all the background apps. So at least some of that (everything used by background apps) is indeed reclaimable on Android.
But that doesn't hold on Linux in general, so we can't really do this for common code.
Also I had a long meeting with Suren, John and other googles yesterday, and the aim is now to try and support all the Android gpu memory accounting needs with cgroups. That should work, and it will allow Android to handle all the Android-ism in a clean way in upstream code. Or that's at least the plan.
I think the only thing we identified that Android still needs on top is the dma-buf sysfs stuff, so that shared buffers (which on Android are always dma-buf, and always stay around as dma-buf fd throughout their lifetime) can be listed/analyzed with full detail.
But aside from this the plan for all the per-process or per-heap account, oom-killer integration and everything else is planned to be done with cgroups. Android (for now) only needs to account overall gpu memory since none of it is swappable on android drivers anyway, plus no vram, so not much needed.
Cheers, Daniel
Quoted 10 lines
Regards,
Christian.Quoted 5 lines
Quoted 5 lines
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Christian.
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Quoted 62 lines · Daniel Vetter
Quoted 40 lines · Christian König
Am 09.02.21 um 18:33 schrieb Suren Baghdasaryan:
Quoted 28 lines · Christian König
Quoted 27 lines
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+void drm_page_pool_add(struct drm_page_pool *pool, struct page *page) +{ + spin_lock(&pool->lock); + list_add_tail(&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
(quoted diff) +5
-0+ pool->count++; + atomic_long_add(1 << pool->order, &total_pages); + spin_unlock(&pool->lock); + + mod_node_page_state(page_pgdat(page),
NR_KERNEL_MISC_RECLAIMABLE,
+ 1 <<pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Quoted 7 lines
Quoted 2 lines
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
IIRC the original motivation for counting ION pooled pages as reclaimable was to include them into /proc/meminfo's MemAvailable calculations.
NR_KERNEL_MISC_RECLAIMABLEdefined as "reclaimable non-slab kernel pages" seems like a good place to account for them but I might be wrong.Quoted 4 lines
Yeah, that's what I see here as well. But exactly that is utterly nonsense.
Those pages are not "free" in the sense that
get_free_pagecould return them directly.Well on Android that is kinda true, because Android has it's oom-killer (way back it was just a shrinker callback, not sure how it works now), which just shot down all the background apps. So at least some of that (everything used by background apps) is indeed reclaimable on Android.
But that doesn't hold on Linux in general, so we can't really do this for common code.
Also I had a long meeting with Suren, John and other googles yesterday, and the aim is now to try and support all the Android gpu memory accounting needs with cgroups. That should work, and it will allow Android to handle all the Android-ism in a clean way in upstream code. Or that's at least the plan.
Quoted 8 lines
I think the only thing we identified that Android still needs on top is the dma-buf sysfs stuff, so that shared buffers (which on Android are always dma-buf, and always stay around as dma-buf fd throughout their lifetime) can be listed/analyzed with full detail.
But aside from this the plan for all the per-process or per-heap account, oom-killer integration and everything else is planned to be done with cgroups.
Until cgroups are ready we probably will need to add a sysfs node to report the total dmabuf pool size and I think that would cover our current accounting need here.
As I mentioned, not including dmabuf pools into MemAvailable would affect that stat and I'm wondering if pools should be considered as part of MemAvailable or not. Since MemAvailable includes SReclaimable I think it makes sense to include them but maybe there are other considerations that I'm missing?
Quoted 14 lines
Android (for now) only needs to account overall gpu memory since none of it is swappable on android drivers anyway, plus no vram, so not much needed.
Cheers, Daniel
Quoted 8 lines
Regards,
Christian.Quoted 4 lines
Quoted 4 lines
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Quoted 8 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Christian.
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Quoted 72 lines · Suren Baghdasaryan
Quoted 62 lines · Daniel Vetter
Quoted 40 lines · Christian König
Am 09.02.21 um 18:33 schrieb Suren Baghdasaryan:
Quoted 28 lines · Christian König
Quoted 27 lines
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+void drm_page_pool_add(struct drm_page_pool *pool, struct page *page) +{ + spin_lock(&pool->lock); + list_add_tail(&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
(quoted diff) +5
-0+ pool->count++; + atomic_long_add(1 << pool->order, &total_pages); + spin_unlock(&pool->lock); + + mod_node_page_state(page_pgdat(page),
NR_KERNEL_MISC_RECLAIMABLE,
+ 1 <<pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Quoted 7 lines
Quoted 2 lines
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
IIRC the original motivation for counting ION pooled pages as reclaimable was to include them into /proc/meminfo's MemAvailable calculations.
NR_KERNEL_MISC_RECLAIMABLEdefined as "reclaimable non-slab kernel pages" seems like a good place to account for them but I might be wrong.Quoted 4 lines
Yeah, that's what I see here as well. But exactly that is utterly nonsense.
Those pages are not "free" in the sense that
get_free_pagecould return them directly.Well on Android that is kinda true, because Android has it's oom-killer (way back it was just a shrinker callback, not sure how it works now), which just shot down all the background apps. So at least some of that (everything used by background apps) is indeed reclaimable on Android.
But that doesn't hold on Linux in general, so we can't really do this for common code.
Also I had a long meeting with Suren, John and other googles yesterday, and the aim is now to try and support all the Android gpu memory accounting needs with cgroups. That should work, and it will allow Android to handle all the Android-ism in a clean way in upstream code. Or that's at least the plan.
Quoted 8 lines
I think the only thing we identified that Android still needs on top is the dma-buf sysfs stuff, so that shared buffers (which on Android are always dma-buf, and always stay around as dma-buf fd throughout their lifetime) can be listed/analyzed with full detail.
But aside from this the plan for all the per-process or per-heap account, oom-killer integration and everything else is planned to be done with cgroups.
Quoted 8 lines
Until cgroups are ready we probably will need to add a sysfs node to report the total dmabuf pool size and I think that would cover our current accounting need here.
As I mentioned, not including dmabuf pools into MemAvailable would affect that stat and I'm wondering if pools should be considered as part of MemAvailable or not. Since MemAvailable includes SReclaimable I think it makes sense to include them but maybe there are other considerations that I'm missing?
On Android, yes, on upstream, not so much. Because upstream doesn't have the android low memory killer cleanup up all the apps, so effectively we can't reclaim that memory, and we shouldn't report it as such. -Daniel
Quoted 23 lines
Quoted 23 lines
Android (for now) only needs to account overall gpu memory since none of it is swappable on android drivers anyway, plus no vram, so not much needed.
Cheers, Daniel
Quoted 10 lines
Regards,
Christian.Quoted 5 lines
Quoted 5 lines
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Christian.
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Quoted 83 lines · Daniel Vetter
Quoted 72 lines · Suren Baghdasaryan
Quoted 62 lines · Daniel Vetter
Quoted 40 lines · Christian König
Am 09.02.21 um 18:33 schrieb Suren Baghdasaryan:
Quoted 28 lines · Christian König
Quoted 27 lines
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+void drm_page_pool_add(struct drm_page_pool *pool, struct page *page) +{ + spin_lock(&pool->lock); + list_add_tail(&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
(quoted diff) +5
-0+ pool->count++; + atomic_long_add(1 << pool->order, &total_pages); + spin_unlock(&pool->lock); + + mod_node_page_state(page_pgdat(page),
NR_KERNEL_MISC_RECLAIMABLE,
+ 1 <<pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Quoted 7 lines
Quoted 2 lines
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
IIRC the original motivation for counting ION pooled pages as reclaimable was to include them into /proc/meminfo's MemAvailable calculations.
NR_KERNEL_MISC_RECLAIMABLEdefined as "reclaimable non-slab kernel pages" seems like a good place to account for them but I might be wrong.Quoted 4 lines
Yeah, that's what I see here as well. But exactly that is utterly nonsense.
Those pages are not "free" in the sense that
get_free_pagecould return them directly.Well on Android that is kinda true, because Android has it's oom-killer (way back it was just a shrinker callback, not sure how it works now), which just shot down all the background apps. So at least some of that (everything used by background apps) is indeed reclaimable on Android.
But that doesn't hold on Linux in general, so we can't really do this for common code.
Also I had a long meeting with Suren, John and other googles yesterday, and the aim is now to try and support all the Android gpu memory accounting needs with cgroups. That should work, and it will allow Android to handle all the Android-ism in a clean way in upstream code. Or that's at least the plan.
Quoted 8 lines
I think the only thing we identified that Android still needs on top is the dma-buf sysfs stuff, so that shared buffers (which on Android are always dma-buf, and always stay around as dma-buf fd throughout their lifetime) can be listed/analyzed with full detail.
But aside from this the plan for all the per-process or per-heap account, oom-killer integration and everything else is planned to be done with cgroups.
Quoted 8 lines
Until cgroups are ready we probably will need to add a sysfs node to report the total dmabuf pool size and I think that would cover our current accounting need here.
As I mentioned, not including dmabuf pools into MemAvailable would affect that stat and I'm wondering if pools should be considered as part of MemAvailable or not. Since MemAvailable includes SReclaimable I think it makes sense to include them but maybe there are other considerations that I'm missing?
Quoted 4 lines
On Android, yes, on upstream, not so much. Because upstream doesn't have the android low memory killer cleanup up all the apps, so effectively we can't reclaim that memory, and we shouldn't report it as such. -Daniel
Hmm. Sorry, I fail to see why Android's low memory killer makes a difference here. In my mind, the pages in the pools are not used but kept there in case heaps need them (maybe that's the part I'm wrong?). These pages can be freed by the shrinker if memory pressure rises. In that sense I think it's very similar to reclaimable slabs which are already accounted as part of MemAvailable. So it seems logical to me to include unused pages in the pools here as well. What am I missing?
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
Android (for now) only needs to account overall gpu memory since none of it is swappable on android drivers anyway, plus no vram, so not much needed.
Cheers, Daniel
Quoted 8 lines
Regards,
Christian.Quoted 4 lines
Quoted 4 lines
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Christian.
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Quoted 4 lines
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Quoted 90 lines · Suren Baghdasaryan
Quoted 83 lines · Daniel Vetter
Quoted 72 lines · Suren Baghdasaryan
Quoted 62 lines · Daniel Vetter
Quoted 40 lines · Christian König
Am 09.02.21 um 18:33 schrieb Suren Baghdasaryan:
Quoted 28 lines · Christian König
Quoted 27 lines
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+void drm_page_pool_add(struct drm_page_pool *pool, struct page *page) +{ + spin_lock(&pool->lock); + list_add_tail(&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
(quoted diff) +5
-0+ pool->count++; + atomic_long_add(1 << pool->order, &total_pages); + spin_unlock(&pool->lock); + + mod_node_page_state(page_pgdat(page),
NR_KERNEL_MISC_RECLAIMABLE,
+ 1 <<pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Quoted 7 lines
Quoted 2 lines
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
IIRC the original motivation for counting ION pooled pages as reclaimable was to include them into /proc/meminfo's MemAvailable calculations.
NR_KERNEL_MISC_RECLAIMABLEdefined as "reclaimable non-slab kernel pages" seems like a good place to account for them but I might be wrong.Quoted 4 lines
Yeah, that's what I see here as well. But exactly that is utterly nonsense.
Those pages are not "free" in the sense that
get_free_pagecould return them directly.Well on Android that is kinda true, because Android has it's oom-killer (way back it was just a shrinker callback, not sure how it works now), which just shot down all the background apps. So at least some of that (everything used by background apps) is indeed reclaimable on Android.
But that doesn't hold on Linux in general, so we can't really do this for common code.
Also I had a long meeting with Suren, John and other googles yesterday, and the aim is now to try and support all the Android gpu memory accounting needs with cgroups. That should work, and it will allow Android to handle all the Android-ism in a clean way in upstream code. Or that's at least the plan.
Quoted 8 lines
I think the only thing we identified that Android still needs on top is the dma-buf sysfs stuff, so that shared buffers (which on Android are always dma-buf, and always stay around as dma-buf fd throughout their lifetime) can be listed/analyzed with full detail.
But aside from this the plan for all the per-process or per-heap account, oom-killer integration and everything else is planned to be done with cgroups.
Quoted 8 lines
Until cgroups are ready we probably will need to add a sysfs node to report the total dmabuf pool size and I think that would cover our current accounting need here.
As I mentioned, not including dmabuf pools into MemAvailable would affect that stat and I'm wondering if pools should be considered as part of MemAvailable or not. Since MemAvailable includes SReclaimable I think it makes sense to include them but maybe there are other considerations that I'm missing?Quoted 4 lines
On Android, yes, on upstream, not so much. Because upstream doesn't have the android low memory killer cleanup up all the apps, so effectively we can't reclaim that memory, and we shouldn't report it as such. -Daniel
Quoted 7 lines
Hmm. Sorry, I fail to see why Android's low memory killer makes a difference here. In my mind, the pages in the pools are not used but kept there in case heaps need them (maybe that's the part I'm wrong?). These pages can be freed by the shrinker if memory pressure rises. In that sense I think it's very similar to reclaimable slabs which are already accounted as part of MemAvailable. So it seems logical to me to include unused pages in the pools here as well. What am I missing?
Ah yes, those page pool pages we can list. But conceptually (at least in the internals) they're shrunk through mm shrinker callbacks, like slab cache memory. So not exactly sure where to list that.
Since we have the same pools for gpu allocations on the ttm side and John is looking into unifying those, maybe we could add that as a patch on top? For some nice consistency across all gpu drivers from android to discrete. I think if you, John and Christian from ttm side can figure out how these page pools should be reported we'll have something that fits? Maybe John can ping you on the other thread with the shared pool rfc between ttm and dma-buf heaps (there's so much going right now all over I'm a bit lost).
Cheers, Daniel
Quoted 30 lines
Quoted 30 lines
Quoted 17 lines
Quoted 17 lines
Android (for now) only needs to account overall gpu memory since none of it is swappable on android drivers anyway, plus no vram, so not much needed.
Cheers, Daniel
Quoted 8 lines
Regards,
Christian.Quoted 4 lines
Quoted 4 lines
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Christian.
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Quoted 104 lines · Daniel Vetter
Quoted 90 lines · Suren Baghdasaryan
Quoted 83 lines · Daniel Vetter
Quoted 72 lines · Suren Baghdasaryan
Quoted 62 lines · Daniel Vetter
Quoted 40 lines · Christian König
Am 09.02.21 um 18:33 schrieb Suren Baghdasaryan:
Quoted 28 lines · Christian König
Quoted 27 lines
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+void drm_page_pool_add(struct drm_page_pool *pool, struct page *page) +{ + spin_lock(&pool->lock); + list_add_tail(&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
(quoted diff) +5
-0+ pool->count++; + atomic_long_add(1 << pool->order, &total_pages); + spin_unlock(&pool->lock); + + mod_node_page_state(page_pgdat(page),
NR_KERNEL_MISC_RECLAIMABLE,
+ 1 <<pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Quoted 7 lines
Quoted 2 lines
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
IIRC the original motivation for counting ION pooled pages as reclaimable was to include them into /proc/meminfo's MemAvailable calculations.
NR_KERNEL_MISC_RECLAIMABLEdefined as "reclaimable non-slab kernel pages" seems like a good place to account for them but I might be wrong.Quoted 4 lines
Yeah, that's what I see here as well. But exactly that is utterly nonsense.
Those pages are not "free" in the sense that
get_free_pagecould return them directly.Well on Android that is kinda true, because Android has it's oom-killer (way back it was just a shrinker callback, not sure how it works now), which just shot down all the background apps. So at least some of that (everything used by background apps) is indeed reclaimable on Android.
But that doesn't hold on Linux in general, so we can't really do this for common code.
Also I had a long meeting with Suren, John and other googles yesterday, and the aim is now to try and support all the Android gpu memory accounting needs with cgroups. That should work, and it will allow Android to handle all the Android-ism in a clean way in upstream code. Or that's at least the plan.
Quoted 8 lines
I think the only thing we identified that Android still needs on top is the dma-buf sysfs stuff, so that shared buffers (which on Android are always dma-buf, and always stay around as dma-buf fd throughout their lifetime) can be listed/analyzed with full detail.
But aside from this the plan for all the per-process or per-heap account, oom-killer integration and everything else is planned to be done with cgroups.
Quoted 8 lines
Until cgroups are ready we probably will need to add a sysfs node to report the total dmabuf pool size and I think that would cover our current accounting need here.
As I mentioned, not including dmabuf pools into MemAvailable would affect that stat and I'm wondering if pools should be considered as part of MemAvailable or not. Since MemAvailable includes SReclaimable I think it makes sense to include them but maybe there are other considerations that I'm missing?Quoted 4 lines
On Android, yes, on upstream, not so much. Because upstream doesn't have the android low memory killer cleanup up all the apps, so effectively we can't reclaim that memory, and we shouldn't report it as such. -Daniel
Quoted 7 lines
Hmm. Sorry, I fail to see why Android's low memory killer makes a difference here. In my mind, the pages in the pools are not used but kept there in case heaps need them (maybe that's the part I'm wrong?). These pages can be freed by the shrinker if memory pressure rises. In that sense I think it's very similar to reclaimable slabs which are already accounted as part of MemAvailable. So it seems logical to me to include unused pages in the pools here as well. What am I missing?
Ah yes, those page pool pages we can list. But conceptually (at least in the internals) they're shrunk through mm shrinker callbacks, like slab cache memory. So not exactly sure where to list that.
Quoted 8 lines
Since we have the same pools for gpu allocations on the ttm side and John is looking into unifying those, maybe we could add that as a patch on top? For some nice consistency across all gpu drivers from android to discrete. I think if you, John and Christian from ttm side can figure out how these page pools should be reported we'll have something that fits? Maybe John can ping you on the other thread with the shared pool rfc between ttm and dma-buf heaps (there's so much going right now all over I'm a bit lost).
Sounds good. I'll follow up with John to see where this discussion fits better. Thanks!
Quoted 36 lines
Cheers, Daniel
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 25 lines
Android (for now) only needs to account overall gpu memory since none of it is swappable on android drivers anyway, plus no vram, so not much needed.
Cheers, Daniel
Quoted 10 lines
Regards,
Christian.Quoted 5 lines
Quoted 5 lines
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Christian.
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.chQuoted 4 lines
Quoted 4 lines
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Quoted 4 lines
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
In reply to Suren BaghdasaryanAm 10.02.21 um 17:39 schrieb Suren Baghdasaryan:
Quoted 77 lines · Daniel Vetter
Quoted 76 lines · Suren Baghdasaryan
Quoted 75 lines · Daniel Vetter
Quoted 58 lines · Christian König
Quoted 38 lines
Am 09.02.21 um 18:33 schrieb Suren Baghdasaryan:
Quoted 28 lines · Christian König
Quoted 27 lines
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+void drm_page_pool_add(struct drm_page_pool *pool, struct page *page) +{ + spin_lock(&pool->lock); + list_add_tail(&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
(quoted diff) +5
-0+ pool->count++; + atomic_long_add(1 << pool->order, &total_pages); + spin_unlock(&pool->lock); + + mod_node_page_state(page_pgdat(page),
NR_KERNEL_MISC_RECLAIMABLE,
+ 1 <<pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Quoted 7 lines
Quoted 2 lines
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
IIRC the original motivation for counting ION pooled pages as reclaimable was to include them into /proc/meminfo's MemAvailable calculations.
NR_KERNEL_MISC_RECLAIMABLEdefined as "reclaimable non-slab kernel pages" seems like a good place to account for them but I might be wrong.Quoted 4 lines
Yeah, that's what I see here as well. But exactly that is utterly nonsense.
Those pages are not "free" in the sense that
get_free_pagecould return them directly.Well on Android that is kinda true, because Android has it's oom-killer (way back it was just a shrinker callback, not sure how it works now), which just shot down all the background apps. So at least some of that (everything used by background apps) is indeed reclaimable on Android.
But that doesn't hold on Linux in general, so we can't really do this for common code.
Also I had a long meeting with Suren, John and other googles yesterday, and the aim is now to try and support all the Android gpu memory accounting needs with cgroups. That should work, and it will allow Android to handle all the Android-ism in a clean way in upstream code. Or that's at least the plan.
Quoted 8 lines
I think the only thing we identified that Android still needs on top is the dma-buf sysfs stuff, so that shared buffers (which on Android are always dma-buf, and always stay around as dma-buf fd throughout their lifetime) can be listed/analyzed with full detail.
But aside from this the plan for all the per-process or per-heap account, oom-killer integration and everything else is planned to be done with cgroups.
Until cgroups are ready we probably will need to add a sysfs node to report the total dmabuf pool size and I think that would cover our current accounting need here.
As I mentioned, not including dmabuf pools into MemAvailable would affect that stat and I'm wondering if pools should be considered as part of MemAvailable or not. Since MemAvailable includes SReclaimable I think it makes sense to include them but maybe there are other considerations that I'm missing?
Quoted 8 lines
Quoted 4 lines
On Android, yes, on upstream, not so much. Because upstream doesn't have the android low memory killer cleanup up all the apps, so effectively we can't reclaim that memory, and we shouldn't report it as such. -Daniel
Hmm. Sorry, I fail to see why Android's low memory killer makes a difference here. In my mind, the pages in the pools are not used but kept there in case heaps need them (maybe that's the part I'm wrong?). These pages can be freed by the shrinker if memory pressure rises.
And exactly that's the difference. They *can* be freed is not the same thing as they *are* free.
Quoted 3 lines
In that sense I think it's very similar to reclaimable slabs which are already accounted as part of MemAvailable. So it seems logical to me to include unused pages in the pools here as well. What am I missing?
See the shrinkers are there because you need to do some action before you can re-use the memory.
In the case of the TTM/DRM pool for example you need to change the caching attributes which might cause sleeping for a TLB flush to finish.
By accounting those pages as free you mess up (for example) the handling which makes sure that there are enough emergency reserves. I can only strongly recommend to not do that.
What you could do is to add a sysfs interface to expose the different shrinkers and the amount of pages in them to userspace. Similar to what /proc/slabinfo is doing.
Regards,
Christian.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Android (for now) only needs to account overall gpu memory since none of it is swappable on android drivers anyway, plus no vram, so not much needed.
Cheers, Daniel
Quoted 7 lines
Regards,
Christian.Quoted 4 lines
Quoted 4 lines
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Christian.
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
--
Daniel Vetter
Software Engineer, Intel Corporation
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fblog.ffwll.ch%2F&data=04%7C01%7Cchristian.koenig%40amd.com%7Cbb7155447ee149a49f3a08d8cde2685d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637485719618349407%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=11ENl28PIoSoUx6FhkEK9u4G6yiLc3YhsYsl1DIzsv8%3D&reserved=0--
Daniel Vetter
Software Engineer, Intel Corporation
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fblog.ffwll.ch%2F&data=04%7C01%7Cchristian.koenig%40amd.com%7Cbb7155447ee149a49f3a08d8cde2685d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637485719618349407%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=11ENl28PIoSoUx6FhkEK9u4G6yiLc3YhsYsl1DIzsv8%3D&reserved=0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Quoted 85 lines · Christian König
Am 10.02.21 um 17:39 schrieb Suren Baghdasaryan:
Quoted 81 lines · Daniel Vetter
Quoted 80 lines · Suren Baghdasaryan
Quoted 67 lines · Daniel Vetter
Quoted 58 lines · Christian König
Quoted 38 lines
Am 09.02.21 um 18:33 schrieb Suren Baghdasaryan:
Quoted 28 lines · Christian König
Quoted 27 lines
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+void drm_page_pool_add(struct drm_page_pool *pool, struct page *page) +{ + spin_lock(&pool->lock); + list_add_tail(&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
(quoted diff) +5
-0+ pool->count++; + atomic_long_add(1 << pool->order, &total_pages); + spin_unlock(&pool->lock); + + mod_node_page_state(page_pgdat(page),
NR_KERNEL_MISC_RECLAIMABLE,
+ 1 <<pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Quoted 7 lines
Quoted 2 lines
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
IIRC the original motivation for counting ION pooled pages as reclaimable was to include them into /proc/meminfo's MemAvailable calculations.
NR_KERNEL_MISC_RECLAIMABLEdefined as "reclaimable non-slab kernel pages" seems like a good place to account for them but I might be wrong.Quoted 4 lines
Yeah, that's what I see here as well. But exactly that is utterly nonsense.
Those pages are not "free" in the sense that
get_free_pagecould return them directly.Well on Android that is kinda true, because Android has it's oom-killer (way back it was just a shrinker callback, not sure how it works now), which just shot down all the background apps. So at least some of that (everything used by background apps) is indeed reclaimable on Android.
But that doesn't hold on Linux in general, so we can't really do this for common code.
Also I had a long meeting with Suren, John and other googles yesterday, and the aim is now to try and support all the Android gpu memory accounting needs with cgroups. That should work, and it will allow Android to handle all the Android-ism in a clean way in upstream code. Or that's at least the plan.
Quoted 8 lines
I think the only thing we identified that Android still needs on top is the dma-buf sysfs stuff, so that shared buffers (which on Android are always dma-buf, and always stay around as dma-buf fd throughout their lifetime) can be listed/analyzed with full detail.
But aside from this the plan for all the per-process or per-heap account, oom-killer integration and everything else is planned to be done with cgroups.
Quoted 8 lines
Until cgroups are ready we probably will need to add a sysfs node to report the total dmabuf pool size and I think that would cover our current accounting need here.
As I mentioned, not including dmabuf pools into MemAvailable would affect that stat and I'm wondering if pools should be considered as part of MemAvailable or not. Since MemAvailable includes SReclaimable I think it makes sense to include them but maybe there are other considerations that I'm missing?On Android, yes, on upstream, not so much. Because upstream doesn't have the android low memory killer cleanup up all the apps, so effectively we can't reclaim that memory, and we shouldn't report it as such. -Daniel
Quoted 7 lines
Quoted 4 lines
Hmm. Sorry, I fail to see why Android's low memory killer makes a difference here. In my mind, the pages in the pools are not used but kept there in case heaps need them (maybe that's the part I'm wrong?). These pages can be freed by the shrinker if memory pressure rises.
And exactly that's the difference. They *can* be freed is not the same thing as they *are* free.
No argument there. That's why I think meminfo has two separate stats for MemFree and MemAvailable. MemFree is self-explanatory. The description of MemAvailable in
https://www.kernel.org/doc/Documentation/filesystems/proc.txt says "An estimate of how much memory is available for starting new applications, without swapping.". Since dropping unused pages from slabs, caches and pools is less expensive than swapping, I would assume that a well-behaved system would do that before resorting to swapping. And if so, such memory should be included in MemAvailable because VM will make it available before swapping. But again, that's my interpretation. WDYT?
Quoted 10 lines
Quoted 4 lines
In that sense I think it's very similar to reclaimable slabs which are already accounted as part of MemAvailable. So it seems logical to me to include unused pages in the pools here as well. What am I missing?
See the shrinkers are there because you need to do some action before you can re-use the memory.
In the case of the TTM/DRM pool for example you need to change the caching attributes which might cause sleeping for a TLB flush to finish.
I see your point here. But how about caches/pools which can be easily dropped? Shouldn't they be part of MemAvailable?
Quoted 8 lines
By accounting those pages as free you mess up (for example) the handling which makes sure that there are enough emergency reserves. I can only strongly recommend to not do that.
What you could do is to add a sysfs interface to expose the different shrinkers and the amount of pages in them to userspace. Similar to what
/proc/slabinfois doing.
True, we can work around this. Just want to make sure whatever we do really makes sense.
Thanks,
Suren.
Quoted 28 lines
Regards,
Christian.Quoted 23 lines
Quoted 23 lines
Quoted 13 lines
Quoted 13 lines
Android (for now) only needs to account overall gpu memory since none of it is swappable on android drivers anyway, plus no vram, so not much needed.
Cheers, Daniel
Quoted 6 lines
Regards,
Christian.Quoted 3 lines
Quoted 3 lines
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Christian.
--
Daniel Vetter
Software Engineer, Intel Corporation
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fblog.ffwll.ch%2F&data=04%7C01%7Cchristian.koenig%40amd.com%7Cbb7155447ee149a49f3a08d8cde2685d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637485719618349407%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=11ENl28PIoSoUx6FhkEK9u4G6yiLc3YhsYsl1DIzsv8%3D&reserved=0--
Daniel Vetter
Software Engineer, Intel Corporation
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fblog.ffwll.ch%2F&data=04%7C01%7Cchristian.koenig%40amd.com%7Cbb7155447ee149a49f3a08d8cde2685d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637485719618349407%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=11ENl28PIoSoUx6FhkEK9u4G6yiLc3YhsYsl1DIzsv8%3D&reserved=0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
Am 10.02.21 um 20:12 schrieb Suren Baghdasaryan:
Quoted 106 lines
Quoted 83 lines · Christian König
Am 10.02.21 um 17:39 schrieb Suren Baghdasaryan:
Quoted 80 lines · Daniel Vetter
Quoted 79 lines · Suren Baghdasaryan
Quoted 66 lines · Daniel Vetter
Quoted 57 lines · Christian König
Quoted 37 lines
Am 09.02.21 um 18:33 schrieb Suren Baghdasaryan:
Quoted 28 lines · Christian König
Quoted 27 lines
Am 09.02.21 um 13:11 schrieb Christian König:
Quoted 17 lines
[SNIP]
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
+void drm_page_pool_add(struct drm_page_pool *pool, struct page *page)
+{
+ spin_lock(&pool->lock);
+ list_add_tail(&page->lru, &pool->items);Quoted 8 lines
Quoted 7 lines
+ pool->count++;
+ atomic_long_add(1 << pool->order, &total_pages);
+ spin_unlock(&pool->lock);
+
+ mod_node_page_state(page_pgdat(page),
NR_KERNEL_MISC_RECLAIMABLE,
+ 1 << pool->order);Hui what? What should that be good for?
Quoted 5 lines
Quoted 5 lines
My sense is it helps with the vmstat/meminfo accounting so folks can see the cached pages are shrinkable/freeable. This maybe falls under other dmabuf accounting/stats discussions, so I'm happy to remove it for now, or let the drivers using the shared page pool logic handle the accounting themselves?
Intentionally separated the discussion for that here.
As far as I can see this is just bluntly incorrect.
Quoted 7 lines
Quoted 2 lines
Either the page is reclaimable or it is part of our pool and freeable through the shrinker, but never ever both.
IIRC the original motivation for counting ION pooled pages as reclaimable was to include them into /proc/meminfo's MemAvailable calculations.
NR_KERNEL_MISC_RECLAIMABLEdefined as "reclaimable non-slab kernel pages" seems like a good place to account for them but I might be wrong.Quoted 4 lines
Yeah, that's what I see here as well. But exactly that is utterly nonsense.
Those pages are not "free" in the sense that
get_free_pagecould return them directly.Well on Android that is kinda true, because Android has it's oom-killer (way back it was just a shrinker callback, not sure how it works now), which just shot down all the background apps. So at least some of that (everything used by background apps) is indeed reclaimable on Android.
But that doesn't hold on Linux in general, so we can't really do this for common code.
Also I had a long meeting with Suren, John and other googles yesterday, and the aim is now to try and support all the Android gpu memory accounting needs with cgroups. That should work, and it will allow Android to handle all the Android-ism in a clean way in upstream code. Or that's at least the plan.
Quoted 8 lines
I think the only thing we identified that Android still needs on top is the dma-buf sysfs stuff, so that shared buffers (which on Android are always dma-buf, and always stay around as dma-buf fd throughout their lifetime) can be listed/analyzed with full detail.
But aside from this the plan for all the per-process or per-heap account, oom-killer integration and everything else is planned to be done with cgroups.
Quoted 8 lines
Until cgroups are ready we probably will need to add a sysfs node to report the total dmabuf pool size and I think that would cover our current accounting need here.
As I mentioned, not including dmabuf pools into MemAvailable would affect that stat and I'm wondering if pools should be considered as part of MemAvailable or not. Since MemAvailable includes SReclaimable I think it makes sense to include them but maybe there are other considerations that I'm missing?On Android, yes, on upstream, not so much. Because upstream doesn't have the android low memory killer cleanup up all the apps, so effectively we can't reclaim that memory, and we shouldn't report it as such. -Daniel
Quoted 6 lines
Quoted 4 lines
Hmm. Sorry, I fail to see why Android's low memory killer makes a difference here. In my mind, the pages in the pools are not used but kept there in case heaps need them (maybe that's the part I'm wrong?). These pages can be freed by the shrinker if memory pressure rises.
And exactly that's the difference. They *can* be freed is not the same thing as they *are* free.
No argument there. That's why I think meminfo has two separate stats
for MemFree and MemAvailable. MemFree is self-explanatory. The
description of MemAvailable in
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kernel.org%2Fdoc%2FDocumentation%2Ffilesystems%2Fproc.txt&data=04%7C01%7Cchristian.koenig%40amd.com%7C4c92877de38440ef18ee08d8cdf7c8ab%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637485811429326241%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=0MI4k9YtAnGvP0QlBYHC6QMCJvQpZoaWMRlqjptvwsA%3D&reserved=0 says "An estimate of how much memory is available for starting new
applications, without swapping.". Since dropping unused pages from
slabs, caches and pools is less expensive than swapping, I would
assume that a well-behaved system would do that before resorting to
swapping. And if so, such memory should be included in MemAvailable
because VM will make it available before swapping. But again, that's
my interpretation. WDYT?Quoted 3 lines
Quoted 3 lines
In that sense I think it's very similar to reclaimable slabs which are already accounted as part of MemAvailable. So it seems logical to me to include unused pages in the pools here as well. What am I missing?
Quoted 7 lines
Quoted 5 lines
See the shrinkers are there because you need to do some action before you can re-use the memory.
In the case of the TTM/DRM pool for example you need to change the caching attributes which might cause sleeping for a TLB flush to finish.
I see your point here. But how about caches/pools which can be easily dropped? Shouldn't they be part of MemAvailable?
Well if it can be easily dropped and reallocated we wouldn't have a pool for that in the first place :)
I mean we have created this page pool because the TLB shot down for the caching change is extremely costly.
It could make sense for slap, but not sure about that.
Regards,
Christian.
Quoted 5 lines
Quoted 5 lines
By accounting those pages as free you mess up (for example) the handling which makes sure that there are enough emergency reserves. I can only strongly recommend to not do that.
Quoted 32 lines
Quoted 3 lines
What you could do is to add a sysfs interface to expose the different shrinkers and the amount of pages in them to userspace. Similar to what
/proc/slabinfois doing.True, we can work around this. Just want to make sure whatever we do really makes sense.
Thanks,
Suren.Quoted 24 lines
Regards,
Christian.Quoted 21 lines
Quoted 21 lines
Quoted 9 lines
Quoted 9 lines
Android (for now) only needs to account overall gpu memory since none of it is swappable on android drivers anyway, plus no vram, so not much needed.
Cheers, Daniel
Quoted 3 lines
Regards,
Christian.Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
In the best case this just messes up the accounting, in the worst case it can cause memory corruption.
Christian.
--
Daniel Vetter
Software Engineer, Intel Corporation
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fblog.ffwll.ch%2F&data=04%7C01%7Cchristian.koenig%40amd.com%7C4c92877de38440ef18ee08d8cdf7c8ab%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637485811429326241%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=vqR0DAK5XkzanA4fqN0hxDm8ZbCazpvlqTDMUqxhDoA%3D&reserved=0--
Daniel Vetter
Software Engineer, Intel Corporation
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fblog.ffwll.ch%2F&data=04%7C01%7Cchristian.koenig%40amd.com%7C4c92877de38440ef18ee08d8cdf7c8ab%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637485811429326241%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=vqR0DAK5XkzanA4fqN0hxDm8ZbCazpvlqTDMUqxhDoA%3D&reserved=0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 1/7] drm: Add a sharable drm page-pool implementation
In reply to Christian KönigQuoted 22 lines · Christian König
Am 05.02.21 um 21:46 schrieb John Stultz:
Quoted 12 lines
Quoted 10 lines · Christian König
Am 05.02.21 um 09:06 schrieb John Stultz:
drivers/gpu/drm/page_pool.c line 1
Quoted 7 lines
drivers/gpu/drm/page_pool.c new file +1
-0@@ -0,0 +1,220 @@ +// SPDX-License-Identifier: GPL-2.0 Please use a BSD/MIT compatible license if you want to copy this from the TTM code.
Quoted 5 lines
Hrm. This may be problematic, as it's not just TTM code, but some of the TTM logic integrated into a page-pool implementation I wrote based on logic from the ION code (which was GPL-2.0 before it was dropped). So I don't think I can just make it MIT. Any extra context on the need for MIT, or suggestions on how to best resolve this?
Quoted 5 lines
Most of the DRM/TTM code is also license able under the BSD/MIT style license since we want to enable the BSD guys to port it over as well.
What stuff do you need from the ION code that you can't just code yourself? As far as I have seen this is like 99% code from the TTM pool.
Yea, it evolved into being mostly logic from the TTM pool (or code that was very similar to begin with), but it's not where it started. My old days at IBM makes me wary of claiming it's no longer the Ship of Theseus.
So instead I think I'll have to just throw out my patch and rewrite it in full (so apologies in advance for any review issues I introduce/reintroduce).
thanks
-john
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH v6 2/7 drm: ttm_pool: Rename the ttm_pool_dma structure to ttm_pool_page_dat
In reply to John StultzThis patch simply renames the ttm_pool_dma structure to ttm_pool_page_dat, as we will extend it to store more then just dma related info in it.
--- drivers/gpu/drm/ttm/ttm_pool.c | 37 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 19 deletions(-)
drivers/gpu/drm/ttm/ttm_pool.c +18 -19
@@ -37,18 +37,17 @@#ifdef CONFIG_X86 #include <asm/set_memory.h> #endif -#include <drm/ttm/ttm_pool.h> #include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_tt.h> /** -* struct ttm_pool_dma - Helper object for coherent DMA mappings +* struct ttm_pool_page_dat - Helper object for coherent DMA mappings * * @addr: original DMA address returned for the mapping * @vaddr: original vaddr return for the mapping and order in the lower bits */ -struct ttm_pool_dma { +struct ttm_pool_page_dat {dma_addr_t addr;unsigned long vaddr; };
@@ -75,7 +74,7 @@ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags, unsigned int order) {unsigned long attr =DMA_ATTR_FORCE_CONTIGUOUS ; -struct ttm_pool_dma *dma; +struct ttm_pool_page_dat *dat;struct page *p;void *vaddr;
@@ -94,15 +93,15 @@ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags,return p; } - dma =kmalloc (sizeof (*dma),GFP_KERNEL ); -if (!dma) + dat =kmalloc (sizeof (*dat),GFP_KERNEL ); +if (!dat)return NULL ;if (order) attr |=DMA_ATTR_NO_WARN ; vaddr =dma_alloc_attrs (pool->dev, (1ULL << order) *PAGE_SIZE , - &dma->addr, gfp_flags, attr); + &dat->addr, gfp_flags, attr);if (!vaddr) goto error_free;
@@ -114,12 +113,12 @@ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags,else p =virt_to_page (vaddr); - dma->vaddr = (unsigned long )vaddr | order; - p->private = (unsigned long )dma; + dat->vaddr = (unsigned long )vaddr | order; + p->private = (unsigned long )dat;return p; error_free: -kfree (dma); +kfree (dat);return NULL ; }
@@ -128,7 +127,7 @@ static void ttm_pool_free_page(struct ttm_pool *pool, enum ttm_caching caching, unsigned int order, struct page *p) { unsigned long attr = DMA_ATTR_FORCE_CONTIGUOUS; -struct ttm_pool_dma *dma; +struct ttm_pool_page_dat *dat;void *vaddr;#ifdef CONFIG_X86
@@ -147,11 +146,11 @@ static void ttm_pool_free_page(struct ttm_pool *pool, enum ttm_caching caching,if (order) attr |=DMA_ATTR_NO_WARN ; - dma = (void *)p->private; - vaddr = (void *)(dma->vaddr &PAGE_MASK ); -dma_free_attrs (pool->dev, (1UL << order) *PAGE_SIZE , vaddr, dma->addr, + dat = (void *)p->private; + vaddr = (void *)(dat->vaddr &PAGE_MASK ); +dma_free_attrs (pool->dev, (1UL << order) *PAGE_SIZE , vaddr, dat->addr, attr); -kfree (dma); +kfree (dat); }/* Apply a new caching to an array of pages */
@@ -184,9 +183,9 @@ static int ttm_pool_map(struct ttm_pool *pool, unsigned int order,unsigned int i;if (pool->use_dma_alloc) { -struct ttm_pool_dma *dma = (void *)p->private; +struct ttm_pool_page_dat *dat = (void *)p->private; - addr = dma->addr; + addr = dat->addr; }else {size_t size = (1ULL << order) *PAGE_SIZE ;
@@ -324,9 +323,9 @@ static unsigned int ttm_pool_shrink(void)static unsigned int ttm_pool_page_order (struct ttm_pool *pool,struct page *p) {if (pool->use_dma_alloc) { -struct ttm_pool_dma *dma = (void *)p->private; +struct ttm_pool_page_dat *dat = (void *)p->private; -return dma->vaddr & ~PAGE_MASK ; +return dat->vaddr & ~PAGE_MASK ; }return p->private;
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH v6 3/7 drm: ttm_pool: Rework ttm_pool_free_page to allow us to use it as a function pointer
In reply to John StultzThis refactors ttm_pool_free_page(), and by adding extra entries to ttm_pool_page_dat, we then use it for all allocations, which allows us to simplify the arguments needed to be passed to ttm_pool_free_page().
This is critical for allowing the free function to be called by the sharable drm_page_pool logic.
--- drivers/gpu/drm/ttm/ttm_pool.c | 60 ++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 28 deletions(-)
drivers/gpu/drm/ttm/ttm_pool.c +32 -28
@@ -44,10 +44,14 @@/** * struct ttm_pool_page_dat - Helper object for coherent DMA mappings * +* @pool: ttm_pool pointer the page was allocated by +* @caching: the caching value the allocated page was configured for * @addr: original DMA address returned for the mapping * @vaddr: original vaddr return for the mapping and order in the lower bits */ struct ttm_pool_page_dat { +struct ttm_pool *pool; +enum ttm_caching caching;dma_addr_t addr;unsigned long vaddr; };
@@ -71,13 +75,20 @@ static struct shrinker mm_shrinker;/* Allocate pages of size 1 << order with the given gfp_flags */ static struct page *ttm_pool_alloc_page (struct ttm_pool *pool,gfp_t gfp_flags, -unsigned int order) +unsigned int order,enum ttm_caching caching) {unsigned long attr =DMA_ATTR_FORCE_CONTIGUOUS ;struct ttm_pool_page_dat *dat;struct page *p;void *vaddr; + dat =kmalloc (sizeof (*dat),GFP_KERNEL ); +if (!dat) +return NULL ; + + dat->pool = pool; + dat->caching = caching; +/* Don't set the __GFP_COMP flag for higher order allocations. * Mapping pages directly into an userspace process and calling * put_page() on a TTM allocated page is illegal.
@@ -88,15 +99,13 @@ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags,if (!pool->use_dma_alloc) { p =alloc_pages (gfp_flags, order); -if (p) - p->private = order; +if (!p) + goto error_free; + dat->vaddr = order; + p->private = (unsigned long )dat;return p; } - dat =kmalloc (sizeof (*dat),GFP_KERNEL ); -if (!dat) -return NULL ; -if (order) attr |=DMA_ATTR_NO_WARN ;
@@ -123,34 +132,34 @@ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags, }/* Reset the caching and pages of size 1 << order */ -static void ttm_pool_free_page (struct ttm_pool *pool,enum ttm_caching caching, -unsigned int order,struct page *p) +static int ttm_pool_free_page (struct page *p,unsigned int order) {unsigned long attr =DMA_ATTR_FORCE_CONTIGUOUS ; -struct ttm_pool_page_dat *dat; +struct ttm_pool_page_dat *dat = (void *)p->private;void *vaddr;#ifdef CONFIG_X86 /* We don't care that set_pages_wb is inefficient here. This is only * used when we have to shrink and CPU overhead is irrelevant then. */ -if (caching != ttm_cached && !PageHighMem (p)) +if (dat->caching != ttm_cached && !PageHighMem (p))set_pages_wb (p,1 << order);#endif -if (!pool || !pool->use_dma_alloc) { +if (!dat->pool || !dat->pool->use_dma_alloc) {__free_pages (p, order); -return ; + goto out; }if (order) attr |=DMA_ATTR_NO_WARN ; - dat = (void *)p->private; vaddr = (void *)(dat->vaddr &PAGE_MASK ); -dma_free_attrs (pool->dev, (1UL << order) *PAGE_SIZE , vaddr, dat->addr, +dma_free_attrs (dat->pool->dev, (1UL << order) *PAGE_SIZE , vaddr, dat->addr, attr); +out:kfree (dat); +return 1 << order; }/* Apply a new caching to an array of pages */
@@ -264,7 +273,7 @@ static void ttm_pool_type_fini(struct ttm_pool_type *pt)mutex_unlock (&shrinker_lock);list_for_each_entry_safe (p, tmp, &pt->pages, lru) -ttm_pool_free_page (pt->pool, pt->caching, pt->order, p); +ttm_pool_free_page (p, pt->order); }/* Return the pool_type to use for the given caching and order */
@@ -307,7 +316,7 @@ static unsigned int ttm_pool_shrink(void) p =ttm_pool_type_take (pt);if (p) { -ttm_pool_free_page (pt->pool, pt->caching, pt->order, p); +ttm_pool_free_page (p, pt->order); num_freed =1 << pt->order; }else { num_freed =0 ;
@@ -322,13 +331,9 @@ static unsigned int ttm_pool_shrink(void)/* Return the allocation order based for a page */ static unsigned int ttm_pool_page_order (struct ttm_pool *pool,struct page *p) { -if (pool->use_dma_alloc) { -struct ttm_pool_page_dat *dat = (void *)p->private; - -return dat->vaddr & ~PAGE_MASK ; - } +struct ttm_pool_page_dat *dat = (void *)p->private; -return p->private; +return dat->vaddr & ~PAGE_MASK ; }/**
@@ -379,7 +384,7 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,if (p) { apply_caching = true; }else { - p =ttm_pool_alloc_page (pool, gfp_flags, order); + p =ttm_pool_alloc_page (pool, gfp_flags, order, tt->caching);if (p &&PageHighMem (p)) apply_caching = true; }
@@ -428,13 +433,13 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,ttm_mem_global_free_page (&ttm_mem_glob, p, (1 << order) *PAGE_SIZE ); error_free_page: -ttm_pool_free_page (pool, tt->caching, order, p); +ttm_pool_free_page (p, order); error_free_all: num_pages = tt->num_pages - num_pages;for (i =0 ; i < num_pages; ) { order =ttm_pool_page_order (pool, tt->pages[i]); -ttm_pool_free_page (pool, tt->caching, order, tt->pages[i]); +ttm_pool_free_page (tt->pages[i], order); i +=1 << order; }
@@ -470,8 +475,7 @@ void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt)if (pt)ttm_pool_type_give (pt, tt->pages[i]);else -ttm_pool_free_page (pool, tt->caching, order, - tt->pages[i]); +ttm_pool_free_page (tt->pages[i], order); i += num_pages; }
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [RFC][PATCH v6 3/7] drm: ttm_pool: Rework ttm_pool_free_page to allow us to use it as a function pointer
Am 05.02.21 um 09:06 schrieb John Stultz:
Quoted 4 lines
This refactors
ttm_pool_free_page(), and by adding extra entries tottm_pool_page_dat, we then use it for all allocations, which allows us to simplify the arguments needed to be passed tottm_pool_free_page().
This is a clear NAK since the peer page data is just a workaround for the DMA-API hack to grab pages from there.
Adding this to all pages would increase the memory footprint drastically.
christian.
Quoted 191 lines
This is critical for allowing the free function to be called by the sharable
drm_page_poollogic.Cc Daniel Vetter <[email protected]>Cc Christian Koenig <[email protected]>Cc Sumit Semwal <[email protected]>Cc Liam Mark <[email protected]>Cc Chris Goldsworthy <[email protected]>Cc Laura Abbott <[email protected]>Cc Brian Starkey <[email protected]>Cc Hridya Valsaraju <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Sandeep Patil <[email protected]>Cc Daniel Mentz <[email protected]>Cc Ørjan Eide <[email protected]>Cc Robin Murphy <[email protected]>Cc Ezequiel Garcia <[email protected]>Cc Simon Ser <[email protected]>Cc James Jones <[email protected]>Signed-off-by John Stultz <[email protected]>--- drivers/gpu/drm/ttm/ttm_pool.c | 60 ++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 28 deletions(-)drivers/gpu/drm/ttm/ttm_pool.c +31
-26@@ -44,10 +44,14 @@/** * struct ttm_pool_page_dat - Helper object for coherent DMA mappings * +* @pool: ttm_pool pointer the page was allocated by +* @caching: the caching value the allocated page was configured for * @addr: original DMA address returned for the mapping * @vaddr: original vaddr return for the mapping and order in the lower bits */ struct ttm_pool_page_dat { +struct ttm_pool *pool; +enum ttm_caching caching;dma_addr_t addr;unsigned long vaddr; };@@ -71,13 +75,20 @@ static struct shrinker mm_shrinker;/* Allocate pages of size 1 << order with the given gfp_flags */ static struct page *ttm_pool_alloc_page (struct ttm_pool *pool,gfp_t gfp_flags, -unsigned int order) +unsigned int order,enum ttm_caching caching) {unsigned long attr =DMA_ATTR_FORCE_CONTIGUOUS ;struct ttm_pool_page_dat *dat;struct page *p;void *vaddr; + dat =kmalloc (sizeof (*dat),GFP_KERNEL ); +if (!dat) +return NULL ; + + dat->pool = pool; + dat->caching = caching; +/* Don't set the __GFP_COMP flag for higher order allocations. * Mapping pages directly into an userspace process and calling * put_page() on a TTM allocated page is illegal. @@ -88,15 +99,13 @@ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags,if (!pool->use_dma_alloc) { p =alloc_pages (gfp_flags, order); -if (p) - p->private = order; +if (!p) + goto error_free; + dat->vaddr = order; + p->private = (unsigned long )dat;return p; } - dat =kmalloc (sizeof (*dat),GFP_KERNEL ); -if (!dat) -return NULL ; -if (order) attr |=DMA_ATTR_NO_WARN ;@@ -123,34 +132,34 @@ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags, }/* Reset the caching and pages of size 1 << order */ -static void ttm_pool_free_page (struct ttm_pool *pool,enum ttm_caching caching, -unsigned int order,struct page *p) +static int ttm_pool_free_page (struct page *p,unsigned int order) {unsigned long attr =DMA_ATTR_FORCE_CONTIGUOUS ; -struct ttm_pool_page_dat *dat; +struct ttm_pool_page_dat *dat = (void *)p->private;void *vaddr;#ifdef CONFIG_X86 /* We don't care that set_pages_wb is inefficient here. This is only * used when we have to shrink and CPU overhead is irrelevant then. */ -if (caching != ttm_cached && !PageHighMem (p)) +if (dat->caching != ttm_cached && !PageHighMem (p))set_pages_wb (p,1 << order);#endif -if (!pool || !pool->use_dma_alloc) { +if (!dat->pool || !dat->pool->use_dma_alloc) {__free_pages (p, order); -return ; + goto out; }if (order) attr |=DMA_ATTR_NO_WARN ; - dat = (void *)p->private; vaddr = (void *)(dat->vaddr &PAGE_MASK ); -dma_free_attrs (pool->dev, (1UL << order) *PAGE_SIZE , vaddr, dat->addr, +dma_free_attrs (dat->pool->dev, (1UL << order) *PAGE_SIZE , vaddr, dat->addr, attr); +out:kfree (dat); +return 1 << order; }/* Apply a new caching to an array of pages */ @@ -264,7 +273,7 @@ static void ttm_pool_type_fini(struct ttm_pool_type *pt)mutex_unlock (&shrinker_lock);list_for_each_entry_safe (p, tmp, &pt->pages, lru) -ttm_pool_free_page (pt->pool, pt->caching, pt->order, p); +ttm_pool_free_page (p, pt->order); }/* Return the pool_type to use for the given caching and order */ @@ -307,7 +316,7 @@ static unsigned int ttm_pool_shrink(void) p =ttm_pool_type_take (pt);if (p) { -ttm_pool_free_page (pt->pool, pt->caching, pt->order, p); +ttm_pool_free_page (p, pt->order); num_freed =1 << pt->order; }else { num_freed =0 ;@@ -322,13 +331,9 @@ static unsigned int ttm_pool_shrink(void)/* Return the allocation order based for a page */ static unsigned int ttm_pool_page_order (struct ttm_pool *pool,struct page *p) { -if (pool->use_dma_alloc) { -struct ttm_pool_page_dat *dat = (void *)p->private; - -return dat->vaddr & ~PAGE_MASK ; - } +struct ttm_pool_page_dat *dat = (void *)p->private; -return p->private; +return dat->vaddr & ~PAGE_MASK ; }/** @@ -379,7 +384,7 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,if (p) { apply_caching = true; }else { - p =ttm_pool_alloc_page (pool, gfp_flags, order); + p =ttm_pool_alloc_page (pool, gfp_flags, order, tt->caching);if (p &&PageHighMem (p)) apply_caching = true; }@@ -428,13 +433,13 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,ttm_mem_global_free_page (&ttm_mem_glob, p, (1 << order) *PAGE_SIZE ); error_free_page: -ttm_pool_free_page (pool, tt->caching, order, p); +ttm_pool_free_page (p, order); error_free_all: num_pages = tt->num_pages - num_pages;for (i =0 ; i < num_pages; ) { order =ttm_pool_page_order (pool, tt->pages[i]); -ttm_pool_free_page (pool, tt->caching, order, tt->pages[i]); +ttm_pool_free_page (tt->pages[i], order); i +=1 << order; }
drivers/gpu/drm/ttm/ttm_pool.c void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt) · line 481
Quoted 9 lines
drivers/gpu/drm/ttm/ttm_pool.c +1
-2@@ -470,8 +475,7 @@ void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt)if (pt)ttm_pool_type_give (pt, tt->pages[i]);else -ttm_pool_free_page (pool, tt->caching, order, - tt->pages[i]); +ttm_pool_free_page (tt->pages[i], order); i += num_pages; }
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 3/7] drm: ttm_pool: Rework ttm_pool_free_page to allow us to use it as a function pointer
Quoted 10 lines · Christian König
Am 05.02.21 um 09:06 schrieb John Stultz:
Quoted 4 lines
This refactors
ttm_pool_free_page(), and by adding extra entries tottm_pool_page_dat, we then use it for all allocations, which allows us to simplify the arguments needed to be passed tottm_pool_free_page().This is a clear NAK since the peer page data is just a workaround for the DMA-API hack to grab pages from there.
Adding this to all pages would increase the memory footprint drastically.
Yea, that's a good point! Hrm... bummer. I'll have to see if there's some other way I can get the needed context for the free from the generic page-pool side.
Thanks so much for the review!
-john
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [RFC][PATCH v6 3/7] drm: ttm_pool: Rework ttm_pool_free_page to allow us to use it as a function pointer
Am 05.02.21 um 20:47 schrieb John Stultz:
Quoted 7 lines
Quoted 5 lines · Christian König
Am 05.02.21 um 09:06 schrieb John Stultz:
Quoted 4 lines
This refactors
ttm_pool_free_page(), and by adding extra entries tottm_pool_page_dat, we then use it for all allocations, which allows us to simplify the arguments needed to be passed tottm_pool_free_page().
Quoted 7 lines
Quoted 4 lines
This is a clear NAK since the peer page data is just a workaround for the DMA-API hack to grab pages from there.
Adding this to all pages would increase the memory footprint drastically.
Yea, that's a good point! Hrm... bummer. I'll have to see if there's some other way I can get the needed context for the free from the generic page-pool side.
What exactly is the problem here? As far as I can see we just have the lru entry (list_head) and the pool.
How the lru is cast to the page can be completely pool implementation specific.
Regards,
Christian.
Quoted 3 lines
Thanks so much for the review!
-john
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH v6 3/7] drm: ttm_pool: Rework ttm_pool_free_page to allow us to use it as a function pointer
Quoted 9 lines · Christian König
Am 05.02.21 um 20:47 schrieb John Stultz:
Quoted 6 lines
Quoted 1 line · Christian König
Adding this to all pages would increase the memory footprint drastically.
Yea, that's a good point! Hrm... bummer. I'll have to see if there's some other way I can get the needed context for the free from the generic page-pool side.
What exactly is the problem here?
Me, usually. :)
Quoted 2 lines
As far as I can see we just have the
lru entry (list_head) and the pool.
Yea, I reworked it to an embedded drm_page_pool struct, but that is mostly a list_head.
Quoted 2 lines
How the lru is cast to the page can be completely pool implementation specific.
Yea, I had it do container_of(), just haven't gotten around to sending it out yet.
Thanks so much for the feedback and ideas!
thanks
-john
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH v6 4/7 drm: ttm_pool: Rework ttm_pool to use drm_page_pool
In reply to John StultzThis patch reworks the ttm_pool logic to utilize the recently added drm_page_pool code.
Basically all the ttm_pool_type structures are replaced with drm_page_pool pointers, and since the drm_page_pool logic has its own shrinker, we can remove all of the ttm_pool shrinker logic.
NOTE: There is one mismatch in the interfaces I'm not totally happy with. The ttm_pool tracks all of its pooled pages across a number of different pools, and tries to keep this size under the specified page_pool_size value. With the drm_page_pool, there may other users, however there is still one global shrinker list of pools. So we can't easily reduce the ttm pool under the ttm specified size without potentially doing a lot of shrinking to other non-ttm pools. So either we can:
1) Try to split it so each user of drm_page_pools manages its own pool shrinking.
2) Push the max value into the drm_page_pool, and have it manage shrinking to fit under that global max. Then share those size/max values out so the ttm_pool debug output can have more context.
I've taken the second path in this patch set, but wanted to call it out so folks could look closely.
Thoughts would be greatly appreciated here!
--- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/ttm/ttm_pool.c | 199 +++++++-------------------------- include/drm/ttm/ttm_pool.h | 23 +--- 3 files changed, 41 insertions(+), 182 deletions(-)
drivers/gpu/drm/Kconfig +1 -0
@@ -181,6 +181,7 @@ config DRM_PAGE_POOL config DRM_TTM tristate depends on DRM && MMU + select DRM_PAGE_POOL help GPU memory management subsystem for devices with multiple GPU memory types. Will be enabled automatically if a device driver
drivers/gpu/drm/ttm/ttm_pool.c +39 -160
314 lines not on this page · raw message
include/drm/ttm/ttm_pool.h +1 -22
@@ -36,27 +36,6 @@ struct ttm_tt;struct ttm_pool ;struct ttm_operation_ctx ; -/** -* ttm_pool_type - Pool for a certain memory type -* -* @pool: the pool we belong to, might be NULL for the global ones -* @order: the allocation order our pages have -* @caching: the caching type our pages have -* @shrinker_list: our place on the global shrinker list -* @lock: protection of the page list -* @pages: the list of pages in the pool -*/ -struct ttm_pool_type { -struct ttm_pool *pool; -unsigned int order; -enum ttm_caching caching; - -struct list_head shrinker_list; - -spinlock_t lock; -struct list_head pages; -}; -/** * ttm_pool - Pool for all caching and orders *
@@ -71,7 +50,7 @@ struct ttm_pool {bool use_dma32;struct { -struct ttm_pool_type orders[MAX_ORDER ]; +struct drm_page_pool *orders[MAX_ORDER ]; } caching[TTM_NUM_CACHING_TYPES ]; };
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [RFC][PATCH v6 4/7] drm: ttm_pool: Rework ttm_pool to use drm_page_pool
Am 05.02.21 um 09:06 schrieb John Stultz:
Quoted 23 lines
This patch reworks the
ttm_poollogic to utilize the recently addeddrm_page_poolcode.Basically all the
ttm_pool_typestructures are replaced withdrm_page_poolpointers, and since thedrm_page_poollogic has its own shrinker, we can remove all of thettm_poolshrinker logic.NOTE: There is one mismatch in the interfaces I'm not totally happy with. The
ttm_pooltracks all of its pooled pages across a number of different pools, and tries to keep this size under the specifiedpage_pool_sizevalue. With thedrm_page_pool, there may other users, however there is still one global shrinker list of pools. So we can't easily reduce the ttm pool under the ttm specified size without potentially doing a lot of shrinking to other non-ttm pools. So either we can:
1) Try to split it so each user ofdrm_page_poolsmanages its own pool shrinking.
2) Push the max value into thedrm_page_pool, and have it manage shrinking to fit under that global max. Then share those size/max values out so thettm_pooldebug output can have more context.
Quoted 2 lines
I've taken the second path in this patch set, but wanted to call it out so folks could look closely.
Option 3: Move the debugging code into the drm_page_pool as well.
I strong think that will be a hard requirement from Daniel for upstreaming this.
Christian.
Quoted 404 lines
Thoughts would be greatly appreciated here!
Cc Daniel Vetter <[email protected]>Cc Christian Koenig <[email protected]>Cc Sumit Semwal <[email protected]>Cc Liam Mark <[email protected]>Cc Chris Goldsworthy <[email protected]>Cc Laura Abbott <[email protected]>Cc Brian Starkey <[email protected]>Cc Hridya Valsaraju <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Sandeep Patil <[email protected]>Cc Daniel Mentz <[email protected]>Cc Ørjan Eide <[email protected]>Cc Robin Murphy <[email protected]>Cc Ezequiel Garcia <[email protected]>Cc Simon Ser <[email protected]>Cc James Jones <[email protected]>Signed-off-by John Stultz <[email protected]>--- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/ttm/ttm_pool.c | 199 +++++++-------------------------- include/drm/ttm/ttm_pool.h | 23 +--- 3 files changed, 41 insertions(+), 182 deletions(-)drivers/gpu/drm/Kconfig +1
-0@@ -181,6 +181,7 @@ config DRM_PAGE_POOL config DRM_TTM tristate depends on DRM && MMU + select DRM_PAGE_POOL help GPU memory management subsystem for devices with multiple GPU memory types. Will be enabled automatically if a device driverdrivers/gpu/drm/ttm/ttm_pool.c +39
-160@@ -37,6 +37,7 @@#ifdef CONFIG_X86 #include <asm/set_memory.h> #endif +#include <drm/page_pool.h> #include <drm/ttm/ttm_pool.h> #include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_tt.h> @@ -63,15 +64,13 @@ module_param(page_pool_size, ulong, 0644);static atomic_long_t allocated_pages; -static struct ttm_pool_type global_write_combined[MAX_ORDER ]; -static struct ttm_pool_type global_uncached[MAX_ORDER ]; +static struct drm_page_pool *global_write_combined[MAX_ORDER ]; +static struct drm_page_pool *global_uncached[MAX_ORDER ]; -static struct ttm_pool_type global_dma32_write_combined[MAX_ORDER ]; -static struct ttm_pool_type global_dma32_uncached[MAX_ORDER ]; +static struct drm_page_pool *global_dma32_write_combined[MAX_ORDER ]; +static struct drm_page_pool *global_dma32_uncached[MAX_ORDER ];static struct mutex shrinker_lock; -static struct list_head shrinker_list; -static struct shrinker mm_shrinker;/* Allocate pages of size 1 << order with the given gfp_flags */ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags,@@ -223,79 +222,26 @@ static void ttm_pool_unmap(struct ttm_pool *pool, dma_addr_t dma_addr, DMA_BIDIRECTIONAL); } -/* Give pages into a specific pool_type */ -static void ttm_pool_type_give (struct ttm_pool_type *pt,struct page *p) -{ -spin_lock (&pt->lock); -list_add (&p->lru, &pt->pages); -spin_unlock (&pt->lock); -atomic_long_add (1 << pt->order, &allocated_pages); -} - -/* Take pages from a specific pool_type, return NULL when nothing available */ -static struct page *ttm_pool_type_take (struct ttm_pool_type *pt) -{ -struct page *p; - -spin_lock (&pt->lock); - p =list_first_entry_or_null (&pt->pages,typeof (*p), lru); -if (p) { -atomic_long_sub (1 << pt->order, &allocated_pages); -list_del (&p->lru); - } -spin_unlock (&pt->lock); - -return p; -} - -/* Initialize and add a pool type to the global shrinker list */ -static void ttm_pool_type_init (struct ttm_pool_type *pt,struct ttm_pool *pool, -enum ttm_caching caching,unsigned int order) -{ - pt->pool = pool; - pt->caching = caching; - pt->order = order; -spin_lock_init (&pt->lock); -INIT_LIST_HEAD (&pt->pages); - -mutex_lock (&shrinker_lock); -list_add_tail (&pt->shrinker_list, &shrinker_list); -mutex_unlock (&shrinker_lock); -} - -/* Remove a pool_type from the global shrinker list and free all pages */ -static void ttm_pool_type_fini (struct ttm_pool_type *pt) -{ -struct page *p, *tmp; - -mutex_lock (&shrinker_lock); -list_del (&pt->shrinker_list); -mutex_unlock (&shrinker_lock); - -list_for_each_entry_safe (p, tmp, &pt->pages, lru) -ttm_pool_free_page (p, pt->order); -} -/* Return the pool_type to use for the given caching and order */ -static struct ttm_pool_type *ttm_pool_select_type (struct ttm_pool *pool, +static struct drm_page_pool *ttm_pool_select_type (struct ttm_pool *pool,enum ttm_caching caching,unsigned int order) {if (pool->use_dma_alloc) -return &pool->caching[caching].orders[order]; +return pool->caching[caching].orders[order];#ifdef CONFIG_X86 switch (caching) {case ttm_write_combined:if (pool->use_dma32) -return &global_dma32_write_combined[order]; +return global_dma32_write_combined[order]; -return &global_write_combined[order]; +return global_write_combined[order];case ttm_uncached:if (pool->use_dma32) -return &global_dma32_uncached[order]; +return global_dma32_uncached[order]; -return &global_uncached[order]; +return global_uncached[order];default :break ; }@@ -304,30 +250,6 @@ static struct ttm_pool_type *ttm_pool_select_type(struct ttm_pool *pool,return NULL ; } -/* Free pages using the global shrinker list */ -static unsigned int ttm_pool_shrink (void ) -{ -struct ttm_pool_type *pt; -unsigned int num_freed; -struct page *p; - -mutex_lock (&shrinker_lock); - pt =list_first_entry (&shrinker_list,typeof (*pt), shrinker_list); - - p =ttm_pool_type_take (pt); -if (p) { -ttm_pool_free_page (p, pt->order); - num_freed =1 << pt->order; - }else { - num_freed =0 ; - } - -list_move_tail (&pt->shrinker_list, &shrinker_list); -mutex_unlock (&shrinker_lock); - -return num_freed; -} -/* Return the allocation order based for a page */ static unsigned int ttm_pool_page_order (struct ttm_pool *pool,struct page *p) {@@ -377,10 +299,10 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,for (order =min (MAX_ORDER -1UL ,__fls (num_pages)); num_pages; order = min_t(unsigned int, order, __fls(num_pages))) {bool apply_caching = false; -struct ttm_pool_type *pt; +struct drm_page_pool *pt; pt =ttm_pool_select_type (pool, tt->caching, order); - p = pt ?ttm_pool_type_take (pt) :NULL ; + p = pt ?drm_page_pool_fetch (pt) :NULL ;if (p) { apply_caching = true; }else {@@ -462,7 +384,7 @@ void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt)for (i =0 ; i < tt->num_pages; ) {struct page *p = tt->pages[i];unsigned int order, num_pages; -struct ttm_pool_type *pt; +struct drm_page_pool *pt; order =ttm_pool_page_order (pool, p); num_pages =1ULL << order;@@ -473,15 +395,12 @@ void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt) pt =ttm_pool_select_type (pool, tt->caching, order);if (pt) -ttm_pool_type_give (pt, tt->pages[i]); +drm_page_pool_add (pt, tt->pages[i]);else ttm_pool_free_page (tt->pages[i], order); i += num_pages; } - -while (atomic_long_read (&allocated_pages) > page_pool_size) -ttm_pool_shrink (); }EXPORT_SYMBOL (ttm_pool_free);@@ -508,8 +427,8 @@ void ttm_pool_init(struct ttm_pool *pool, struct device *dev,for (i =0 ; i <TTM_NUM_CACHING_TYPES ; ++i)for (j =0 ; j <MAX_ORDER ; ++j) -ttm_pool_type_init (&pool->caching[i].orders[j], - pool, i, j); + pool->caching[i].orders[j] =drm_page_pool_create (j, + ttm_pool_free_page); }/** @@ -526,33 +445,18 @@ void ttm_pool_fini(struct ttm_pool *pool)for (i =0 ; i <TTM_NUM_CACHING_TYPES ; ++i)for (j =0 ; j <MAX_ORDER ; ++j) -ttm_pool_type_fini (&pool->caching[i].orders[j]); +drm_page_pool_destroy (pool->caching[i].orders[j]); }#ifdef CONFIG_DEBUG_FS -/* Count the number of pages available in a pool_type */ -static unsigned int ttm_pool_type_count (struct ttm_pool_type *pt) -{ -unsigned int count =0 ; -struct page *p; - -spin_lock (&pt->lock); -/* Only used for debugfs, the overhead doesn't matter */ -list_for_each_entry (p, &pt->pages, lru) - ++count; -spin_unlock (&pt->lock); - -return count; -} -/* Dump information about the different pool types */ -static void ttm_pool_debugfs_orders (struct ttm_pool_type *pt, +static void ttm_pool_debugfs_orders (struct drm_page_pool **pt,struct seq_file *m) {unsigned int i;for (i =0 ; i <MAX_ORDER ; ++i) -seq_printf (m," %8u" ,ttm_pool_type_count (&pt[i])); +seq_printf (m," %8u" ,drm_page_pool_get_size (pt[i]));seq_puts (m,"\n" ); }@@ -602,7 +506,10 @@ int ttm_pool_debugfs(struct ttm_pool *pool, struct seq_file *m) }seq_printf (m,"\ntotal\t: %8lu of %8lu\n" , -atomic_long_read (&allocated_pages), page_pool_size); +atomic_long_read (&allocated_pages), +drm_page_pool_get_max ()); +seq_printf (m,"(%8lu in non-ttm pools)\n" ,drm_page_pool_get_total () - +atomic_long_read (&allocated_pages));mutex_unlock (&shrinker_lock);@@ -612,28 +519,6 @@ EXPORT_SYMBOL(ttm_pool_debugfs);#endif -/* As long as pages are available make sure to release at least one */ -static unsigned long ttm_pool_shrinker_scan (struct shrinker *shrink, -struct shrink_control *sc) -{ -unsigned long num_freed =0 ; - -do - num_freed +=ttm_pool_shrink (); -while (!num_freed &&atomic_long_read (&allocated_pages)); - -return num_freed; -} - -/* Return the number of pages available or SHRINK_EMPTY if we have none */ -static unsigned long ttm_pool_shrinker_count (struct shrinker *shrink, -struct shrink_control *sc) -{ -unsigned long num_pages =atomic_long_read (&allocated_pages); - -return num_pages ? num_pages :SHRINK_EMPTY ; -} -/** * ttm_pool_mgr_init - Initialize globals * @@ -648,24 +533,21 @@ int ttm_pool_mgr_init(unsigned long num_pages)if (!page_pool_size) page_pool_size = num_pages; +drm_page_pool_set_max (page_pool_size); +mutex_init (&shrinker_lock); -INIT_LIST_HEAD (&shrinker_list);for (i =0 ; i <MAX_ORDER ; ++i) { -ttm_pool_type_init (&global_write_combined[i],NULL , - ttm_write_combined, i); -ttm_pool_type_init (&global_uncached[i],NULL , ttm_uncached, i); - -ttm_pool_type_init (&global_dma32_write_combined[i],NULL , - ttm_write_combined, i); -ttm_pool_type_init (&global_dma32_uncached[i],NULL , - ttm_uncached, i); + global_write_combined[i] =drm_page_pool_create (i, + ttm_pool_free_page); + global_uncached[i] =drm_page_pool_create (i, + ttm_pool_free_page); + global_dma32_write_combined[i] =drm_page_pool_create (i, + ttm_pool_free_page); + global_dma32_uncached[i] =drm_page_pool_create (i, + ttm_pool_free_page); } - - mm_shrinker.count_objects = ttm_pool_shrinker_count; - mm_shrinker.scan_objects = ttm_pool_shrinker_scan; - mm_shrinker.seeks =1 ; -return register_shrinker (&mm_shrinker); +return 0 ; }/** @@ -678,13 +560,10 @@ void ttm_pool_mgr_fini(void)unsigned int i;for (i =0 ; i <MAX_ORDER ; ++i) { -ttm_pool_type_fini (&global_write_combined[i]); -ttm_pool_type_fini (&global_uncached[i]); +drm_page_pool_destroy (global_write_combined[i]); +drm_page_pool_destroy (global_uncached[i]); -ttm_pool_type_fini (&global_dma32_write_combined[i]); -ttm_pool_type_fini (&global_dma32_uncached[i]); +drm_page_pool_destroy (global_dma32_write_combined[i]); +drm_page_pool_destroy (global_dma32_uncached[i]); } - -unregister_shrinker (&mm_shrinker); -WARN_ON (!list_empty (&shrinker_list)); }include/drm/ttm/ttm_pool.h +0
-21@@ -36,27 +36,6 @@ struct ttm_tt;struct ttm_pool ;struct ttm_operation_ctx ; -/** -* ttm_pool_type - Pool for a certain memory type -* -* @pool: the pool we belong to, might be NULL for the global ones -* @order: the allocation order our pages have -* @caching: the caching type our pages have -* @shrinker_list: our place on the global shrinker list -* @lock: protection of the page list -* @pages: the list of pages in the pool -*/ -struct ttm_pool_type { -struct ttm_pool *pool; -unsigned int order; -enum ttm_caching caching; - -struct list_head shrinker_list; - -spinlock_t lock; -struct list_head pages; -}; -/** * ttm_pool - Pool for all caching and orders *
include/drm/ttm/ttm_pool.h struct ttm_pool { · line 56
Quoted 8 lines
include/drm/ttm/ttm_pool.h +1
-1@@ -71,7 +50,7 @@ struct ttm_pool {bool use_dma32;struct { -struct ttm_pool_type orders[MAX_ORDER ]; +struct drm_page_pool *orders[MAX_ORDER ]; } caching[TTM_NUM_CACHING_TYPES ]; };
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
kernel test robot
build botRe: [RFC][PATCH v6 4/7] drm: ttm_pool: Rework ttm_pool to use drm_page_pool
In reply to John Stultz[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi John,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.11-rc6]
[cannot apply to drm-intel/for-linux-next drm-tip/drm-tip drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next drm/drm-next next-20210125] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/John-Stultz/Generic-page-pool-deferred-freeing-for-system-dmabuf-heap/20210205-160846 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2ab38c17aac10bf55ab3efde4c4db3893d8691d2 config: parisc-randconfig-r022-20210205 (attached as .config) compiler: hppa-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/cd4c7dca917a05949a5aae69ba3537660fc9bcae
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review John-Stultz/Generic-page-pool-deferred-freeing-for-system-dmabuf-heap/20210205-160846 git checkout cd4c7dca917a05949a5aae69ba3537660fc9bcae
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=parisc
If you fix the issue, kindly add following tag as appropriate
All error/warnings (new ones prefixed by >>):
>> drivers/gpu/drm/page_pool.c:215:5: warning: no previous prototype for 'drm_page_pool_init_shrinker' [-Wmissing-prototypes]
215 | int drm_page_pool_init_shrinker(void)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
--
hppa-linux-ld: drivers/gpu/drm/page_pool.o: in function `init_module':
>> (.text.drm_page_pool_init_shrinker+0x0): multiple definition of `init_module'; drivers/gpu/drm/drm_drv.o:drivers/gpu/drm/drm_drv.o:(.init.text+0x0): first defined here
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC PATCH v6 5/7 dma-buf: heaps: Add deferred-free-helper library code
In reply to John StultzThis patch provides infrastructure for deferring buffer frees.
This is a feature ION provided which when used with some form of a page pool, provides a nice performance boost in an allocation microbenchmark. The reason it helps is it allows the page-zeroing to be done out of the normal allocation/free path, and pushed off to a kthread.
As not all heaps will find this useful, its implemented as a optional helper library that heaps can utilize.
---
v2:
* Fix sleep in atomic issue from using a mutex, by switching to a spinlock as Reported-by: kernel test robot <[email protected]>
* Cleanup API to use a reason enum for clarity and add some documentation comments as suggested by Suren Baghdasaryan.
v3:
* Minor tweaks so it can be built as a module
* A few small fixups suggested by Daniel Mentz
v4:
* Tweak from Daniel Mentz to make sure the shrinker count/freed values are tracked in pages not bytes
v5:
* Fix up page count tracking as suggested by Suren Baghdasaryan
--- drivers/dma-buf/heaps/Kconfig | 3 + drivers/dma-buf/heaps/Makefile | 1 + drivers/dma-buf/heaps/deferred-free-helper.c | 145 +++++++++++++++++++ drivers/dma-buf/heaps/deferred-free-helper.h | 55 +++++++ 4 files changed, 204 insertions(+) create mode 100644 drivers/dma-buf/heaps/deferred-free-helper.c create mode 100644 drivers/dma-buf/heaps/deferred-free-helper.h
drivers/dma-buf/heaps/Kconfig +3 -0
@@ -1,3 +1,6 @@ +config DMABUF_HEAPS_DEFERRED_FREE + tristate + config DMABUF_HEAPS_SYSTEM bool "DMA-BUF System Heap" depends on DMABUF_HEAPS
drivers/dma-buf/heaps/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_DMABUF_HEAPS_DEFERRED_FREE) += deferred-free-helper.o obj-$(CONFIG_DMABUF_HEAPS_SYSTEM) += system_heap.o obj-$(CONFIG_DMABUF_HEAPS_CMA) += cma_heap.o
drivers/dma-buf/heaps/deferred-free-helper.c new file +145 -0
145 lines not on this page · raw message
drivers/dma-buf/heaps/deferred-free-helper.h new file +55 -0
55 lines not on this page · raw message
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH v6 6/7 dma-buf: system_heap: Add drm pagepool support to system heap
In reply to John StultzUtilize the drm pagepool code to speed up allocation performance.
This is similar to the ION pagepool usage, but tries to utilize generic code instead of a custom implementation.
---
v2:
* Fix build issue caused by selecting PAGE_POOL w/o NET as Reported-by: kernel test robot <[email protected]>
v3:
* Simplify the page zeroing logic a bit by using kmap_atomic instead of vmap as suggested by Daniel Mentz
v5:
* Shift away from networking page pool completely to dmabuf page pool implementation
v6:
* Switch again to using the drm_page_pool code shared w/ ttm_pool
--- drivers/dma-buf/heaps/Kconfig | 1 + drivers/dma-buf/heaps/system_heap.c | 56 +++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-)
drivers/dma-buf/heaps/Kconfig +1 -0
@@ -4,6 +4,7 @@ config DMABUF_HEAPS_DEFERRED_FREE config DMABUF_HEAPS_SYSTEM bool "DMA-BUF System Heap" depends on DMABUF_HEAPS + select DRM_PAGE_POOL 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.
drivers/dma-buf/heaps/system_heap.c +53 -3
96 lines not on this page · raw message
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
kernel test robot
build botRe: [RFC][PATCH v6 6/7] dma-buf: system_heap: Add drm pagepool support to system heap
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi John,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.11-rc6]
[cannot apply to drm-intel/for-linux-next drm-tip/drm-tip drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next drm/drm-next next-20210125] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/John-Stultz/Generic-page-pool-deferred-freeing-for-system-dmabuf-heap/20210205-160846 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2ab38c17aac10bf55ab3efde4c4db3893d8691d2 config: i386-randconfig-s001-20210205 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.3-215-g0fb77bb6-dirty # https://github.com/0day-ci/linux/commit/47bdae8428bf2e9710c79eafb451beb9a184f2c9 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review John-Stultz/Generic-page-pool-deferred-freeing-for-system-dmabuf-heap/20210205-160846 git checkout 47bdae8428bf2e9710c79eafb451beb9a184f2c9 # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
ld: drivers/dma-buf/heaps/system_heap.o: in function `system_heap_create':
>> drivers/dma-buf/heaps/system_heap.c:470: undefined reference to `drm_page_pool_create' ld: drivers/dma-buf/heaps/system_heap.o: in function `system_heap_dma_buf_release': >> drivers/dma-buf/heaps/system_heap.c:329: undefined reference to `drm_page_pool_add' ld: drivers/dma-buf/heaps/system_heap.o: in function `alloc_largest_available': >> drivers/dma-buf/heaps/system_heap.c:360: undefined reference to `drm_page_pool_fetch' ld: drivers/dma-buf/heaps/system_heap.o: in function `system_heap_create': >> drivers/dma-buf/heaps/system_heap.c:477: undefined reference to `drm_page_pool_destroy'
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for DRM_PAGE_POOL Depends on HAS_IOMEM && DRM
Selected by
- DMABUF_HEAPS_SYSTEM && DMABUF_HEAPS
vim +470 drivers/dma-buf/heaps/system_heap.c
310
311 static void system_heap_dma_buf_release(struct dma_buf *dmabuf)
312 {
313 struct system_heap_buffer *buffer = dmabuf->priv;
314 struct sg_table *table;
315 struct scatterlist *sg;
316 int i, j;
317
318 /* Zero the buffer pages before adding back to the pool */
319 system_heap_zero_buffer(buffer);
320
321 table = &buffer->sg_table;
322 for_each_sg(table->sgl, sg, table->nents, i) {
323 struct page *page = sg_page(sg);
324
325 for (j = 0; j < NUM_ORDERS; j++) {
326 if (compound_order(page) == orders[j])
327 break;
328 }
> 329 drm_page_pool_add(pools[j], page);
330 }
331 sg_free_table(table);
332 kfree(buffer);
333 }
334
335 static const struct dma_buf_ops system_heap_buf_ops = {
336 .attach = system_heap_attach,
337 .detach = system_heap_detach,
338 .map_dma_buf = system_heap_map_dma_buf,
339 .unmap_dma_buf = system_heap_unmap_dma_buf,
340 .begin_cpu_access = system_heap_dma_buf_begin_cpu_access,
341 .end_cpu_access = system_heap_dma_buf_end_cpu_access,
342 .mmap = system_heap_mmap,
343 .vmap = system_heap_vmap,
344 .vunmap = system_heap_vunmap,
345 .release = system_heap_dma_buf_release,
346 };
347
348 static struct page *alloc_largest_available(unsigned long size,
349 unsigned int max_order)
350 {
351 struct page *page;
352 int i;
353
354 for (i = 0; i < NUM_ORDERS; i++) {
355 if (size < (PAGE_SIZE << orders[i]))
356 continue;
357 if (max_order < orders[i])
358 continue;
359
> 360 page = drm_page_pool_fetch(pools[i]);
361 if (!page)
362 page = alloc_pages(order_flags[i], orders[i]);
363 if (!page)
364 continue;
365 return page;
366 }
367 return NULL;
368 }
369
370 static int system_heap_allocate(struct dma_heap *heap,
371 unsigned long len,
372 unsigned long fd_flags,
373 unsigned long heap_flags)
374 {
375 struct system_heap_buffer *buffer;
376 DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
377 unsigned long size_remaining = len;
378 unsigned int max_order = orders[0];
379 struct dma_buf *dmabuf;
380 struct sg_table *table;
381 struct scatterlist *sg;
382 struct list_head pages;
383 struct page *page, *tmp_page;
384 int i, ret = -ENOMEM;
385
386 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
387 if (!buffer)
388 return -ENOMEM;
389
390 INIT_LIST_HEAD(&buffer->attachments);
391 mutex_init(&buffer->lock);
392 buffer->heap = heap;
393 buffer->len = len;
394
395 INIT_LIST_HEAD(&pages);
396 i = 0;
397 while (size_remaining > 0) {
398 /*
399 * Avoid trying to allocate memory if the process
400 * has been killed by SIGKILL
401 */
402 if (fatal_signal_pending(current))
403 goto free_buffer;
404
405 page = alloc_largest_available(size_remaining, max_order);
406 if (!page)
407 goto free_buffer;
408
409 list_add_tail(&page->lru, &pages);
410 size_remaining -= page_size(page);
411 max_order = compound_order(page);
412 i++;
413 }
414
415 table = &buffer->sg_table;
416 if (sg_alloc_table(table, i, GFP_KERNEL))
417 goto free_buffer;
418
419 sg = table->sgl;
420 list_for_each_entry_safe(page, tmp_page, &pages, lru) {
421 sg_set_page(sg, page, page_size(page), 0);
422 sg = sg_next(sg);
423 list_del(&page->lru);
424 }
425
426 /* create the dmabuf */
427 exp_info.ops = &system_heap_buf_ops;
428 exp_info.size = buffer->len;
429 exp_info.flags = fd_flags;
430 exp_info.priv = buffer;
431 dmabuf = dma_buf_export(&exp_info);
432 if (IS_ERR(dmabuf)) {
433 ret = PTR_ERR(dmabuf);
434 goto free_pages;
435 }
436
437 ret = dma_buf_fd(dmabuf, fd_flags);
438 if (ret < 0) {
439 dma_buf_put(dmabuf);
440 /* just return, as put will call release and that will free */
441 return ret;
442 }
443 return ret;
444
445 free_pages:
446 for_each_sgtable_sg(table, sg, i) {
447 struct page *p = sg_page(sg);
448
449 __free_pages(p, compound_order(p));
450 }
451 sg_free_table(table);
452 free_buffer:
453 list_for_each_entry_safe(page, tmp_page, &pages, lru)
454 __free_pages(page, compound_order(page));
455 kfree(buffer);
456
457 return ret;
458 }
459
460 static const struct dma_heap_ops system_heap_ops = {
461 .allocate = system_heap_allocate,
462 };
463
464 static int system_heap_create(void)
465 {
466 struct dma_heap_export_info exp_info;
467 int i;
468
469 for (i = 0; i < NUM_ORDERS; i++) {
> 470 pools[i] = drm_page_pool_create(orders[i],
471 system_heap_free_pages);
472 if (IS_ERR(pools[i])) {
473 int j;
474
475 pr_err("%s: page pool creation failed!\n", __func__);
476 for (j = 0; j < i; j++)
> 477 drm_page_pool_destroy(pools[j]);---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [RFC][PATCH v6 6/7] dma-buf: system_heap: Add drm pagepool support to system heap
In reply to John Stultz[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi John,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linux/master]
[also build test WARNING on linus/master v5.11-rc6]
[cannot apply to drm-intel/for-linux-next drm-tip/drm-tip drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next drm/drm-next next-20210125] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/John-Stultz/Generic-page-pool-deferred-freeing-for-system-dmabuf-heap/20210205-160846 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2ab38c17aac10bf55ab3efde4c4db3893d8691d2 config: mips-randconfig-r033-20210205 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c9439ca36342fb6013187d0a69aef92736951476)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install mips cross compiling tool for clang build
# apt-get install binutils-mips-linux-gnu
# https://github.com/0day-ci/linux/commit/47bdae8428bf2e9710c79eafb451beb9a184f2c9
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review John-Stultz/Generic-page-pool-deferred-freeing-for-system-dmabuf-heap/20210205-160846 git checkout 47bdae8428bf2e9710c79eafb451beb9a184f2c9
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/gpu/drm/page_pool.c:215:5: warning: no previous prototype for function 'drm_page_pool_init_shrinker' [-Wmissing-prototypes]
int drm_page_pool_init_shrinker(void)
^ drivers/gpu/drm/page_pool.c:215:1: note: declare 'static' if the function is not intended to be used outside of this translation unit int drm_page_pool_init_shrinker(void)
^
static
1 warning generated.
vim +/drm_page_pool_init_shrinker +215 drivers/gpu/drm/page_pool.c
7bd04c721ea25c John Stultz 2021-02-05 2147bd04c721ea25c John Stultz 2021-02-05 @215 int drm_page_pool_init_shrinker(void)
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC PATCH v6 7/7 dma-buf: system_heap: Add deferred freeing to the system heap
In reply to John StultzUtilize 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.
---
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(-)
drivers/dma-buf/heaps/Kconfig +1 -0
@@ -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.
drivers/dma-buf/heaps/system_heap.c +24 -7
@@ -22,6 +22,7 @@#include <linux/vmalloc.h> #include <drm/page_pool.h> +#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,
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerAm 05.02.21 um 09:06 schrieb John Stultz:
Quoted 32 lines
This series is starting to get long, so I figured I'd add a short cover letter for context.
The point of this series is trying to add both deferred-freeing logic as well as a page pool to the DMA-BUF system heap.
This is desired, as the combination of deferred freeing along with the page pool allows us to offload page-zeroing out of the allocation hot path. This was done originally with ION and this patch series allows the DMA-BUF system heap to match ION's system heap allocation performance in a simple microbenchmark [1] (ION re-added to the kernel for comparision, running on an x86 vm image):
./dmabuf-heap-bench -i 0 1 system
Testing dmabuf system vs ion heaptype 0 (flags:0x1)
---------------------------------------------dmabuf heap: alloc 4096 bytes 5000 times in 86572223 ns 17314 ns/call ion heap: alloc 4096 bytes 5000 times in 97442526 ns 19488 ns/call dmabuf heap: alloc 1048576 bytes 5000 times in 196635057 ns 39327 ns/call ion heap: alloc 1048576 bytes 5000 times in 357323629 ns 71464 ns/call dmabuf heap: alloc 8388608 bytes 5000 times in 3165445534 ns 633089 ns/call ion heap: alloc 8388608 bytes 5000 times in 3699591271 ns 739918 ns/call dmabuf heap: alloc 33554432 bytes 5000 times in 13327402517 ns 2665480 ns/call ion heap: alloc 33554432 bytes 5000 times in 15292352796 ns 3058470 ns/callDaniel didn't like earlier attempts to re-use the network page-pool code to achieve this, and suggested the
ttm_poolbe used instead. This required pulling the fairly tightly knitttm_poollogic apart, but after many failed attmempts I think I found a workable abstraction to split out shared logic.
Quoted 7 lines
So this series contains a new generic
drm_page_poolhelper library, converts thettm_poolto use it, and then adds the dmabuf deferred freeing and adds support to the dmabuf system heap to use both deferred freeing and the newdrm_page_pool.Input would be greatly appreciated. Testing as well, as I don't have any development hardware that utilizes the ttm pool.
We can easily do the testing and the general idea sounds solid to me.
I see three major things we need to clean up here.
1. The licensing, you are moving from BSD/MIT to GPL2.
2. Don't add any new overhead to the TTM pool, especially allocating a private object per page is a no-go.
3. What are you doing with the reclaim stuff and why?
4. Keeping the documentation would be nice to have.
Regards,
Christian.
Quoted 47 lines
thanks
-johnCc Daniel Vetter <[email protected]>Cc Christian Koenig <[email protected]>Cc Sumit Semwal <[email protected]>Cc Liam Mark <[email protected]>Cc Chris Goldsworthy <[email protected]>Cc Laura Abbott <[email protected]>Cc Brian Starkey <[email protected]>Cc Hridya Valsaraju <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Sandeep Patil <[email protected]>Cc Daniel Mentz <[email protected]>Cc Ørjan Eide <[email protected]>Cc Robin Murphy <[email protected]>Cc Ezequiel Garcia <[email protected]>Cc Simon Ser <[email protected]>Cc James Jones <[email protected]>John Stultz (7):
drm: Add a sharable drm page-pool implementation
drm:ttm_pool: Rename thettm_pool_dmastructure tottm_pool_page_dat
drm:ttm_pool: Reworkttm_pool_free_pageto allow us to use it as a
function pointer
drm:ttm_pool: Reworkttm_poolto usedrm_page_pool
dma-buf: heaps: Add deferred-free-helper library code
dma-buf:system_heap: Add drm pagepool support to system heap
dma-buf:system_heap: Add deferred freeing to the system heapdrivers/dma-buf/heaps/Kconfig | 5 + drivers/dma-buf/heaps/Makefile | 1 + drivers/dma-buf/heaps/deferred-free-helper.c | 145 ++++++++++ drivers/dma-buf/heaps/deferred-free-helper.h | 55 ++++ drivers/dma-buf/heaps/system_heap.c | 77 ++++- drivers/gpu/drm/Kconfig | 5 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/page_pool.c | 220 +++++++++++++++ drivers/gpu/drm/ttm/ttm_pool.c | 278 ++++++------------- include/drm/page_pool.h | 54 ++++ include/drm/ttm/ttm_pool.h | 23 +- 11 files changed, 639 insertions(+), 225 deletions(-)
Quoted 5 lines
create mode 100644
drivers/dma-buf/heaps/deferred-free-helper.ccreate mode 100644drivers/dma-buf/heaps/deferred-free-helper.hcreate mode 100644drivers/gpu/drm/page_pool.c
create mode 100644include/drm/page_pool.h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 6 lines · Christian König
Am 05.02.21 um 09:06 schrieb John Stultz:
Quoted 2 lines
Input would be greatly appreciated. Testing as well, as I don't have any development hardware that utilizes the ttm pool.
We can easily do the testing and the general idea sounds solid to me.
Thanks so much again for the feedback!
Quoted 2 lines
I see three major things we need to clean up here.
1. The licensing, you are moving from BSD/MIT to GPL2.
Yea, this may be sticky, as it's not just code re-used from one dual licensed file, but combination of GPL2 work, so advice here would be appreciated.
Quoted 2 lines
2. Don't add any new overhead to the TTM pool, especially allocating a private object per page is a no-go.
This will need some more series rework to solve. I've got some ideas, but we'll see if they work.
Quoted 1 line
3. What are you doing with the reclaim stuff and why?
As I mentioned, it's a holdover from earlier code, and I'm happy to drop it and defer to other accounting/stats discussions that are ongoing.
Quoted 1 line
4. Keeping the documentation would be nice to have.
True. I didn't spend much time with documentation, as I worried folks may have disagreed with the whole approach. I'll work to improve it for the next go around.
Thanks so much again for the review and feedback! I really appreciate your time here.
-john
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel