diff mbox series

[3/6] iomap: Use __set_page_dirty_nobuffers

Message ID 20210615162342.1669332-4-willy@infradead.org (mailing list archive)
State New
Headers show
Series Further set_page_dirty cleanups | expand

Commit Message

Matthew Wilcox June 15, 2021, 4:23 p.m. UTC
The only difference between iomap_set_page_dirty() and
__set_page_dirty_nobuffers() is that the latter includes a debugging
check that a !Uptodate page has private data.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/gfs2/aops.c         |  2 +-
 fs/iomap/buffered-io.c | 27 +--------------------------
 fs/xfs/xfs_aops.c      |  2 +-
 fs/zonefs/super.c      |  2 +-
 include/linux/iomap.h  |  1 -
 5 files changed, 4 insertions(+), 30 deletions(-)

Comments

Christoph Hellwig June 15, 2021, 4:37 p.m. UTC | #1
On Tue, Jun 15, 2021 at 05:23:39PM +0100, Matthew Wilcox (Oracle) wrote:
> The only difference between iomap_set_page_dirty() and
> __set_page_dirty_nobuffers() is that the latter includes a debugging
> check that a !Uptodate page has private data.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
Greg Kroah-Hartman June 15, 2021, 5:19 p.m. UTC | #2
On Tue, Jun 15, 2021 at 05:23:39PM +0100, Matthew Wilcox (Oracle) wrote:
> The only difference between iomap_set_page_dirty() and
> __set_page_dirty_nobuffers() is that the latter includes a debugging
> check that a !Uptodate page has private data.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>  fs/gfs2/aops.c         |  2 +-
>  fs/iomap/buffered-io.c | 27 +--------------------------
>  fs/xfs/xfs_aops.c      |  2 +-
>  fs/zonefs/super.c      |  2 +-
>  include/linux/iomap.h  |  1 -
>  5 files changed, 4 insertions(+), 30 deletions(-)
> 
> diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
> index 50dd1771d00c..746b78c3a91d 100644
> --- a/fs/gfs2/aops.c
> +++ b/fs/gfs2/aops.c
> @@ -784,7 +784,7 @@ static const struct address_space_operations gfs2_aops = {
>  	.writepages = gfs2_writepages,
>  	.readpage = gfs2_readpage,
>  	.readahead = gfs2_readahead,
> -	.set_page_dirty = iomap_set_page_dirty,
> +	.set_page_dirty = __set_page_dirty_nobuffers,

Using __ functions in structures in different modules feels odd to me.
Why not just have iomap_set_page_dirty be a #define to this function now
if you want to do this?

Or take the __ off of the function name?

Anyway, logic here is fine, but feels odd.

greg k-h
Matthew Wilcox June 15, 2021, 5:32 p.m. UTC | #3
On Tue, Jun 15, 2021 at 07:19:59PM +0200, Greg Kroah-Hartman wrote:
> On Tue, Jun 15, 2021 at 05:23:39PM +0100, Matthew Wilcox (Oracle) wrote:
> Using __ functions in structures in different modules feels odd to me.
> Why not just have iomap_set_page_dirty be a #define to this function now
> if you want to do this?
> 
> Or take the __ off of the function name?
> 
> Anyway, logic here is fine, but feels odd.

heh, that was how I did it the first time.  Then I thought that it was
better to follow Christoph's patch:

 static const struct address_space_operations adfs_aops = {
+       .set_page_dirty = __set_page_dirty_buffers,
(etc)
Christoph Hellwig June 15, 2021, 5:34 p.m. UTC | #4
On Tue, Jun 15, 2021 at 06:32:37PM +0100, Matthew Wilcox wrote:
> On Tue, Jun 15, 2021 at 07:19:59PM +0200, Greg Kroah-Hartman wrote:
> > On Tue, Jun 15, 2021 at 05:23:39PM +0100, Matthew Wilcox (Oracle) wrote:
> > Using __ functions in structures in different modules feels odd to me.
> > Why not just have iomap_set_page_dirty be a #define to this function now
> > if you want to do this?
> > 
> > Or take the __ off of the function name?
> > 
> > Anyway, logic here is fine, but feels odd.
> 
> heh, that was how I did it the first time.  Then I thought that it was
> better to follow Christoph's patch:
> 
>  static const struct address_space_operations adfs_aops = {
> +       .set_page_dirty = __set_page_dirty_buffers,
> (etc)

Eventually everything around set_page_dirty should be changed to operate
on folios, and that will be a good time to come up with a sane
naming scheme without introducing extra churn.
Greg Kroah-Hartman June 15, 2021, 6:04 p.m. UTC | #5
On Tue, Jun 15, 2021 at 07:34:53PM +0200, Christoph Hellwig wrote:
> On Tue, Jun 15, 2021 at 06:32:37PM +0100, Matthew Wilcox wrote:
> > On Tue, Jun 15, 2021 at 07:19:59PM +0200, Greg Kroah-Hartman wrote:
> > > On Tue, Jun 15, 2021 at 05:23:39PM +0100, Matthew Wilcox (Oracle) wrote:
> > > Using __ functions in structures in different modules feels odd to me.
> > > Why not just have iomap_set_page_dirty be a #define to this function now
> > > if you want to do this?
> > > 
> > > Or take the __ off of the function name?
> > > 
> > > Anyway, logic here is fine, but feels odd.
> > 
> > heh, that was how I did it the first time.  Then I thought that it was
> > better to follow Christoph's patch:
> > 
> >  static const struct address_space_operations adfs_aops = {
> > +       .set_page_dirty = __set_page_dirty_buffers,
> > (etc)
> 
> Eventually everything around set_page_dirty should be changed to operate
> on folios, and that will be a good time to come up with a sane
> naming scheme without introducing extra churn.

Ok, that's fine, I don't normally touch these files, so it's not an
issue for me :)
Matthew Wilcox June 15, 2021, 6:13 p.m. UTC | #6
On Tue, Jun 15, 2021 at 07:34:53PM +0200, Christoph Hellwig wrote:
> On Tue, Jun 15, 2021 at 06:32:37PM +0100, Matthew Wilcox wrote:
> > On Tue, Jun 15, 2021 at 07:19:59PM +0200, Greg Kroah-Hartman wrote:
> > > On Tue, Jun 15, 2021 at 05:23:39PM +0100, Matthew Wilcox (Oracle) wrote:
> > > Using __ functions in structures in different modules feels odd to me.
> > > Why not just have iomap_set_page_dirty be a #define to this function now
> > > if you want to do this?
> > > 
> > > Or take the __ off of the function name?
> > > 
> > > Anyway, logic here is fine, but feels odd.
> > 
> > heh, that was how I did it the first time.  Then I thought that it was
> > better to follow Christoph's patch:
> > 
> >  static const struct address_space_operations adfs_aops = {
> > +       .set_page_dirty = __set_page_dirty_buffers,
> > (etc)
> 
> Eventually everything around set_page_dirty should be changed to operate
> on folios, and that will be a good time to come up with a sane
> naming scheme without introducing extra churn.

The way it currently looks in my tree ...

set_page_dirty(page) is a thin wrapper that calls folio_mark_dirty(folio).
folio_mark_dirty() calls a_ops->dirty_folio(mapping, folio) (which
	returns bool).
__set_page_dirty_nobuffers() becomes filemap_dirty_folio()
__set_page_dirty_buffers() becomes block_dirty_folio()
__set_page_dirty_no_writeback() becomes dirty_folio_no_writeback()

Now I look at it, maybe that last should be nowb_dirty_folio().
Greg Kroah-Hartman June 16, 2021, 6:50 a.m. UTC | #7
On Tue, Jun 15, 2021 at 07:13:16PM +0100, Matthew Wilcox wrote:
> On Tue, Jun 15, 2021 at 07:34:53PM +0200, Christoph Hellwig wrote:
> > On Tue, Jun 15, 2021 at 06:32:37PM +0100, Matthew Wilcox wrote:
> > > On Tue, Jun 15, 2021 at 07:19:59PM +0200, Greg Kroah-Hartman wrote:
> > > > On Tue, Jun 15, 2021 at 05:23:39PM +0100, Matthew Wilcox (Oracle) wrote:
> > > > Using __ functions in structures in different modules feels odd to me.
> > > > Why not just have iomap_set_page_dirty be a #define to this function now
> > > > if you want to do this?
> > > > 
> > > > Or take the __ off of the function name?
> > > > 
> > > > Anyway, logic here is fine, but feels odd.
> > > 
> > > heh, that was how I did it the first time.  Then I thought that it was
> > > better to follow Christoph's patch:
> > > 
> > >  static const struct address_space_operations adfs_aops = {
> > > +       .set_page_dirty = __set_page_dirty_buffers,
> > > (etc)
> > 
> > Eventually everything around set_page_dirty should be changed to operate
> > on folios, and that will be a good time to come up with a sane
> > naming scheme without introducing extra churn.
> 
> The way it currently looks in my tree ...
> 
> set_page_dirty(page) is a thin wrapper that calls folio_mark_dirty(folio).
> folio_mark_dirty() calls a_ops->dirty_folio(mapping, folio) (which
> 	returns bool).
> __set_page_dirty_nobuffers() becomes filemap_dirty_folio()
> __set_page_dirty_buffers() becomes block_dirty_folio()
> __set_page_dirty_no_writeback() becomes dirty_folio_no_writeback()
> 
> Now I look at it, maybe that last should be nowb_dirty_folio().

Not to be a pain, but you are mixing "folio" at the front and back of
the api name?  We messed up in the driver core with this for some things
(get_device() being one), I would recommend just sticking with one
naming scheme now as you are getting to pick what you want to use.

So perhaps for the above:
	folio_mark_dirty()
	folio_dirty_no_writeback()
	folio_dirty_filemap()
	folio_dirty_block()

much like "set_page" is used today?

Anyway, just bikeshedding, it's your code, your choice :)

thanks for doing this work overall.

greg k-h
Matthew Wilcox June 16, 2021, 4:28 p.m. UTC | #8
On Wed, Jun 16, 2021 at 08:50:40AM +0200, Greg Kroah-Hartman wrote:
> On Tue, Jun 15, 2021 at 07:13:16PM +0100, Matthew Wilcox wrote:
> > On Tue, Jun 15, 2021 at 07:34:53PM +0200, Christoph Hellwig wrote:
> > > Eventually everything around set_page_dirty should be changed to operate
> > > on folios, and that will be a good time to come up with a sane
> > > naming scheme without introducing extra churn.
> > 
> > The way it currently looks in my tree ...
> > 
> > set_page_dirty(page) is a thin wrapper that calls folio_mark_dirty(folio).
> > folio_mark_dirty() calls a_ops->dirty_folio(mapping, folio) (which
> > 	returns bool).
> > __set_page_dirty_nobuffers() becomes filemap_dirty_folio()
> > __set_page_dirty_buffers() becomes block_dirty_folio()
> > __set_page_dirty_no_writeback() becomes dirty_folio_no_writeback()
> > 
> > Now I look at it, maybe that last should be nowb_dirty_folio().
> 
> Not to be a pain, but you are mixing "folio" at the front and back of
> the api name?  We messed up in the driver core with this for some things
> (get_device() being one), I would recommend just sticking with one
> naming scheme now as you are getting to pick what you want to use.

That is mostly what I'm doing.  eg,

get_page -> folio_get
lock_page -> folio_lock
PageUptodate -> folio_uptodate
set_page_dirty -> folio_mark_dirty

What I haven't dealt with yet is the naming of the
address_space_operations.  My thinking with those is that they should
be verb_folio, since they _aren't_ the functions that get called.
ie it looks like this:

folio_mark_dirty()
  aops->dirty_folio()
    ext4_dirty_folio()
      buffer_dirty_folio()

I actually see the inconsistency here as a good thing -- these are
implementations of the aop, so foo_verb_folio() means you're doing
something weird and internal instead of going through the vfs/mm.

That implies doing things like renaming ->readpage to ->read_folio, but
if we're changing the API from passing a struct page to a struct folio,
that can all be done at the same time with no additional disruption.
Greg Kroah-Hartman June 16, 2021, 4:35 p.m. UTC | #9
On Wed, Jun 16, 2021 at 05:28:14PM +0100, Matthew Wilcox wrote:
> On Wed, Jun 16, 2021 at 08:50:40AM +0200, Greg Kroah-Hartman wrote:
> > On Tue, Jun 15, 2021 at 07:13:16PM +0100, Matthew Wilcox wrote:
> > > On Tue, Jun 15, 2021 at 07:34:53PM +0200, Christoph Hellwig wrote:
> > > > Eventually everything around set_page_dirty should be changed to operate
> > > > on folios, and that will be a good time to come up with a sane
> > > > naming scheme without introducing extra churn.
> > > 
> > > The way it currently looks in my tree ...
> > > 
> > > set_page_dirty(page) is a thin wrapper that calls folio_mark_dirty(folio).
> > > folio_mark_dirty() calls a_ops->dirty_folio(mapping, folio) (which
> > > 	returns bool).
> > > __set_page_dirty_nobuffers() becomes filemap_dirty_folio()
> > > __set_page_dirty_buffers() becomes block_dirty_folio()
> > > __set_page_dirty_no_writeback() becomes dirty_folio_no_writeback()
> > > 
> > > Now I look at it, maybe that last should be nowb_dirty_folio().
> > 
> > Not to be a pain, but you are mixing "folio" at the front and back of
> > the api name?  We messed up in the driver core with this for some things
> > (get_device() being one), I would recommend just sticking with one
> > naming scheme now as you are getting to pick what you want to use.
> 
> That is mostly what I'm doing.  eg,
> 
> get_page -> folio_get
> lock_page -> folio_lock
> PageUptodate -> folio_uptodate
> set_page_dirty -> folio_mark_dirty

Nice.

> What I haven't dealt with yet is the naming of the
> address_space_operations.  My thinking with those is that they should
> be verb_folio, since they _aren't_ the functions that get called.
> ie it looks like this:
> 
> folio_mark_dirty()
>   aops->dirty_folio()
>     ext4_dirty_folio()
>       buffer_dirty_folio()
> 
> I actually see the inconsistency here as a good thing -- these are
> implementations of the aop, so foo_verb_folio() means you're doing
> something weird and internal instead of going through the vfs/mm.
> 
> That implies doing things like renaming ->readpage to ->read_folio, but
> if we're changing the API from passing a struct page to a struct folio,
> that can all be done at the same time with no additional disruption.

Ok, as long as there's a reason for the naming scheme, I'm happy as
hopefully it will make sense to others as well.

thanks,

greg k-h
diff mbox series

Patch

diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
index 50dd1771d00c..746b78c3a91d 100644
--- a/fs/gfs2/aops.c
+++ b/fs/gfs2/aops.c
@@ -784,7 +784,7 @@  static const struct address_space_operations gfs2_aops = {
 	.writepages = gfs2_writepages,
 	.readpage = gfs2_readpage,
 	.readahead = gfs2_readahead,
-	.set_page_dirty = iomap_set_page_dirty,
+	.set_page_dirty = __set_page_dirty_nobuffers,
 	.releasepage = iomap_releasepage,
 	.invalidatepage = iomap_invalidatepage,
 	.bmap = gfs2_bmap,
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 2bf4778f2098..41da4f14c00b 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -640,31 +640,6 @@  iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags,
 	return status;
 }
 
-int
-iomap_set_page_dirty(struct page *page)
-{
-	struct address_space *mapping = page_mapping(page);
-	int newly_dirty;
-
-	if (unlikely(!mapping))
-		return !TestSetPageDirty(page);
-
-	/*
-	 * Lock out page's memcg migration to keep PageDirty
-	 * synchronized with per-memcg dirty page counters.
-	 */
-	lock_page_memcg(page);
-	newly_dirty = !TestSetPageDirty(page);
-	if (newly_dirty)
-		__set_page_dirty(page, mapping, 0);
-	unlock_page_memcg(page);
-
-	if (newly_dirty)
-		__mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
-	return newly_dirty;
-}
-EXPORT_SYMBOL_GPL(iomap_set_page_dirty);
-
 static size_t __iomap_write_end(struct inode *inode, loff_t pos, size_t len,
 		size_t copied, struct page *page)
 {
@@ -684,7 +659,7 @@  static size_t __iomap_write_end(struct inode *inode, loff_t pos, size_t len,
 	if (unlikely(copied < len && !PageUptodate(page)))
 		return 0;
 	iomap_set_range_uptodate(page, offset_in_page(pos), len);
-	iomap_set_page_dirty(page);
+	__set_page_dirty_nobuffers(page);
 	return copied;
 }
 
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 826caa6b4a5a..a335d79dcff8 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -561,7 +561,7 @@  const struct address_space_operations xfs_address_space_operations = {
 	.readahead		= xfs_vm_readahead,
 	.writepage		= xfs_vm_writepage,
 	.writepages		= xfs_vm_writepages,
-	.set_page_dirty		= iomap_set_page_dirty,
+	.set_page_dirty		= __set_page_dirty_nobuffers,
 	.releasepage		= iomap_releasepage,
 	.invalidatepage		= iomap_invalidatepage,
 	.bmap			= xfs_vm_bmap,
diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
index cd145d318b17..3aacf016c7c2 100644
--- a/fs/zonefs/super.c
+++ b/fs/zonefs/super.c
@@ -185,7 +185,7 @@  static const struct address_space_operations zonefs_file_aops = {
 	.readahead		= zonefs_readahead,
 	.writepage		= zonefs_writepage,
 	.writepages		= zonefs_writepages,
-	.set_page_dirty		= iomap_set_page_dirty,
+	.set_page_dirty		= __set_page_dirty_nobuffers,
 	.releasepage		= iomap_releasepage,
 	.invalidatepage		= iomap_invalidatepage,
 	.migratepage		= iomap_migrate_page,
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index c87d0cb0de6d..479c1da3e221 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -159,7 +159,6 @@  ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from,
 		const struct iomap_ops *ops);
 int iomap_readpage(struct page *page, const struct iomap_ops *ops);
 void iomap_readahead(struct readahead_control *, const struct iomap_ops *ops);
-int iomap_set_page_dirty(struct page *page);
 int iomap_is_partially_uptodate(struct page *page, unsigned long from,
 		unsigned long count);
 int iomap_releasepage(struct page *page, gfp_t gfp_mask);