From: Hsin-Yi Wang <hsinyi@chromium.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: "Song, Xiongwei" <Xiongwei.Song@windriver.com>,
"phillip@squashfs.org.uk" <phillip@squashfs.org.uk>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"squashfs-devel@lists.sourceforge.net"
<squashfs-devel@lists.sourceforge.net>
Subject: Re: squashfs performance regression and readahea
Date: Mon, 9 May 2022 15:05:56 +0800 [thread overview]
Message-ID: <CAJMQK-jNYoJVqsri4REV=E3bG8AS7T82HrVSAUPzbUiWask01A@mail.gmail.com> (raw)
In-Reply-To: <Ynfzh2ifG85MZEoN@casper.infradead.org>
On Mon, May 9, 2022 at 12:45 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Sun, May 08, 2022 at 02:46:40PM +0000, Song, Xiongwei wrote:
> > I am facing a performance regression on squashfs. There are many squashfs
> > partitions on our board. I am doing the operations below on 90 squashfs
> > partitions:
>
> Hi Xiongwei. Thanks for the report. Hsin-Ye and I have been working on
> this problem off-list. Hsin-Ye, could you send the latest version?
Hi Matthew,
This is the patch of the latest version. Since it's just being
reviewed halfway done, I posted the patch here, or should I send it to
the list directly?
Thanks
From 03558dcaab93ed3c32498eb70c7f2b1382b218d6 Mon Sep 17 00:00:00 2001
From: Hsin-Yi Wang <hsinyi@chromium.org>
Date: Sun, 10 Oct 2021 21:22:25 +0800
Subject: [PATCH] squashfs: implement readahead
Implement readahead callback for squashfs. It will read datablocks
which cover pages in readahead request. For a few cases it will
not mark page as uptodate, including:
- file end is 0.
- current batch of pages isn't in the same datablock or not enough in a
datablock.
Otherwise pages will be marked as uptodate. The unhandled pages will be
updated by readpage later.
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
---
fs/squashfs/file.c | 72 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 71 insertions(+), 1 deletion(-)
diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c
index 89d492916dea..20ec48cf97c5 100644
--- a/fs/squashfs/file.c
+++ b/fs/squashfs/file.c
@@ -39,6 +39,7 @@
#include "squashfs_fs_sb.h"
#include "squashfs_fs_i.h"
#include "squashfs.h"
+#include "page_actor.h"
/*
* Locate cache slot in range [offset, index] for specified inode. If
@@ -494,7 +495,76 @@ static int squashfs_readpage(struct file *file,
struct page *page)
return 0;
}
+static void squashfs_readahead(struct readahead_control *ractl)
+{
+ struct inode *inode = ractl->mapping->host;
+ struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
+ size_t mask = (1UL << msblk->block_log) - 1;
+ size_t shift = msblk->block_log - PAGE_SHIFT;
+ loff_t req_end = readahead_pos(ractl) + readahead_length(ractl);
+ loff_t start = readahead_pos(ractl) &~ mask;
+ size_t len = readahead_length(ractl) + readahead_pos(ractl) - start;
+ struct squashfs_page_actor *actor;
+ unsigned int nr_pages = 0;
+ struct page **pages;
+ u64 block = 0;
+ int bsize, res, i, index;
+ int file_end = i_size_read(inode) >> msblk->block_log;
+ int max_pages = 1UL << shift;
+
+ readahead_expand(ractl, start, (len | mask) + 1);
+
+ if (readahead_pos(ractl) + readahead_length(ractl) < req_end)
+ return;
+
+ nr_pages = readahead_count(ractl);
+ pages = kmalloc_array(nr_pages, sizeof(void *), GFP_KERNEL);
+ if (!pages)
+ return;
+
+ actor = squashfs_page_actor_init_special(pages, nr_pages, 0);
+ if (!actor)
+ goto out;
+
+ for (;;) {
+ nr_pages = __readahead_batch(ractl, pages, max_pages);
+ if (!nr_pages)
+ break;
+
+ if (readahead_pos(ractl) >= i_size_read(inode) ||
+ file_end == 0 || nr_pages < max_pages)
+ goto skip_pages;
+
+ index = pages[0]->index >> shift;
+ bsize = read_blocklist(inode, index, &block);
+ res = squashfs_read_data(inode->i_sb, block, bsize, NULL,
+ actor);
+
+ if (res >=0 && (pages[nr_pages - 1]->index >> shift) == index)
+ for (i = 0; i < nr_pages; i++)
+ SetPageUptodate(pages[i]);
+
+ for (i = 0; i < nr_pages; i++) {
+ unlock_page(pages[i]);
+ put_page(pages[i]);
+ }
+ }
+
+ kfree(actor);
+ return;
+
+skip_pages:
+ for (i = 0; i < nr_pages; i++) {
+ unlock_page(pages[i]);
+ put_page(pages[i]);
+ }
+
+ kfree(actor);
+out:
+ kfree(pages);
+}
const struct address_space_operations squashfs_aops = {
- .readpage = squashfs_readpage
+ .readpage = squashfs_readpage,
+ .readahead = squashfs_readahead
};
--
2.31.0
next prev parent reply other threads:[~2022-05-09 7:06 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-08 14:46 Song, Xiongwei
2022-05-08 16:44 ` Matthew Wilcox
2022-05-09 7:05 ` Hsin-Yi Wang [this message]
2022-05-09 7:10 ` Hsin-Yi Wang
2022-05-09 9:42 ` Song, Xiongwei
2022-05-09 12:43 ` Xiongwei Song
2022-05-09 13:21 ` Matthew Wilcox
2022-05-09 14:29 ` Hsin-Yi Wang
2022-05-10 12:30 ` Xiongwei Song
2022-05-10 12:47 ` Hsin-Yi Wang
2022-05-10 13:18 ` Xiongwei Song
2022-05-11 15:12 ` Hsin-Yi Wang
2022-05-11 19:13 ` Phillip Lougher
2022-05-12 6:23 ` Hsin-Yi Wang
2022-05-13 5:33 ` Phillip Lougher
2022-05-13 6:35 ` Hsin-Yi Wang
2022-05-15 0:54 ` Phillip Lougher
2022-05-16 8:23 ` Hsin-Yi Wang
2022-05-16 9:00 ` Xiongwei Song
2022-05-16 9:10 ` Hsin-Yi Wang
2022-05-16 9:34 ` Xiongwei Song
2022-05-16 11:01 ` Hsin-Yi Wang
2022-05-13 13:09 ` Matthew Wilcox
2022-05-15 0:05 ` Phillip Lougher
2022-05-13 12:16 ` Xiongwei Song
2022-05-13 12:29 ` Xiongwei Song
2022-05-13 16:43 ` Hsin-Yi Wang
2022-05-13 18:12 ` Matthew Wilcox
2022-05-13 23:12 ` Xiongwei Song
2022-05-14 11:51 ` Hsin-Yi Wang
2022-05-10 1:11 ` Phillip Lougher
2022-05-10 2:35 ` Matthew Wilcox
2022-05-10 3:20 ` Phillip Lougher
2022-05-10 3:41 ` Phillip Lougher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJMQK-jNYoJVqsri4REV=E3bG8AS7T82HrVSAUPzbUiWask01A@mail.gmail.com' \
--to=hsinyi@chromium.org \
--cc=Xiongwei.Song@windriver.com \
--cc=linux-mm@kvack.org \
--cc=phillip@squashfs.org.uk \
--cc=squashfs-devel@lists.sourceforge.net \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox