All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v14 075/138] mm/writeback: Add folio_account_redirty()
  2021-07-15  3:34 [PATCH v14 000/138] Memory folios Matthew Wilcox (Oracle)
@ 2021-07-15  3:36 ` Matthew Wilcox (Oracle)
  2021-08-10 21:25   ` David Howells
  2021-08-12 16:27   ` Vlastimil Babka
  0 siblings, 2 replies; 4+ messages in thread
From: Matthew Wilcox (Oracle) @ 2021-07-15  3:36 UTC (permalink / raw)
  To: linux-kernel
  Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel,
	Christoph Hellwig

Account the number of pages in the folio that we're redirtying.
Turn account_page_dirty() into a wrapper around it.  Also turn
the comment on folio_account_redirty() into kernel-doc and
edit it slightly so it makes sense to its potential callers.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/writeback.h |  6 +++++-
 mm/page-writeback.c       | 32 +++++++++++++++++++-------------
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index eda9cc778ef6..50cb6e25ab9e 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -399,7 +399,11 @@ void tag_pages_for_writeback(struct address_space *mapping,
 			     pgoff_t start, pgoff_t end);
 
 bool filemap_dirty_folio(struct address_space *mapping, struct folio *folio);
-void account_page_redirty(struct page *page);
+void folio_account_redirty(struct folio *folio);
+static inline void account_page_redirty(struct page *page)
+{
+	folio_account_redirty(page_folio(page));
+}
 
 void sb_mark_inode_writeback(struct inode *inode);
 void sb_clear_inode_writeback(struct inode *inode);
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 66060bbf6aad..d7bd5580c91e 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -1084,7 +1084,7 @@ static void wb_update_write_bandwidth(struct bdi_writeback *wb,
 	 * write_bandwidth = ---------------------------------------------------
 	 *                                          period
 	 *
-	 * @written may have decreased due to account_page_redirty().
+	 * @written may have decreased due to folio_account_redirty().
 	 * Avoid underflowing @bw calculation.
 	 */
 	bw = written - min(written, wb->written_stamp);
@@ -2527,30 +2527,36 @@ bool filemap_dirty_folio(struct address_space *mapping, struct folio *folio)
 }
 EXPORT_SYMBOL(filemap_dirty_folio);
 
-/*
- * Call this whenever redirtying a page, to de-account the dirty counters
- * (NR_DIRTIED, WB_DIRTIED, tsk->nr_dirtied), so that they match the written
- * counters (NR_WRITTEN, WB_WRITTEN) in long term. The mismatches will lead to
- * systematic errors in balanced_dirty_ratelimit and the dirty pages position
- * control.
+/**
+ * folio_account_redirty - Manually account for redirtying a page.
+ * @folio: The folio which is being redirtied.
+ *
+ * Most filesystems should call folio_redirty_for_writepage() instead
+ * of this fuction.  If your filesystem is doing writeback outside the
+ * context of a writeback_control(), it can call this when redirtying
+ * a folio, to de-account the dirty counters (NR_DIRTIED, WB_DIRTIED,
+ * tsk->nr_dirtied), so that they match the written counters (NR_WRITTEN,
+ * WB_WRITTEN) in long term. The mismatches will lead to systematic errors
+ * in balanced_dirty_ratelimit and the dirty pages position control.
  */
-void account_page_redirty(struct page *page)
+void folio_account_redirty(struct folio *folio)
 {
-	struct address_space *mapping = page->mapping;
+	struct address_space *mapping = folio->mapping;
 
 	if (mapping && mapping_can_writeback(mapping)) {
 		struct inode *inode = mapping->host;
 		struct bdi_writeback *wb;
 		struct wb_lock_cookie cookie = {};
+		unsigned nr = folio_nr_pages(folio);
 
 		wb = unlocked_inode_to_wb_begin(inode, &cookie);
-		current->nr_dirtied--;
-		dec_node_page_state(page, NR_DIRTIED);
-		dec_wb_stat(wb, WB_DIRTIED);
+		current->nr_dirtied -= nr;
+		node_stat_mod_folio(folio, NR_DIRTIED, -nr);
+		wb_stat_mod(wb, WB_DIRTIED, -nr);
 		unlocked_inode_to_wb_end(inode, &cookie);
 	}
 }
-EXPORT_SYMBOL(account_page_redirty);
+EXPORT_SYMBOL(folio_account_redirty);
 
 /*
  * When a writepage implementation decides that it doesn't want to write this
-- 
2.30.2


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

* Re: [PATCH v14 075/138] mm/writeback: Add folio_account_redirty()
@ 2021-07-18 18:10 kernel test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2021-07-18 18:10 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 5562 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210715033704.692967-76-willy@infradead.org>
References: <20210715033704.692967-76-willy@infradead.org>
TO: "Matthew Wilcox (Oracle)" <willy@infradead.org>
TO: linux-kernel(a)vger.kernel.org
CC: "Matthew Wilcox (Oracle)" <willy@infradead.org>
CC: linux-mm(a)kvack.org
CC: linux-fsdevel(a)vger.kernel.org
CC: Christoph Hellwig <hch@lst.de>

Hi "Matthew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[cannot apply to hnaz-linux-mm/master xfs-linux/for-next tip/perf/core v5.14-rc1 next-20210716]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Matthew-Wilcox-Oracle/Memory-folios/20210715-133101
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 8096acd7442e613fad0354fc8dfdb2003cceea0b
:::::: branch date: 4 days ago
:::::: commit date: 4 days ago
config: x86_64-rhel-8.3-kselftests (attached as .config)
compiler: gcc-10 (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-341-g8af24329-dirty
        # https://github.com/0day-ci/linux/commit/0c8f837126e446aec4f81618cacd58411a390951
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Matthew-Wilcox-Oracle/Memory-folios/20210715-133101
        git checkout 0c8f837126e446aec4f81618cacd58411a390951
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)
   mm/page-writeback.c: note: in included file (through include/linux/rculist.h, include/linux/dcache.h, include/linux/fs.h):
>> include/linux/rcupdate.h:716:9: sparse: sparse: context imbalance in 'folio_account_redirty' - different lock contexts for basic block
   include/linux/rcupdate.h:716:9: sparse: sparse: context imbalance in '__folio_cancel_dirty' - different lock contexts for basic block
   include/linux/rcupdate.h:716:9: sparse: sparse: context imbalance in 'folio_clear_dirty_for_io' - different lock contexts for basic block

vim +/folio_account_redirty +716 include/linux/rcupdate.h

^1da177e4c3f415 Linus Torvalds   2005-04-16  691  
^1da177e4c3f415 Linus Torvalds   2005-04-16  692  /*
^1da177e4c3f415 Linus Torvalds   2005-04-16  693   * So where is rcu_write_lock()?  It does not exist, as there is no
^1da177e4c3f415 Linus Torvalds   2005-04-16  694   * way for writers to lock out RCU readers.  This is a feature, not
^1da177e4c3f415 Linus Torvalds   2005-04-16  695   * a bug -- this property is what provides RCU's performance benefits.
^1da177e4c3f415 Linus Torvalds   2005-04-16  696   * Of course, writers must coordinate with each other.  The normal
^1da177e4c3f415 Linus Torvalds   2005-04-16  697   * spinlock primitives work well for this, but any other technique may be
^1da177e4c3f415 Linus Torvalds   2005-04-16  698   * used as well.  RCU does not care how the writers keep out of each
^1da177e4c3f415 Linus Torvalds   2005-04-16  699   * others' way, as long as they do so.
^1da177e4c3f415 Linus Torvalds   2005-04-16  700   */
3d76c082907e8f8 Paul E. McKenney 2009-09-28  701  
3d76c082907e8f8 Paul E. McKenney 2009-09-28  702  /**
ca5ecddfa8fcbd9 Paul E. McKenney 2010-04-28  703   * rcu_read_unlock() - marks the end of an RCU read-side critical section.
3d76c082907e8f8 Paul E. McKenney 2009-09-28  704   *
0223846010750e2 Paul E. McKenney 2021-04-29  705   * In almost all situations, rcu_read_unlock() is immune from deadlock.
0223846010750e2 Paul E. McKenney 2021-04-29  706   * In recent kernels that have consolidated synchronize_sched() and
0223846010750e2 Paul E. McKenney 2021-04-29  707   * synchronize_rcu_bh() into synchronize_rcu(), this deadlock immunity
0223846010750e2 Paul E. McKenney 2021-04-29  708   * also extends to the scheduler's runqueue and priority-inheritance
0223846010750e2 Paul E. McKenney 2021-04-29  709   * spinlocks, courtesy of the quiescent-state deferral that is carried
0223846010750e2 Paul E. McKenney 2021-04-29  710   * out when rcu_read_unlock() is invoked with interrupts disabled.
f27bc4873fa8b75 Paul E. McKenney 2014-05-04  711   *
3d76c082907e8f8 Paul E. McKenney 2009-09-28  712   * See rcu_read_lock() for more information.
3d76c082907e8f8 Paul E. McKenney 2009-09-28  713   */
bc33f24bdca8b6e Paul E. McKenney 2009-08-22  714  static inline void rcu_read_unlock(void)
bc33f24bdca8b6e Paul E. McKenney 2009-08-22  715  {
f78f5b90c4ffa55 Paul E. McKenney 2015-06-18 @716  	RCU_LOCKDEP_WARN(!rcu_is_watching(),
bde23c6892878e4 Heiko Carstens   2012-02-01  717  			 "rcu_read_unlock() used illegally while idle");
bc33f24bdca8b6e Paul E. McKenney 2009-08-22  718  	__release(RCU);
bc33f24bdca8b6e Paul E. McKenney 2009-08-22  719  	__rcu_read_unlock();
d24209bb689e2c7 Paul E. McKenney 2015-01-21  720  	rcu_lock_release(&rcu_lock_map); /* Keep acq info for rls diags. */
bc33f24bdca8b6e Paul E. McKenney 2009-08-22  721  }
^1da177e4c3f415 Linus Torvalds   2005-04-16  722  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 42159 bytes --]

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

* Re: [PATCH v14 075/138] mm/writeback: Add folio_account_redirty()
  2021-07-15  3:36 ` [PATCH v14 075/138] mm/writeback: Add folio_account_redirty() Matthew Wilcox (Oracle)
