Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2391734iof; Wed, 8 Jun 2022 04:06:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfY2vVww2xypFlhsFaHHq28lx5UPJfIP5ONb8XxHFeN8HntvnpETWs2F2yRLf5R1+8KhhQ X-Received: by 2002:a17:902:b58c:b0:163:920c:6164 with SMTP id a12-20020a170902b58c00b00163920c6164mr34483233pls.58.1654686412203; Wed, 08 Jun 2022 04:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654686412; cv=none; d=google.com; s=arc-20160816; b=UlpWfbO0hWefzm2b82ev7nIp1AczmjQFGNWFU4zLZiBgngM5K11ESCKh2jBRqCFIDP Bta34pgBsUl6RYwV8Ya9IJ4fdu5Fw0i5dYjiBs6oCtaE1uj+nH9S6by7Db1hluHZN8zY BtIISdFFKooIosdTmD3JEt5gM1YtDPuzPmUBNU1lsqzZz8hn0BIw0gd9iLfMEgjBlhp8 OcuBRINyixXQIGycKoFgw1sfFSqnMU5enC6ju5Dh/uk9qLFMsWaUkL5kZb9LPwWOsbRT PozNprWfc4hL+SoBRD0jFKQ0iQAa9cyuOURyqS+Tq3dTQq9xRf+Ya146hwp8+rfdkKt1 M2Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=MOErlrKzcQ0fQGKzKCELcp2CMfm4h2E469Ifi2WUjpY=; b=08jkno3wI8E49TRnmkMaVNkbkVHyfcduFfcNdsT7Bo15D/5e6w6tEEYNLdtEgw7TPh DmObG0TJPE8yy4dBA0yzp2J7dxOwASKXOC6srZvVikLfSadcuYJ1pfi3JYoD29IhLmHz Vedl30JLBai2z8KnTWTWNW/TJD99pcYAf/PjPbVpA9Kbx9DpiHFGBod9yHICMCR+Ok8a vGVD5vvpVqwjaB8d1w5Yjit5fyMMnGXQHR14E98bzyDV0p+uAschVpm6Bp4BLHehMmjr wKbc64CKWjbdQ049FQkf6kafqUF9sYnsYlw9plVe80x5djpnSt5V2EPCc7tdOFoTmHjK z1XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WJvip2ib; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u185-20020a6385c2000000b003fd3d60322bsi19177523pgd.320.2022.06.08.04.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 04:06:52 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WJvip2ib; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 02D5020A5F0; Wed, 8 Jun 2022 03:31:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237343AbiFHKaw (ORCPT + 99 others); Wed, 8 Jun 2022 06:30:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237903AbiFHK3a (ORCPT ); Wed, 8 Jun 2022 06:29:30 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D93FC0469 for ; Wed, 8 Jun 2022 03:20:38 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id o7so7212107eja.1 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=CVSFnKxjR8E71kjceH5tJLOTpiC5C4XkCXPJUapD/qMh5xiK5lwBgXTNC+LM/TOCP2 3bdYcnHyuPa3I6JvsFpqIDMduh3x/DAeGrfvSALZjFw5wenx5TuNYrGTJu1CNGWSQdyT DHdgFQxdLP3tMRawE+G31pezvyeJ38cynGI74CyA9f/xQ1Vr25T1gU09WKDt1e6QNCu5 kpEPPDA7CTIEpBYr1uMyKBHt9prJjj4BeLsPouSpNmpylv+zScFPZSXU2UmH9uYDJKme aiRrkp/KbpiOlL7/E9OC/sa1qkPLdoasmDXzz55CEVzsxkfg5x3XCrz5M2sAxMc2I27i r5/w== X-Gm-Message-State: AOAM531eQteQ1XfYRzjvUiKqrBPNXfBs/WE0XgD6eoqsgO6MPaERCxZW LMN2opi3EwY5BerNXuISE1CkW8BP4Ntwg9LfpS4p3w== 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 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > > > > > > > > >