From patchwork Fri Nov 29 05:50:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13888420 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D25C1547FF; Fri, 29 Nov 2024 05:51:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732859476; cv=none; b=MQT1SNzZfZluoM0FUyVeK4xF1Tx3E/PDtrNvwe4tWdUcn1G3BdGo3YdR9xWqaPmEbb5WMNgZhZzvi5Y+D7IC+4dZR0JPSeMJgbLmg/KdFZJzanN+q55zvM21elpQ0cRGAzhhgB4tIWciEFM4NwiDcL9LM/btAeMcexgPH+EbNtg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732859476; c=relaxed/simple; bh=Mo7AaEyggumGpBesl6r/leiOUwc/0DwY7vPrbKdhupk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o9Kz++v3HM04+iE3fapiDRlIPmqRfkQxsc3ACtT6EK3YLGi/wcCoW/iiZv5B94dfQyA8DQYI+qdDhTTVT0Xw29pYoBmhzZXhJqqt0ndcl3/bEwPbZcheUqAHguKFeOYq7yeHX0NCPuquunZv0XP+QrrSIVCKtkniV4TPBiDp2Rs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=UQe0kAs0; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="UQe0kAs0" 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=9osMA2BWyr113bhiYGTMNySakfScKek4ObQ9ddCkgzs=; b=UQe0kAs0+02ehYdvpAScpGxVHK 4jEt3FxJidT7jWXeUCbtWbDXcqVv33bL1Du+U3GsCktrjvsB27FdvpnB3aNBRnJR20gT8GxZLMjxQ hW7XJlYlW9okA35joiMkD5bE5rBMf+gyWc/Ixsqn0UmG4VWkCk0shDH1IrO1Qa2XBM4+msjjzZPV8 KNy1Hl76vWjcb34N1mamDgJNmMiVMdDUz5Sea0BS99BW+l41hd7ca9HBzH0N/IOOHeJcNWPutkmlU ez4Qo49bv2B9tsFMwplQjOkfjlC8tVq+tlgzH7dAofaVy6qlhp4JK5yQp7WAX5kD0OYjcn3rwCKFl RXlvsvGQ==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tGtu9-00000003bS8-0lg6; Fri, 29 Nov 2024 05:51:01 +0000 From: "Matthew Wilcox (Oracle)" To: Ilya Dryomov Cc: "Matthew Wilcox (Oracle)" , Xiubo Li , ceph-devel@vger.kernel.org, Jeff Layton , linux-fsdevel@vger.kernel.org, David Howells Subject: [PATCH 1/5] ceph: Do not look at the index of an encrypted page Date: Fri, 29 Nov 2024 05:50:52 +0000 Message-ID: <20241129055058.858940-2-willy@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241129055058.858940-1-willy@infradead.org> References: <20241129055058.858940-1-willy@infradead.org> Precedence: bulk X-Mailing-List: ceph-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If the pages array contains encrypted pages, we cannot look at page->index because that field is uninitialised. Instead, use the new ceph_fscrypt_pagecache_folio() to get the pagecache folio and look at the index of that. Fixes: 4de77f25fd85 (ceph: use osd_req_op_extent_osd_iter for netfs reads) Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Jeff Layton --- fs/ceph/addr.c | 5 ++++- fs/ceph/crypto.h | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 4c82348fe1e6..284a6244fcdf 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1346,8 +1346,11 @@ static int ceph_writepages_start(struct address_space *mapping, memset(data_pages + i, 0, locked_pages * sizeof(*pages)); } else { + struct folio *folio; + BUG_ON(num_ops != req->r_num_ops); - index = pages[i - 1]->index + 1; + folio = ceph_fscrypt_pagecache_folio(pages[i - 1]); + index = folio->index + 1; /* request message now owns the pages array */ pages = NULL; } diff --git a/fs/ceph/crypto.h b/fs/ceph/crypto.h index 47e0c319fc68..7d75c4874aa8 100644 --- a/fs/ceph/crypto.h +++ b/fs/ceph/crypto.h @@ -280,6 +280,13 @@ static inline struct page *ceph_fscrypt_pagecache_page(struct page *page) } #endif /* CONFIG_FS_ENCRYPTION */ +static inline struct folio *ceph_fscrypt_pagecache_folio(struct page *page) +{ + if (fscrypt_is_bounce_page(page)) + page = fscrypt_pagecache_page(page); + return page_folio(page); +} + static inline loff_t ceph_fscrypt_page_offset(struct page *page) { return page_offset(ceph_fscrypt_pagecache_page(page)); From patchwork Fri Nov 29 05:50:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13888418 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1805D1547FF; Fri, 29 Nov 2024 05:51:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732859470; cv=none; b=Z/drqd1ar8JIRZAyh07bYgq57AY3m71Bokx0ZSbffgW370cXPeYmPA9XH7oW/q3KNwHy/90HL+nfVboCqE9k5KI01RJGFzANj6QKfUqE1sBj4syKRgfi2OuLXofDPYRerMYYED5IP/DuEfaDTyY7T8BAhrgnuYhlHi46ghlnCuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732859470; c=relaxed/simple; bh=D92FE35Fk/CFs1/lSYl2/RKgdMp2Jonrjc12LbHhgTo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ozsqHRU8yP/+XqnSk+0howFhAKm9KR8OQFOJwu3yYSmDBtokTI5iNG4IXeXUrz7c1wlUrHCx6S7BuKCMZfGIFQ0uzch0j77zHv8vYhBJGcMMcNnRySMmLWiTiG9w1JOBK2hTtXgENYZeoUWmRgsKYHpcjStBCAuXCZc4rdMCIhQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=RnPPorrB; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="RnPPorrB" 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=L6RYcpip9PIPAEEeJcaJdFO0izrVL0D7iO1BcmZeoNI=; b=RnPPorrBOIH4lq0yIUnXyeciZp t7xQMkVKxdSbHVTsS5JAeIOOD7BA2EJKY+wreRpfUb33xAGiZ/4YfW1aDmc+Utfl+IdRtkq7QT7O6 IpiATPj43WBJI9v1WImwT1ShvTyQuf0ifns3LkF5DcYVDlmji4k/S4trdWo9uOYbkMDzOr+O0eUCF E0zR9NDhLPZw/szgU5i18ag6K2hfesH97NdoPTfp+A1dLUjwXNI8gadBbOYK6Tz8nyCyK1G0pwbla g/7mDmcLTBNL1xT5JU4/qCd7/HBh3Y3nuO4cdZK5PRbZRxBRB5kssxfhgZnOgzNjRNTnr4gPU6viH lTTmw3KA==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tGtu9-00000003bSA-15BV; Fri, 29 Nov 2024 05:51:01 +0000 From: "Matthew Wilcox (Oracle)" To: Ilya Dryomov Cc: "Matthew Wilcox (Oracle)" , Xiubo Li , ceph-devel@vger.kernel.org, Jeff Layton , linux-fsdevel@vger.kernel.org, David Howells Subject: [PATCH 2/5] ceph: Use a folio in ceph_page_mkwrite() Date: Fri, 29 Nov 2024 05:50:53 +0000 Message-ID: <20241129055058.858940-3-willy@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241129055058.858940-1-willy@infradead.org> References: <20241129055058.858940-1-willy@infradead.org> Precedence: bulk X-Mailing-List: ceph-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Convert the passed page to a folio and use it throughout ceph_page_mkwrite(). Removes the last call to page_mkwrite_check_truncate(), the last call to offset_in_thp() and one of the last calls to thp_size(). Saves a few calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ceph/addr.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 284a6244fcdf..a5c59fec8a76 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1711,8 +1711,8 @@ static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf) struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_file_info *fi = vma->vm_file->private_data; struct ceph_cap_flush *prealloc_cf; - struct page *page = vmf->page; - loff_t off = page_offset(page); + struct folio *folio = page_folio(vmf->page); + loff_t off = folio_pos(folio); loff_t size = i_size_read(inode); size_t len; int want, got, err; @@ -1729,10 +1729,10 @@ static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf) sb_start_pagefault(inode->i_sb); ceph_block_sigs(&oldset); - if (off + thp_size(page) <= size) - len = thp_size(page); + if (off + folio_size(folio) <= size) + len = folio_size(folio); else - len = offset_in_thp(page, size); + len = offset_in_folio(folio, size); doutc(cl, "%llx.%llx %llu~%zd getting caps i_size %llu\n", ceph_vinop(inode), off, len, size); @@ -1749,30 +1749,30 @@ static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf) doutc(cl, "%llx.%llx %llu~%zd got cap refs on %s\n", ceph_vinop(inode), off, len, ceph_cap_string(got)); - /* Update time before taking page lock */ + /* Update time before taking folio lock */ file_update_time(vma->vm_file); inode_inc_iversion_raw(inode); do { struct ceph_snap_context *snapc; - lock_page(page); + folio_lock(folio); - if (page_mkwrite_check_truncate(page, inode) < 0) { - unlock_page(page); + if (folio_mkwrite_check_truncate(folio, inode) < 0) { + folio_unlock(folio); ret = VM_FAULT_NOPAGE; break; } - snapc = ceph_find_incompatible(page); + snapc = ceph_find_incompatible(&folio->page); if (!snapc) { - /* success. we'll keep the page locked. */ - set_page_dirty(page); + /* success. we'll keep the folio locked. */ + folio_mark_dirty(folio); ret = VM_FAULT_LOCKED; break; } - unlock_page(page); + folio_unlock(folio); if (IS_ERR(snapc)) { ret = VM_FAULT_SIGBUS; From patchwork Fri Nov 29 05:50:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13888415 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82276BA4B; Fri, 29 Nov 2024 05:51:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732859465; cv=none; b=WgxTM34iMghaGFlqSZFsCgZiBuYKgSiiuwcVONya+4BdyvFqUxygPBgyO8IFHqpqdUGi7XfGg4ON1mU7NolugHbGT0fW6zejc3x+0RkfpBTGTy99EysVF/ROaG1+6eHMcn3VGq2H/ubSsYJYGjiVrajiEgW5C44BHpJ/mqsN3DA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732859465; c=relaxed/simple; bh=8egUAUxj44zpRy76l9tzygtGd3+xLyjW8P3/YBcigIY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dRNYx3zxEhZohuqE83F46/ShSGRINcsFMLtZ0rkBs6g6+10KFm8wC1BPTH0jkLhsZBmC3t6smTfE90APzwZQxApPOCDTntClPL+9dubFmO6sMVJvXeN582XPrFRgyIjJjMuP3e8r4/e9LMu+9fhitfdFmm3gWhX3x6/6Um1L5v4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=KY+Bnw+S; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="KY+Bnw+S" 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=nuJhl9O2BQBA34eEY7w/GPOuwSdJHGPa+T+5bh/RH8s=; b=KY+Bnw+SsJi/wcpgAqGwlae7eQ bcKBVRNimMFvQr8q0m+fBaevOSbTQF8CtIziIrQgawGhsCUPbkHwldY6zS0QhcW+8GrwY/NSKfVAB zLpqNT1obqDcRoZ7oOoHGzoo4pd9KZ2k0neWEhgn1MwsfFvWD57hi0gSl1W2wMyKsEEg6bisqn3V0 X23kO7jSU96gRqyaKjZtBYbPq+BVEqi6wNwgY+Xo2Pp1/DcctczhbwS5SqtA/a2bz6G6HM0lKm2Nd f0DPw9vL+OBF6o0NzvK5qPw8Cj9SbSh5HVigPFxTfjP7czPzyEcBl514EgQ4fWB5vfEjfXE3DeweM V4fWIdXQ==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tGtu9-00000003bSC-1O2G; Fri, 29 Nov 2024 05:51:01 +0000 From: "Matthew Wilcox (Oracle)" To: Ilya Dryomov Cc: "Matthew Wilcox (Oracle)" , Xiubo Li , ceph-devel@vger.kernel.org, Jeff Layton , linux-fsdevel@vger.kernel.org, David Howells Subject: [PATCH 3/5] ceph: Convert ceph_readdir_cache_control to store a folio Date: Fri, 29 Nov 2024 05:50:54 +0000 Message-ID: <20241129055058.858940-4-willy@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241129055058.858940-1-willy@infradead.org> References: <20241129055058.858940-1-willy@infradead.org> Precedence: bulk X-Mailing-List: ceph-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Pass a folio around instead of a page. This removes an access to page->index and a few hidden calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ceph/dir.c | 12 ++++++------ fs/ceph/inode.c | 26 ++++++++++++++------------ fs/ceph/super.h | 2 +- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index 952109292d69..d646e1976d65 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -141,17 +141,17 @@ __dcache_find_get_entry(struct dentry *parent, u64 idx, if (ptr_pos >= i_size_read(dir)) return NULL; - if (!cache_ctl->page || ptr_pgoff != cache_ctl->page->index) { + if (!cache_ctl->folio || ptr_pgoff != cache_ctl->folio->index) { ceph_readdir_cache_release(cache_ctl); - cache_ctl->page = find_lock_page(&dir->i_data, ptr_pgoff); - if (!cache_ctl->page) { + cache_ctl->folio = filemap_lock_folio(&dir->i_data, ptr_pgoff); + if (!cache_ctl->folio) { doutc(cl, " page %lu not found\n", ptr_pgoff); return ERR_PTR(-EAGAIN); } /* reading/filling the cache are serialized by - i_rwsem, no need to use page lock */ - unlock_page(cache_ctl->page); - cache_ctl->dentries = kmap(cache_ctl->page); + i_rwsem, no need to use folio lock */ + folio_unlock(cache_ctl->folio); + cache_ctl->dentries = kmap_local_folio(cache_ctl->folio, 0); } cache_ctl->index = idx & idx_mask; diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 315ef02f9a3f..7e0376c771a6 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -1845,10 +1845,9 @@ static int readdir_prepopulate_inodes_only(struct ceph_mds_request *req, void ceph_readdir_cache_release(struct ceph_readdir_cache_control *ctl) { - if (ctl->page) { - kunmap(ctl->page); - put_page(ctl->page); - ctl->page = NULL; + if (ctl->folio) { + folio_release_kmap(ctl->folio, ctl->dentries); + ctl->folio = NULL; } } @@ -1862,20 +1861,23 @@ static int fill_readdir_cache(struct inode *dir, struct dentry *dn, unsigned idx = ctl->index % nsize; pgoff_t pgoff = ctl->index / nsize; - if (!ctl->page || pgoff != ctl->page->index) { + if (!ctl->folio || pgoff != ctl->folio->index) { ceph_readdir_cache_release(ctl); + fgf_t fgf = FGP_LOCK; + if (idx == 0) - ctl->page = grab_cache_page(&dir->i_data, pgoff); - else - ctl->page = find_lock_page(&dir->i_data, pgoff); - if (!ctl->page) { + fgf |= FGP_ACCESSED | FGP_CREAT; + + ctl->folio = __filemap_get_folio(&dir->i_data, pgoff, + fgf, mapping_gfp_mask(&dir->i_data)); + if (!ctl->folio) { ctl->index = -1; return idx == 0 ? -ENOMEM : 0; } /* reading/filling the cache are serialized by - * i_rwsem, no need to use page lock */ - unlock_page(ctl->page); - ctl->dentries = kmap(ctl->page); + * i_rwsem, no need to use folio lock */ + folio_unlock(ctl->folio); + ctl->dentries = kmap_local_folio(ctl->folio, 0); if (idx == 0) memset(ctl->dentries, 0, PAGE_SIZE); } diff --git a/fs/ceph/super.h b/fs/ceph/super.h index 037eac35a9e0..135bb43b22be 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -904,7 +904,7 @@ ceph_find_rw_context(struct ceph_file_info *cf) } struct ceph_readdir_cache_control { - struct page *page; + struct folio *folio; struct dentry **dentries; int index; }; From patchwork Fri Nov 29 05:50:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13888419 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC9361547FF; Fri, 29 Nov 2024 05:51:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732859473; cv=none; b=A2NA0R9fxDbBhAwaxO969jF6/Bf4vEvAQx3CzqoZxi7LuhBYFVClFrWkucwiU24SfRat0H1yC13ZVtSPDEfSzGQOuSzTmiQoRFR0y4RdpH9ck49l9Uz3dSwXqwa1dLOcQJT1muv5Y+lOhDXABrjLoJacPitXXdUn/Db0q+8YEyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732859473; c=relaxed/simple; bh=aDtdq9caWDRhpliU4N7JPTCsamZ1q2ke8PI42WXds1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j/oqaJqo45dSe4UKeCnQbN/fFN/nDq2EIHThg/BawM2dKbiOYoY/7TpLdkJJrD44Owg1gg4fapj+O+YMARlzwuzuelPTWU5sUQ7iU/tn6R/GVnsnsGo+CMoBjfaf3VFCd0HTh87s9eYojgwC6dT14LPV1YZ7syeQ35rk4EX5z2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=oWoqSeft; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="oWoqSeft" 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=uWZkCEwwYb4dP6PPOM0IVSKbmg2RK8kTAbzH0C95S7g=; b=oWoqSeftByZWcIP+U4SR7tF/Hj XzSBb/cuP1d6VK7vaVo+f5fJOsOLTcPIhSxrFPtdTSWF7iaj7wQ8y+HGYAC+vrUXLOAPLBMs46Qou OJoBE/zIoQZt1MyvokLyo5RMolw+dsWbg+wlk40MNi/fotKEov4TsAux9GP40CZZJXyWlZcMbDWgA 6VkLHQK83TxiKxKt1Z851FbqCZQwi8C+4c2Hk9Y+B3w+GTWB7VluBXvkUBWIbZcztNaKxANqxRVEU jO0501MqHamEW6FX5DryhFuP5zqE5JW6jzPLOhfPHhKoV0M2KNRYMmBb2lu98guIS8xCh76dz+2Rz Qt6Ye+OA==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tGtu9-00000003bSE-1mXv; Fri, 29 Nov 2024 05:51:01 +0000 From: "Matthew Wilcox (Oracle)" To: Ilya Dryomov Cc: "Matthew Wilcox (Oracle)" , Xiubo Li , ceph-devel@vger.kernel.org, Jeff Layton , linux-fsdevel@vger.kernel.org, David Howells Subject: [PATCH 4/5] ceph: Use a folio throughout writepage_nounlock() Date: Fri, 29 Nov 2024 05:50:55 +0000 Message-ID: <20241129055058.858940-5-willy@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241129055058.858940-1-willy@infradead.org> References: <20241129055058.858940-1-willy@infradead.org> Precedence: bulk X-Mailing-List: ceph-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove references to page->index, page->mapping, thp_size(), page_offset() and other page APIs in favour of their more efficient folio replacements. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ceph/addr.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index a5c59fec8a76..aba8d55bd533 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -664,14 +664,14 @@ static u64 get_writepages_data_length(struct inode *inode, static int writepage_nounlock(struct page *page, struct writeback_control *wbc) { struct folio *folio = page_folio(page); - struct inode *inode = page->mapping->host; + struct inode *inode = folio->mapping->host; struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_fs_client *fsc = ceph_inode_to_fs_client(inode); struct ceph_client *cl = fsc->client; struct ceph_snap_context *snapc, *oldest; - loff_t page_off = page_offset(page); + loff_t page_off = folio_pos(folio); int err; - loff_t len = thp_size(page); + loff_t len = folio_size(folio); loff_t wlen; struct ceph_writeback_ctl ceph_wbc; struct ceph_osd_client *osdc = &fsc->client->osdc; @@ -679,8 +679,8 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc) bool caching = ceph_is_cache_enabled(inode); struct page *bounce_page = NULL; - doutc(cl, "%llx.%llx page %p idx %lu\n", ceph_vinop(inode), page, - page->index); + doutc(cl, "%llx.%llx folio %p idx %lu\n", ceph_vinop(inode), folio, + folio->index); if (ceph_inode_is_shutdown(inode)) return -EIO; @@ -688,18 +688,18 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc) /* verify this is a writeable snap context */ snapc = page_snap_context(page); if (!snapc) { - doutc(cl, "%llx.%llx page %p not dirty?\n", ceph_vinop(inode), - page); + doutc(cl, "%llx.%llx folio %p not dirty?\n", ceph_vinop(inode), + folio); return 0; } oldest = get_oldest_context(inode, &ceph_wbc, snapc); if (snapc->seq > oldest->seq) { - doutc(cl, "%llx.%llx page %p snapc %p not writeable - noop\n", - ceph_vinop(inode), page, snapc); + doutc(cl, "%llx.%llx folio %p snapc %p not writeable - noop\n", + ceph_vinop(inode), folio, snapc); /* we should only noop if called by kswapd */ WARN_ON(!(current->flags & PF_MEMALLOC)); ceph_put_snap_context(oldest); - redirty_page_for_writepage(wbc, page); + folio_redirty_for_writepage(wbc, folio); return 0; } ceph_put_snap_context(oldest); @@ -716,8 +716,8 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc) len = ceph_wbc.i_size - page_off; wlen = IS_ENCRYPTED(inode) ? round_up(len, CEPH_FSCRYPT_BLOCK_SIZE) : len; - doutc(cl, "%llx.%llx page %p index %lu on %llu~%llu snapc %p seq %lld\n", - ceph_vinop(inode), page, page->index, page_off, wlen, snapc, + doutc(cl, "%llx.%llx folio %p index %lu on %llu~%llu snapc %p seq %lld\n", + ceph_vinop(inode), folio, folio->index, page_off, wlen, snapc, snapc->seq); if (atomic_long_inc_return(&fsc->writeback_count) > @@ -730,14 +730,14 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc) ceph_wbc.truncate_seq, ceph_wbc.truncate_size, true); if (IS_ERR(req)) { - redirty_page_for_writepage(wbc, page); + folio_redirty_for_writepage(wbc, folio); return PTR_ERR(req); } if (wlen < len) len = wlen; - set_page_writeback(page); + folio_start_writeback(folio); if (caching) ceph_set_page_fscache(page); ceph_fscache_write_to_cache(inode, page_off, len, caching); @@ -747,15 +747,15 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc) CEPH_FSCRYPT_BLOCK_SIZE, 0, GFP_NOFS); if (IS_ERR(bounce_page)) { - redirty_page_for_writepage(wbc, page); - end_page_writeback(page); + folio_redirty_for_writepage(wbc, folio); + folio_end_writeback(folio); ceph_osdc_put_request(req); return PTR_ERR(bounce_page); } } /* it may be a short write due to an object boundary */ - WARN_ON_ONCE(len > thp_size(page)); + WARN_ON_ONCE(len > folio_size(folio)); osd_req_op_extent_osd_data_pages(req, 0, bounce_page ? &bounce_page : &page, wlen, 0, false, false); @@ -781,25 +781,25 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc) if (err == -ERESTARTSYS) { /* killed by SIGKILL */ doutc(cl, "%llx.%llx interrupted page %p\n", - ceph_vinop(inode), page); - redirty_page_for_writepage(wbc, page); - end_page_writeback(page); + ceph_vinop(inode), folio); + folio_redirty_for_writepage(wbc, folio); + folio_end_writeback(folio); return err; } if (err == -EBLOCKLISTED) fsc->blocklisted = true; - doutc(cl, "%llx.%llx setting page/mapping error %d %p\n", - ceph_vinop(inode), err, page); + doutc(cl, "%llx.%llx setting mapping error %d %p\n", + ceph_vinop(inode), err, folio); mapping_set_error(&inode->i_data, err); wbc->pages_skipped++; } else { doutc(cl, "%llx.%llx cleaned page %p\n", - ceph_vinop(inode), page); + ceph_vinop(inode), folio); err = 0; /* vfs expects us to return 0 */ } - oldest = detach_page_private(page); + oldest = folio_detach_private(folio); WARN_ON_ONCE(oldest != snapc); - end_page_writeback(page); + folio_end_writeback(folio); ceph_put_wrbuffer_cap_refs(ci, 1, snapc); ceph_put_snap_context(snapc); /* page's reference */ From patchwork Fri Nov 29 05:50:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13888416 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 822C915250F; Fri, 29 Nov 2024 05:51:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732859465; cv=none; b=S6hRzx9sVRwWRvIAT+DNGdVscS7hiXOrK58hMh++aARGVAWgXVirAN671n5ohnCAydRZumQBqBhDBX8tml6txPFqJjOJHtXVM1T2v4kLJRTBxRTVV3rOTRYkeMFdY0qOg8TMGQZgddKl3GInUuyiiLYoOI/8zwYoiNcJCVJaErk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732859465; c=relaxed/simple; bh=6nNwnsy9XDF6fTEJKOBprenqS8ZpNx8mkM8SleI8y5o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SBMJYZUjD6XTCLuWYG32ZxmPHh9nUAV+fuJAhwVKPGJ+M9AV+YwB+DKRpiNaEp6vHVLs4VDadTvs/gWwxicWAtElwFvoC5dwCBeNiDDWuAuE8KKsQ16KA1jv7omTOyyta0ZbhfqtAilgPW1qFmfHPNHr+N4vr63np5WC+8iLyR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=UnTZD3+t; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="UnTZD3+t" 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=3FD4RxgDA+riPCAsGTZ05CrmziQl4duAAOIqznO9dI8=; b=UnTZD3+t+OFh3OWN4/MsxJePVs TxgcfWiIjz7YENUJVRrUZoNdlno4NtD8bgAGJ1/mB5oRCS1rbLUVjnLz5nvc1YLeyJzmKpyq9Fbvu AaYxSqCWH4oBRCti/sUXYXiePKn+9Ts3N9s3MxvMQvQPLVzbwtxZAdRQAA1SdybDcXyOk/L3PQy4g pclKD6gOGnpoZufyw9vwb9FnURvyUo1//FlFkMF6utFEUK/qjeG1IyhmIEeoCic42NzUuTWu3TBVp hKU38/SFhSaEELiKhIzIecf3lX6+hG0tE3ssb4I9JKoGb1uocoYfveBmdGBfn/PSVzFR6oBkM2cYt pwo+xi6Q==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tGtu9-00000003bSG-2A2j; Fri, 29 Nov 2024 05:51:01 +0000 From: "Matthew Wilcox (Oracle)" To: Ilya Dryomov Cc: "Matthew Wilcox (Oracle)" , Xiubo Li , ceph-devel@vger.kernel.org, Jeff Layton , linux-fsdevel@vger.kernel.org, David Howells Subject: [PATCH 5/5] ceph: Use a folio in ceph_writepages_start() Date: Fri, 29 Nov 2024 05:50:56 +0000 Message-ID: <20241129055058.858940-6-willy@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241129055058.858940-1-willy@infradead.org> References: <20241129055058.858940-1-willy@infradead.org> Precedence: bulk X-Mailing-List: ceph-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We currently convert the folio returned from filemap_get_folios_tag() to a page and operate on that page. Remove this and operate on the folio. Removes a lot of calls to obsolete functions and references to page->index and page->mapping. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ceph/addr.c | 55 +++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index aba8d55bd533..1e0c982f5abe 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1056,22 +1056,21 @@ static int ceph_writepages_start(struct address_space *mapping, for (i = 0; i < nr_folios && locked_pages < max_pages; i++) { struct folio *folio = fbatch.folios[i]; - page = &folio->page; - doutc(cl, "? %p idx %lu\n", page, page->index); + doutc(cl, "? %p idx %lu\n", folio, folio->index); if (locked_pages == 0) - lock_page(page); /* first page */ - else if (!trylock_page(page)) + folio_lock(folio); /* first page */ + else if (!folio_trylock(folio)) break; /* only dirty pages, or our accounting breaks */ - if (unlikely(!PageDirty(page)) || - unlikely(page->mapping != mapping)) { - doutc(cl, "!dirty or !mapping %p\n", page); - unlock_page(page); + if (unlikely(!folio_test_dirty(folio)) || + unlikely(folio->mapping != mapping)) { + doutc(cl, "!dirty or !mapping %p\n", folio); + folio_unlock(folio); continue; } /* only if matching snap context */ - pgsnapc = page_snap_context(page); + pgsnapc = page_snap_context(&folio->page); if (pgsnapc != snapc) { doutc(cl, "page snapc %p %lld != oldest %p %lld\n", pgsnapc, pgsnapc->seq, snapc, snapc->seq); @@ -1079,10 +1078,10 @@ static int ceph_writepages_start(struct address_space *mapping, !ceph_wbc.head_snapc && wbc->sync_mode != WB_SYNC_NONE) should_loop = true; - unlock_page(page); + folio_unlock(folio); continue; } - if (page_offset(page) >= ceph_wbc.i_size) { + if (folio_pos(folio) >= ceph_wbc.i_size) { doutc(cl, "folio at %lu beyond eof %llu\n", folio->index, ceph_wbc.i_size); if ((ceph_wbc.size_stable || @@ -1093,9 +1092,9 @@ static int ceph_writepages_start(struct address_space *mapping, folio_unlock(folio); continue; } - if (strip_unit_end && (page->index > strip_unit_end)) { - doutc(cl, "end of strip unit %p\n", page); - unlock_page(page); + if (strip_unit_end && (folio->index > strip_unit_end)) { + doutc(cl, "end of strip unit %p\n", folio); + folio_unlock(folio); break; } if (folio_test_writeback(folio) || @@ -1110,9 +1109,9 @@ static int ceph_writepages_start(struct address_space *mapping, folio_wait_private_2(folio); /* [DEPRECATED] */ } - if (!clear_page_dirty_for_io(page)) { - doutc(cl, "%p !clear_page_dirty_for_io\n", page); - unlock_page(page); + if (!folio_clear_dirty_for_io(folio)) { + doutc(cl, "%p !clear_page_dirty_for_io\n", folio); + folio_unlock(folio); continue; } @@ -1128,7 +1127,7 @@ static int ceph_writepages_start(struct address_space *mapping, u32 xlen; /* prepare async write request */ - offset = (u64)page_offset(page); + offset = folio_pos(folio); ceph_calc_file_object_mapping(&ci->i_layout, offset, wsize, &objnum, &objoff, @@ -1136,7 +1135,7 @@ static int ceph_writepages_start(struct address_space *mapping, len = xlen; num_ops = 1; - strip_unit_end = page->index + + strip_unit_end = folio->index + ((len - 1) >> PAGE_SHIFT); BUG_ON(pages); @@ -1151,23 +1150,23 @@ static int ceph_writepages_start(struct address_space *mapping, } len = 0; - } else if (page->index != + } else if (folio->index != (offset + len) >> PAGE_SHIFT) { if (num_ops >= (from_pool ? CEPH_OSD_SLAB_OPS : CEPH_OSD_MAX_OPS)) { - redirty_page_for_writepage(wbc, page); - unlock_page(page); + folio_redirty_for_writepage(wbc, folio); + folio_unlock(folio); break; } num_ops++; - offset = (u64)page_offset(page); + offset = folio_pos(folio); len = 0; } /* note position of first page in fbatch */ doutc(cl, "%llx.%llx will write page %p idx %lu\n", - ceph_vinop(inode), page, page->index); + ceph_vinop(inode), folio, folio->index); if (atomic_long_inc_return(&fsc->writeback_count) > CONGESTION_ON_THRESH( @@ -1187,17 +1186,17 @@ static int ceph_writepages_start(struct address_space *mapping, /* better not fail on first page! */ BUG_ON(locked_pages == 0); pages[locked_pages] = NULL; - redirty_page_for_writepage(wbc, page); - unlock_page(page); + folio_redirty_for_writepage(wbc, folio); + folio_unlock(folio); break; } ++locked_pages; } else { - pages[locked_pages++] = page; + pages[locked_pages++] = &folio->page; } fbatch.folios[i] = NULL; - len += thp_size(page); + len += folio_size(folio); } /* did we get anything? */