From mboxrd@z Thu Jan 1 00:00:00 1970 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 84A22CCA473 for ; Thu, 9 Jun 2022 14:47:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D57788D0024; Thu, 9 Jun 2022 10:47:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D2AE08D0022; Thu, 9 Jun 2022 10:47:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE1198D0024; Thu, 9 Jun 2022 10:47:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9BC178D0022 for ; Thu, 9 Jun 2022 10:47:04 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 686916140B for ; Thu, 9 Jun 2022 14:47:04 +0000 (UTC) X-FDA: 79558974768.09.FCDADF6 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf05.hostedemail.com (Postfix) with ESMTP id C4F3F10004D for ; Thu, 9 Jun 2022 14:47:03 +0000 (UTC) Received: by mail-pf1-f179.google.com with SMTP id b135so21254170pfb.12 for ; Thu, 09 Jun 2022 07:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=doMJm8RAJKQPombCk8jeFX6F/mzrF+61GJARc3fQjTE=; b=jWjLafpjePKW0FtxVCCEkUGe1afjkKYksBfPtbiwYG0xZnT0K22f2SCu22aId33jok vNBqt8E+iAWjsDrrNj6aa6QtDCPga0bniWCiSmkRZTpB4iLL8kNh++/He/EGLiAgk8kY T6cFoR0nzxCwlCc8vz4hEnVYPbArJSGuaiw3FVAu9xK2LpHj+OxT1vaBDLKH9d2G3qBv Fh8euTzGsmZavSe8WNRv2V05y5vhkJL43CtZjb4g1mvxwKNFNbCgkqPZIypPtak0YuuY QaFhshoLYJUKgZxzXWVpTgJr0q/PL/FI2yDK8XjFBEkZAj9uJ9xypeF4vndQsawWgt2F y66A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=doMJm8RAJKQPombCk8jeFX6F/mzrF+61GJARc3fQjTE=; b=vGGzxIy0tfyQSNADY8YSWkCGrqyc/kN+E4A4cVVaepcWnteb6qW57KJh0QvDeitjYj BHHUaqdkeOLN9N+4TEb6THq3dGKKOZnII3OJylCcuzFaSccdlkTp7kGYR8bbmKXE1YAA 8I2LVwpc5khhT8UnLKB0yuDv++ZBhj1JNME+mN/q3d6dOjiq16PfUtVNJaBfrNcQR+NB Y/yYsWoOSs5xLp8jgL4fauqEWWYToRlziSdIUU7SEHu5uo/OeuEafIo17UV9kGe1j/Vh oWRcT13vVyy1gPYL28pPOuREdRzZw5946Txebk+0RYFx3Wo00dNCs/9u9SJLQ6TouK61 3Sbw== X-Gm-Message-State: AOAM532nV5kVpDKrhAypnEDNKzezfQ2P9Zyh1FzKIznA4Vm7qscRrj1D yNI9WFsRd07+FsYEGZMInuduIy4Lz4QCMjcItnc= X-Google-Smtp-Source: ABdhPJx5ha8f6h+E3NHWYdwnjCRQfgq7Py3/YA4sCBWpN00hsfKv9Qj2eDas9cMNkp+qNyQ9IFpTrFx4LTSN4t5eALw= X-Received: by 2002:aa7:9f84:0:b0:51b:b64d:fc69 with SMTP id z4-20020aa79f84000000b0051bb64dfc69mr8403049pfr.7.1654786022670; Thu, 09 Jun 2022 07:47:02 -0700 (PDT) MIME-Version: 1.0 References: <20220606150305.1883410-1-hsinyi@chromium.org> <20220606150305.1883410-4-hsinyi@chromium.org> In-Reply-To: <20220606150305.1883410-4-hsinyi@chromium.org> From: Xiongwei Song Date: Thu, 9 Jun 2022 22:46:36 +0800 Message-ID: Subject: Re: [PATCH v5 3/3] squashfs: implement readahead To: Hsin-Yi Wang Cc: Phillip Lougher , Matthew Wilcox , Xiongwei Song , Marek Szyprowski , Andrew Morton , Zheng Liang , Zhang Yi , Hou Tao , Miao Xie , "linux-mm @ kvack . org" , "squashfs-devel @ lists . sourceforge . net" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654786023; a=rsa-sha256; cv=none; b=L9xCQyrkY4MnUaNdfQgFT81noigJjumOqyInwq0afIddsRt+MFIvEFR0jSFI9/ouNczWO0 5jMyf7X1aNj0Mo+tPldrjQgOEdrEN26KzfCA/YzfDPc0EuB6GtTZ04StLXG830uFgt1sbd T2rS+X88lFC0dumPhVXGt8zBLjTE9Jc= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jWjLafpj; spf=pass (imf05.hostedemail.com: domain of sxwjean@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=sxwjean@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654786023; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=doMJm8RAJKQPombCk8jeFX6F/mzrF+61GJARc3fQjTE=; b=v2wGCNMXf7tTZdjwzsezecsqmaK27XvsO/GjGDwV1FIWYV3ibucnqsDHbm6P3cT34eL+HI MNfeOYc4oBWvDB537tWvGsTbGwTdRS8uFazjnPz9Shzf40IRL3RR7gONntkwOswVCXutbF f+WqDpusj1NyQD6LZdRK5Z9S5UzCwzE= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C4F3F10004D X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jWjLafpj; spf=pass (imf05.hostedemail.com: domain of sxwjean@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=sxwjean@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: 91h69q9nqwzumikfj7uhnyqbnqoom3gz X-HE-Tag: 1654786023-329619 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 version is bad for my test. I ran the test below "for cnt in $(seq 0 9); do echo 3 > /proc/sys/vm/drop_caches; echo "Loop ${cnt}:"; time -v find /software/test[0-9][0-9] | xargs -P 24 -i cat {} > /dev/null 2>/dev/null; echo ""; done" in 90 partitions. With 9eec1d897139 reverted: 1:06.18 (1m + 6.18s) 1:05.65 1:06.34 1:06.88 1:06.52 1:06.78 1:06.61 1:06.99 1:06.60 1:06.79 With this version: 2:36.85 (2m + 36.85s) 2:28.89 1:43.46 1:41.50 1:42.75 1:43.46 1:43.67 1:44.41 1:44.91 1:45.44 Any thoughts? Regards, Xiongwei On Mon, Jun 6, 2022 at 11:03 PM Hsin-Yi Wang wrote: > > 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. > - zero filled blocks. > - current batch of pages isn't in the same datablock. > - decompressor error. > Otherwise pages will be marked as uptodate. The unhandled pages will be > updated by readpage later. > > Suggested-by: Matthew Wilcox > Signed-off-by: Hsin-Yi Wang > Reported-by: Matthew Wilcox > Reported-by: Phillip Lougher > Reported-by: Xiongwei Song > Reported-by: Marek Szyprowski > Reported-by: Andrew Morton > --- > v4->v5: > - Handle short file cases reported by Marek and Matthew. > - Fix checkpatch error reported by Andrew. > > v4: https://lore.kernel.org/lkml/20220601103922.1338320-4-hsinyi@chromium.org/ > v3: https://lore.kernel.org/lkml/20220523065909.883444-4-hsinyi@chromium.org/ > v2: https://lore.kernel.org/lkml/20220517082650.2005840-4-hsinyi@chromium.org/ > v1: https://lore.kernel.org/lkml/20220516105100.1412740-3-hsinyi@chromium.org/ > --- > fs/squashfs/file.c | 124 ++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 123 insertions(+), 1 deletion(-) > > diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c > index a8e495d8eb86..fbd096cd15f4 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 > @@ -495,7 +496,128 @@ static int squashfs_read_folio(struct file *file, struct folio *folio) > 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; > + unsigned short shift = msblk->block_log - PAGE_SHIFT; > + 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; > + int i, file_end = i_size_read(inode) >> msblk->block_log; > + unsigned int max_pages = 1UL << shift; > + > + readahead_expand(ractl, start, (len | mask) + 1); > + > + if (file_end == 0) > + return; > + > + pages = kmalloc_array(max_pages, sizeof(void *), GFP_KERNEL); > + if (!pages) > + return; > + > + actor = squashfs_page_actor_init_special(pages, max_pages, 0); > + if (!actor) > + goto out; > + > + for (;;) { > + pgoff_t index; > + int res, bsize; > + u64 block = 0; > + unsigned int expected; > + > + nr_pages = __readahead_batch(ractl, pages, max_pages); > + if (!nr_pages) > + break; > + > + if (readahead_pos(ractl) >= i_size_read(inode)) > + goto skip_pages; > + > + index = pages[0]->index >> shift; > + if ((pages[nr_pages - 1]->index >> shift) != index) > + goto skip_pages; > + > + expected = index == file_end ? > + (i_size_read(inode) & (msblk->block_size - 1)) : > + msblk->block_size; > + > + bsize = read_blocklist(inode, index, &block); > + if (bsize == 0) > + goto skip_pages; > + > + if (nr_pages < max_pages) { > + struct squashfs_cache_entry *buffer; > + unsigned int block_mask = max_pages - 1; > + int offset = pages[0]->index - (pages[0]->index & ~block_mask); > + > + buffer = squashfs_get_datablock(inode->i_sb, block, > + bsize); > + if (buffer->error) { > + squashfs_cache_put(buffer); > + goto skip_pages; > + } > + > + expected -= offset * PAGE_SIZE; > + for (i = 0; i < nr_pages && expected > 0; i++, > + expected -= PAGE_SIZE, offset++) { > + int avail = min_t(int, expected, PAGE_SIZE); > + > + squashfs_fill_page(pages[i], buffer, > + offset * PAGE_SIZE, avail); > + unlock_page(pages[i]); > + } > + > + squashfs_cache_put(buffer); > + continue; > + } > + > + res = squashfs_read_data(inode->i_sb, block, bsize, NULL, > + actor); > + > + if (res == expected) { > + int bytes; > + > + /* Last page may have trailing bytes not filled */ > + bytes = res % PAGE_SIZE; > + if (bytes) { > + void *pageaddr; > + > + pageaddr = kmap_atomic(pages[nr_pages - 1]); > + memset(pageaddr + bytes, 0, PAGE_SIZE - bytes); > + kunmap_atomic(pageaddr); > + } > + > + for (i = 0; i < nr_pages; i++) { > + flush_dcache_page(pages[i]); > + SetPageUptodate(pages[i]); > + } > + } > + > + for (i = 0; i < nr_pages; i++) { > + unlock_page(pages[i]); > + put_page(pages[i]); > + } > + } > + > + kfree(actor); > + kfree(pages); > + 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 = { > - .read_folio = squashfs_read_folio > + .read_folio = squashfs_read_folio, > + .readahead = squashfs_readahead > }; > -- > 2.36.1.255.ge46751e96f-goog > >