Skip to contentSkip to conversation

Does swap_set_page_dirty() calling ->set_page_dirty() make sense?

DISCUSSION Jan Kara 4 participants 6 messages Sep 17, 2012 – Sep 18, 2012 Memory management

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

Hi,

I tripped over a crash in reiserfs which happened due to PageSwapCache
page being passed to reiserfs_set_page_dirty(). Now it's not that hard to make reiserfs_set_page_dirty() check that case but I really wonder: Does it make sense to call mapping->a_ops->set_page_dirty() for a PageSwapCache page? The page is going to be written via direct IO so from the POV of the filesystem there's no need for any dirtiness tracking. Also there are several ->set_page_dirty() implementations which will spectacularly crash because they do things like page->mapping->host, or call __set_page_dirty_buffers() which expects buffer heads in page->private. Or what is the reason for calling filesystem's set_page_dirty() function?

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#1 lore raw
Quoted 11 lines · Jan Kara

I tripped over a crash in reiserfs which happened due to PageSwapCache
page being passed to reiserfs_set_page_dirty(). Now it's not that hard to make reiserfs_set_page_dirty() check that case but I really wonder: Does it make sense to call mapping->a_ops->set_page_dirty() for a PageSwapCache page? The page is going to be written via direct IO so from the POV of the filesystem there's no need for any dirtiness tracking. Also there are several ->set_page_dirty() implementations which will spectacularly crash because they do things like page->mapping->host, or call __set_page_dirty_buffers() which expects buffer heads in page->private. Or what is the reason for calling filesystem's set_page_dirty() function?

This is a question for Mel, really: it used not to call the filesystem.

But my reading of the 3.6 code says that it still will not call the filesystem, unless the filesystem (only nfs) provides a swap_activate method, which should be the only case in which SWP_FILE gets set. And I rather think Mel does want to use the filesystem set_page_dirty in that case. Am I misreading?

Did you see this on a vanilla kernel? Or is it possible that you have a private patch merged in, with something else sharing the SWP_FILE bit (defined in include/linux/swap.h) by mistake?

Hugh

Quoted 48 lines

[PATCH] mm: Remove swap_set_page_dirty()

It doesn't make much sense to call filesystem's ->set_page_dirty() method for PageSwapCache page. It will be written through direct IO so filesystem doesn't care about its dirtiness and several filesystems actually don't count with such pages getting into their ->set_page_dirty() functions.

---
 mm/page_io.c    |   12 ------------
 mm/swap_state.c |    2 +-
 2 files changed, 1 insertions(+), 13 deletions(-)
mm/page_io.c +0 -12
index 78eee32..8520a4f 100644
@@ -278,15 +278,3 @@ int swap_readpage(struct page *page)
 out:
 	return ret;
 }
-
-int swap_set_page_dirty(struct page *page)
-{
-	struct swap_info_struct *sis = page_swap_info(page);
-
-	if (sis->flags & SWP_FILE) {
-		struct address_space *mapping = sis->swap_file->f_mapping;
-		return mapping->a_ops->set_page_dirty(page);
-	} else {
-		return __set_page_dirty_no_writeback(page);
-	}
-}
mm/swap_state.c +1 -1
index 0cb36fb..01852cd 100644
@@ -27,7 +27,7 @@
  */
 static const struct address_space_operations swap_aops = {
 	.writepage	= swap_writepage,
-	.set_page_dirty	= swap_set_page_dirty,
+	.set_page_dirty	= set_page_dirty_no_writeback,
 	.migratepage	= migrate_page,
 };
 
Signature · 1 line
1.7.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#2 lore raw
Quoted 21 lines · Hugh Dickins
Quoted 11 lines · Jan Kara

I tripped over a crash in reiserfs which happened due to PageSwapCache
page being passed to reiserfs_set_page_dirty(). Now it's not that hard to make reiserfs_set_page_dirty() check that case but I really wonder: Does it make sense to call mapping->a_ops->set_page_dirty() for a PageSwapCache page? The page is going to be written via direct IO so from the POV of the filesystem there's no need for any dirtiness tracking. Also there are several ->set_page_dirty() implementations which will spectacularly crash because they do things like page->mapping->host, or call __set_page_dirty_buffers() which expects buffer heads in page->private. Or what is the reason for calling filesystem's set_page_dirty() function?

This is a question for Mel, really: it used not to call the filesystem.

But my reading of the 3.6 code says that it still will not call the filesystem, unless the filesystem (only nfs) provides a swap_activate method, which should be the only case in which SWP_FILE gets set. And I rather think Mel does want to use the filesystem set_page_dirty in that case. Am I misreading?

Quoted 3 lines

Did you see this on a vanilla kernel? Or is it possible that you have a private patch merged in, with something else sharing the SWP_FILE bit (defined in include/linux/swap.h) by mistake?

