All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs: judging context via current_is_kswapd instead of gfp_flag
@ 2021-12-08  8:37 Huangzhaoyang
  2021-12-08 20:26 ` David Howells
  0 siblings, 1 reply; 5+ messages in thread
From: Huangzhaoyang @ 2021-12-08  8:37 UTC (permalink / raw)
  To: David Howells, Marc Dionne, Zhaoyang Huang, linux-kernel

From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

Kswapd uses GFP_KERNEL as gfp_flag which make the judgment of
context is unexpected. fix it by using current_is_kswapd.

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 fs/afs/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/afs/file.c b/fs/afs/file.c
index eb11d04..6c199d5 100644
--- a/fs/afs/file.c
+++ b/fs/afs/file.c
@@ -485,7 +485,7 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)
 	 * elected to wait */
 #ifdef CONFIG_AFS_FSCACHE
 	if (PageFsCache(page)) {
-		if (!(gfp_flags & __GFP_DIRECT_RECLAIM) || !(gfp_flags & __GFP_FS))
+		if (current_is_kswapd() || !(gfp_flags & __GFP_FS))
 			return false;
 		wait_on_page_fscache(page);
 	}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] fs: judging context via current_is_kswapd instead of gfp_flag
  2021-12-08  8:37 [PATCH] fs: judging context via current_is_kswapd instead of gfp_flag Huangzhaoyang
@ 2021-12-08 20:26 ` David Howells
  2021-12-10  1:19   ` Zhaoyang Huang
  2021-12-21 15:00   ` David Howells
  0 siblings, 2 replies; 5+ messages in thread
From: David Howells @ 2021-12-08 20:26 UTC (permalink / raw)
  To: Huangzhaoyang
  Cc: dhowells, Marc Dionne, Zhaoyang Huang, linux-cachefs, linux-kernel

Huangzhaoyang <huangzhaoyang@gmail.com> wrote:

[adding linux-cachefs to the cc list]

> Kswapd uses GFP_KERNEL as gfp_flag which make the judgment of
> context is unexpected. fix it by using current_is_kswapd.
> 
> Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> ---
>  fs/afs/file.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/afs/file.c b/fs/afs/file.c
> index eb11d04..6c199d5 100644
> --- a/fs/afs/file.c
> +++ b/fs/afs/file.c
> @@ -485,7 +485,7 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)
>  	 * elected to wait */
>  #ifdef CONFIG_AFS_FSCACHE
>  	if (PageFsCache(page)) {
> -		if (!(gfp_flags & __GFP_DIRECT_RECLAIM) || !(gfp_flags & __GFP_FS))
> +		if (current_is_kswapd() || !(gfp_flags & __GFP_FS))
>  			return false;
>  		wait_on_page_fscache(page);
>  	}

I have several of these in my fscache-rewrite branch, spread across a number
of filesystems.  Should I fix all of them the same way?

fs/9p/vfs_addr.c:               if (!gfpflags_allow_blocking(gfp) || !(gfp & __GFP_FS))
fs/afs/file.c:          if (!gfpflags_allow_blocking(gfp) || !(gfp & __GFP_FS))
fs/nfs/file.c:          if (!gfpflags_allow_blocking(gfp) || !(gfp & __GFP_FS))
fs/nfs/fscache.h:               if (!gfpflags_allow_blocking(gfp) || !(gfp & __GFP_FS))

