Re: [PATCH v2] ION: Sys_heap: Add cached pool to spead up cached buffer alloc
Greg, I checkout your staging tree[1]. Not find this patch. Can you take it thanks! [1]git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git On 2016/6/5 23:02, Greg KH wrote: > On Sun, Jun 05, 2016 at 04:51:23PM +0800, Chen Feng wrote: >> Hi Greg, >> >> Can you take this patch? > > It's in my queue, please wait, staging patches are at the bottom of it, > rightfully so... > > thanks, > > greg k-h > > . >
Re: [PATCH v2] ION: Sys_heap: Add cached pool to spead up cached buffer alloc
Greg, I checkout your staging tree[1]. Not find this patch. Can you take it thanks! [1]git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git On 2016/6/5 23:02, Greg KH wrote: > On Sun, Jun 05, 2016 at 04:51:23PM +0800, Chen Feng wrote: >> Hi Greg, >> >> Can you take this patch? > > It's in my queue, please wait, staging patches are at the bottom of it, > rightfully so... > > thanks, > > greg k-h > > . >
Re: [PATCH v2] ION: Sys_heap: Add cached pool to spead up cached buffer alloc
On Sun, Jun 05, 2016 at 04:51:23PM +0800, Chen Feng wrote: > Hi Greg, > > Can you take this patch? It's in my queue, please wait, staging patches are at the bottom of it, rightfully so... thanks, greg k-h
Re: [PATCH v2] ION: Sys_heap: Add cached pool to spead up cached buffer alloc
On Sun, Jun 05, 2016 at 04:51:23PM +0800, Chen Feng wrote: > Hi Greg, > > Can you take this patch? It's in my queue, please wait, staging patches are at the bottom of it, rightfully so... thanks, greg k-h
Re: [PATCH v2] ION: Sys_heap: Add cached pool to spead up cached buffer alloc
Hi Greg, Can you take this patch? Thanks On 2016年05月24日 06:32, Laura Abbott wrote: > On 05/18/2016 08:03 PM, Chen Feng wrote: >> Add ion cached pool in system heap. This patch add a cached pool >> in system heap. It has a great improvement of alloc for cached >> buffer. >> >> With memory pressue alloc test 800MB in userspace used iontest. >> The result avg is 577ms. Without patch it's avg is about 883ms. >> >> v1: Makes the cached buffer zeroed before going to pool >> v2: Add cached param in pool to distinguish wheather need to flush >> cache at a fresh alloc. >> Rework the shrink function. >> >> Signed-off-by: Chen Feng>> Signed-off-by: Xia Qing >> Reviewed-by: Fu Jun > > Acked-by: Laura Abbott > >> --- >> drivers/staging/android/ion/ion_page_pool.c | 10 +- >> drivers/staging/android/ion/ion_priv.h| 5 +- >> drivers/staging/android/ion/ion_system_heap.c | 183 >> +- >> 3 files changed, 133 insertions(+), 65 deletions(-) >> >> diff --git a/drivers/staging/android/ion/ion_page_pool.c >> b/drivers/staging/android/ion/ion_page_pool.c >> index 1fe8016..2c5e5c5 100644 >> --- a/drivers/staging/android/ion/ion_page_pool.c >> +++ b/drivers/staging/android/ion/ion_page_pool.c >> @@ -30,8 +30,9 @@ static void *ion_page_pool_alloc_pages(struct >> ion_page_pool *pool) >> >> if (!page) >> return NULL; >> -ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, >> -DMA_BIDIRECTIONAL); >> +if (!pool->cached) >> +ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, >> + DMA_BIDIRECTIONAL); >> return page; >> } >> >> @@ -147,7 +148,8 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, >> gfp_t gfp_mask, >> return freed; >> } >> >> -struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int >> order) >> +struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int >> order, >> + bool cached) >> { >> struct ion_page_pool *pool = kmalloc(sizeof(*pool), GFP_KERNEL); >> >> @@ -161,6 +163,8 @@ struct ion_page_pool *ion_page_pool_create(gfp_t >> gfp_mask, unsigned int order) >> pool->order = order; >> mutex_init(>mutex); >> plist_node_init(>list, order); >> +if (cached) >> +pool->cached = true; >> >> return pool; >> } >> diff --git a/drivers/staging/android/ion/ion_priv.h >> b/drivers/staging/android/ion/ion_priv.h >> index 0239883..f3cb8b4 100644 >> --- a/drivers/staging/android/ion/ion_priv.h >> +++ b/drivers/staging/android/ion/ion_priv.h >> @@ -360,6 +360,7 @@ void ion_carveout_free(struct ion_heap *heap, >> ion_phys_addr_t addr, >> * @gfp_mask:gfp_mask to use from alloc >> * @order:order of pages in the pool >> * @list:plist node for list of pools >> + * @cached:it's cached pool or not >> * >> * Allows you to keep a pool of pre allocated pages to use from your heap. >> * Keeping a pool of pages that is ready for dma, ie any cached mapping have >> @@ -369,6 +370,7 @@ void ion_carveout_free(struct ion_heap *heap, >> ion_phys_addr_t addr, >> struct ion_page_pool { >> int high_count; >> int low_count; >> +bool cached; >> struct list_head high_items; >> struct list_head low_items; >> struct mutex mutex; >> @@ -377,7 +379,8 @@ struct ion_page_pool { >> struct plist_node list; >> }; >> >> -struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int >> order); >> +struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int >> order, >> + bool cached); >> void ion_page_pool_destroy(struct ion_page_pool *); >> struct page *ion_page_pool_alloc(struct ion_page_pool *); >> void ion_page_pool_free(struct ion_page_pool *, struct page *); >> diff --git a/drivers/staging/android/ion/ion_system_heap.c >> b/drivers/staging/android/ion/ion_system_heap.c >> index b69dfc7..32a0ebf 100644 >> --- a/drivers/staging/android/ion/ion_system_heap.c >> +++ b/drivers/staging/android/ion/ion_system_heap.c >> @@ -26,16 +26,18 @@ >> #include "ion.h" >> #include "ion_priv.h" >> >> +#define NUM_ORDERS ARRAY_SIZE(orders) >> + >> static gfp_t high_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | >> __GFP_NOWARN | >> __GFP_NORETRY) & ~__GFP_RECLAIM; >> static gfp_t low_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | >> __GFP_NOWARN); >> static const unsigned int orders[] = {8, 4, 0}; >> -static const int num_orders = ARRAY_SIZE(orders); >> + >> static int order_to_index(unsigned int order) >> { >> int i; >> >> -for (i = 0; i < num_orders; i++) >> +for (i = 0; i < NUM_ORDERS; i++) >> if (order == orders[i]) >> return i; >> BUG(); >> @@ -49,47 +51,55 @@ static inline unsigned int order_to_size(int order) >> >>
Re: [PATCH v2] ION: Sys_heap: Add cached pool to spead up cached buffer alloc
Hi Greg, Can you take this patch? Thanks On 2016年05月24日 06:32, Laura Abbott wrote: > On 05/18/2016 08:03 PM, Chen Feng wrote: >> Add ion cached pool in system heap. This patch add a cached pool >> in system heap. It has a great improvement of alloc for cached >> buffer. >> >> With memory pressue alloc test 800MB in userspace used iontest. >> The result avg is 577ms. Without patch it's avg is about 883ms. >> >> v1: Makes the cached buffer zeroed before going to pool >> v2: Add cached param in pool to distinguish wheather need to flush >> cache at a fresh alloc. >> Rework the shrink function. >> >> Signed-off-by: Chen Feng >> Signed-off-by: Xia Qing >> Reviewed-by: Fu Jun > > Acked-by: Laura Abbott > >> --- >> drivers/staging/android/ion/ion_page_pool.c | 10 +- >> drivers/staging/android/ion/ion_priv.h| 5 +- >> drivers/staging/android/ion/ion_system_heap.c | 183 >> +- >> 3 files changed, 133 insertions(+), 65 deletions(-) >> >> diff --git a/drivers/staging/android/ion/ion_page_pool.c >> b/drivers/staging/android/ion/ion_page_pool.c >> index 1fe8016..2c5e5c5 100644 >> --- a/drivers/staging/android/ion/ion_page_pool.c >> +++ b/drivers/staging/android/ion/ion_page_pool.c >> @@ -30,8 +30,9 @@ static void *ion_page_pool_alloc_pages(struct >> ion_page_pool *pool) >> >> if (!page) >> return NULL; >> -ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, >> -DMA_BIDIRECTIONAL); >> +if (!pool->cached) >> +ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, >> + DMA_BIDIRECTIONAL); >> return page; >> } >> >> @@ -147,7 +148,8 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, >> gfp_t gfp_mask, >> return freed; >> } >> >> -struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int >> order) >> +struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int >> order, >> + bool cached) >> { >> struct ion_page_pool *pool = kmalloc(sizeof(*pool), GFP_KERNEL); >> >> @@ -161,6 +163,8 @@ struct ion_page_pool *ion_page_pool_create(gfp_t >> gfp_mask, unsigned int order) >> pool->order = order; >> mutex_init(>mutex); >> plist_node_init(>list, order); >> +if (cached) >> +pool->cached = true; >> >> return pool; >> } >> diff --git a/drivers/staging/android/ion/ion_priv.h >> b/drivers/staging/android/ion/ion_priv.h >> index 0239883..f3cb8b4 100644 >> --- a/drivers/staging/android/ion/ion_priv.h >> +++ b/drivers/staging/android/ion/ion_priv.h >> @@ -360,6 +360,7 @@ void ion_carveout_free(struct ion_heap *heap, >> ion_phys_addr_t addr, >> * @gfp_mask:gfp_mask to use from alloc >> * @order:order of pages in the pool >> * @list:plist node for list of pools >> + * @cached:it's cached pool or not >> * >> * Allows you to keep a pool of pre allocated pages to use from your heap. >> * Keeping a pool of pages that is ready for dma, ie any cached mapping have >> @@ -369,6 +370,7 @@ void ion_carveout_free(struct ion_heap *heap, >> ion_phys_addr_t addr, >> struct ion_page_pool { >> int high_count; >> int low_count; >> +bool cached; >> struct list_head high_items; >> struct list_head low_items; >> struct mutex mutex; >> @@ -377,7 +379,8 @@ struct ion_page_pool { >> struct plist_node list; >> }; >> >> -struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int >> order); >> +struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int >> order, >> + bool cached); >> void ion_page_pool_destroy(struct ion_page_pool *); >> struct page *ion_page_pool_alloc(struct ion_page_pool *); >> void ion_page_pool_free(struct ion_page_pool *, struct page *); >> diff --git a/drivers/staging/android/ion/ion_system_heap.c >> b/drivers/staging/android/ion/ion_system_heap.c >> index b69dfc7..32a0ebf 100644 >> --- a/drivers/staging/android/ion/ion_system_heap.c >> +++ b/drivers/staging/android/ion/ion_system_heap.c >> @@ -26,16 +26,18 @@ >> #include "ion.h" >> #include "ion_priv.h" >> >> +#define NUM_ORDERS ARRAY_SIZE(orders) >> + >> static gfp_t high_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | >> __GFP_NOWARN | >> __GFP_NORETRY) & ~__GFP_RECLAIM; >> static gfp_t low_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | >> __GFP_NOWARN); >> static const unsigned int orders[] = {8, 4, 0}; >> -static const int num_orders = ARRAY_SIZE(orders); >> + >> static int order_to_index(unsigned int order) >> { >> int i; >> >> -for (i = 0; i < num_orders; i++) >> +for (i = 0; i < NUM_ORDERS; i++) >> if (order == orders[i]) >> return i; >> BUG(); >> @@ -49,47 +51,55 @@ static inline unsigned int order_to_size(int order) >> >> struct ion_system_heap { >> struct ion_heap heap; >> -struct ion_page_pool *pools[0]; >> +
Re: [PATCH v2] ION: Sys_heap: Add cached pool to spead up cached buffer alloc
On 05/18/2016 08:03 PM, Chen Feng wrote: Add ion cached pool in system heap. This patch add a cached pool in system heap. It has a great improvement of alloc for cached buffer. With memory pressue alloc test 800MB in userspace used iontest. The result avg is 577ms. Without patch it's avg is about 883ms. v1: Makes the cached buffer zeroed before going to pool v2: Add cached param in pool to distinguish wheather need to flush cache at a fresh alloc. Rework the shrink function. Signed-off-by: Chen FengSigned-off-by: Xia Qing Reviewed-by: Fu Jun Acked-by: Laura Abbott --- drivers/staging/android/ion/ion_page_pool.c | 10 +- drivers/staging/android/ion/ion_priv.h| 5 +- drivers/staging/android/ion/ion_system_heap.c | 183 +- 3 files changed, 133 insertions(+), 65 deletions(-) diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c index 1fe8016..2c5e5c5 100644 --- a/drivers/staging/android/ion/ion_page_pool.c +++ b/drivers/staging/android/ion/ion_page_pool.c @@ -30,8 +30,9 @@ static void *ion_page_pool_alloc_pages(struct ion_page_pool *pool) if (!page) return NULL; - ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, - DMA_BIDIRECTIONAL); + if (!pool->cached) + ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, + DMA_BIDIRECTIONAL); return page; } @@ -147,7 +148,8 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask, return freed; } -struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order) +struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order, + bool cached) { struct ion_page_pool *pool = kmalloc(sizeof(*pool), GFP_KERNEL); @@ -161,6 +163,8 @@ struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order) pool->order = order; mutex_init(>mutex); plist_node_init(>list, order); + if (cached) + pool->cached = true; return pool; } diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 0239883..f3cb8b4 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -360,6 +360,7 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, * @gfp_mask: gfp_mask to use from alloc * @order: order of pages in the pool * @list: plist node for list of pools + * @cached:it's cached pool or not * * Allows you to keep a pool of pre allocated pages to use from your heap. * Keeping a pool of pages that is ready for dma, ie any cached mapping have @@ -369,6 +370,7 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, struct ion_page_pool { int high_count; int low_count; + bool cached; struct list_head high_items; struct list_head low_items; struct mutex mutex; @@ -377,7 +379,8 @@ struct ion_page_pool { struct plist_node list; }; -struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order); +struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order, + bool cached); void ion_page_pool_destroy(struct ion_page_pool *); struct page *ion_page_pool_alloc(struct ion_page_pool *); void ion_page_pool_free(struct ion_page_pool *, struct page *); diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index b69dfc7..32a0ebf 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -26,16 +26,18 @@ #include "ion.h" #include "ion_priv.h" +#define NUM_ORDERS ARRAY_SIZE(orders) + static gfp_t high_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY) & ~__GFP_RECLAIM; static gfp_t low_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN); static const unsigned int orders[] = {8, 4, 0}; -static const int num_orders = ARRAY_SIZE(orders); + static int order_to_index(unsigned int order) { int i; - for (i = 0; i < num_orders; i++) + for (i = 0; i < NUM_ORDERS; i++) if (order == orders[i]) return i; BUG(); @@ -49,47 +51,55 @@ static inline unsigned int order_to_size(int order) struct ion_system_heap { struct ion_heap heap; - struct ion_page_pool *pools[0]; + struct ion_page_pool *uncached_pools[NUM_ORDERS]; + struct ion_page_pool *cached_pools[NUM_ORDERS]; }; +/** + * The page from page-pool are all
Re: [PATCH v2] ION: Sys_heap: Add cached pool to spead up cached buffer alloc
On 05/18/2016 08:03 PM, Chen Feng wrote: Add ion cached pool in system heap. This patch add a cached pool in system heap. It has a great improvement of alloc for cached buffer. With memory pressue alloc test 800MB in userspace used iontest. The result avg is 577ms. Without patch it's avg is about 883ms. v1: Makes the cached buffer zeroed before going to pool v2: Add cached param in pool to distinguish wheather need to flush cache at a fresh alloc. Rework the shrink function. Signed-off-by: Chen Feng Signed-off-by: Xia Qing Reviewed-by: Fu Jun Acked-by: Laura Abbott --- drivers/staging/android/ion/ion_page_pool.c | 10 +- drivers/staging/android/ion/ion_priv.h| 5 +- drivers/staging/android/ion/ion_system_heap.c | 183 +- 3 files changed, 133 insertions(+), 65 deletions(-) diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c index 1fe8016..2c5e5c5 100644 --- a/drivers/staging/android/ion/ion_page_pool.c +++ b/drivers/staging/android/ion/ion_page_pool.c @@ -30,8 +30,9 @@ static void *ion_page_pool_alloc_pages(struct ion_page_pool *pool) if (!page) return NULL; - ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, - DMA_BIDIRECTIONAL); + if (!pool->cached) + ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, + DMA_BIDIRECTIONAL); return page; } @@ -147,7 +148,8 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask, return freed; } -struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order) +struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order, + bool cached) { struct ion_page_pool *pool = kmalloc(sizeof(*pool), GFP_KERNEL); @@ -161,6 +163,8 @@ struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order) pool->order = order; mutex_init(>mutex); plist_node_init(>list, order); + if (cached) + pool->cached = true; return pool; } diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 0239883..f3cb8b4 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -360,6 +360,7 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, * @gfp_mask: gfp_mask to use from alloc * @order: order of pages in the pool * @list: plist node for list of pools + * @cached:it's cached pool or not * * Allows you to keep a pool of pre allocated pages to use from your heap. * Keeping a pool of pages that is ready for dma, ie any cached mapping have @@ -369,6 +370,7 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, struct ion_page_pool { int high_count; int low_count; + bool cached; struct list_head high_items; struct list_head low_items; struct mutex mutex; @@ -377,7 +379,8 @@ struct ion_page_pool { struct plist_node list; }; -struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order); +struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order, + bool cached); void ion_page_pool_destroy(struct ion_page_pool *); struct page *ion_page_pool_alloc(struct ion_page_pool *); void ion_page_pool_free(struct ion_page_pool *, struct page *); diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index b69dfc7..32a0ebf 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -26,16 +26,18 @@ #include "ion.h" #include "ion_priv.h" +#define NUM_ORDERS ARRAY_SIZE(orders) + static gfp_t high_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY) & ~__GFP_RECLAIM; static gfp_t low_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN); static const unsigned int orders[] = {8, 4, 0}; -static const int num_orders = ARRAY_SIZE(orders); + static int order_to_index(unsigned int order) { int i; - for (i = 0; i < num_orders; i++) + for (i = 0; i < NUM_ORDERS; i++) if (order == orders[i]) return i; BUG(); @@ -49,47 +51,55 @@ static inline unsigned int order_to_size(int order) struct ion_system_heap { struct ion_heap heap; - struct ion_page_pool *pools[0]; + struct ion_page_pool *uncached_pools[NUM_ORDERS]; + struct ion_page_pool *cached_pools[NUM_ORDERS]; }; +/** + * The page from page-pool are all zeroed before. We need do cache + * clean for cached buffer. The uncached buffer are always
[PATCH v2] ION: Sys_heap: Add cached pool to spead up cached buffer alloc
Add ion cached pool in system heap. This patch add a cached pool in system heap. It has a great improvement of alloc for cached buffer. With memory pressue alloc test 800MB in userspace used iontest. The result avg is 577ms. Without patch it's avg is about 883ms. v1: Makes the cached buffer zeroed before going to pool v2: Add cached param in pool to distinguish wheather need to flush cache at a fresh alloc. Rework the shrink function. Signed-off-by: Chen FengSigned-off-by: Xia Qing Reviewed-by: Fu Jun --- drivers/staging/android/ion/ion_page_pool.c | 10 +- drivers/staging/android/ion/ion_priv.h| 5 +- drivers/staging/android/ion/ion_system_heap.c | 183 +- 3 files changed, 133 insertions(+), 65 deletions(-) diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c index 1fe8016..2c5e5c5 100644 --- a/drivers/staging/android/ion/ion_page_pool.c +++ b/drivers/staging/android/ion/ion_page_pool.c @@ -30,8 +30,9 @@ static void *ion_page_pool_alloc_pages(struct ion_page_pool *pool) if (!page) return NULL; - ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, - DMA_BIDIRECTIONAL); + if (!pool->cached) + ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, + DMA_BIDIRECTIONAL); return page; } @@ -147,7 +148,8 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask, return freed; } -struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order) +struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order, + bool cached) { struct ion_page_pool *pool = kmalloc(sizeof(*pool), GFP_KERNEL); @@ -161,6 +163,8 @@ struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order) pool->order = order; mutex_init(>mutex); plist_node_init(>list, order); + if (cached) + pool->cached = true; return pool; } diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 0239883..f3cb8b4 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -360,6 +360,7 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, * @gfp_mask: gfp_mask to use from alloc * @order: order of pages in the pool * @list: plist node for list of pools + * @cached:it's cached pool or not * * Allows you to keep a pool of pre allocated pages to use from your heap. * Keeping a pool of pages that is ready for dma, ie any cached mapping have @@ -369,6 +370,7 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, struct ion_page_pool { int high_count; int low_count; + bool cached; struct list_head high_items; struct list_head low_items; struct mutex mutex; @@ -377,7 +379,8 @@ struct ion_page_pool { struct plist_node list; }; -struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order); +struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order, + bool cached); void ion_page_pool_destroy(struct ion_page_pool *); struct page *ion_page_pool_alloc(struct ion_page_pool *); void ion_page_pool_free(struct ion_page_pool *, struct page *); diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index b69dfc7..32a0ebf 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -26,16 +26,18 @@ #include "ion.h" #include "ion_priv.h" +#define NUM_ORDERS ARRAY_SIZE(orders) + static gfp_t high_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY) & ~__GFP_RECLAIM; static gfp_t low_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN); static const unsigned int orders[] = {8, 4, 0}; -static const int num_orders = ARRAY_SIZE(orders); + static int order_to_index(unsigned int order) { int i; - for (i = 0; i < num_orders; i++) + for (i = 0; i < NUM_ORDERS; i++) if (order == orders[i]) return i; BUG(); @@ -49,47 +51,55 @@ static inline unsigned int order_to_size(int order) struct ion_system_heap { struct ion_heap heap; - struct ion_page_pool *pools[0]; + struct ion_page_pool *uncached_pools[NUM_ORDERS]; + struct ion_page_pool *cached_pools[NUM_ORDERS]; }; +/** + * The page from page-pool are all zeroed before. We need do cache + * clean for cached buffer. The uncached buffer
[PATCH v2] ION: Sys_heap: Add cached pool to spead up cached buffer alloc
Add ion cached pool in system heap. This patch add a cached pool in system heap. It has a great improvement of alloc for cached buffer. With memory pressue alloc test 800MB in userspace used iontest. The result avg is 577ms. Without patch it's avg is about 883ms. v1: Makes the cached buffer zeroed before going to pool v2: Add cached param in pool to distinguish wheather need to flush cache at a fresh alloc. Rework the shrink function. Signed-off-by: Chen Feng Signed-off-by: Xia Qing Reviewed-by: Fu Jun --- drivers/staging/android/ion/ion_page_pool.c | 10 +- drivers/staging/android/ion/ion_priv.h| 5 +- drivers/staging/android/ion/ion_system_heap.c | 183 +- 3 files changed, 133 insertions(+), 65 deletions(-) diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c index 1fe8016..2c5e5c5 100644 --- a/drivers/staging/android/ion/ion_page_pool.c +++ b/drivers/staging/android/ion/ion_page_pool.c @@ -30,8 +30,9 @@ static void *ion_page_pool_alloc_pages(struct ion_page_pool *pool) if (!page) return NULL; - ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, - DMA_BIDIRECTIONAL); + if (!pool->cached) + ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, + DMA_BIDIRECTIONAL); return page; } @@ -147,7 +148,8 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask, return freed; } -struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order) +struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order, + bool cached) { struct ion_page_pool *pool = kmalloc(sizeof(*pool), GFP_KERNEL); @@ -161,6 +163,8 @@ struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order) pool->order = order; mutex_init(>mutex); plist_node_init(>list, order); + if (cached) + pool->cached = true; return pool; } diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 0239883..f3cb8b4 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -360,6 +360,7 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, * @gfp_mask: gfp_mask to use from alloc * @order: order of pages in the pool * @list: plist node for list of pools + * @cached:it's cached pool or not * * Allows you to keep a pool of pre allocated pages to use from your heap. * Keeping a pool of pages that is ready for dma, ie any cached mapping have @@ -369,6 +370,7 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, struct ion_page_pool { int high_count; int low_count; + bool cached; struct list_head high_items; struct list_head low_items; struct mutex mutex; @@ -377,7 +379,8 @@ struct ion_page_pool { struct plist_node list; }; -struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order); +struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order, + bool cached); void ion_page_pool_destroy(struct ion_page_pool *); struct page *ion_page_pool_alloc(struct ion_page_pool *); void ion_page_pool_free(struct ion_page_pool *, struct page *); diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index b69dfc7..32a0ebf 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -26,16 +26,18 @@ #include "ion.h" #include "ion_priv.h" +#define NUM_ORDERS ARRAY_SIZE(orders) + static gfp_t high_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY) & ~__GFP_RECLAIM; static gfp_t low_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN); static const unsigned int orders[] = {8, 4, 0}; -static const int num_orders = ARRAY_SIZE(orders); + static int order_to_index(unsigned int order) { int i; - for (i = 0; i < num_orders; i++) + for (i = 0; i < NUM_ORDERS; i++) if (order == orders[i]) return i; BUG(); @@ -49,47 +51,55 @@ static inline unsigned int order_to_size(int order) struct ion_system_heap { struct ion_heap heap; - struct ion_page_pool *pools[0]; + struct ion_page_pool *uncached_pools[NUM_ORDERS]; + struct ion_page_pool *cached_pools[NUM_ORDERS]; }; +/** + * The page from page-pool are all zeroed before. We need do cache + * clean for cached buffer. The uncached buffer are always non-cached + * since it's allocated. So no need for non-cached