mm/writeback: Add folio_wait_stable()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 4 Mar 2021 16:25:25 +0000 (11:25 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 27 Sep 2021 13:27:30 +0000 (09:27 -0400)
Move wait_for_stable_page() into the folio compatibility file.
folio_wait_stable() avoids a call to compound_head() and is 14 bytes
smaller than wait_for_stable_page() was.  The net text size grows by 16
bytes as a result of this patch.  We can also remove thp_head() as this
was the last user.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Jeff Layton <jlayton@kernel.org>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Reviewed-by: David Howells <dhowells@redhat.com>
include/linux/huge_mm.h
include/linux/pagemap.h
mm/folio-compat.c
mm/page-writeback.c

index f123e15d966e84dd85055ccb204313519f607ae3..f280f33ff223731041dfd3dad7fc37f2f91d3ea3 100644 (file)
@@ -250,15 +250,6 @@ static inline spinlock_t *pud_trans_huge_lock(pud_t *pud,
                return NULL;
 }
 
-/**
- * thp_head - Head page of a transparent huge page.
- * @page: Any page (tail, head or regular) found in the page cache.
- */
-static inline struct page *thp_head(struct page *page)
-{
-       return compound_head(page);
-}
-
 /**
  * thp_order - Order of a transparent huge page.
  * @page: Head page of a transparent huge page.
@@ -336,12 +327,6 @@ static inline struct list_head *page_deferred_list(struct page *page)
 #define HPAGE_PUD_MASK ({ BUILD_BUG(); 0; })
 #define HPAGE_PUD_SIZE ({ BUILD_BUG(); 0; })
 
-static inline struct page *thp_head(struct page *page)
-{
-       VM_BUG_ON_PGFLAGS(PageTail(page), page);
-       return page;
-}
-
 static inline unsigned int thp_order(struct page *page)
 {
        VM_BUG_ON_PGFLAGS(PageTail(page), page);
index e6013c063986cb69d485de38e8bad180e94f3382..ee39ad7b42f17ebf96a65228d95a961c94ded44e 100644 (file)
@@ -771,6 +771,7 @@ int folio_wait_writeback_killable(struct folio *folio);
 void end_page_writeback(struct page *page);
 void folio_end_writeback(struct folio *folio);
 void wait_for_stable_page(struct page *page);
+void folio_wait_stable(struct folio *folio);
 
 void __set_page_dirty(struct page *, struct address_space *, int warn);
 int __set_page_dirty_nobuffers(struct page *page);
index 41275dac7a92a73a44e05d37b3e7bab051c1c3cd..3c83f03b80d7f88f4298ae683c3c017cf12bdf41 100644 (file)
@@ -29,3 +29,9 @@ void wait_on_page_writeback(struct page *page)
        return folio_wait_writeback(page_folio(page));
 }
 EXPORT_SYMBOL_GPL(wait_on_page_writeback);
+
+void wait_for_stable_page(struct page *page)
+{
+       return folio_wait_stable(page_folio(page));
+}
+EXPORT_SYMBOL_GPL(wait_for_stable_page);
index c7f40c954217ba295069d60005d339b2111248b6..0b0b7cd81a93d0e35bd774dd379ff64a9b9304ce 100644 (file)
@@ -2920,17 +2920,21 @@ int folio_wait_writeback_killable(struct folio *folio)
 EXPORT_SYMBOL_GPL(folio_wait_writeback_killable);
 
 /**
- * wait_for_stable_page() - wait for writeback to finish, if necessary.
- * @page:      The page to wait on.
+ * folio_wait_stable() - wait for writeback to finish, if necessary.
+ * @folio: The folio to wait on.
  *
- * This function determines if the given page is related to a backing device
- * that requires page contents to be held stable during writeback.  If so, then
- * it will wait for any pending writeback to complete.
+ * This function determines if the given folio is related to a backing
+ * device that requires folio contents to be held stable during writeback.
+ * If so, then it will wait for any pending writeback to complete.
+ *
+ * Context: Sleeps.  Must be called in process context and with
+ * no spinlocks held.  Caller should hold a reference on the folio.
+ * If the folio is not locked, writeback may start again after writeback
+ * has finished.
  */
-void wait_for_stable_page(struct page *page)
+void folio_wait_stable(struct folio *folio)
 {
-       page = thp_head(page);
-       if (page->mapping->host->i_sb->s_iflags & SB_I_STABLE_WRITES)
-               wait_on_page_writeback(page);
+       if (folio->mapping->host->i_sb->s_iflags & SB_I_STABLE_WRITES)
+               folio_wait_writeback(folio);
 }
-EXPORT_SYMBOL_GPL(wait_for_stable_page);
+EXPORT_SYMBOL_GPL(folio_wait_stable);