Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * DMA BUF page pool system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2020 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Based on the ION page pool code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 2011 Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/freezer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "page_pool.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static LIST_HEAD(pool_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static DEFINE_MUTEX(pool_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) struct page *dmabuf_page_pool_alloc_pages(struct dmabuf_page_pool *pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	if (fatal_signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	return alloc_pages(pool->gfp_mask, pool->order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static inline void dmabuf_page_pool_free_pages(struct dmabuf_page_pool *pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 					       struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	__free_pages(page, pool->order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static void dmabuf_page_pool_add(struct dmabuf_page_pool *pool, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (PageHighMem(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		index = POOL_HIGHPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		index = POOL_LOWPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	mutex_lock(&pool->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	list_add_tail(&page->lru, &pool->items[index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	pool->count[index]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	mod_node_page_state(page_pgdat(page), NR_KERNEL_MISC_RECLAIMABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			    1 << pool->order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	mutex_unlock(&pool->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static struct page *dmabuf_page_pool_remove(struct dmabuf_page_pool *pool, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	mutex_lock(&pool->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	page = list_first_entry_or_null(&pool->items[index], struct page, lru);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		pool->count[index]--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		list_del(&page->lru);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		mod_node_page_state(page_pgdat(page), NR_KERNEL_MISC_RECLAIMABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 				    -(1 << pool->order));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	mutex_unlock(&pool->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static struct page *dmabuf_page_pool_fetch(struct dmabuf_page_pool *pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct page *page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	page = dmabuf_page_pool_remove(pool, POOL_HIGHPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		page = dmabuf_page_pool_remove(pool, POOL_LOWPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) struct page *dmabuf_page_pool_alloc(struct dmabuf_page_pool *pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct page *page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (WARN_ON(!pool))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	page = dmabuf_page_pool_fetch(pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		page = dmabuf_page_pool_alloc_pages(pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) EXPORT_SYMBOL_GPL(dmabuf_page_pool_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) void dmabuf_page_pool_free(struct dmabuf_page_pool *pool, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (WARN_ON(pool->order != compound_order(page)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	dmabuf_page_pool_add(pool, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) EXPORT_SYMBOL_GPL(dmabuf_page_pool_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int dmabuf_page_pool_total(struct dmabuf_page_pool *pool, bool high)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	int count = pool->count[POOL_LOWPAGE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (high)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		count += pool->count[POOL_HIGHPAGE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return count << pool->order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct dmabuf_page_pool *dmabuf_page_pool_create(gfp_t gfp_mask, unsigned int order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct dmabuf_page_pool *pool = kmalloc(sizeof(*pool), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (!pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	for (i = 0; i < POOL_TYPE_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		pool->count[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		INIT_LIST_HEAD(&pool->items[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	pool->gfp_mask = gfp_mask | __GFP_COMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	pool->order = order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	mutex_init(&pool->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	mutex_lock(&pool_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	list_add(&pool->list, &pool_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	mutex_unlock(&pool_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	return pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) EXPORT_SYMBOL_GPL(dmabuf_page_pool_create);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) void dmabuf_page_pool_destroy(struct dmabuf_page_pool *pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* Remove us from the pool list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	mutex_lock(&pool_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	list_del(&pool->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	mutex_unlock(&pool_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	/* Free any remaining pages in the pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	for (i = 0; i < POOL_TYPE_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		while ((page = dmabuf_page_pool_remove(pool, i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			dmabuf_page_pool_free_pages(pool, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	kfree(pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) EXPORT_SYMBOL_GPL(dmabuf_page_pool_destroy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int dmabuf_page_pool_do_shrink(struct dmabuf_page_pool *pool, gfp_t gfp_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 				      int nr_to_scan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	int freed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	bool high;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (current_is_kswapd())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		high = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		high = !!(gfp_mask & __GFP_HIGHMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (nr_to_scan == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return dmabuf_page_pool_total(pool, high);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	while (freed < nr_to_scan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		/* Try to free low pages first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		page = dmabuf_page_pool_remove(pool, POOL_LOWPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			page = dmabuf_page_pool_remove(pool, POOL_HIGHPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		dmabuf_page_pool_free_pages(pool, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		freed += (1 << pool->order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return freed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static int dmabuf_page_pool_shrink(gfp_t gfp_mask, int nr_to_scan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct dmabuf_page_pool *pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	int nr_total = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	int nr_freed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	int only_scan = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (!nr_to_scan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		only_scan = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	mutex_lock(&pool_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	list_for_each_entry(pool, &pool_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		if (only_scan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			nr_total += dmabuf_page_pool_do_shrink(pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 							       gfp_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 							       nr_to_scan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			nr_freed = dmabuf_page_pool_do_shrink(pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 							      gfp_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 							      nr_to_scan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			nr_to_scan -= nr_freed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			nr_total += nr_freed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			if (nr_to_scan <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	mutex_unlock(&pool_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	return nr_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static unsigned long dmabuf_page_pool_shrink_count(struct shrinker *shrinker,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 						   struct shrink_control *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return dmabuf_page_pool_shrink(sc->gfp_mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static unsigned long dmabuf_page_pool_shrink_scan(struct shrinker *shrinker,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 						  struct shrink_control *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (sc->nr_to_scan == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	return dmabuf_page_pool_shrink(sc->gfp_mask, sc->nr_to_scan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct shrinker pool_shrinker = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	.count_objects = dmabuf_page_pool_shrink_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	.scan_objects = dmabuf_page_pool_shrink_scan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	.seeks = DEFAULT_SEEKS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	.batch = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int dmabuf_page_pool_init_shrinker(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	return register_shrinker(&pool_shrinker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) module_init(dmabuf_page_pool_init_shrinker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) MODULE_LICENSE("GPL v2");