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 22562C433EF for ; Wed, 8 Jun 2022 10:20:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9765C8D0025; Wed, 8 Jun 2022 06:20:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9240B8D0021; Wed, 8 Jun 2022 06:20:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 813EC8D0025; Wed, 8 Jun 2022 06:20:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 719568D0021 for ; Wed, 8 Jun 2022 06:20:38 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3C9E4F72 for ; Wed, 8 Jun 2022 10:20:38 +0000 (UTC) X-FDA: 79554674556.07.5BA5DB7 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf19.hostedemail.com (Postfix) with ESMTP id C45261A0051 for ; Wed, 8 Jun 2022 10:20:37 +0000 (UTC) Received: by mail-ej1-f52.google.com with SMTP id fu3so39009990ejc.7 for ; Wed, 08 Jun 2022 03:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=MOErlrKzcQ0fQGKzKCELcp2CMfm4h2E469Ifi2WUjpY=; b=WJvip2ibSrEZvbDiUNa7JekF+K4j2m3EL1NncxpLz5TkY7DE479sifvRs+9BiZ+G2t oWeUoIkAdWfyjSKtpwzZ3ndWz8TL0RLVKwZPh1A9BPnkdXUbNNdE86E2xIiFBGypXTbz 0WLlFaQu42r991k4noZxW4cSiSYm3kd+vsaEM= 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:content-transfer-encoding; bh=MOErlrKzcQ0fQGKzKCELcp2CMfm4h2E469Ifi2WUjpY=; b=qHHxK+mmg0Db5reh2+FzwaV7G9eYYWXZsU6jRuPAVcVgzrCOBp6kdrHSGv5AyERSis sbVXhLRZIyc6YFj7dGrCeVM8ThgPv3PGMACYvGDsdR84C26J48B6pd5sA1ayOmgi6Sm9 3yZt5uiiQ9e81xkvHvIR9PVYCYBvBgsEyFiQXuvYhvFxm4dFJcCZvjP5TOManT5hitK6 F2l6/d6Yapvekmgm68aUL0MjFXf2uFOodgTfdqb1Rm9C/aoInjIWHjGlLJzSW++d4X29 jx/97C9IZLBU0eQv9V8h+QDdi+mztvZK+i4rr+7E3KDqVqa9X/MXRkbgDoiV0pA7A+rL Qrcg== X-Gm-Message-State: AOAM5326ImduiehS5b31fA1f7lZZgKT9Hs6dgXhqELeXGNVABLcZVK/p SpOkTMTmEw5pc4G66ZMYc6NLDU+3p2kDpMqc/jNQ2g== X-Google-Smtp-Source: ABdhPJxRuD7qoNFPxC5yA3clz7LmXcRRFdUy1KgowVtGWClNjAStxI/Cd9NKgyaKhPsrkpEE1CkW+7A0RESM2g3V3PQ= X-Received: by 2002:a17:907:2ce2:b0:6ff:30e2:25c3 with SMTP id hz2-20020a1709072ce200b006ff30e225c3mr30423037ejc.494.1654683636410; Wed, 08 Jun 2022 03:20:36 -0700 (PDT) MIME-Version: 1.0 References: <20220606150305.1883410-1-hsinyi@chromium.org> <20220606150305.1883410-4-hsinyi@chromium.org> <1794711.atdPhlSkOF@opensuse> In-Reply-To: <1794711.atdPhlSkOF@opensuse> From: Hsin-Yi Wang Date: Wed, 8 Jun 2022 18:20:10 +0800 Message-ID: Subject: Re: [PATCH v5 3/3] squashfs: implement readahead To: "Fabio M. De Francesco" 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@vger.kernel.org, ira.weiny@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=WJvip2ib; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf19.hostedemail.com: domain of hsinyi@chromium.org designates 209.85.218.52 as permitted sender) smtp.mailfrom=hsinyi@chromium.org X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C45261A0051 X-Rspam-User: X-Stat-Signature: xpwmj36si1hi8rn38gnt9mmxna4wxsyt X-HE-Tag: 1654683637-783080 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: On Wed, Jun 8, 2022 at 3:29 AM Fabio M. De Francesco wrote: > > On luned=C3=AC 6 giugno 2022 17:03:05 CEST 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@chromi= um.org/ > > v3: https://lore.kernel.org/lkml/20220523065909.883444-4-hsinyi@chromiu= m.org/ > > v2: https://lore.kernel.org/lkml/20220517082650.2005840-4-hsinyi@chromi= um.org/ > > v1: https://lore.kernel.org/lkml/20220516105100.1412740-3-hsinyi@chromi= um.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 =3D ractl->mapping->host; > > + struct squashfs_sb_info *msblk =3D inode->i_sb->s_fs_info; > > + size_t mask =3D (1UL << msblk->block_log) - 1; > > + unsigned short shift =3D msblk->block_log - PAGE_SHIFT; > > + loff_t start =3D readahead_pos(ractl) & ~mask; > > + size_t len =3D readahead_length(ractl) + readahead_pos(ractl) - > start; > > + struct squashfs_page_actor *actor; > > + unsigned int nr_pages =3D 0; > > + struct page **pages; > > + int i, file_end =3D i_size_read(inode) >> msblk->block_log; > > + unsigned int max_pages =3D 1UL << shift; > > + > > + readahead_expand(ractl, start, (len | mask) + 1); > > + > > + if (file_end =3D=3D 0) > > + return; > > + > > + pages =3D kmalloc_array(max_pages, sizeof(void *), GFP_KERNEL); > > + if (!pages) > > + return; > > + > > + actor =3D squashfs_page_actor_init_special(pages, max_pages, 0); > > + if (!actor) > > + goto out; > > + > > + for (;;) { > > + pgoff_t index; > > + int res, bsize; > > + u64 block =3D 0; > > + unsigned int expected; > > + > > + nr_pages =3D __readahead_batch(ractl, pages, max_pages); > > + if (!nr_pages) > > + break; > > + > > + if (readahead_pos(ractl) >=3D i_size_read(inode)) > > + goto skip_pages; > > + > > + index =3D pages[0]->index >> shift; > > + if ((pages[nr_pages - 1]->index >> shift) !=3D index) > > + goto skip_pages; > > + > > + expected =3D index =3D=3D file_end ? > > + (i_size_read(inode) & (msblk->block_size - > 1)) : > > + msblk->block_size; > > + > > + bsize =3D read_blocklist(inode, index, &block); > > + if (bsize =3D=3D 0) > > + goto skip_pages; > > + > > + if (nr_pages < max_pages) { > > + struct squashfs_cache_entry *buffer; > > + unsigned int block_mask =3D max_pages - 1; > > + int offset =3D pages[0]->index - (pages[0]- > >index & ~block_mask); > > + > > + buffer =3D squashfs_get_datablock(inode->i_sb, > block, > > + > bsize); > > + if (buffer->error) { > > + squashfs_cache_put(buffer); > > + goto skip_pages; > > + } > > + > > + expected -=3D offset * PAGE_SIZE; > > + for (i =3D 0; i < nr_pages && expected > 0; i+ > +, > > + expected -=3D > PAGE_SIZE, offset++) { > > + int avail =3D 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 =3D squashfs_read_data(inode->i_sb, block, bsize, > NULL, > > + actor); > > + > > + if (res =3D=3D expected) { > > + int bytes; > > + > > + /* Last page may have trailing bytes not > filled */ > > + bytes =3D res % PAGE_SIZE; > > + if (bytes) { > > + void *pageaddr; > > + > > + pageaddr =3D > kmap_atomic(pages[nr_pages - 1]); > > + memset(pageaddr + bytes, 0, > PAGE_SIZE - bytes); > > + kunmap_atomic(pageaddr); > > + } > > Hi Hsin-Yi, > > kmap_atomic() shouldn't be used in new code, unless there are special > reasons that I am not able to spot here. > > Why not use kmap_local_page(), preferably via memzero_page? Right, these can be replaced with kmap_local_page(pages[nr_pages - 1], bytes, PAGE_SIZE - bytes); Thanks for the suggestion. > > Thanks, > > Fabio > > > + > > + for (i =3D 0; i < nr_pages; i++) { > > + flush_dcache_page(pages[i]); > > + SetPageUptodate(pages[i]); > > + } > > + } > > + > > + for (i =3D 0; i < nr_pages; i++) { > > + unlock_page(pages[i]); > > + put_page(pages[i]); > > + } > > + } > > + > > + kfree(actor); > > + kfree(pages); > > + return; > > + > > +skip_pages: > > + for (i =3D 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 =3D { > > - .read_folio =3D squashfs_read_folio > > + .read_folio =3D squashfs_read_folio, > > + .readahead =3D squashfs_readahead > > }; > > -- > > 2.36.1.255.ge46751e96f-goog > > > > > > > > > >