diff mbox series

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

Message ID 20230408142517.800549-1-qiang1.zhang@intel.com (mailing list archive)
State Superseded
Headers show
Series [v3] rcu/kvfree: Prevents cache growing when the backoff_page_cache_fill is set | expand

Commit Message

Zqiang April 8, 2023, 2:25 p.m. UTC
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().

Signed-off-by: Zqiang <qiang1.zhang@intel.com>
---
 kernel/rcu/tree.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Paul E. McKenney April 10, 2023, 11:34 p.m. UTC | #1
On Sat, Apr 08, 2023 at 10:25:17PM +0800, Zqiang wrote:
> 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().
> 
> Signed-off-by: Zqiang <qiang1.zhang@intel.com>

Much improved!  But still some questions below...

							Thanx, Paul

> ---
>  kernel/rcu/tree.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index cc34d13be181..9d9d3772cc45 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -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?

>  	// 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?

>  		bnode = (struct kvfree_rcu_bulk_data *)
> -- 
> 2.32.0
>
Zqiang April 11, 2023, 4:04 a.m. UTC | #2
> 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().
> 
> Signed-off-by: Zqiang <qiang1.zhang@intel.com>
>
>Much improved!  But still some questions below...
>
>							Thanx, Paul
>
> ---
>  kernel/rcu/tree.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index cc34d13be181..9d9d3772cc45 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -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.