@ 2021-08-10 21:25   ` David Howells
  2021-08-12 16:27   ` Vlastimil Babka
  1 sibling, 0 replies; 4+ messages in thread
From: David Howells @ 2021-08-10 21:25 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: dhowells, linux-kernel, linux-mm, linux-fsdevel,
	Christoph Hellwig

Matthew Wilcox (Oracle) <willy@infradead.org> wrote:

> Account the number of pages in the folio that we're redirtying.
> Turn account_page_dirty() into a wrapper around it.  Also turn
> the comment on folio_account_redirty() into kernel-doc and
> edit it slightly so it makes sense to its potential callers.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: David Howells <dhowells@redhat.com>


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

* Re: [PATCH v14 075/138] mm/writeback: Add folio_account_redirty()
  2021-07-15  3:36 ` [PATCH v14 075/138] mm/writeback: Add folio_account_redirty() Matthew Wilcox (Oracle)
  2021-08-10 21:25   ` David Howells
@ 2021-08-12 16:27   ` Vlastimil Babka
  1 sibling, 0 replies; 4+ messages in thread
From: Vlastimil Babka @ 2021-08-12 16:27 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle), linux-kernel
  Cc: linux-mm, linux-fsdevel, Christoph Hellwig

On 7/15/21 5:36 AM, Matthew Wilcox (Oracle) wrote:
> Account the number of pages in the folio that we're redirtying.
> Turn account_page_dirty() into a wrapper around it.  Also turn
> the comment on folio_account_redirty() into kernel-doc and
> edit it slightly so it makes sense to its potential callers.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Reviewed-by: Christoph Hellwig <hch@lst.de>

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

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

end of thread, other threads:[~2021-08-12 16:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-18 18:10 [PATCH v14 075/138] mm/writeback: Add folio_account_redirty() kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2021-07-15  3:34 [PATCH v14 000/138] Memory folios Matthew Wilcox (Oracle)
2021-07-15  3:36 ` [PATCH v14 075/138] mm/writeback: Add folio_account_redirty() Matthew Wilcox (Oracle)
2021-08-10 21:25   ` David Howells
2021-08-12 16:27   ` Vlastimil Babka

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.