From patchwork Mon Dec 16 16:26:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 13910030 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB895E77180 for ; Mon, 16 Dec 2024 16:27:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D33F28D0009; Mon, 16 Dec 2024 11:27:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CE3848D0006; Mon, 16 Dec 2024 11:27:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B362B8D0009; Mon, 16 Dec 2024 11:27:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 92A1A8D0006 for ; Mon, 16 Dec 2024 11:27:16 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 497FAA0C4D for ; Mon, 16 Dec 2024 16:27:16 +0000 (UTC) X-FDA: 82901351148.10.DFD9C4B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf26.hostedemail.com (Postfix) with ESMTP id 3DE9614000A for ; Mon, 16 Dec 2024 16:26:52 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=kWfCA+n0; dmarc=none; spf=none (imf26.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734366407; a=rsa-sha256; cv=none; b=7OLI03e9I+fkTbhFwicxQIrOHJuROIoyDeYs9NY9OnU00LdSmrSdRMwxbwDmHi64gLXQMX nWDTrOp02LmDFzt94eRHR3HBG2ZSQn3VQ8yOaCjPegFoqwIfYj5S7EgrYfKgV1t6dVYDru gfj2qwkMy7GNmSICf2Fr2+BTvTXaSSA= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=kWfCA+n0; dmarc=none; spf=none (imf26.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734366407; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Qu/PiL85fu1e3QcMJHhgZFh62m9BJTBqStwrlLOLtZQ=; b=7GZQ9kS249Qy9GUPTw3VhytexTkqyywyhbnFmMzfc8BOBqHxu4FlEBHMZbfljnp49t63Gd /OaZMeuBteBTVnXnM3jvPL8JxpRuUytHcYw7i3aguhl7knjnp+/+O2zfUMagh3DzQedO03 PNM858OemvWdSC1dWE6M3FpCxxOdUiw= 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=Qu/PiL85fu1e3QcMJHhgZFh62m9BJTBqStwrlLOLtZQ=; b=kWfCA+n0L40xOuhLiv91kDlJhr 2T2FXHN8IBznmYsGX8qZ36MMuO5FzKzQimyLDB9b2O/1rt2dnl/C37LMZISbzu3DoRG9uS/RS5RK5 v78DL1Ddk4mulAZaXdEruEj8LiaRBOpzVFnOyAzNj52NAb63/QlBZPHOVVkXlFeXMaE3Gim0jHVm2 NBkci6eYlT4nadFfn/usX5ttZqo4epj3HdrSA3iNtMJdvmtV+c3Q0qpfpZ2ROIdNUIBH3MzzjsMbD MuDrDPs4E0yP9J5ypdlyyoRuwFFEOMn4MCE3XKfSIDF8hlSr/jJU7/WBnhiEDFDGqMF/naRsWflDE hzGliwiQ==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tNDw0-00000000Ez8-1qLx; Mon, 16 Dec 2024 16:27:04 +0000 From: "Matthew Wilcox (Oracle)" To: Phillip Lougher Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/5] squashfs; Convert squashfs_copy_cache() to take a folio Date: Mon, 16 Dec 2024 16:26:58 +0000 Message-ID: <20241216162701.57549-4-willy@infradead.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241216162701.57549-1-willy@infradead.org> References: <20241216162701.57549-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3DE9614000A X-Stat-Signature: 9zikqyrwudbxt8kdsirweromsfo9otp6 X-Rspam-User: X-HE-Tag: 1734366412-530645 X-HE-Meta: U2FsdGVkX1+e/sbJEXO+Kz7tjKDNy6hUA9rquj14rIzrenhgX2NBo90AYLrGri4WTJAXXlwZs30916zstKO1NbYxRzvgNsuwU+r4qCXtVyRmlJRqoXwrUyNf20xLeL8sRCrFbLAA8aHlZ5/FWCyLvUg0BLduTjyQv5ECzpByR9x5Cv5EibqbGGjylfauTYlJAv3a+569ZecSmgqFrjDdNnrPMiULbYmGORAJaJILchaejRrCO+pSMf7oSRF0vwj5iSJ21vhZBPWxyPbW2MYriiXpBo2VFMqXNt+Clbf1yuojt/3ojIoladOnIuoO7nXdKcm5QHjlOZy8nnVvmSY3hB6YYeOOxEjGTatH6om8F6pc/P2IVpCQOqNmqXLqewJ+R1NxmryJSdpQ2hREqZtOb5JxCEFha6wKcSfPbfWVOap1ZrsaasXQadYB+iCX0FZd52cQ212SkcckElImPEIz9WSsZxR4RHrEEl2enQDyBT8KhfeGe5x/5wXJIxq0Joip4QckafvPTb54ES/4NgotzxxwlQaqVp9BCWjlbT0NqPJFdLivOjoKHLQqvMqpshI5A36118UVg0ePFCKN3oRBCjG0c34xFlZI1k+mMKJ6Mq37bqpBfkIBouoKeqI+A/ap6ZoyyaM0n6CtZIkjrPdSpgqCBANX0J6kY8T05MzHug6J6iRP+uTlexa8jFGEkzr5Pv3/bIxZ1XYSpmhO1VIwE/Ldj5WZ81ElDdHCGd7HT3oU7Fk6T/LVpBNDSwFIMBbX4YUKrVAJXYUZzCuQDUZ2lsnxRml5hzj5qvdVuUQwLJ9m3iOzfw/icEU3/tnPssKNHExneDjXeLf5tZO8NK/GpmtQpfzy8quu9e4toK+bnf52vDHgQj76Z48C+KFsD7QUtdViQYnD647OEsW+12g1v+VhBwncEoEybE2b0bUc9N2g+bh1Xy/62WHTGP4wtIIUOcfNDC53aB3FJ/1RIhA L6J1RWiN xrQ6X0udeNAIWNbW3b0G4WSX7vCZzfXzsHKnUUubNQVTsoOEo4MiS834Dol0n8SG9oMiSRGL8iB67PiAFV1CBaXdTVjuzB2l7aKCguKjGoGczHb/iKwW6OOCvIB1MJrtWZAWJQpi8LhbK1+eMQPCYAjHVT5ZBRt5J8XtPrFjuz1je8GKxNMxJVVtovcUjdzkE+rsXINQi9G8cBlW3/mQFBDCV3IRiOXCnlw6BdG/6A8MBaHy8gP0fQG+NQTnuQNQzw2r15txNfzuzLG6Ufnxw5Ddyr15DyfMnbSfG X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Remove accesses to page->index and page->mapping. Also use folio APIs where available. This code still assumes order 0 folios. Signed-off-by: Matthew Wilcox (Oracle) --- fs/squashfs/file.c | 46 ++++++++++++++++++++++------------------ fs/squashfs/file_cache.c | 2 +- fs/squashfs/squashfs.h | 4 ++-- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index 5b81e26b1226..1f27e8161319 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -378,13 +378,15 @@ void squashfs_fill_page(struct page *page, struct squashfs_cache_entry *buffer, } /* Copy data into page cache */ -void squashfs_copy_cache(struct page *page, struct squashfs_cache_entry *buffer, - int bytes, int offset) +void squashfs_copy_cache(struct folio *folio, + struct squashfs_cache_entry *buffer, size_t bytes, + size_t offset) { - struct inode *inode = page->mapping->host; + struct address_space *mapping = folio->mapping; + struct inode *inode = mapping->host; struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info; int i, mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1; - int start_index = page->index & ~mask, end_index = start_index | mask; + int start_index = folio->index & ~mask, end_index = start_index | mask; /* * Loop copying datablock into pages. As the datablock likely covers @@ -394,25 +396,27 @@ void squashfs_copy_cache(struct page *page, struct squashfs_cache_entry *buffer, */ for (i = start_index; i <= end_index && bytes > 0; i++, bytes -= PAGE_SIZE, offset += PAGE_SIZE) { - struct page *push_page; - int avail = buffer ? min_t(int, bytes, PAGE_SIZE) : 0; + struct folio *push_folio; + size_t avail = buffer ? min(bytes, PAGE_SIZE) : 0; - TRACE("bytes %d, i %d, available_bytes %d\n", bytes, i, avail); + TRACE("bytes %zu, i %d, available_bytes %zu\n", bytes, i, avail); - push_page = (i == page->index) ? page : - grab_cache_page_nowait(page->mapping, i); + push_folio = (i == folio->index) ? folio : + __filemap_get_folio(mapping, i, + FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT, + mapping_gfp_mask(mapping)); - if (!push_page) + if (!push_folio) continue; - if (PageUptodate(push_page)) - goto skip_page; + if (folio_test_uptodate(push_folio)) + goto skip_folio; - squashfs_fill_page(push_page, buffer, offset, avail); -skip_page: - unlock_page(push_page); - if (i != page->index) - put_page(push_page); + squashfs_fill_page(&push_folio->page, buffer, offset, avail); +skip_folio: + folio_unlock(push_folio); + if (i != folio->index) + folio_put(push_folio); } } @@ -430,16 +434,16 @@ static int squashfs_readpage_fragment(struct folio *folio, int expected) squashfs_i(inode)->fragment_block, squashfs_i(inode)->fragment_size); else - squashfs_copy_cache(&folio->page, buffer, expected, + squashfs_copy_cache(folio, buffer, expected, squashfs_i(inode)->fragment_offset); squashfs_cache_put(buffer); return res; } -static int squashfs_readpage_sparse(struct page *page, int expected) +static int squashfs_readpage_sparse(struct folio *folio, int expected) { - squashfs_copy_cache(page, NULL, expected, 0); + squashfs_copy_cache(folio, NULL, expected, 0); return 0; } @@ -470,7 +474,7 @@ static int squashfs_read_folio(struct file *file, struct folio *folio) goto out; if (res == 0) - res = squashfs_readpage_sparse(&folio->page, expected); + res = squashfs_readpage_sparse(folio, expected); else res = squashfs_readpage_block(folio, block, res, expected); } else diff --git a/fs/squashfs/file_cache.c b/fs/squashfs/file_cache.c index 0360d22a77d4..40e59a43d098 100644 --- a/fs/squashfs/file_cache.c +++ b/fs/squashfs/file_cache.c @@ -29,7 +29,7 @@ int squashfs_readpage_block(struct folio *folio, u64 block, int bsize, int expec ERROR("Unable to read page, block %llx, size %x\n", block, bsize); else - squashfs_copy_cache(&folio->page, buffer, expected, 0); + squashfs_copy_cache(folio, buffer, expected, 0); squashfs_cache_put(buffer); return res; diff --git a/fs/squashfs/squashfs.h b/fs/squashfs/squashfs.h index 0f5373479516..9295556ecfd0 100644 --- a/fs/squashfs/squashfs.h +++ b/fs/squashfs/squashfs.h @@ -68,8 +68,8 @@ extern __le64 *squashfs_read_fragment_index_table(struct super_block *, /* file.c */ void squashfs_fill_page(struct page *, struct squashfs_cache_entry *, int, int); -void squashfs_copy_cache(struct page *, struct squashfs_cache_entry *, int, - int); +void squashfs_copy_cache(struct folio *, struct squashfs_cache_entry *, + size_t bytes, size_t offset); /* file_xxx.c */ int squashfs_readpage_block(struct folio *, u64 block, int bsize, int expected);