Skip to contentSkip to conversation

rcu/kvfree: Make fill page cache start from krcp->nr_bkv_objs

PATCH Applied Zqiang 3 participants 3 messages Apr 12, 2023 – Apr 13, 2023 RCU

lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH 1/1 rcu/kvfree: Make fill page cache start from krcp->nr_bkv_objs

The fill_page_cache_func() is invoked and start from zero to allocate nr_pages of page, if the kfree_rcu_work() executes before the fill_page_cache_func(), the krcp->nr_bkv_objs is updated before enter for-loop and equal to nr_pages, since the page is allocated first, and then check the krcp->nr_bkv_objs in put_cached_bnode(), this produces a meaningless __get_free_page() call, this commit therefore make allocate page start from krcp->nr_bkv_objs and check krcp->nr_bkv_objs before allocate page.

---
 kernel/rcu/tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/tree.c +1 -1
index 41daae3239b5..dcb86f9f2dd6 100644
@@ -3223,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)
 	nr_pages = atomic_read(&krcp->backoff_page_cache_fill) ?
 		1 : rcu_min_cached_objs;
 
-	for (i = 0; i < nr_pages; i++) {
+	for (i = READ_ONCE(krcp->nr_bkv_objs); i < nr_pages; i++) {
 		bnode = (struct kvfree_rcu_bulk_data *)
 			__get_free_page(GFP_KERNEL | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN);
 
Signature · 1 line
2.32.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Zqiang

The fill_page_cache_func() is invoked and start from zero to allocate nr_pages of page, if the kfree_rcu_work() executes before the fill_page_cache_func(), the krcp->nr_bkv_objs is updated before enter for-loop and equal to nr_pages, since the page is allocated first, and then check the krcp->nr_bkv_objs in put_cached_bnode(), this produces a meaningless __get_free_page() call, this commit therefore make allocate page start from krcp->nr_bkv_objs and check krcp->nr_bkv_objs before allocate page.

---
 kernel/rcu/tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/tree.c +1 -1
index 41daae3239b5..dcb86f9f2dd6 100644
@@ -3223,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)
 	nr_pages = atomic_read(&krcp->backoff_page_cache_fill) ?
 		1 : rcu_min_cached_objs;
 
-	for (i = 0; i < nr_pages; i++) {
+	for (i = READ_ONCE(krcp->nr_bkv_objs); i < nr_pages; i++) {
 		bnode = (struct kvfree_rcu_bulk_data *)
 			__get_free_page(GFP_KERNEL | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN);
 
Signature · 1 line
2.32.0

--
Uladzislau Rezki

maintainer Applied
#2 lore raw
Quoted 28 lines · Uladzislau Rezki
Quoted 27 lines · Zqiang

The fill_page_cache_func() is invoked and start from zero to allocate nr_pages of page, if the kfree_rcu_work() executes before the fill_page_cache_func(), the krcp->nr_bkv_objs is updated before enter for-loop and equal to nr_pages, since the page is allocated first, and then check the krcp->nr_bkv_objs in put_cached_bnode(), this produces a meaningless __get_free_page() call, this commit therefore make allocate page start from krcp->nr_bkv_objs and check krcp->nr_bkv_objs before allocate page.

---
 kernel/rcu/tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/tree.c +1 -1
index 41daae3239b5..dcb86f9f2dd6 100644
@@ -3223,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)
 	nr_pages = atomic_read(&krcp->backoff_page_cache_fill) ?
 		1 : rcu_min_cached_objs;
 
-	for (i = 0; i < nr_pages; i++) {
+	for (i = READ_ONCE(krcp->nr_bkv_objs); i < nr_pages; i++) {
 		bnode = (struct kvfree_rcu_bulk_data *)
 			__get_free_page(GFP_KERNEL | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN);
 
Quoted 4 lines
Quoted 3 lines
Signature · 1 line
2.32.0

Queued and pushed, thank you both!

Thanx, Paul