Thanks for mentioning this, I didn't think of this before
Uladzislau Rezki April 11, 2023, 2:25 p.m. UTC | #3
On Tue, Apr 11, 2023 at 04:04:45AM +0000, Zhang, Qiang1 wrote:
> > 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().
> > 
> > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> >
> >Much improved!  But still some questions below...
> >
> >							Thanx, Paul
> >
> > ---
> >  kernel/rcu/tree.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > index cc34d13be181..9d9d3772cc45 100644
> > --- a/kernel/rcu/tree.c
> > +++ b/kernel/rcu/tree.c
> > @@ -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.
> 
> Thanks for mentioning this, I didn't think of this before
Zqiang April 11, 2023, 2:42 p.m. UTC | #4
> > 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().
> > 
> > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> >
> >Much improved!  But still some questions below...
> >
> >							Thanx, Paul
> >
> > ---
> >  kernel/rcu/tree.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > index cc34d13be181..9d9d3772cc45 100644
> > --- a/kernel/rcu/tree.c
> > +++ b/kernel/rcu/tree.c
> > @@ -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.
> 
> Thanks for mentioning this, I didn't think of this before
Uladzislau Rezki April 11, 2023, 2:58 p.m. UTC | #5
On Tue, Apr 11, 2023 at 02:42:27PM +0000, Zhang, Qiang1 wrote:
> > > 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().
> > > 
> > > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> > >
> > >Much improved!  But still some questions below...
> > >
> > >							Thanx, Paul
> > >
> > > ---
> > >  kernel/rcu/tree.c | 4 +++-
> > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > > index cc34d13be181..9d9d3772cc45 100644
> > > --- a/kernel/rcu/tree.c
> > > +++ b/kernel/rcu/tree.c
> > > @@ -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.
> > 
> > Thanks for mentioning this, I didn't think of this before
Zqiang April 11, 2023, 3:09 p.m. UTC | #6
> > > 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().
> > > 
> > > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> > >
> > >Much improved!  But still some questions below...
> > >
> > >							Thanx, Paul
> > >
> > > ---
> > >  kernel/rcu/tree.c | 4 +++-
> > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > > index cc34d13be181..9d9d3772cc45 100644
> > > --- a/kernel/rcu/tree.c
> > > +++ b/kernel/rcu/tree.c
> > > @@ -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.
> > 
> > Thanks for mentioning this, I didn't think of this before
Uladzislau Rezki April 11, 2023, 3:14 p.m. UTC | #7
On Tue, Apr 11, 2023 at 03:09:13PM +0000, Zhang, Qiang1 wrote:
> > > > 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().
> > > > 
> > > > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> > > >
> > > >Much improved!  But still some questions below...
> > > >
> > > >							Thanx, Paul
> > > >
> > > > ---
> > > >  kernel/rcu/tree.c | 4 +++-
> > > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > > > index cc34d13be181..9d9d3772cc45 100644
> > > > --- a/kernel/rcu/tree.c
> > > > +++ b/kernel/rcu/tree.c
> > > > @@ -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.
> > > 
> > > Thanks for mentioning this, I didn't think of this before
Paul E. McKenney April 11, 2023, 4:42 p.m. UTC | #8
On Tue, Apr 11, 2023 at 04:58:22PM +0200, Uladzislau Rezki wrote:
> On Tue, Apr 11, 2023 at 02:42:27PM +0000, Zhang, Qiang1 wrote:
> > > > 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().
> > > > 
> > > > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> > > >
> > > >Much improved!  But still some questions below...
> > > >
> > > >							Thanx, Paul
> > > >
> > > > ---
> > > >  kernel/rcu/tree.c | 4 +++-
> > > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > > > index cc34d13be181..9d9d3772cc45 100644
> > > > --- a/kernel/rcu/tree.c
> > > > +++ b/kernel/rcu/tree.c
> > > > @@ -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.
> > > 
> > > Thanks for mentioning this, I didn't think of this before
Uladzislau Rezki April 11, 2023, 5:10 p.m. UTC | #9
On Tue, Apr 11, 2023 at 09:42:37AM -0700, Paul E. McKenney wrote:
> On Tue, Apr 11, 2023 at 04:58:22PM +0200, Uladzislau Rezki wrote:
> > On Tue, Apr 11, 2023 at 02:42:27PM +0000, Zhang, Qiang1 wrote:
> > > > > 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().
> > > > > 
> > > > > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> > > > >
> > > > >Much improved!  But still some questions below...
> > > > >
> > > > >							Thanx, Paul
> > > > >
> > > > > ---
> > > > >  kernel/rcu/tree.c | 4 +++-
> > > > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > > > > index cc34d13be181..9d9d3772cc45 100644
> > > > > --- a/kernel/rcu/tree.c
> > > > > +++ b/kernel/rcu/tree.c
> > > > > @@ -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.
> > > > 
> > > > Thanks for mentioning this, I didn't think of this before
Zqiang April 12, 2023, 9:14 a.m. UTC | #10
> On Tue, Apr 11, 2023 at 04:58:22PM +0200, Uladzislau Rezki wrote:
> > On Tue, Apr 11, 2023 at 02:42:27PM +0000, Zhang, Qiang1 wrote:
> > > > > 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().
> > > > > 
> > > > > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> > > > >
> > > > >Much improved!  But still some questions below...
> > > > >
> > > > >							Thanx, Paul
> > > > >
> > > > > ---
> > > > >  kernel/rcu/tree.c | 4 +++-
> > > > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 
> > > > > cc34d13be181..9d9d3772cc45 100644
> > > > > --- a/kernel/rcu/tree.c
> > > > > +++ b/kernel/rcu/tree.c
> > > > > @@ -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.
> > > > 
> > > > Thanks for mentioning this, I didn't think of this before
Uladzislau Rezki April 12, 2023, 12:32 p.m. UTC | #11
On Wed, Apr 12, 2023 at 09:14:15AM +0000, Zhang, Qiang1 wrote:
> 
> > On Tue, Apr 11, 2023 at 04:58:22PM +0200, Uladzislau Rezki wrote:
> > > On Tue, Apr 11, 2023 at 02:42:27PM +0000, Zhang, Qiang1 wrote:
> > > > > > 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().
> > > > > > 
> > > > > > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> > > > > >
> > > > > >Much improved!  But still some questions below...
> > > > > >
> > > > > >							Thanx, Paul
> > > > > >
> > > > > > ---
> > > > > >  kernel/rcu/tree.c | 4 +++-
> > > > > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > > > > 
> > > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 
> > > > > > cc34d13be181..9d9d3772cc45 100644
> > > > > > --- a/kernel/rcu/tree.c
> > > > > > +++ b/kernel/rcu/tree.c
> > > > > > @@ -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.
> > > > > 
> > > > > Thanks for mentioning this, I didn't think of this before
Zqiang April 12, 2023, 2:21 p.m. UTC | #12
> > On Tue, Apr 11, 2023 at 04:58:22PM +0200, Uladzislau Rezki wrote:
> > > On Tue, Apr 11, 2023 at 02:42:27PM +0000, Zhang, Qiang1 wrote:
> > > > > > 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().
> > > > > > 
> > > > > > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
> > > > > >
> > > > > >Much improved!  But still some questions below...
> > > > > >
> > > > > >							Thanx, Paul
> > > > > >
> > > > > > ---
> > > > > >  kernel/rcu/tree.c | 4 +++-
> > > > > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > > > > 
> > > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 
> > > > > > cc34d13be181..9d9d3772cc45 100644
> > > > > > --- a/kernel/rcu/tree.c
> > > > > > +++ b/kernel/rcu/tree.c
> > > > > > @@ -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.
> > > > > 
> > > > > Thanks for mentioning this, I didn't think of this before
diff mbox series

Patch

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index cc34d13be181..9d9d3772cc45 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -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 *)