diff mbox series

Assert that pages being written back are locked

Message ID 20201027224645.GY20115@casper.infradead.org (mailing list archive)
State New, archived
Headers show
Series Assert that pages being written back are locked | expand

Commit Message

Matthew Wilcox Oct. 27, 2020, 10:46 p.m. UTC
From: Matthew Wilcox (Oracle) <willy@infradead.org>

In write_cache_pages(), we rely on PageLock to prevent writeback from
starting on locked pages.  I'm not sure if we document anywhere that pages
that we're starting writes on must be locked, but having an assertion
will make it clear to users that this is required.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Comments

Matthew Wilcox Nov. 11, 2020, 12:39 a.m. UTC | #1
Anyone want to review this for me?

On Tue, Oct 27, 2020 at 10:46:45PM +0000, Matthew Wilcox wrote:
> From: Matthew Wilcox (Oracle) <willy@infradead.org>
> 
> In write_cache_pages(), we rely on PageLock to prevent writeback from
> starting on locked pages.  I'm not sure if we document anywhere that pages
> that we're starting writes on must be locked, but having an assertion
> will make it clear to users that this is required.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> 
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index 3671568d433f..f83dd855594d 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -2774,6 +2774,8 @@ int __test_set_page_writeback(struct page *page, bool keep_write)
>  	struct address_space *mapping = page_mapping(page);
>  	int ret, access_ret;
>  
> +	VM_BUG_ON_PGFLAGS(!PageLocked(page), page);
> +
>  	lock_page_memcg(page);
>  	if (mapping && mapping_use_writeback_tags(mapping)) {
>  		XA_STATE(xas, &mapping->i_pages, page_index(page));
>
William Kucharski Nov. 11, 2020, 3:37 a.m. UTC | #2
Looks good.

Reviewed-by: William Kucharski <william.kucharski@oracle.com>

> On Oct 27, 2020, at 4:46 PM, Matthew Wilcox <willy@infradead.org> wrote:
> 
> From: Matthew Wilcox (Oracle) <willy@infradead.org>
> 
> In write_cache_pages(), we rely on PageLock to prevent writeback from
> starting on locked pages.  I'm not sure if we document anywhere that pages
> that we're starting writes on must be locked, but having an assertion
> will make it clear to users that this is required.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> 
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index 3671568d433f..f83dd855594d 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -2774,6 +2774,8 @@ int __test_set_page_writeback(struct page *page, bool keep_write)
> 	struct address_space *mapping = page_mapping(page);
> 	int ret, access_ret;
> 
> +	VM_BUG_ON_PGFLAGS(!PageLocked(page), page);
> +
> 	lock_page_memcg(page);
> 	if (mapping && mapping_use_writeback_tags(mapping)) {
> 		XA_STATE(xas, &mapping->i_pages, page_index(page));
>
diff mbox series

Patch

diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 3671568d433f..f83dd855594d 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2774,6 +2774,8 @@  int __test_set_page_writeback(struct page *page, bool keep_write)
 	struct address_space *mapping = page_mapping(page);
 	int ret, access_ret;
 
+	VM_BUG_ON_PGFLAGS(!PageLocked(page), page);
+
 	lock_page_memcg(page);
 	if (mapping && mapping_use_writeback_tags(mapping)) {
 		XA_STATE(xas, &mapping->i_pages, page_index(page));