rcu/kvfree: Prevents cache growing when the backoff_page_cache_fill is set
PATCH v3 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 disable allocated page in fill_page_cache_func().
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/rcu/tree.c +3 -1
@@ -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;
@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) { bnode = (struct kvfree_rcu_bulk_data *)
Signature · 1 line
2.32.0
Paul E. McKenney
maintainerQuoted 9 lines · Zqiang
Currently, in
kfree_rcu_shrink_scan(), thedrain_page_cache()is executed beforekfree_rcu_monitor()to drain page cache, if the bnode structure's->gp_snap has done, thekvfree_rcu_bulk()will fill the page cache again inkfree_rcu_monitor(), this commit add a check for krcp structure's->backoff_page_cache_fill input_cached_bnode(), if the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and disable allocated page infill_page_cache_func().Signed-off-by Zqiang <[email protected]>
Much improved! But still some questions below...
Thanx, Paul
Quoted 9 lines
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/rcu/tree.c +0
-0
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 will mean that under low-memory conditions, we will keep zero pages in ->bkvcache. All attempts to put something there will fail.
This is probably not an issue for structures containing an rcu_head that are passed to kfree_rcu(p, field), but doesn't this mean that kfree_rcu_mightsleep() unconditionally invokes synchronize_rcu()? This could seriously slow up freeing under low-memory conditions, which might exacerbate the low-memory conditions.
Is this really what we want? Zero cached rather than just fewer cached?
kernel/rcu/tree.c static void fill_page_cache_func(struct work_struct *work) · line 3228
Quoted 11 lines
kernel/rcu/tree.c +1
-1// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) {
I am still confused as to why we start "i" at zero rather than at ->nr_bkv_objs. What am I missing here?
Quoted 4 lines
kernel/rcu/tree.c +0
-0bnode = (struct kvfree_rcu_bulk_data *)Signature · 1 line
2.32.0
Quoted 32 lines
Currently, in
kfree_rcu_shrink_scan(), thedrain_page_cache()is executed beforekfree_rcu_monitor()to drain page cache, if the bnode structure's->gp_snap has done, thekvfree_rcu_bulk()will fill the page cache again inkfree_rcu_monitor(), this commit add a check for krcp structure's->backoff_page_cache_fill input_cached_bnode(), if the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and disable allocated page infill_page_cache_func().Signed-off-by Zqiang <[email protected]>Much improved! But still some questions below...
Thanx, Paul
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)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 will mean that under low-memory conditions, we will keep zero pages in ->bkvcache. All attempts to put something there will fail.
Quoted 5 lines
This is probably not an issue for structures containing an
rcu_headthat are passed tokfree_rcu(p, field), but doesn't this mean thatkfree_rcu_mightsleep()unconditionally invokessynchronize_rcu()? This could seriously slow up freeing under low-memory conditions, which might exacerbate the low-memory conditions.
Thanks for mentioning this, I didn't think of this before😊.
Quoted 17 lines
Is this really what we want? Zero cached rather than just fewer cached?
kernel/rcu/tree.c +1
-1// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) {
Quoted 2 lines
I am still confused as to why we start "i" at zero rather than at ->nr_bkv_objs. What am I missing here?
No, you are right, I missed this place.
kernel/rcu/tree.c +3 -1
@@ -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);
thoughts?
Thanks
Zqiang
Quoted 5 lines
bnode = (struct
kvfree_rcu_bulk_data*)Signature · 1 line
2.32.0
Uladzislau Rezki
maintainerQuoted 66 lines · On Tue, Apr 11, 2023 at 04:04:45AM +0000, Zhang, Qiang1 wrote:
Quoted 32 lines
Currently, in
kfree_rcu_shrink_scan(), thedrain_page_cache()is executed beforekfree_rcu_monitor()to drain page cache, if the bnode structure's->gp_snap has done, thekvfree_rcu_bulk()will fill the page cache again inkfree_rcu_monitor(), this commit add a check for krcp structure's->backoff_page_cache_fill input_cached_bnode(), if the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and disable allocated page infill_page_cache_func().Signed-off-by Zqiang <[email protected]>Much improved! But still some questions below...
Thanx, Paul
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)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 will mean that under low-memory conditions, we will keep zero pages in ->bkvcache. All attempts to put something there will fail.
Quoted 5 lines
This is probably not an issue for structures containing an
rcu_headthat are passed tokfree_rcu(p, field), but doesn't this mean thatkfree_rcu_mightsleep()unconditionally invokessynchronize_rcu()? This could seriously slow up freeing under low-memory conditions, which might exacerbate the low-memory conditions.Thanks for mentioning this, I didn't think of this before😊.
Quoted 17 lines
Is this really what we want? Zero cached rather than just fewer cached?
kernel/rcu/tree.c +1
-1// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) {Quoted 2 lines
I am still confused as to why we start "i" at zero rather than at ->nr_bkv_objs. What am I missing here?
No, you are right, I missed this place.
kernel/rcu/tree.c static inline bool · line 2913
Quoted 6 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 is broken, unfortunately. If a low memory condition we fill fill a cache with at least one page anyway because of we do not want to hit a slow path.
kernel/rcu/tree.c static void fill_page_cache_func(struct work_struct *work) · line 3231
Quoted 13 lines
kernel/rcu/tree.c +0
-0// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;kernel/rcu/tree.c +1
-1@@ -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);
IMHO, it should be send as a separate patch explaining why it it is needed.
--
Uladzislau Rezki
Quoted 72 lines
Quoted 32 lines
Currently, in
kfree_rcu_shrink_scan(), thedrain_page_cache()is executed beforekfree_rcu_monitor()to drain page cache, if the bnode structure's->gp_snap has done, thekvfree_rcu_bulk()will fill the page cache again inkfree_rcu_monitor(), this commit add a check for krcp structure's->backoff_page_cache_fill input_cached_bnode(), if the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and disable allocated page infill_page_cache_func().Signed-off-by Zqiang <[email protected]>Much improved! But still some questions below...
Thanx, Paul
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)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 will mean that under low-memory conditions, we will keep zero pages in ->bkvcache. All attempts to put something there will fail.
Quoted 5 lines
This is probably not an issue for structures containing an
rcu_headthat are passed tokfree_rcu(p, field), but doesn't this mean thatkfree_rcu_mightsleep()unconditionally invokessynchronize_rcu()? This could seriously slow up freeing under low-memory conditions, which might exacerbate the low-memory conditions.Thanks for mentioning this, I didn't think of this before😊.
Quoted 17 lines
Is this really what we want? Zero cached rather than just fewer cached?
kernel/rcu/tree.c +1
-1// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) {Quoted 2 lines
I am still confused as to why we start "i" at zero rather than at ->nr_bkv_objs. What am I missing here?
No, you are right, I missed this place.
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;
Quoted 3 lines
This is broken, unfortunately. If a low memory condition we fill fill a cache with at least one page anyway because of we do not want to hit a slow path.
Thanks remind, please ignore my v4 patch, how about the following?
kernel/rcu/tree.c +3 -0
@@ -3238,6 +3238,9 @@ static void fill_page_cache_func(struct work_struct *work)free_page ((unsigned long ) bnode);break ; } + +if (atomic_read (&krcp->backoff_page_cache_fill)) +break ; }atomic_set (&krcp->work_in_progress,0 );
Quoted 14 lines
// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs) return false;kernel/rcu/tree.c +1
-1@@ -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);
Quoted 2 lines
IMHO, it should be send as a separate patch explaining why it it is needed.
Agree.
Thanks
Zqiang
Quoted 3 lines
--
Uladzislau Rezki
Uladzislau Rezki
maintainerQuoted 83 lines · On Tue, Apr 11, 2023 at 02:42:27PM +0000, Zhang, Qiang1 wrote:
Quoted 72 lines
Quoted 32 lines
Currently, in
kfree_rcu_shrink_scan(), thedrain_page_cache()is executed beforekfree_rcu_monitor()to drain page cache, if the bnode structure's->gp_snap has done, thekvfree_rcu_bulk()will fill the page cache again inkfree_rcu_monitor(), this commit add a check for krcp structure's->backoff_page_cache_fill input_cached_bnode(), if the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and disable allocated page infill_page_cache_func().Signed-off-by Zqiang <[email protected]>Much improved! But still some questions below...
Thanx, Paul
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)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 will mean that under low-memory conditions, we will keep zero pages in ->bkvcache. All attempts to put something there will fail.
Quoted 5 lines
This is probably not an issue for structures containing an
rcu_headthat are passed tokfree_rcu(p, field), but doesn't this mean thatkfree_rcu_mightsleep()unconditionally invokessynchronize_rcu()? This could seriously slow up freeing under low-memory conditions, which might exacerbate the low-memory conditions.Thanks for mentioning this, I didn't think of this before😊.
Quoted 17 lines
Is this really what we want? Zero cached rather than just fewer cached?
kernel/rcu/tree.c +1
-1// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) {Quoted 2 lines
I am still confused as to why we start "i" at zero rather than at ->nr_bkv_objs. What am I missing here?
No, you are right, I missed this place.
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;Quoted 3 lines
This is broken, unfortunately. If a low memory condition we fill fill a cache with at least one page anyway because of we do not want to hit a slow path.
Thanks remind, please ignore my v4 patch, how about the following?
kernel/rcu/tree.c +0
-0
kernel/rcu/tree.c static void fill_page_cache_func(struct work_struct *work) · line 3244
Quoted 7 lines
kernel/rcu/tree.c +3
-0@@ -3238,6 +3238,9 @@ static void fill_page_cache_func(struct work_struct *work)free_page ((unsigned long ) bnode);break ; } + +if (atomic_read (&krcp->backoff_page_cache_fill)) +break ; }
It does not fix an "issue" you are reporting. kvfree_rcu_bulk() function can still fill it back. IMHO, the solution here is to disable cache if a low memory condition and enable back later on.
The cache size is controlled by the rcu_min_cached_objs variable. We can set it to 1 and restore it back to original value to make the cache operating as before.
--
Uladzislau Rezki
Quoted 95 lines
Quoted 72 lines
Quoted 32 lines
Currently, in
kfree_rcu_shrink_scan(), thedrain_page_cache()is executed beforekfree_rcu_monitor()to drain page cache, if the bnode structure's->gp_snap has done, thekvfree_rcu_bulk()will fill the page cache again inkfree_rcu_monitor(), this commit add a check for krcp structure's->backoff_page_cache_fill input_cached_bnode(), if the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and disable allocated page infill_page_cache_func().Signed-off-by Zqiang <[email protected]>Much improved! But still some questions below...
Thanx, Paul
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)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 will mean that under low-memory conditions, we will keep zero pages in ->bkvcache. All attempts to put something there will fail.
Quoted 5 lines
This is probably not an issue for structures containing an
rcu_headthat are passed tokfree_rcu(p, field), but doesn't this mean thatkfree_rcu_mightsleep()unconditionally invokessynchronize_rcu()? This could seriously slow up freeing under low-memory conditions, which might exacerbate the low-memory conditions.Thanks for mentioning this, I didn't think of this before😊.
Quoted 17 lines
Is this really what we want? Zero cached rather than just fewer cached?
kernel/rcu/tree.c +1
-1// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) {Quoted 2 lines
I am still confused as to why we start "i" at zero rather than at ->nr_bkv_objs. What am I missing here?
No, you are right, I missed this place.
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;Quoted 3 lines
This is broken, unfortunately. If a low memory condition we fill fill a cache with at least one page anyway because of we do not want to hit a slow path.
Thanks remind, please ignore my v4 patch, how about the following?
kernel/rcu/tree.c +3
-0@@ -3238,6 +3238,9 @@ static void fill_page_cache_func(struct work_struct *work)free_page ((unsigned long ) bnode);break ; } + +if (atomic_read (&krcp->backoff_page_cache_fill)) +break ; }It does not fix an "issue" you are reporting.
kvfree_rcu_bulk()function can still fill it back. IMHO, the solution here is to disable cache if a low memory condition and enable back later on.
Quoted 3 lines
The cache size is controlled by the
rcu_min_cached_objsvariable. We can set it to 1 and restore it back to original value to make the cache operating as before.
A good suggestion. a question, when need to restore rcu_min_cached_objs? after the execution of kfree_rcu_shrink_scan() ends?
Thanks
Zqiang
Quoted 3 lines
--
Uladzislau Rezki
Uladzislau Rezki
maintainerQuoted 95 lines · On Tue, Apr 11, 2023 at 03:09:13PM +0000, Zhang, Qiang1 wrote:
Quoted 95 lines
Quoted 72 lines
Quoted 32 lines
Currently, in
kfree_rcu_shrink_scan(), thedrain_page_cache()is executed beforekfree_rcu_monitor()to drain page cache, if the bnode structure's->gp_snap has done, thekvfree_rcu_bulk()will fill the page cache again inkfree_rcu_monitor(), this commit add a check for krcp structure's->backoff_page_cache_fill input_cached_bnode(), if the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and disable allocated page infill_page_cache_func().Signed-off-by Zqiang <[email protected]>Much improved! But still some questions below...
Thanx, Paul
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)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 will mean that under low-memory conditions, we will keep zero pages in ->bkvcache. All attempts to put something there will fail.
Quoted 5 lines
This is probably not an issue for structures containing an
rcu_headthat are passed tokfree_rcu(p, field), but doesn't this mean thatkfree_rcu_mightsleep()unconditionally invokessynchronize_rcu()? This could seriously slow up freeing under low-memory conditions, which might exacerbate the low-memory conditions.Thanks for mentioning this, I didn't think of this before😊.
Quoted 17 lines
Is this really what we want? Zero cached rather than just fewer cached?
kernel/rcu/tree.c +1
-1// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) {Quoted 2 lines
I am still confused as to why we start "i" at zero rather than at ->nr_bkv_objs. What am I missing here?
No, you are right, I missed this place.
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;Quoted 3 lines
This is broken, unfortunately. If a low memory condition we fill fill a cache with at least one page anyway because of we do not want to hit a slow path.
Thanks remind, please ignore my v4 patch, how about the following?
kernel/rcu/tree.c +3
-0@@ -3238,6 +3238,9 @@ static void fill_page_cache_func(struct work_struct *work)free_page ((unsigned long ) bnode);break ; } + +if (atomic_read (&krcp->backoff_page_cache_fill)) +break ; }It does not fix an "issue" you are reporting.
kvfree_rcu_bulk()function can still fill it back. IMHO, the solution here is to disable cache if a low memory condition and enable back later on.
Quoted 7 lines
Quoted 3 lines
The cache size is controlled by the
rcu_min_cached_objsvariable. We can set it to 1 and restore it back to original value to make the cache operating as before.A good suggestion. a question, when need to restore
rcu_min_cached_objs? after the execution ofkfree_rcu_shrink_scan()ends?
We do not know when a low memory condition ends :) Therefore we defer a refill work for a certain time. In the fill_page_cache_func() we allow the cache operate as normal again:
...
atomic_set(&krcp->backoff_page_cache_fill, 0);
...
--
Uladzislau Rezki
Paul E. McKenney
maintainerQuoted 95 lines · Uladzislau Rezki
Quoted 83 lines · On Tue, Apr 11, 2023 at 02:42:27PM +0000, Zhang, Qiang1 wrote:
Quoted 72 lines
Quoted 32 lines
Currently, in
kfree_rcu_shrink_scan(), thedrain_page_cache()is executed beforekfree_rcu_monitor()to drain page cache, if the bnode structure's->gp_snap has done, thekvfree_rcu_bulk()will fill the page cache again inkfree_rcu_monitor(), this commit add a check for krcp structure's->backoff_page_cache_fill input_cached_bnode(), if the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and disable allocated page infill_page_cache_func().Signed-off-by Zqiang <[email protected]>Much improved! But still some questions below...
Thanx, Paul
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)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 will mean that under low-memory conditions, we will keep zero pages in ->bkvcache. All attempts to put something there will fail.
Quoted 5 lines
This is probably not an issue for structures containing an
rcu_headthat are passed tokfree_rcu(p, field), but doesn't this mean thatkfree_rcu_mightsleep()unconditionally invokessynchronize_rcu()? This could seriously slow up freeing under low-memory conditions, which might exacerbate the low-memory conditions.Thanks for mentioning this, I didn't think of this before😊.
Quoted 17 lines
Is this really what we want? Zero cached rather than just fewer cached?
kernel/rcu/tree.c +1
-1// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) {Quoted 2 lines
I am still confused as to why we start "i" at zero rather than at ->nr_bkv_objs. What am I missing here?
No, you are right, I missed this place.
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;Quoted 3 lines
This is broken, unfortunately. If a low memory condition we fill fill a cache with at least one page anyway because of we do not want to hit a slow path.
Thanks remind, please ignore my v4 patch, how about the following?
kernel/rcu/tree.c +0
-0kernel/rcu/tree.c static void fill_page_cache_func(struct work_struct *work) · line 3244
Quoted 7 lines
kernel/rcu/tree.c +3
-0@@ -3238,6 +3238,9 @@ static void fill_page_cache_func(struct work_struct *work)free_page ((unsigned long ) bnode);break ; } + +if (atomic_read (&krcp->backoff_page_cache_fill)) +break ; }It does not fix an "issue" you are reporting.
kvfree_rcu_bulk()function can still fill it back. IMHO, the solution here is to disable cache if a low memory condition and enable back later on.
Quoted 3 lines
The cache size is controlled by the
rcu_min_cached_objsvariable. We can set it to 1 and restore it back to original value to make the cache operating as before.
It would be best to use a second variable for this. Users might get annoyed if their changes to rcu_min_cached_objs got overwritten once things got set back to normal operation.
Thanx, Paul
Uladzislau Rezki
maintainerQuoted 96 lines · Paul E. McKenney
Quoted 95 lines · Uladzislau Rezki
Quoted 83 lines · On Tue, Apr 11, 2023 at 02:42:27PM +0000, Zhang, Qiang1 wrote:
Quoted 72 lines
Quoted 32 lines
Currently, in
kfree_rcu_shrink_scan(), thedrain_page_cache()is executed beforekfree_rcu_monitor()to drain page cache, if the bnode structure's->gp_snap has done, thekvfree_rcu_bulk()will fill the page cache again inkfree_rcu_monitor(), this commit add a check for krcp structure's->backoff_page_cache_fill input_cached_bnode(), if the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and disable allocated page infill_page_cache_func().Signed-off-by Zqiang <[email protected]>Much improved! But still some questions below...
Thanx, Paul
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)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 will mean that under low-memory conditions, we will keep zero pages in ->bkvcache. All attempts to put something there will fail.
Quoted 5 lines
This is probably not an issue for structures containing an
rcu_headthat are passed tokfree_rcu(p, field), but doesn't this mean thatkfree_rcu_mightsleep()unconditionally invokessynchronize_rcu()? This could seriously slow up freeing under low-memory conditions, which might exacerbate the low-memory conditions.Thanks for mentioning this, I didn't think of this before😊.
Quoted 17 lines
Is this really what we want? Zero cached rather than just fewer cached?
kernel/rcu/tree.c +1
-1// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) {Quoted 2 lines
I am still confused as to why we start "i" at zero rather than at ->nr_bkv_objs. What am I missing here?
No, you are right, I missed this place.
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;Quoted 3 lines
This is broken, unfortunately. If a low memory condition we fill fill a cache with at least one page anyway because of we do not want to hit a slow path.
Thanks remind, please ignore my v4 patch, how about the following?
kernel/rcu/tree.c +0
-0kernel/rcu/tree.c static void fill_page_cache_func(struct work_struct *work) · line 3244
Quoted 7 lines
kernel/rcu/tree.c +3
-0@@ -3238,6 +3238,9 @@ static void fill_page_cache_func(struct work_struct *work)free_page ((unsigned long ) bnode);break ; } + +if (atomic_read (&krcp->backoff_page_cache_fill)) +break ; }It does not fix an "issue" you are reporting.
kvfree_rcu_bulk()function can still fill it back. IMHO, the solution here is to disable cache if a low memory condition and enable back later on.
Quoted 8 lines
Quoted 3 lines
The cache size is controlled by the
rcu_min_cached_objsvariable. We can set it to 1 and restore it back to original value to make the cache operating as before.It would be best to use a second variable for this. Users might get annoyed if their changes to
rcu_min_cached_objsgot overwritten once things got set back to normal operation.
Agree. So we do not make it visible over sysfs interface for user that we manipulate it.
--
Uladzislau Rezki
Quoted 101 lines · Uladzislau Rezki
Quoted 95 lines · On Tue, Apr 11, 2023 at 02:42:27PM +0000, Zhang, Qiang1 wrote:
Quoted 83 lines
Quoted 72 lines
Quoted 31 lines
Currently, in
kfree_rcu_shrink_scan(), thedrain_page_cache()
is executed beforekfree_rcu_monitor()to drain page cache, if
the bnode structure's->gp_snap has done, thekvfree_rcu_bulk()
will fill the page cache again inkfree_rcu_monitor(), this
commit add a check for krcp
structure's->backoff_page_cache_fill input_cached_bnode(), if
the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and disable allocated page infill_page_cache_func().Signed-off-by Zqiang <[email protected]>Much improved! But still some questions below...
Thanx, Paul
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/rcu/tree.c index renamed from kernel/rcu/tree.c +0
-0
cc34d13be181..9d9d3772cc45100644kernel/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 will mean that under low-memory conditions, we will keep zero pages in ->bkvcache. All attempts to put something there will fail.
Quoted 6 lines
This is probably not an issue for structures containing an
rcu_headthat are passed tokfree_rcu(p, field), but doesn't this mean thatkfree_rcu_mightsleep()unconditionally invokessynchronize_rcu()? This could seriously slow up freeing under low-memory conditions, which might exacerbate the low-memory conditions.Thanks for mentioning this, I didn't think of this before😊.
Quoted 17 lines
Is this really what we want? Zero cached rather than just fewer cached?
kernel/rcu/tree.c +1
-1// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) {Quoted 3 lines
I am still confused as to why we start "i" at zero rather than at
->nr_bkv_objs. What am I missing here?No, you are right, I missed this place.
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;Quoted 3 lines
This is broken, unfortunately. If a low memory condition we fill fill a cache with at least one page anyway because of we do not want to hit a slow path.
Thanks remind, please ignore my v4 patch, how about the following?
kernel/rcu/tree.c index renamed from kernel/rcu/tree.c +0
-0
41daae3239b5..e2e8412e687f100644kernel/rcu/tree.c static void fill_page_cache_func(struct work_struct *work) · line 3244
Quoted 7 lines
kernel/rcu/tree.c +3
-0@@ -3238,6 +3238,9 @@ static void fill_page_cache_func(struct work_struct *work)free_page ((unsigned long ) bnode);break ; } + +if (atomic_read (&krcp->backoff_page_cache_fill)) +break ; }It does not fix an "issue" you are reporting.
kvfree_rcu_bulk()function can still fill it back. IMHO, the solution here is to disable cache if a low memory condition and enable back later on.Quoted 3 lines
The cache size is controlled by the
rcu_min_cached_objsvariable. We can set it to 1 and restore it back to original value to make the cache operating as before.
Quoted 7 lines
It would be best to use a second variable for this. Users might get annoyed if their changes to
rcu_min_cached_objsgot overwritten once things got set back to normal operation.Agree. So we do not make it visible over sysfs interface for user that we manipulate it.
The rcu_min_cached_objs is read-only, Users cannot be set rcu_min_cached_objs dynamically.
-r--r--r-- 1 root root 4.0K Apr 12 01:08 rcu_min_cached_objs
kernel/rcu/tree.c +2 -1
@@ -2909,7 +2909,8 @@ put_cached_bnode(struct kfree_rcu_cpu *krcp, struct kvfree_rcu_bulk_data *bnode) {// Check the limit. -if (krcp->nr_bkv_objs >= rcu_min_cached_objs) +if ((atomic_read (&krcp->backoff_page_cache_fill) && krcp->nr_bkv_objs) || + krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;llist_add ((struct llist_node *) bnode, &krcp->bkvcache);
thoughts?
Thanks
Zqiang
Quoted 3 lines
--
Uladzislau Rezki
Uladzislau Rezki
maintainerQuoted 105 lines · On Wed, Apr 12, 2023 at 09:14:15AM +0000, Zhang, Qiang1 wrote:
Quoted 105 lines · Uladzislau Rezki
Quoted 95 lines · On Tue, Apr 11, 2023 at 02:42:27PM +0000, Zhang, Qiang1 wrote:
Quoted 83 lines
Quoted 72 lines
Quoted 31 lines
Currently, in
kfree_rcu_shrink_scan(), thedrain_page_cache()
is executed beforekfree_rcu_monitor()to drain page cache, if
the bnode structure's->gp_snap has done, thekvfree_rcu_bulk()
will fill the page cache again inkfree_rcu_monitor(), this
commit add a check for krcp
structure's->backoff_page_cache_fill input_cached_bnode(), if
the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and disable allocated page infill_page_cache_func().Signed-off-by Zqiang <[email protected]>Much improved! But still some questions below...
Thanx, Paul
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/rcu/tree.c index renamed from kernel/rcu/tree.c +0
-0
cc34d13be181..9d9d3772cc45100644kernel/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 will mean that under low-memory conditions, we will keep zero pages in ->bkvcache. All attempts to put something there will fail.
Quoted 6 lines
This is probably not an issue for structures containing an
rcu_headthat are passed tokfree_rcu(p, field), but doesn't this mean thatkfree_rcu_mightsleep()unconditionally invokessynchronize_rcu()? This could seriously slow up freeing under low-memory conditions, which might exacerbate the low-memory conditions.Thanks for mentioning this, I didn't think of this before😊.
Quoted 17 lines
Is this really what we want? Zero cached rather than just fewer cached?
kernel/rcu/tree.c +1
-1// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) {Quoted 3 lines
I am still confused as to why we start "i" at zero rather than at
->nr_bkv_objs. What am I missing here?No, you are right, I missed this place.
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;Quoted 3 lines
This is broken, unfortunately. If a low memory condition we fill fill a cache with at least one page anyway because of we do not want to hit a slow path.
Thanks remind, please ignore my v4 patch, how about the following?
kernel/rcu/tree.c index renamed from kernel/rcu/tree.c +0
-0
41daae3239b5..e2e8412e687f100644kernel/rcu/tree.c static void fill_page_cache_func(struct work_struct *work) · line 3244
Quoted 7 lines
kernel/rcu/tree.c +3
-0@@ -3238,6 +3238,9 @@ static void fill_page_cache_func(struct work_struct *work)free_page ((unsigned long ) bnode);break ; } + +if (atomic_read (&krcp->backoff_page_cache_fill)) +break ; }It does not fix an "issue" you are reporting.
kvfree_rcu_bulk()function can still fill it back. IMHO, the solution here is to disable cache if a low memory condition and enable back later on.Quoted 3 lines
The cache size is controlled by the
rcu_min_cached_objsvariable. We can set it to 1 and restore it back to original value to make the cache operating as before.It would be best to use a second variable for this. Users might get annoyed if their changes to
rcu_min_cached_objsgot overwritten once things got set back to normal operation.
Quoted 9 lines
Quoted 3 lines
Agree. So we do not make it visible over sysfs interface for user that we manipulate it.
The
rcu_min_cached_objsis read-only, Users cannot be setrcu_min_cached_objsdynamically.-r--r--r-- 1 root root 4.0K Apr 12 01:08
rcu_min_cached_objs
You can set it as a boot parameter: rcutree.rcu_min_cached_objs=XXX
kernel/rcu/tree.c put_cached_bnode(struct kfree_rcu_cpu *krcp, · line 2915
Quoted 13 lines
kernel/rcu/tree.c +2
-1@@ -2909,7 +2909,8 @@ put_cached_bnode(struct kfree_rcu_cpu *krcp, struct kvfree_rcu_bulk_data *bnode) {// Check the limit. -if (krcp->nr_bkv_objs >= rcu_min_cached_objs) +if ((atomic_read (&krcp->backoff_page_cache_fill) && krcp->nr_bkv_objs) || + krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;
We can eliminate the backoff_page_cache_fill per-cpu atomic variable and just change a new one, say, min_cached_objs, if a low memory condition. Restore it to a default what is the rcu_min_cached_objs.
I can post here an example if it helps to make it more clear.
--
Uladzislau Rezki
Quoted 104 lines
Quoted 104 lines · Uladzislau Rezki
Quoted 95 lines · On Tue, Apr 11, 2023 at 02:42:27PM +0000, Zhang, Qiang1 wrote:
Quoted 83 lines
Quoted 72 lines
Quoted 31 lines
Currently, in
kfree_rcu_shrink_scan(), thedrain_page_cache()
is executed beforekfree_rcu_monitor()to drain page cache, if
the bnode structure's->gp_snap has done, thekvfree_rcu_bulk()
will fill the page cache again inkfree_rcu_monitor(), this
commit add a check for krcp
structure's->backoff_page_cache_fill input_cached_bnode(), if
the krcp structure's->backoff_page_cache_fill is set, prevent page cache growing and disable allocated page infill_page_cache_func().Signed-off-by Zqiang <[email protected]>Much improved! But still some questions below...
Thanx, Paul
--- kernel/rcu/tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/rcu/tree.c index renamed from kernel/rcu/tree.c +0
-0
cc34d13be181..9d9d3772cc45100644kernel/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 will mean that under low-memory conditions, we will keep zero pages in ->bkvcache. All attempts to put something there will fail.
Quoted 6 lines
This is probably not an issue for structures containing an
rcu_headthat are passed tokfree_rcu(p, field), but doesn't this mean thatkfree_rcu_mightsleep()unconditionally invokessynchronize_rcu()? This could seriously slow up freeing under low-memory conditions, which might exacerbate the low-memory conditions.Thanks for mentioning this, I didn't think of this before😊.
Quoted 17 lines
Is this really what we want? Zero cached rather than just fewer cached?
kernel/rcu/tree.c +1
-1// Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;@@ -3221,7 +3223,7 @@ static void fill_page_cache_func(struct work_struct *work)int i; nr_pages =atomic_read (&krcp->backoff_page_cache_fill) ? -1 : rcu_min_cached_objs; +0 : rcu_min_cached_objs;for (i =0 ; i < nr_pages; i++) {Quoted 3 lines
I am still confused as to why we start "i" at zero rather than at
->nr_bkv_objs. What am I missing here?No, you are right, I missed this place.
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;Quoted 3 lines
This is broken, unfortunately. If a low memory condition we fill fill a cache with at least one page anyway because of we do not want to hit a slow path.
Thanks remind, please ignore my v4 patch, how about the following?
kernel/rcu/tree.c index renamed from kernel/rcu/tree.c +0
-0
41daae3239b5..e2e8412e687f100644kernel/rcu/tree.c static void fill_page_cache_func(struct work_struct *work) · line 3244
Quoted 7 lines
kernel/rcu/tree.c +3
-0@@ -3238,6 +3238,9 @@ static void fill_page_cache_func(struct work_struct *work)free_page ((unsigned long ) bnode);break ; } + +if (atomic_read (&krcp->backoff_page_cache_fill)) +break ; }It does not fix an "issue" you are reporting.
kvfree_rcu_bulk()function can still fill it back. IMHO, the solution here is to disable cache if a low memory condition and enable back later on.Quoted 3 lines
The cache size is controlled by the
rcu_min_cached_objsvariable. We can set it to 1 and restore it back to original value to make the cache operating as before.It would be best to use a second variable for this. Users might get annoyed if their changes to
rcu_min_cached_objsgot overwritten once things got set back to normal operation.
Quoted 9 lines
Quoted 3 lines
Agree. So we do not make it visible over sysfs interface for user that we manipulate it.
The
rcu_min_cached_objsis read-only, Users cannot be setrcu_min_cached_objsdynamically.-r--r--r-- 1 root root 4.0K Apr 12 01:08
rcu_min_cached_objs
You can set it as a boot parameter: rcutree.rcu_min_cached_objs=XXX
Quoted 13 lines
kernel/rcu/tree.c +2
-1@@ -2909,7 +2909,8 @@ put_cached_bnode(struct kfree_rcu_cpu *krcp, struct kvfree_rcu_bulk_data *bnode) {// Check the limit. -if (krcp->nr_bkv_objs >= rcu_min_cached_objs) +if ((atomic_read (&krcp->backoff_page_cache_fill) && krcp->nr_bkv_objs) || + krcp->nr_bkv_objs >= rcu_min_cached_objs)return false;
Quoted 3 lines
We can eliminate the
backoff_page_cache_fillper-cpu atomic variable and just change a new one, say,min_cached_objs, if a low memory condition. Restore it to a default what is thercu_min_cached_objs.
Thanks for suggestion, will be modified in this way.
Quoted 5 lines
I can post here an example if it helps to make it more clear.
--
Uladzislau Rezki