Skip to content

Commit

Permalink
mm/writeback: Add folio_redirty_for_writepage()
Browse files Browse the repository at this point in the history
Reimplement redirty_page_for_writepage() as a wrapper around
folio_redirty_for_writepage().  Account the number of pages in the
folio, add kernel-doc and move the prototype to writeback.h.

Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Reviewed-by: David Howells <[email protected]>
Acked-by: Vlastimil Babka <[email protected]>
  • Loading branch information
Matthew Wilcox (Oracle) committed Oct 18, 2021
1 parent 25ff8b1 commit cd78ab1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions fs/jfs/jfs_metapage.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/buffer_head.h>
#include <linux/mempool.h>
#include <linux/seq_file.h>
#include <linux/writeback.h>
#include "jfs_incore.h"
#include "jfs_superblock.h"
#include "jfs_filsys.h"
Expand Down
4 changes: 0 additions & 4 deletions include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
struct mempolicy;
struct anon_vma;
struct anon_vma_chain;
struct file_ra_state;
struct user_struct;
struct writeback_control;
struct pt_regs;

extern int sysctl_page_lock_unfairness;
Expand Down Expand Up @@ -2003,8 +2001,6 @@ extern int try_to_release_page(struct page * page, gfp_t gfp_mask);
extern void do_invalidatepage(struct page *page, unsigned int offset,
unsigned int length);

int redirty_page_for_writepage(struct writeback_control *wbc,
struct page *page);
bool folio_mark_dirty(struct folio *folio);
bool set_page_dirty(struct page *page);
int set_page_dirty_lock(struct page *page);
Expand Down
2 changes: 2 additions & 0 deletions include/linux/writeback.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ static inline void account_page_redirty(struct page *page)
{
folio_account_redirty(page_folio(page));
}
bool folio_redirty_for_writepage(struct writeback_control *, struct folio *);
bool redirty_page_for_writepage(struct writeback_control *, struct page *);

void sb_mark_inode_writeback(struct inode *inode);
void sb_clear_inode_writeback(struct inode *inode);
Expand Down
7 changes: 7 additions & 0 deletions mm/folio-compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,10 @@ bool clear_page_dirty_for_io(struct page *page)
return folio_clear_dirty_for_io(page_folio(page));
}
EXPORT_SYMBOL(clear_page_dirty_for_io);

bool redirty_page_for_writepage(struct writeback_control *wbc,
struct page *page)
{
return folio_redirty_for_writepage(wbc, page_folio(page));
}
EXPORT_SYMBOL(redirty_page_for_writepage);
30 changes: 20 additions & 10 deletions mm/page-writeback.c
Original file line number Diff line number Diff line change
Expand Up @@ -2575,21 +2575,31 @@ void folio_account_redirty(struct folio *folio)
}
EXPORT_SYMBOL(folio_account_redirty);

/*
* When a writepage implementation decides that it doesn't want to write this
* page for some reason, it should redirty the locked page via
* redirty_page_for_writepage() and it should then unlock the page and return 0
/**
* folio_redirty_for_writepage - Decline to write a dirty folio.
* @wbc: The writeback control.
* @folio: The folio.
*
* When a writepage implementation decides that it doesn't want to write
* @folio for some reason, it should call this function, unlock @folio and
* return 0.
*
* Return: True if we redirtied the folio. False if someone else dirtied
* it first.
*/
int redirty_page_for_writepage(struct writeback_control *wbc, struct page *page)
bool folio_redirty_for_writepage(struct writeback_control *wbc,
struct folio *folio)
{
int ret;
bool ret;
long nr = folio_nr_pages(folio);

wbc->pages_skipped += nr;
ret = filemap_dirty_folio(folio->mapping, folio);
folio_account_redirty(folio);

wbc->pages_skipped++;
ret = __set_page_dirty_nobuffers(page);
account_page_redirty(page);
return ret;
}
EXPORT_SYMBOL(redirty_page_for_writepage);
EXPORT_SYMBOL(folio_redirty_for_writepage);

/**
* folio_mark_dirty - Mark a folio as being modified.
Expand Down

0 comments on commit cd78ab1

Please sign in to comment.