Argh, sorry. It is indeed a SLES specific bug. I missed that SWP_FILE bit
gets set only when swap_activate() is provided (SLES code works a bit differently in this area but I wasn't really looking into that since I was focused elsewhere).

So just one minor nit for Mel. SWP_FILE looks like a bit confusing name for a flag that gets set only for some swap files ;) At least I didn't pay attention to it because I thought it's set for all of them. Maybe call it SWP_FILE_CALL_AOPS or something like that?

Thanks Hugh for having a look.

Honza

Signature · 8 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

Dne Út 18. září 2012 04:16:27 Jan Kara napsal(a):

Quoted 34 lines · Hugh Dickins
Quoted 24 lines · Jan Kara
Quoted 14 lines

I tripped over a crash in reiserfs which happened due to PageSwapCache

page being passed to reiserfs_set_page_dirty(). Now it's not that hard to make reiserfs_set_page_dirty() check that case but I really wonder:
Does it make sense to call mapping->a_ops->set_page_dirty() for a PageSwapCache page? The page is going to be written via direct IO so from the POV of the filesystem there's no need for any dirtiness tracking. Also there are several ->set_page_dirty() implementations which will spectacularly crash because they do things like page->mapping->host, or call
__set_page_dirty_buffers() which expects buffer heads in page->private. Or what is the reason for calling filesystem's set_page_dirty() function?

This is a question for Mel, really: it used not to call the filesystem.

But my reading of the 3.6 code says that it still will not call the filesystem, unless the filesystem (only nfs) provides a swap_activate method, which should be the only case in which SWP_FILE gets set. And I rather think Mel does want to use the filesystem set_page_dirty in that case. Am I misreading?

Quoted 3 lines

Did you see this on a vanilla kernel? Or is it possible that you have a private patch merged in, with something else sharing the SWP_FILE bit (defined in include/linux/swap.h) by mistake?

Argh, sorry. It is indeed a SLES specific bug. I missed that SWP_FILE bit
gets set only when swap_activate() is provided (SLES code works a bit differently in this area but I wasn't really looking into that since I was focused elsewhere).

Quoted 4 lines

So just one minor nit for Mel. SWP_FILE looks like a bit confusing name for a flag that gets set only for some swap files ;) At least I didn't pay attention to it because I thought it's set for all of them. Maybe call it SWP_FILE_CALL_AOPS or something like that?

Same here. In fact, I believed that other filesystems only work by accident (because they don't have to access the mapping). I'm not even sure about the semantics of the swap_activate operation. Is this documented somewhere?

Petr Tesarik
SUSE Linux

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
In reply to Hugh Dickins
Quoted 13 lines · Hugh Dickins
Quoted 11 lines · Jan Kara

I tripped over a crash in reiserfs which happened due to PageSwapCache
page being passed to reiserfs_set_page_dirty(). Now it's not that hard to make reiserfs_set_page_dirty() check that case but I really wonder: Does it make sense to call mapping->a_ops->set_page_dirty() for a PageSwapCache page? The page is going to be written via direct IO so from the POV of the filesystem there's no need for any dirtiness tracking. Also there are several ->set_page_dirty() implementations which will spectacularly crash because they do things like page->mapping->host, or call __set_page_dirty_buffers() which expects buffer heads in page->private. Or what is the reason for calling filesystem's set_page_dirty() function?

Quoted 2 lines

This is a question for Mel, really: it used not to call the filesystem.

And now it should only be called if SWP_FILE is set to perform read/write of pages through the filesystem. In practice I only expect this to happen when a swapfile is activated on NFS.

Quoted 6 lines

But my reading of the 3.6 code says that it still will not call the filesystem, unless the filesystem (only nfs) provides a swap_activate method, which should be the only case in which SWP_FILE gets set. And I rather think Mel does want to use the filesystem set_page_dirty in that case. Am I misreading?

That was the intention at least.

Quoted 4 lines

Did you see this on a vanilla kernel? Or is it possible that you have a private patch merged in, with something else sharing the SWP_FILE bit (defined in include/linux/swap.h) by mistake?

I see that Jan followed up that this was observed on SLES. The implementaiton there is based on a much earlier revision of swap-over-NFS than what was finally merged to mainline. I'll check it out.

Thanks.

Signature · 8 lines
Mel Gorman
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw
In reply to Petr Tesarik
Quoted 7 lines · Petr Tesarik
Quoted 6 lines

<SNIP>

So just one minor nit for Mel. SWP_FILE looks like a bit confusing name for a flag that gets set only for some swap files ;) At least I didn't pay attention to it because I thought it's set for all of them. Maybe call it SWP_FILE_CALL_AOPS or something like that?

I guess it would be a slightly better name all right.

Quoted 4 lines

Same here. In fact, I believed that other filesystems only work by accident (because they don't have to access the mapping). I'm not even sure about the semantics of the swap_activate operation. Is this documented somewhere?

Documentation/filesystems/vfs.txt *briefly* describes what swap_activate() does even though now that I read it I see that it's inaccurate. It says that it proxies to the address spaces swapin_[out|in] method but it really gets proxied to the direct_IO interface for writes and readpage for reads (direct_IO could have been used for reads but my recollection was that the locking was very awkward).

Signature · 8 lines
Mel Gorman
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>