Skip to contentSkip to conversation

rcu/kvfree: Prevents cache growing when the backoff_page_cache_fill is set

PATCH In review Zqiang 2 participants 3 messages Apr 11, 2023 – Apr 12, 2023 RCU

lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH v4 1/1 rcu/kvfree: Prevents cache growing when the backoff_page_cache_fill is set

Currently, in kfree_rcu_shrink_scan(), the drain_page_cache() is executed before kfree_rcu_monitor() to drain page cache, if the bnode structure's->gp_snap has done, the kvfree_rcu_bulk() will fill the page cache again in kfree_rcu_monitor(), this commit add a check for krcp structure's->backoff_page_cache_fill in put_cached_bnode(), if the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and start fill page from krcp->nr_bkv_objs, if the krcp->nr_bkv_objs is greater or equal to nr_pages, not alloc page, avoid unnecessary __get_free_page() calls.

---
 kernel/rcu/tree.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/rcu/tree.c +3 -1
index 41daae3239b5..d5639025bd1a 100644
@@ -2908,6 +2908,8 @@ static inline bool
 put_cached_bnode(struct kfree_rcu_cpu *krcp,
 	struct kvfree_rcu_bulk_data *bnode)
 {
+	if (atomic_read(&krcp->backoff_page_cache_fill))
+		return false;
 	// Check the limit.
 	if (krcp->nr_bkv_objs >= rcu_min_cached_objs)
 		return false;
@@ -3223,7 +3225,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 = 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
#1 lore raw
Quoted 20 lines · Zqiang

Currently, in kfree_rcu_shrink_scan(), the drain_page_cache() is executed before kfree_rcu_monitor() to drain page cache, if the bnode structure's->gp_snap has done, the kvfree_rcu_bulk() will fill the page cache again in kfree_rcu_monitor(), this commit add a check for krcp structure's->backoff_page_cache_fill in put_cached_bnode(), if the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and start fill page from krcp->nr_bkv_objs, if the krcp->nr_bkv_objs is greater or equal to nr_pages, not alloc page, avoid unnecessary __get_free_page() calls.

---
 kernel/rcu/tree.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/rcu/tree.c +0 -0
index 41daae3239b5..d5639025bd1a 100644

kernel/rcu/tree.c static inline bool · line 2912

Quoted 5 lines
kernel/rcu/tree.c +2 -0
@@ -2908,6 +2908,8 @@ static inline bool
 put_cached_bnode(struct kfree_rcu_cpu *krcp,
 	struct kvfree_rcu_bulk_data *bnode)
 {
+	if (atomic_read(&krcp->backoff_page_cache_fill))
+		return false;

This one is still missing the logic that allows that cache to hold one page during low memory? Or is that being handled somewhere else?

Thanx, Paul

Quoted 15 lines
kernel/rcu/tree.c +1 -1
 	// Check the limit.
 	if (krcp->nr_bkv_objs >= rcu_min_cached_objs)
 		return false;
@@ -3223,7 +3225,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 = 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
#2 lore raw
Quoted 26 lines

Currently, in kfree_rcu_shrink_scan(), the drain_page_cache() is executed before kfree_rcu_monitor() to drain page cache, if the bnode structure's->gp_snap has done, the kvfree_rcu_bulk() will fill the page cache again in kfree_rcu_monitor(), this commit add a check for krcp structure's->backoff_page_cache_fill in put_cached_bnode(), if the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and start fill page from krcp->nr_bkv_objs, if the krcp->nr_bkv_objs is greater or equal to nr_pages, not alloc page, avoid unnecessary __get_free_page() calls.

---
 kernel/rcu/tree.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/rcu/tree.c +2 -0
index 41daae3239b5..d5639025bd1a 100644
@@ -2908,6 +2908,8 @@ static inline bool
 put_cached_bnode(struct kfree_rcu_cpu *krcp,
 	struct kvfree_rcu_bulk_data *bnode)
 {
+	if (atomic_read(&krcp->backoff_page_cache_fill))
+		return false;
 
Quoted 3 lines

This one is still missing the logic that allows that cache to hold one page during low memory? Or is that being handled somewhere else?

Sorry, please ignore this patch, I will resend as suggested by Ulad, thanks for review😊.

Quoted 18 lines

Thanx, Paul

kernel/rcu/tree.c +1 -1
 	// Check the limit.
 	if (krcp->nr_bkv_objs >= rcu_min_cached_objs)
 		return false;
@@ -3223,7 +3225,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 = 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