ANDROID: dma-buf: heaps: Move dmabuf_page_pool struct out of the KMI

Users of dmabuf_page_pool should not need to refer to its fields, so
hide them from the KMI. Add dmabuf_page_pool_get_size to fullfill the
needs of users. Update the system_heap to use the new API.

Bug: 264474028
Bug: 275698445
Change-Id: I848ff52e73a13568f561deeb6aea48f40dc0960b
Signed-off-by: T.J. Mercier <tjmercier@google.com>
This commit is contained in:
T.J. Mercier
2023-03-21 19:55:15 +00:00
committed by Carlos Llamas
parent 754ba89a30
commit 7a3538cd40
3 changed files with 53 additions and 37 deletions

View File

@@ -16,6 +16,35 @@
#include <linux/swap.h>
#include <linux/sched/signal.h>
/* page types we track in the pool */
enum {
POOL_LOWPAGE, /* Clean lowmem pages */
POOL_HIGHPAGE, /* Clean highmem pages */
POOL_TYPE_SIZE,
};
/**
* struct dmabuf_page_pool - pagepool struct
* @count[]: array of number of pages of that type in the pool
* @items[]: array of list of pages of the specific type
* @lock: lock protecting this struct and especially the count
* item list
* @gfp_mask: gfp_mask to use from alloc
* @order: order of pages in the pool
* @list: list node for list of pools
*
* Allows you to keep a pool of pre allocated pages to use
*/
struct dmabuf_page_pool {
int count[POOL_TYPE_SIZE];
struct list_head items[POOL_TYPE_SIZE];
struct spinlock lock;
gfp_t gfp_mask;
unsigned int order;
struct list_head list;
};
static LIST_HEAD(pool_list);
static DEFINE_MUTEX(pool_list_lock);
@@ -158,6 +187,21 @@ void dmabuf_page_pool_destroy(struct dmabuf_page_pool *pool)
}
EXPORT_SYMBOL_GPL(dmabuf_page_pool_destroy);
unsigned long dmabuf_page_pool_get_size(struct dmabuf_page_pool *pool)
{
int i;
unsigned long num_pages = 0;
spin_lock(&pool->lock);
for (i = 0; i < POOL_TYPE_SIZE; ++i)
num_pages += pool->count[i];
spin_unlock(&pool->lock);
num_pages <<= pool->order; /* pool order is immutable */
return num_pages * PAGE_SIZE;
}
EXPORT_SYMBOL_GPL(dmabuf_page_pool_get_size);
static int dmabuf_page_pool_do_shrink(struct dmabuf_page_pool *pool, gfp_t gfp_mask,
int nr_to_scan)
{

View File

@@ -11,37 +11,9 @@
#define _DMABUF_PAGE_POOL_H
#include <linux/mm_types.h>
#include <linux/spinlock_types.h>
#include <linux/types.h>
/* page types we track in the pool */
enum {
POOL_LOWPAGE, /* Clean lowmem pages */
POOL_HIGHPAGE, /* Clean highmem pages */
POOL_TYPE_SIZE,
};
/**
* struct dmabuf_page_pool - pagepool struct
* @count[]: array of number of pages of that type in the pool
* @items[]: array of list of pages of the specific type
* @lock: lock protecting this struct and especially the count
* item list
* @gfp_mask: gfp_mask to use from alloc
* @order: order of pages in the pool
* @list: list node for list of pools
*
* Allows you to keep a pool of pre allocated pages to use
*/
struct dmabuf_page_pool {
int count[POOL_TYPE_SIZE];
struct list_head items[POOL_TYPE_SIZE];
struct spinlock lock;
gfp_t gfp_mask;
unsigned int order;
struct list_head list;
};
struct dmabuf_page_pool;
struct dmabuf_page_pool *dmabuf_page_pool_create(gfp_t gfp_mask,
unsigned int order);
@@ -49,4 +21,7 @@ void dmabuf_page_pool_destroy(struct dmabuf_page_pool *pool);
struct page *dmabuf_page_pool_alloc(struct dmabuf_page_pool *pool);
void dmabuf_page_pool_free(struct dmabuf_page_pool *pool, struct page *page);
/* get pool size in bytes */
unsigned long dmabuf_page_pool_get_size(struct dmabuf_page_pool *pool);
#endif /* _DMABUF_PAGE_POOL_H */

View File

@@ -493,16 +493,13 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
static long system_get_pool_size(struct dma_heap *heap)
{
int i;
long num_pages = 0;
struct dmabuf_page_pool **pool;
unsigned long num_bytes = 0;
struct dmabuf_page_pool **pool = pools;
pool = pools;
for (i = 0; i < NUM_ORDERS; i++, pool++) {
num_pages += ((*pool)->count[POOL_LOWPAGE] +
(*pool)->count[POOL_HIGHPAGE]) << (*pool)->order;
}
for (i = 0; i < NUM_ORDERS; i++, pool++)
num_bytes += dmabuf_page_pool_get_size(*pool);
return num_pages << PAGE_SHIFT;
return num_bytes;
}
static const struct dma_heap_ops system_heap_ops = {