David


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fs: judging context via current_is_kswapd instead of gfp_flag
  2021-12-08 20:26 ` David Howells
@ 2021-12-10  1:19   ` Zhaoyang Huang
  2021-12-21 15:00   ` David Howells
  1 sibling, 0 replies; 5+ messages in thread
From: Zhaoyang Huang @ 2021-12-10  1:19 UTC (permalink / raw)
  To: David Howells; +Cc: Marc Dionne, Zhaoyang Huang, linux-cachefs, LKML

On Thu, Dec 9, 2021 at 4:26 AM David Howells <dhowells@redhat.com> wrote:
>
> Huangzhaoyang <huangzhaoyang@gmail.com> wrote:
>
> [adding linux-cachefs to the cc list]
>
> > Kswapd uses GFP_KERNEL as gfp_flag which make the judgment of
> > context is unexpected. fix it by using current_is_kswapd.
> >
> > Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> > ---
> >  fs/afs/file.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/fs/afs/file.c b/fs/afs/file.c
> > index eb11d04..6c199d5 100644
> > --- a/fs/afs/file.c
> > +++ b/fs/afs/file.c
> > @@ -485,7 +485,7 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)
> >        * elected to wait */
> >  #ifdef CONFIG_AFS_FSCACHE
> >       if (PageFsCache(page)) {
> > -             if (!(gfp_flags & __GFP_DIRECT_RECLAIM) || !(gfp_flags & __GFP_FS))
> > +             if (current_is_kswapd() || !(gfp_flags & __GFP_FS))
> >                       return false;
> >               wait_on_page_fscache(page);
> >       }
>
> I have several of these in my fscache-rewrite branch, spread across a number
> of filesystems.  Should I fix all of them the same way?
>
> fs/9p/vfs_addr.c:               if (!gfpflags_allow_blocking(gfp) || !(gfp & __GFP_FS))
> fs/afs/file.c:          if (!gfpflags_allow_blocking(gfp) || !(gfp & __GFP_FS))
> fs/nfs/file.c:          if (!gfpflags_allow_blocking(gfp) || !(gfp & __GFP_FS))
> fs/nfs/fscache.h:               if (!gfpflags_allow_blocking(gfp) || !(gfp & __GFP_FS))
>
> David
If the gfp flag here is used for judging kswapd context, I think the
answer is yes as kswapd applied __GFP_DIRECT_RECLAIM.
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fs: judging context via current_is_kswapd instead of gfp_flag
  2021-12-08 20:26 ` David Howells
  2021-12-10  1:19   ` Zhaoyang Huang
@ 2021-12-21 15:00   ` David Howells
  2021-12-22  8:02     ` Zhaoyang Huang
  1 sibling, 1 reply; 5+ messages in thread
From: David Howells @ 2021-12-21 15:00 UTC (permalink / raw)
  To: Zhaoyang Huang; +Cc: dhowells, Marc Dionne, Zhaoyang Huang, linux-cachefs, LKML

Zhaoyang Huang <huangzhaoyang@gmail.com> wrote:

> > > -             if (!(gfp_flags & __GFP_DIRECT_RECLAIM) || !(gfp_flags & __GFP_FS))
> > > +             if (current_is_kswapd() || !(gfp_flags & __GFP_FS))
> > >                       return false;
> > >               wait_on_page_fscache(page);
> ...
> If the gfp flag here is used for judging kswapd context, I think the
> answer is yes as kswapd applied __GFP_DIRECT_RECLAIM.

Now I come to look at applying it, I'm not sure whether this change is right.

I don't know if kswapd has anything to do with it.  The check is to see if
we're allowed to block at this point - and wait is just for the completion of
a DIO write to disk.

It would seem like gfpflags_allow_blocking() is the right thing to call - and
that should use current_is_kswapd() if appropriate.

David


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fs: judging context via current_is_kswapd instead of gfp_flag
  2021-12-21 15:00   ` David Howells
@ 2021-12-22  8:02     ` Zhaoyang Huang
  0 siblings, 0 replies; 5+ messages in thread
From: Zhaoyang Huang @ 2021-12-22  8:02 UTC (permalink / raw)
  To: David Howells; +Cc: Marc Dionne, Zhaoyang Huang, linux-cachefs, LKML

On Tue, Dec 21, 2021 at 11:01 PM David Howells <dhowells@redhat.com> wrote:
>
> Zhaoyang Huang <huangzhaoyang@gmail.com> wrote:
>
> > > > -             if (!(gfp_flags & __GFP_DIRECT_RECLAIM) || !(gfp_flags & __GFP_FS))
> > > > +             if (current_is_kswapd() || !(gfp_flags & __GFP_FS))
> > > >                       return false;
> > > >               wait_on_page_fscache(page);
> > ...
> > If the gfp flag here is used for judging kswapd context, I think the
> > answer is yes as kswapd applied __GFP_DIRECT_RECLAIM.
>
> Now I come to look at applying it, I'm not sure whether this change is right.
>
> I don't know if kswapd has anything to do with it.  The check is to see if
> we're allowed to block at this point - and wait is just for the completion of
> a DIO write to disk.
>
> It would seem like gfpflags_allow_blocking() is the right thing to call - and
> that should use current_is_kswapd() if appropriate.
>
> David
According to my understanding, this check is redundant according to
current vmscan logic. For the allocation which deny
__GFP_DIRECT_RECLAIM could NOT have the context reach here as there is
no synchronous reclaiming. while kswapd also has __GFP_DIRECT_RECLAIM
set and would also block on the page's release.
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-22  8:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-08  8:37 [PATCH] fs: judging context via current_is_kswapd instead of gfp_flag Huangzhaoyang
2021-12-08 20:26 ` David Howells
2021-12-10  1:19   ` Zhaoyang Huang
2021-12-21 15:00   ` David Howells
2021-12-22  8:02     ` Zhaoyang Huang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.