VM: Fix the gfp_mask in invalidate_complete_page2
Subsystems (2)
PATCH 1/1 VM: Fix the gfp_mask in invalidate_complete_page2
If try_to_release_page() is called with a zero gfp mask, then the filesystem is effectively denied the possibility of sleeping while attempting to release the page. There doesn't appear to be any valid reason why this should be banned, given that we're not calling this from a memory allocation context.
For this reason, change the gfp_mask argument of the call to GFP_KERNEL.
Note: I am less sure of what the callers of invalidate_complete_page() require, and so this patch does not touch that mask.
---
mm/truncate.c +1 -1
@@ -302,7 +302,7 @@ invalidate_complete_page2(struct addressif (page->mapping != mapping)return 0 ; -if (PagePrivate (page) && !try_to_release_page (page,0 )) +if (PagePrivate (page) && !try_to_release_page (page,GFP_KERNEL ))return 0 ;write_lock_irq (&mapping->tree_lock);
Quoted 18 lines · Trond Myklebust
If
try_to_release_page()is called with a zero gfp mask, then the filesystem is effectively denied the possibility of sleeping while attempting to release the page. There doesn't appear to be any valid reason why this should be banned, given that we're not calling this from a memory allocation context.For this reason, change the
gfp_maskargument of the call toGFP_KERNEL.Note: I am less sure of what the callers of
invalidate_complete_page()require, and so this patch does not touch that mask.Signed-off-by Trond Myklebust <[email protected]>---
mm/truncate.c +0
-0
mm/truncate.c invalidate_complete_page2(struct address · line 308
Quoted 8 lines
mm/truncate.c +1
-1@@ -302,7 +302,7 @@ invalidate_complete_page2(struct addressif (page->mapping != mapping)return 0 ; -if (PagePrivate (page) && !try_to_release_page (page,0 )) +if (PagePrivate (page) && !try_to_release_page (page,GFP_KERNEL ))return 0 ;write_lock_irq (&mapping->tree_lock);
Well I was using mapping_gfp_mask(mapping) as the argument to try_to_release_page() which also worked... but isn't this just plugging one of many holes? Meaning try_to_release_page is called from a number of places with a zero gfp_mask so shouldn't those also be fixed as well OR removed the gfp_mask as an argument as the comment at the top of try_to_release_page() alludes to?
steved.
Quoted 22 lines · Steve Dickson
Quoted 21 lines · Trond Myklebust
If
try_to_release_page()is called with a zero gfp mask, then the filesystem is effectively denied the possibility of sleeping while attempting to release the page. There doesn't appear to be any valid reason why this should be banned, given that we're not calling this from a memory allocation context.For this reason, change the
gfp_maskargument of the call toGFP_KERNEL.Note: I am less sure of what the callers of
invalidate_complete_page()require, and so this patch does not touch that mask.Signed-off-by Trond Myklebust <[email protected]>---
mm/truncate.c +0
-0@@ -302,7 +302,7 @@ invalidate_complete_page2(struct addressif (page->mapping != mapping)return 0 ;
Quoted 8 lines
mm/truncate.c invalidate_complete_page2(struct address · line 308
Quoted 5 lines
mm/truncate.c +1
-1-if (PagePrivate (page) && !try_to_release_page (page,0 )) +if (PagePrivate (page) && !try_to_release_page (page,GFP_KERNEL ))return 0 ;write_lock_irq (&mapping->tree_lock);Well I was using
mapping_gfp_mask(mapping)as the argument totry_to_release_page()which also worked... but isn't this just plugging one of many holes?
Yeah using mapping_gfp_mask(mapping) sounds like a better option.
...and yes, there are other callers that need to be audited. I'm particularly curious about the effect of the call in block_invalidatepage() on XFS, which has a similar test to ours.
The call in fallback_migrate_page() should probably be using mapping_gfp_mask() too.
Quoted 4 lines
Meaning
try_to_release_pageis called
from a number of places with a zerogfp_maskso shouldn't those also be fixed as well OR removed thegfp_maskas an argument as the comment at the top oftry_to_release_page()alludes to?
Nope. In order to make it work correctly with NFS and XFS, all calls to try_to_release_page() would have to be allowed to be blocking. The problem is that shrink_page_list() still wants to call try_to_release_page() from a memory allocation context.
Cheers,
Trond
Quoted 1 line · Trond Myklebust
Yeah using
mapping_gfp_mask(mapping)sounds like a better option.
Revised patch is attached...
Cheers,
Trond
Quoted 4 lines · On Fri, 06 Oct 2006 18:19:27 -0400 Trond Myklebust…
Quoted 1 line · Trond Myklebust
Yeah using
mapping_gfp_mask(mapping)sounds like a better option.Revised patch is attached...
Well, it wasn't attached, but I can simulate it.
invalidate_complete_page() wants to be called from inside spinlocks by drop_pagecache(), so if we wanted to pull the same trick there we'd need to pass a new flag into invalidate_inode_pages().
It's not 100% clear what the gfp_t _means_ in the try_to_release_page() context. Callees will rarely want to allocate memory (true?). So it conveys two concepts:
a) can sleep. (__GFP_WAIT). That's fairly straightforward
b) can take fs locks (__GFP_FS). This is less clear. By passing down __GFP_FS we're telling the callee that it's OK to take i_mutex, even lock_page(). That sounds pretty unsafe in this context, particularly the latter, as we're already holding a page lock.
So perhaps the safer and more appropriate solution here is to pass in a bare __GFP_WAIT.
Quoted 8 lines · Andrew Morton
Quoted 4 lines · On Fri, 06 Oct 2006 18:19:27 -0400 Trond Myklebust…
Quoted 1 line · Trond Myklebust
Yeah using
mapping_gfp_mask(mapping)sounds like a better option.
Quoted 8 lines
Quoted 1 line
Revised patch is attached...
Well, it wasn't attached, but I can simulate it.
invalidate_complete_page()wants to be called from inside spinlocks bydrop_pagecache(), so if we wanted to pull the same trick there we'd need to pass a new flag intoinvalidate_inode_pages().
That seems abit broken (wrt performance) that drop_pagecache_sb() holds the fairly popular inode_lock while it invalidate pages... Nobody else seem to...
Quoted 7 lines
It's not 100% clear what the
gfp_t_means_ in thetry_to_release_page()context. Callees will rarely want to allocate memory (true?). So it conveys two concepts:a) can sleep. (
__GFP_WAIT). That's fairly straightforward
Quoted 7 lines
b) can take fs locks (
__GFP_FS). This is less clear. By passing down__GFP_FSwe're telling the callee that it's OK to takei_mutex, evenlock_page(). That sounds pretty unsafe in this context, particularly the latter, as we're already holding a page lock.So perhaps the safer and more appropriate solution here is to pass in a bare
__GFP_WAIT.
I agree... __GFP_WAIT does seem to be a bit more straightforward... either way is find.. as long as it cause NFS to flush its pages...
steved.
Quoted 8 lines · On Fri, 06 Oct 2006 19:09:29 -0400 Steve Dickson <[email protected]> wrote:
Quoted 5 lines
Well, it wasn't attached, but I can simulate it.
invalidate_complete_page()wants to be called from inside spinlocks bydrop_pagecache(), so if we wanted to pull the same trick there we'd need to pass a new flag intoinvalidate_inode_pages().That seems abit broken (wrt performance) that
drop_pagecache_sb()holds the fairly popularinode_lockwhile it invalidate pages... Nobody else seem to...
Yes, it was very rude of me. But it's just a debugging thing, and is privileged.
I removed a cond_resched() from in there in the process. If we make the invalidate_inode_pages() caller pass in a must_be_atomic flag then the cond_resched() can be resuscitated.
Quoted 12 lines · On Fri, 06 Oct 2006 19:09:29 -0400 Steve Dickson <[email protected]> wrote:
Quoted 12 lines
It's not 100% clear what the
gfp_t_means_ in thetry_to_release_page()context. Callees will rarely want to allocate memory (true?). So it conveys two concepts:a) can sleep. (
__GFP_WAIT). That's fairly straightforwardb) can take fs locks (
__GFP_FS). This is less clear. By passing down__GFP_FSwe're telling the callee that it's OK to takei_mutex, evenlock_page(). That sounds pretty unsafe in this context, particularly the latter, as we're already holding a page lock.
Quoted 4 lines
Quoted 2 lines
So perhaps the safer and more appropriate solution here is to pass in a bare
__GFP_WAIT.I agree...
__GFP_WAITdoes seem to be a bit more straightforward... either way is find.. as long as it cause NFS to flush its pages...
Except NFS looks at __GFP_FS, so __GFP_WAIT won't help.
Oh well. Passing __GFP_FS in here sort-of implies that it's OK to run lock_page(), but if a ->releasepage() impementation tries to lock the page it's passed then it needs its head read.
I made it GFP_KERNEL.
mm/truncate.c invalidate_complete_page2(struct address · line 305
Quoted 2 lines · Trond Myklebust
mm/truncate.c +1
-1-if (PagePrivate (page) && !try_to_release_page (page,0 )) +if (PagePrivate (page) && !try_to_release_page (page,GFP_KERNEL ))
This can't be the right way to fix things. try_to_release_page() may fail whatever GFP flags you give it. If the page *must* be invalidated at this point then you _must_ call the invalidatepage() op, not the releasepage() op.
What is currently there allows an instikill to take place on a page at this point, but defers the kill on pages that are busy until all the pages have been scanned once, thus giving I/O time to happen on busy pages whilst reaping pages that can be made immediately available.
David
Quoted 8 lines · David Howells
mm/truncate.c invalidate_complete_page2(struct address · line 305
Quoted 2 lines · Trond Myklebust
mm/truncate.c +1
-1-if (PagePrivate (page) && !try_to_release_page (page,0 )) +if (PagePrivate (page) && !try_to_release_page (page,GFP_KERNEL ))This can't be the right way to fix things.
try_to_release_page()may fail whatever GFP flags you give it. If the page *must* be invalidated at this point then you _must_ call theinvalidatepage()op, not thereleasepage()op.
No. Invalidatepage does precisely the wrong thing: it invalidates dirty data instead of committing it to disk. If you need to have the data invalidated, then you should call truncate_inode_pages().
Trond
Quoted 4 lines · Trond Myklebust
No. Invalidatepage does precisely the wrong thing: it invalidates dirty data instead of committing it to disk. If you need to have the data invalidated, then you should call
truncate_inode_pages().
Just curious... would it make sense to call truncate_inode_pages() to purge the the readdir cache? Meaning, in nfs_revalidate_mapping() truncate_inode_pages() would be called for S_ISDIR inodes?
It seems to me that it would be more of a decisive why to ensure the readdir cache is purged...
steved.
Quoted 9 lines · Steve Dickson
Quoted 4 lines · Trond Myklebust
No. Invalidatepage does precisely the wrong thing: it invalidates dirty data instead of committing it to disk. If you need to have the data invalidated, then you should call
truncate_inode_pages().Just curious... would it make sense to call
truncate_inode_pages()to purge the the readdir cache? Meaning, innfs_revalidate_mapping()truncate_inode_pages()would be called forS_ISDIRinodes?
Why? If, as in the case of an NFS directory, there are no dirty pages then the two are supposed to be 100% equivalent.
Trond
Quoted 11 lines · Trond Myklebust
Quoted 7 lines · Steve Dickson
Quoted 3 lines · Trond Myklebust
No. Invalidatepage does precisely the wrong thing: it invalidates dirty data instead of committing it to disk. If you need to have the data invalidated, then you should call
truncate_inode_pages().Just curious... would it make sense to call
truncate_inode_pages()to purge the the readdir cache? Meaning, innfs_revalidate_mapping()truncate_inode_pages()would be called forS_ISDIRinodes?Why? If, as in the case of an NFS directory, there are no dirty pages then the two are supposed to be 100% equivalent.
Well as you know, lately we've had problems with invalidate_inode_pages2() failing to invalidate pages (regardless of their state). So I was thinking truncate_inode_pages() might be
better for directories since there seem to be more a guarantee that
the pages will be gone with truncate_inode_pages() thaninvalidate_inode_pages2() (due to the fact there will not be any
dirty pages).
But since you have to call truncate_inode_pages under the inode->i_mutex, there might be a performance hit...
steved.
Quoted 11 lines · Steve Dickson
Quoted 2 lines · Trond Myklebust
Why? If, as in the case of an NFS directory, there are no dirty pages then the two are supposed to be 100% equivalent.
Well as you know, lately we've had problems with
invalidate_inode_pages2()failing to invalidate pages (regardless of their state). So I was thinkingtruncate_inode_pages()might be better for directories since there seem to be more a guarantee that the pages will be gone withtruncate_inode_pages()thaninvalidate_inode_pages2()(due to the fact there will not be any dirty pages).
truncate_inode_pages and invalidate_inode_pages2 are supposed to result in exactly the same behaviour on NFS directories. If they don't then that would be a bug.
Trond
Quoted 3 lines · Trond Myklebust
No. Invalidatepage does precisely the wrong thing: it invalidates dirty data instead of committing it to disk. If you need to have the data invalidated, then you should call
truncate_inode_pages().
Hmmm... Good point, but you still need to handle try_to_release_page() failing, but that only means checking the return value of invalidate_inode_pages2_range (which you don't do, I notice). Or is it defined that if must succeed if __GFP_WAIT is set?
With the two-phase thing, I think I'm thinking of the wrong portion of that file (I'm thinking of truncate_inode_pages_range()).
Should invalidate_inode_pages2_range() take a gfp_t argument to pass on down?
David
Quoted 10 lines · David Howells
Quoted 3 lines · Trond Myklebust
No. Invalidatepage does precisely the wrong thing: it invalidates dirty data instead of committing it to disk. If you need to have the data invalidated, then you should call
truncate_inode_pages().Hmmm... Good point, but you still need to handle
try_to_release_page()failing, but that only means checking the return value ofinvalidate_inode_pages2_range(which you don't do, I notice). Or is it defined that if must succeed if__GFP_WAITis set?
The only way for it to fail if __GFP_IO is set, is if someone kills the process.
Note that since the NFS client itself will flush out all dirty data to disk prior to calling invalidate_inode_pages2, the only thing we're trying to do here is to avoid races while invalidating those pages.
Quoted 4 lines
With the two-phase thing, I think I'm thinking of the wrong portion of that file (I'm thinking of
truncate_inode_pages_range()).Should
invalidate_inode_pages2_range()take agfp_targument to pass on down?
Maybe. Do any of the current callers care? NFS should be quite happy with the patch that is currently in Andrew's tree.
Trond