diff mbox series

[v14,072/138] mm/writeback: Add folio_account_cleaned()

Message ID 20210715033704.692967-73-willy@infradead.org (mailing list archive)
State New
Headers show
Series Memory folios | expand

Commit Message

Matthew Wilcox July 15, 2021, 3:35 a.m. UTC
Get the statistics right; compound pages were being accounted as a
single page.  This didn't matter before now as no filesystem which
supported compound pages did writeback.  Also move the declaration
to filemap.h since this is part of the page cache.  Add a wrapper for
account_page_cleaned().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/mm.h      |  3 ---
 include/linux/pagemap.h |  7 +++++++
 mm/page-writeback.c     | 11 ++++++-----
 3 files changed, 13 insertions(+), 8 deletions(-)

Comments

David Howells Aug. 10, 2021, 9:22 p.m. UTC | #1
Matthew Wilcox (Oracle) <willy@infradead.org> wrote:

> Get the statistics right; compound pages were being accounted as a
> single page.  This didn't matter before now as no filesystem which
> supported compound pages did writeback.  Also move the declaration
> to filemap.h since this is part of the page cache.  Add a wrapper for
> account_page_cleaned().
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: David Howells <dhowells@redhat.com>
Vlastimil Babka Aug. 12, 2021, 4:14 p.m. UTC | #2
On 7/15/21 5:35 AM, Matthew Wilcox (Oracle) wrote:
> Get the statistics right; compound pages were being accounted as a
> single page.  This didn't matter before now as no filesystem which
> supported compound pages did writeback.  Also move the declaration
> to filemap.h since this is part of the page cache.  Add a wrapper for

Seems to be pagemap.h :)

> account_page_cleaned().
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

Nit below:
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index bd97c461d499..792a83bd3917 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -2453,14 +2453,15 @@ static void folio_account_dirtied(struct folio *folio,
>   *
>   * Caller must hold lock_page_memcg().
>   */
> -void account_page_cleaned(struct page *page, struct address_space *mapping,
> +void folio_account_cleaned(struct folio *folio, struct address_space *mapping,
>  			  struct bdi_writeback *wb)
>  {
>  	if (mapping_can_writeback(mapping)) {
> -		dec_lruvec_page_state(page, NR_FILE_DIRTY);
> -		dec_zone_page_state(page, NR_ZONE_WRITE_PENDING);
> -		dec_wb_stat(wb, WB_RECLAIMABLE);
> -		task_io_account_cancelled_write(PAGE_SIZE);
> +		long nr = folio_nr_pages(folio);
> +		lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, -nr);
> +		zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr);
> +		wb_stat_mod(wb, WB_RECLAIMABLE, -nr);
> +		task_io_account_cancelled_write(folio_size(folio));

In "mm/writeback: Add __folio_mark_dirty()" you used nr*PAGE_SIZE. Consistency?

>  	}
>  }
>  
>
Matthew Wilcox Aug. 15, 2021, 10:53 a.m. UTC | #3
On Thu, Aug 12, 2021 at 06:14:22PM +0200, Vlastimil Babka wrote:
> On 7/15/21 5:35 AM, Matthew Wilcox (Oracle) wrote:
> > Get the statistics right; compound pages were being accounted as a
> > single page.  This didn't matter before now as no filesystem which
> > supported compound pages did writeback.  Also move the declaration
> > to filemap.h since this is part of the page cache.  Add a wrapper for
> 
> Seems to be pagemap.h :)

Ugh, right.  filemap.c.  pagemap.h.  obviously.

> > +		wb_stat_mod(wb, WB_RECLAIMABLE, -nr);
> > +		task_io_account_cancelled_write(folio_size(folio));
> 
> In "mm/writeback: Add __folio_mark_dirty()" you used nr*PAGE_SIZE. Consistency?

We don't have any ;-)  I'll change that.  Some places we use <<
PAGE_SHIFT, some places we use * PAGE_SIZE ... either are better than
calling folio_size() unnecessarily.
diff mbox series

Patch

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 43c1b5731c7f..481019481d10 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -39,7 +39,6 @@  struct anon_vma_chain;
 struct file_ra_state;
 struct user_struct;
 struct writeback_control;
-struct bdi_writeback;
 struct pt_regs;
 
 extern int sysctl_page_lock_unfairness;
@@ -2003,8 +2002,6 @@  extern void do_invalidatepage(struct page *page, unsigned int offset,
 
 int redirty_page_for_writepage(struct writeback_control *wbc,
 				struct page *page);
-void account_page_cleaned(struct page *page, struct address_space *mapping,
-			  struct bdi_writeback *wb);
 bool folio_mark_dirty(struct folio *folio);
 bool set_page_dirty(struct page *page);
 int set_page_dirty_lock(struct page *page);
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 3d88c17fedc9..665ba6a67385 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -779,6 +779,13 @@  static inline void __set_page_dirty(struct page *page,
 {
 	__folio_mark_dirty(page_folio(page), mapping, warn);
 }
+void folio_account_cleaned(struct folio *folio, struct address_space *mapping,
+			  struct bdi_writeback *wb);
+static inline void account_page_cleaned(struct page *page,
+		struct address_space *mapping, struct bdi_writeback *wb)
+{
+	return folio_account_cleaned(page_folio(page), mapping, wb);
+}
 
 int __set_page_dirty_nobuffers(struct page *page);
 int __set_page_dirty_no_writeback(struct page *page);
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index bd97c461d499..792a83bd3917 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2453,14 +2453,15 @@  static void folio_account_dirtied(struct folio *folio,
  *
  * Caller must hold lock_page_memcg().
  */
-void account_page_cleaned(struct page *page, struct address_space *mapping,
+void folio_account_cleaned(struct folio *folio, struct address_space *mapping,
 			  struct bdi_writeback *wb)
 {
 	if (mapping_can_writeback(mapping)) {
-		dec_lruvec_page_state(page, NR_FILE_DIRTY);
-		dec_zone_page_state(page, NR_ZONE_WRITE_PENDING);
-		dec_wb_stat(wb, WB_RECLAIMABLE);
-		task_io_account_cancelled_write(PAGE_SIZE);
+		long nr = folio_nr_pages(folio);
+		lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, -nr);
+		zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr);
+		wb_stat_mod(wb, WB_RECLAIMABLE, -nr);
+		task_io_account_cancelled_write(folio_size(folio));
 	}
 }