From patchwork Fri Jun 17 03:03:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Lougher X-Patchwork-Id: 12885058 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 A5BBAC433EF for ; Fri, 17 Jun 2022 03:04:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DA286B0071; Thu, 16 Jun 2022 23:04:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18A846B0073; Thu, 16 Jun 2022 23:04:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0516B6B0074; Thu, 16 Jun 2022 23:04:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E844D6B0071 for ; Thu, 16 Jun 2022 23:04:06 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B9E0E202C9 for ; Fri, 17 Jun 2022 03:04:06 +0000 (UTC) X-FDA: 79586233692.27.2147203 Received: from p3plwbeout17-03.prod.phx3.secureserver.net (p3plsmtp17-03-2.prod.phx3.secureserver.net [173.201.193.166]) by imf19.hostedemail.com (Postfix) with ESMTP id 1496B1A008C for ; Fri, 17 Jun 2022 03:04:05 +0000 (UTC) Received: from mailex.mailcore.me ([94.136.40.142]) by :WBEOUT: with ESMTP id 22HEoD9Yslh6D22HEoLnFO; Thu, 16 Jun 2022 20:04:04 -0700 X-CMAE-Analysis: v=2.4 cv=HdvR8gI8 c=1 sm=1 tr=0 ts=62abef25 a=s1hRAmXuQnGNrIj+3lWWVA==:117 a=84ok6UeoqCVsigPHarzEiQ==:17 a=ggZhUymU-5wA:10 a=JPEYwPQDsx4A:10 a=FXvPX3liAAAA:8 a=Lo680ACL7Cit5IcG_IsA:9 a=UObqyxdv-6Yh2QiB9mM_:22 X-SECURESERVER-ACCT: phillip@squashfs.org.uk X-SID: 22HEoD9Yslh6D Received: from 82-69-79-175.dsl.in-addr.zen.co.uk ([82.69.79.175] helo=localhost.localdomain) by smtp11.mailcore.me with esmtpa (Exim 4.94.2) (envelope-from ) id 1o22HD-0005dm-Ey; Fri, 17 Jun 2022 04:04:03 +0100 From: Phillip Lougher To: hsinyi@chromium.org Cc: Xiongwei.Song@windriver.com, akpm@linux-foundation.org, houtao1@huawei.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, m.szyprowski@samsung.com, miaoxie@huawei.com, phillip@squashfs.org.uk, squashfs-devel@lists.sourceforge.net, willy@infradead.org, yi.zhang@huawei.com, zhengliang6@huawei.com Subject: [PATCH 4/3] squashfs: support reading fragments in readahead call Date: Fri, 17 Jun 2022 04:03:45 +0100 Message-Id: <20220617030345.24712-1-phillip@squashfs.org.uk> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220613082802.1301238-4-hsinyi@chromium.org> References: <20220613082802.1301238-4-hsinyi@chromium.org> MIME-Version: 1.0 X-Mailcore-Auth: 439999529 X-Mailcore-Domain: 1394945 X-123-reg-Authenticated: phillip@squashfs.org.uk X-Originating-IP: 82.69.79.175 X-CMAE-Envelope: MS4xfD+Pq7/gTk7esNB2XnfOnxYyknrWWdgF997sD6BQ45/14WsN0W62L2/m8F3R8hFl21VoVWEplTmVtZIxCcI4KsW/hlSBb+q8c+ZBrTfkRAd3LXhA4cMJ g5Ji6kj0NBzdDyx1R2Q76Y33Iq4rEYPzdqTyIsL+i9RLldijPFgBAu/3GFXS/AtQuvAqdW4mXGc8WewPqTKjKTnsacYHncCNCWk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=none; spf=none (imf19.hostedemail.com: domain of phillip@squashfs.org.uk has no SPF policy when checking 173.201.193.166) smtp.mailfrom=phillip@squashfs.org.uk ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655435046; 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; bh=Ow8bB7bEfG9VT2oXOR1/1WiRXNIlOLlhlaka2k9vOUA=; b=kaMkS206FQYFHwTqJQkhnYdFexnPs0Z3Tz0u/9kKSAmc1PIZ0IvCCOswOSdKY/XZzCLFgl V3m4/9r+GkjGmUr9o0kWggCj5BYzuHBNBzEYS1n/iwGbUgUh1iim4eOJiS5ivQsXOio1Sl c5NPM1uD59c4H37mS6ihcAHmE5LcClI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655435046; a=rsa-sha256; cv=none; b=tOBqLNKWZW/iq4VNSTlK+wQXO3/3zmG/a64Ujsjwr+/n5a7tLj/3IZU9zKX2Z73e1yfKtF mamQlGnlQX+80O1DAqH5v4/R/bsXSVK+sPrXJjfSb/BID1nLzfX0WBFVZ8EeoffSqrOr+V 1D3sbjYn8hfFKqy+bN4oKCzuMiDhHsY= X-Stat-Signature: kgi551acu9zst5sbkkm8y6scutyc6a6g X-Rspamd-Queue-Id: 1496B1A008C X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=none (imf19.hostedemail.com: domain of phillip@squashfs.org.uk has no SPF policy when checking 173.201.193.166) smtp.mailfrom=phillip@squashfs.org.uk X-Rspamd-Server: rspam10 X-HE-Tag: 1655435045-458621 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: This patch adds a function which can be used to read fragments in the readahead call. This function is necessary because filesystems built with the -tailends (or -always-use-fragments) option may have fragments present which cannot be currently handled. Signed-off-by: Phillip Lougher --- fs/squashfs/file.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index f0c64ee272d5..3a4cce16d7da 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -497,6 +497,41 @@ static int squashfs_read_folio(struct file *file, struct folio *folio) return res; } +static unsigned int squashfs_readahead_fragment(struct page **page, + unsigned int pages, unsigned int expected) +{ + struct inode *inode = page[0]->mapping->host; + struct squashfs_cache_entry *buffer = squashfs_get_fragment(inode->i_sb, + squashfs_i(inode)->fragment_block, + squashfs_i(inode)->fragment_size); + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info; + unsigned int n, mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1; + + if (buffer->error) + goto out; + + expected += squashfs_i(inode)->fragment_offset; + + for (n = 0; n < pages; n++) { + unsigned int base = (page[n]->index & mask) << PAGE_SHIFT; + unsigned int offset = base + squashfs_i(inode)->fragment_offset; + + if (expected > offset) { + unsigned int avail = min_t(unsigned int, expected - + offset, PAGE_SIZE); + + squashfs_fill_page(page[n], buffer, offset, avail); + } + + unlock_page(page[n]); + put_page(page[n]); + } + +out: + squashfs_cache_put(buffer); + return buffer->error; +} + static void squashfs_readahead(struct readahead_control *ractl) { struct inode *inode = ractl->mapping->host;