page_pool: refill page when alloc.count of pool is zero
Subsystems (3)
PATCH v2 1/1 page_pool: refill page when alloc.count of pool is zero
"do {} while" in page_pool_refill_alloc_cache will always refill page once whether refill is true or false, and whether alloc.count of pool is less than PP_ALLOC_CACHE_REFILL or not this is wrong, and will cause overflow of pool->alloc.cache
the caller of __page_pool_get_cached should provide guarantee that pool->alloc.cache is safe to access, so in_serving_softirq should be removed as suggested by Jesper Dangaard Brouer in
https://patchwork.ozlabs.org/patch/1233713/
so fix this issue by calling page_pool_refill_alloc_cache() only when pool->alloc.count is zero
Suggested: Jesper Dangaard Brouer <[email protected]>
---
v1-->v2: remove the in_serving_softirq test
net/core/page_pool.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)
net/core/page_pool.c +8 -14
@@ -99,8 +99,7 @@ EXPORT_SYMBOL(page_pool_create);static void __page_pool_return_page (struct page_pool *pool,struct page *page);noinline -static struct page *page_pool_refill_alloc_cache(struct page_pool *pool, -bool refill) +static struct page *page_pool_refill_alloc_cache(struct page_pool *pool) {struct ptr_ring *r = &pool->ring;struct page *page;
@@ -141,8 +140,7 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool, page =NULL ;break ; } - }while (pool->alloc.count <PP_ALLOC_CACHE_REFILL && - refill); + }while (pool->alloc.count <PP_ALLOC_CACHE_REFILL );/* Return last page */ if (likely (pool->alloc.count >0 ))
@@ -155,20 +153,16 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool,/* fast path */ static struct page *__page_pool_get_cached (struct page_pool *pool) { -bool refill = false;struct page *page; -/* Test for safe-context, caller should provide this guarantee */ -if (likely (in_serving_softirq ())) { -if (likely (pool->alloc.count)) { -/* Fast-path */ - page = pool->alloc.cache[--pool->alloc.count]; -return page; - } - refill = true; +/* Caller MUST guarantee safe non-concurrent access, e.g. softirq */ +if (likely (pool->alloc.count)) { +/* Fast-path */ + page = pool->alloc.cache[--pool->alloc.count]; + }else { + page =page_pool_refill_alloc_cache (pool); } - page =page_pool_refill_alloc_cache (pool, refill);return page; }
Signature · 1 line
2.16.2
Ilias Apalodimas
maintainerHi Li,
Quoted 5 lines · Li RongQing
"do {} while" in
page_pool_refill_alloc_cachewill always refill page once whether refill is true or false, and whether alloc.count of pool is less thanPP_ALLOC_CACHE_REFILLor not this is wrong, and will cause overflow ofpool->alloc.cache
Quoted 7 lines
the caller of
__page_pool_get_cachedshould provide guarantee thatpool->alloc.cacheis safe to access, soin_serving_softirqshould be removed as suggested by Jesper Dangaard Brouer in
https://patchwork.ozlabs.org/patch/1233713/so fix this issue by calling
page_pool_refill_alloc_cache()only whenpool->alloc.countis zero
Please include me on any future mails regarding pate pool. I almost missed this one
Thanks
/Ilias
Quoted 64 lines
Fixes 44768decb7c0 ("page_pool: handle page recycle for NUMA_NO_NODE condition")Signed-off-by Li RongQing <[email protected]>Suggested: Jesper Dangaard Brouer <[email protected]>
---
v1-->v2: remove thein_serving_softirqtestnet/core/page_pool.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)net/core/page_pool.c +8
-14@@ -99,8 +99,7 @@ EXPORT_SYMBOL(page_pool_create);static void __page_pool_return_page (struct page_pool *pool,struct page *page);noinline -static struct page *page_pool_refill_alloc_cache(struct page_pool *pool, -bool refill) +static struct page *page_pool_refill_alloc_cache(struct page_pool *pool) {struct ptr_ring *r = &pool->ring;struct page *page;@@ -141,8 +140,7 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool, page =NULL ;break ; } - }while (pool->alloc.count <PP_ALLOC_CACHE_REFILL && - refill); + }while (pool->alloc.count <PP_ALLOC_CACHE_REFILL );/* Return last page */ if (likely (pool->alloc.count >0 ))@@ -155,20 +153,16 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool,/* fast path */ static struct page *__page_pool_get_cached (struct page_pool *pool) { -bool refill = false;struct page *page; -/* Test for safe-context, caller should provide this guarantee */ -if (likely (in_serving_softirq ())) { -if (likely (pool->alloc.count)) { -/* Fast-path */ - page = pool->alloc.cache[--pool->alloc.count]; -return page; - } - refill = true; +/* Caller MUST guarantee safe non-concurrent access, e.g. softirq */ +if (likely (pool->alloc.count)) { +/* Fast-path */ + page = pool->alloc.cache[--pool->alloc.count]; + }else { + page =page_pool_refill_alloc_cache (pool); } - page =page_pool_refill_alloc_cache (pool, refill);return page; }Signature · 1 line
2.16.2
Quoted 10 lines · On Tue, 11 Feb 2020 10:13:44 +0800 Li RongQing <[email protected]> wrote:
"do {} while" in
page_pool_refill_alloc_cachewill always refill page once whether refill is true or false, and whether alloc.count of pool is less thanPP_ALLOC_CACHE_REFILLor not this is wrong, and will cause overflow ofpool->alloc.cachethe caller of
__page_pool_get_cachedshould provide guarantee thatpool->alloc.cacheis safe to access, soin_serving_softirqshould be removed as suggested by Jesper Dangaard Brouer in
https://patchwork.ozlabs.org/patch/1233713/
Quoted 6 lines
so fix this issue by calling
page_pool_refill_alloc_cache()only whenpool->alloc.countis zeroFixes 44768decb7c0 ("page_pool: handle page recycle for NUMA_NO_NODE condition")Signed-off-by Li RongQing <[email protected]>Suggested: Jesper Dangaard Brouer <[email protected]>
You forgot the "-by" part of "suggested-by:", added it below so patchwork pick it up.
Quoted 2 lines
---
v1-->v2: remove thein_serving_softirqtest
I've tested the patch and gave it some exercise with my page_pool benchmarks tools, everything looked good.
Quoted 54 lines
net/core/page_pool.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)net/core/page_pool.c +8
-14@@ -99,8 +99,7 @@ EXPORT_SYMBOL(page_pool_create);static void __page_pool_return_page (struct page_pool *pool,struct page *page);noinline -static struct page *page_pool_refill_alloc_cache(struct page_pool *pool, -bool refill) +static struct page *page_pool_refill_alloc_cache(struct page_pool *pool) {struct ptr_ring *r = &pool->ring;struct page *page;@@ -141,8 +140,7 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool, page =NULL ;break ; } - }while (pool->alloc.count <PP_ALLOC_CACHE_REFILL && - refill); + }while (pool->alloc.count <PP_ALLOC_CACHE_REFILL );/* Return last page */ if (likely (pool->alloc.count >0 ))@@ -155,20 +153,16 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool,/* fast path */ static struct page *__page_pool_get_cached (struct page_pool *pool) { -bool refill = false;struct page *page; -/* Test for safe-context, caller should provide this guarantee */ -if (likely (in_serving_softirq ())) { -if (likely (pool->alloc.count)) { -/* Fast-path */ - page = pool->alloc.cache[--pool->alloc.count]; -return page; - } - refill = true; +/* Caller MUST guarantee safe non-concurrent access, e.g. softirq */ +if (likely (pool->alloc.count)) { +/* Fast-path */ + page = pool->alloc.cache[--pool->alloc.count]; + }else { + page =page_pool_refill_alloc_cache (pool); } - page =page_pool_refill_alloc_cache (pool, refill);return page; }
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Quoted 76 lines · Li RongQing
"do {} while" in
page_pool_refill_alloc_cachewill always refill page once whether refill is true or false, and whether alloc.count of pool is less thanPP_ALLOC_CACHE_REFILLor not this is wrong, and will cause overflow ofpool->alloc.cachethe caller of
__page_pool_get_cachedshould provide guarantee thatpool->alloc.cacheis safe to access, soin_serving_softirqshould be removed as suggested by Jesper Dangaard Brouer in
https://patchwork.ozlabs.org/patch/1233713/so fix this issue by calling
page_pool_refill_alloc_cache()only whenpool->alloc.countis zeroFixes 44768decb7c0 ("page_pool: handle page recycle for NUMA_NO_NODE condition")Signed-off-by Li RongQing <[email protected]>Suggested: Jesper Dangaard Brouer <[email protected]>
---
v1-->v2: remove thein_serving_softirqtestnet/core/page_pool.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)net/core/page_pool.c +8
-14@@ -99,8 +99,7 @@ EXPORT_SYMBOL(page_pool_create);static void __page_pool_return_page (struct page_pool *pool,struct page *page);noinline -static struct page *page_pool_refill_alloc_cache(struct page_pool *pool, -bool refill) +static struct page *page_pool_refill_alloc_cache(struct page_pool *pool) {struct ptr_ring *r = &pool->ring;struct page *page;@@ -141,8 +140,7 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool, page =NULL ;break ; } - }while (pool->alloc.count <PP_ALLOC_CACHE_REFILL && - refill); + }while (pool->alloc.count <PP_ALLOC_CACHE_REFILL );/* Return last page */ if (likely (pool->alloc.count >0 ))@@ -155,20 +153,16 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool,/* fast path */ static struct page *__page_pool_get_cached (struct page_pool *pool) { -bool refill = false;struct page *page; -/* Test for safe-context, caller should provide this guarantee */ -if (likely (in_serving_softirq ())) { -if (likely (pool->alloc.count)) { -/* Fast-path */ - page = pool->alloc.cache[--pool->alloc.count]; -return page; - } - refill = true; +/* Caller MUST guarantee safe non-concurrent access, e.g. softirq */ +if (likely (pool->alloc.count)) { +/* Fast-path */ + page = pool->alloc.cache[--pool->alloc.count]; + }else { + page =page_pool_refill_alloc_cache (pool); } - page =page_pool_refill_alloc_cache (pool, refill);return page; }Signature · 1 line
2.16.2