Add a function, unlock_page_private_2(), to unlock PG_private_2 analogous to that of PG_lock. Add a kerneldoc banner to that indicating the example usage case.
A wrapper will need to be placed in the netfs header in the patch that adds that. [This implements a suggestion by Linus to not mix the terminology of PG_private_2 and PG_fscache in the mm core function] Suggested-by: Linus Torvalds <torva...@linux-foundation.org> Signed-off-by: David Howells <dhowe...@redhat.com> cc: Linus Torvalds <torva...@linux-foundation.org> cc: Matthew Wilcox (Oracle) <wi...@infradead.org> cc: Alexander Viro <v...@zeniv.linux.org.uk> cc: Christoph Hellwig <h...@lst.de> cc: linux...@kvack.org cc: linux-cach...@redhat.com cc: linux-...@lists.infradead.org cc: linux-...@vger.kernel.org cc: linux-c...@vger.kernel.org cc: ceph-de...@vger.kernel.org cc: v9fs-develo...@lists.sourceforge.net cc: linux-fsde...@vger.kernel.org Link: https://lore.kernel.org/linux-fsdevel/1330473.1612974...@warthog.procyon.org.uk/ Link: https://lore.kernel.org/linux-fsdevel/CAHk-=wjgA-74ddehziVk=xaemtkswpu1yw4uaro1r3ibs27...@mail.gmail.com/ --- include/linux/pagemap.h | 1 + mm/filemap.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index d5570deff400..365a28ece763 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -591,6 +591,7 @@ extern int __lock_page_async(struct page *page, struct wait_page_queue *wait); extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm, unsigned int flags); extern void unlock_page(struct page *page); +extern void unlock_page_private_2(struct page *page); /* * Return true if the page was successfully locked diff --git a/mm/filemap.c b/mm/filemap.c index 5c9d564317a5..7d321152d579 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1466,6 +1466,26 @@ void unlock_page(struct page *page) } EXPORT_SYMBOL(unlock_page); +/** + * unlock_page_private_2 - Unlock a page that's locked with PG_private_2 + * @page: The page + * + * Unlocks a page that's locked with PG_private_2 and wakes up sleepers in + * wait_on_page_private_2(). + * + * This is, for example, used when a netfs page is being written to a local + * disk cache, thereby allowing writes to the cache for the same page to be + * serialised. + */ +void unlock_page_private_2(struct page *page) +{ + page = compound_head(page); + VM_BUG_ON_PAGE(!PagePrivate2(page), page); + clear_bit_unlock(PG_private_2, &page->flags); + wake_up_page_bit(page, PG_private_2); +} +EXPORT_SYMBOL(unlock_page_private_2); + /** * end_page_writeback - end writeback against a page * @page: the page