From patchwork Sun May 8 20:28:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12842798 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 023D0C433EF for ; Sun, 8 May 2022 20:29:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232148AbiEHUc5 (ORCPT ); Sun, 8 May 2022 16:32:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232018AbiEHUc5 (ORCPT ); Sun, 8 May 2022 16:32:57 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35383BE3B for ; Sun, 8 May 2022 13:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=kkCNfBTfba7xDrYz14rR4zqJeO5mJifkXG11yRqXDzM=; b=MfA1Epxuu29kkBTujfGOcx8L08 H/9FcoQc8OjsQ4MhTa0LfQZzi5W8I4RZkKNP07x1wDytj5FGUb4hqKep27nEjYcww3sEDyS4JTsyI 1WNt94iU3s2Mf8Qkev1jH7CjfaWD7sjBp/3+C5ED8zn2bA9NG4SUznBiuSA7F4IX5OdpcBCPnc84y SQQD8Xhway0Ze0v5KYvhQ7aOxYe6jvEA9Vis48dpHAJSco294fiuzUKdo3SGYB+6hOCqeCh0x9xiK mbNrJxAZB/eclVsBZbDxgBO9XYRWyh5IAow5DTGvhwuQG67Xp0U4K7dwD/TAokFYw6M0VK9CfVsrj gs1iPkCw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nnnWY-002nUC-D4; Sun, 08 May 2022 20:29:02 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH] Appoint myself page cache maintainer Date: Sun, 8 May 2022 21:28:48 +0100 Message-Id: <20220508202849.666756-1-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This feels like a sufficiently distinct area of responsibility to be worth separating out from both MM and VFS. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Dave Chinner Reviewed-by: Darrick J. Wong Reviewed-by: Jeff Layton Acked-by: Christian Brauner (Microsoft) Acked-by: Vlastimil Babka --- MAINTAINERS | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 9d47c5e7c6ae..5871ec2e1b3e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14833,6 +14833,18 @@ F: Documentation/core-api/padata.rst F: include/linux/padata.h F: kernel/padata.c +PAGE CACHE +M: Matthew Wilcox (Oracle) +L: linux-fsdevel@vger.kernel.org +S: Supported +T: git git://git.infradead.org/users/willy/pagecache.git +F: Documentation/filesystems/locking.rst +F: Documentation/filesystems/vfs.rst +F: include/linux/pagemap.h +F: mm/filemap.c +F: mm/page-writeback.c +F: mm/readahead.c + PAGE POOL M: Jesper Dangaard Brouer M: Ilias Apalodimas From patchwork Sun May 8 20:30:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12842841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C365AC433EF for ; Sun, 8 May 2022 20:31:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232263AbiEHUfT (ORCPT ); Sun, 8 May 2022 16:35:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232416AbiEHUfA (ORCPT ); Sun, 8 May 2022 16:35:00 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2928110FCE for ; Sun, 8 May 2022 13:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=O1t4085GeyAcPbSh9EMTxNvJaZKXVDwCSXz6nFjuqnI=; b=Os0+TkWWU1R9ravRpGD9MmrAgf z4hLTYGO28fZ67OhFP91o0Ysp0NVk7aDjOzUDgCJY5/7D7/Pr5gE7hMWKyqPVpVvrQRpP09I9Dy2h pUab2BPF6m39S06vv7y8mnU/tgsa2tFW3tDjJzP0KpWz39LM3eopbhs+7x1ESVXvI0kGAM/Q25kEC HMd26FcOVEs1XpJFD4mAtLdO4En5X9BZieGndVUdPBIijiV87RJUourSsIIzIpMoZu17gNIUNDaOv RzPYxAzxss6vgMXlxdRY1ijHYCp/F5eTPGiNFf5C/EbGoPeRTUCHPOraJBUDQsOi5gvu7M4EK0vEc oucbyY+w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nnnYL-002ni6-FZ; Sun, 08 May 2022 20:30:53 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 3/3] filemap: Update the folio_mark_dirty documentation Date: Sun, 8 May 2022 21:30:48 +0100 Message-Id: <20220508203048.667631-4-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220508203048.667631-1-willy@infradead.org> References: <20220508203048.667631-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The previous comment was not terribly helpful. Be a bit more explicit about the necessary locking environment. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 7e2da284e427..fa1117db4610 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2602,10 +2602,12 @@ EXPORT_SYMBOL(folio_redirty_for_writepage); * folio_mark_dirty - Mark a folio as being modified. * @folio: The folio. * - * For folios with a mapping this should be done with the folio lock held - * for the benefit of asynchronous memory errors who prefer a consistent - * dirty state. This rule can be broken in some special cases, - * but should be better not to. + * The folio may not be truncated while this function is running. + * Holding the folio lock is sufficient to prevent truncation, but some + * callers cannot acquire a sleeping lock. These callers instead hold + * the page table lock for a page table which contains at least one page + * in this folio. Truncation will block on the page table lock as it + * unmaps pages before removing the folio from its mapping. * * Return: True if the folio was newly dirtied, false if it was already dirty. */ From patchwork Sun May 8 20:31:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12842844 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A51F4C433F5 for ; Sun, 8 May 2022 20:31:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232363AbiEHUfX (ORCPT ); Sun, 8 May 2022 16:35:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232759AbiEHUfO (ORCPT ); Sun, 8 May 2022 16:35:14 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9DF311C3B for ; Sun, 8 May 2022 13:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=iowfFgK37qRBiUVnNnBiba13bS0wbMRvoKqm+0fXgj0=; b=wTTOZC870wPDR+TRQyOgCgzR3r Edu++yZRu2lyRweEUhyVwEb++OMdyB2jAtpQF0Lq9icG9iskn+DkZAjeXFwpZKCXTxVJKQSAz2eMS CqTnvXmoA3dFtUprlEPb6NXb49XotDV5zajpOBF++swNMR0+TPnbbs9XfuGXOrW+mCHYHB1HhSBOF Wzb4oLMBHBqFy0EHBxBOxSOP/1RYywiljZ8PZvUeCS3Czd0OzI9mXulE28JpUINS6XqkjP6zObZtj QDLHoZG8AdDhXRNYTmkL+iwjLjnHs/uDVTw8Mr9U9m+mg2k8lOUuk6xp5eCDuCdsbWWVzBYP5C+IR c+VLh95g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nnnYi-002nki-23; Sun, 08 May 2022 20:31:16 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , Christoph Hellwig Subject: [PATCH 4/4] buffer: Rewrite nobh_truncate_page() to use folios Date: Sun, 8 May 2022 21:31:11 +0100 Message-Id: <20220508203111.667840-5-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220508203111.667840-1-willy@infradead.org> References: <20220508203111.667840-1-willy@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org - Calculate iblock directly instead of using a while loop - Move has_buffers to the end to remove a backwards jump - Use __filemap_get_folio() instead of grab_cache_page(), which removes a spurious FGP_ACCESSED flag. - Eliminate length and pos variables - Use folio APIs where they exist Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig --- fs/buffer.c | 64 ++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index fb4df259c92d..9737e0dbe3ec 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2791,44 +2791,28 @@ int nobh_truncate_page(struct address_space *mapping, loff_t from, get_block_t *get_block) { pgoff_t index = from >> PAGE_SHIFT; - unsigned offset = from & (PAGE_SIZE-1); - unsigned blocksize; - sector_t iblock; - unsigned length, pos; struct inode *inode = mapping->host; - struct page *page; + unsigned blocksize = i_blocksize(inode); + struct folio *folio; struct buffer_head map_bh; + size_t offset; + sector_t iblock; int err; - blocksize = i_blocksize(inode); - length = offset & (blocksize - 1); - /* Block boundary? Nothing to do */ - if (!length) + if (!(from & (blocksize - 1))) return 0; - length = blocksize - length; - iblock = (sector_t)index << (PAGE_SHIFT - inode->i_blkbits); - - page = grab_cache_page(mapping, index); + folio = __filemap_get_folio(mapping, index, FGP_LOCK | FGP_CREAT, + mapping_gfp_mask(mapping)); err = -ENOMEM; - if (!page) + if (!folio) goto out; - if (page_has_buffers(page)) { -has_buffers: - unlock_page(page); - put_page(page); - return block_truncate_page(mapping, from, get_block); - } - - /* Find the buffer that contains "offset" */ - pos = blocksize; - while (offset >= pos) { - iblock++; - pos += blocksize; - } + if (folio_buffers(folio)) + goto has_buffers; + iblock = from >> inode->i_blkbits; map_bh.b_size = blocksize; map_bh.b_state = 0; err = get_block(inode, iblock, &map_bh, 0); @@ -2839,29 +2823,35 @@ int nobh_truncate_page(struct address_space *mapping, goto unlock; /* Ok, it's mapped. Make sure it's up-to-date */ - if (!PageUptodate(page)) { - err = mapping->a_ops->readpage(NULL, page); + if (!folio_test_uptodate(folio)) { + err = mapping->a_ops->readpage(NULL, &folio->page); if (err) { - put_page(page); + folio_put(folio); goto out; } - lock_page(page); - if (!PageUptodate(page)) { + folio_lock(folio); + if (!folio_test_uptodate(folio)) { err = -EIO; goto unlock; } - if (page_has_buffers(page)) + if (folio_buffers(folio)) goto has_buffers; } - zero_user(page, offset, length); - set_page_dirty(page); + offset = offset_in_folio(folio, from); + folio_zero_segment(folio, offset, round_up(offset, blocksize)); + folio_mark_dirty(folio); err = 0; unlock: - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); out: return err; + +has_buffers: + folio_unlock(folio); + folio_put(folio); + return block_truncate_page(mapping, from, get_block); } EXPORT_SYMBOL(nobh_truncate_page);