Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2197574iof; Tue, 7 Jun 2022 22:56:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxthbjWhb8bv+BrFZBHPF84ujhRE2ZDalzxbjcGzsnMgaRG0WCiyefTojhdBmI/mw7MSl9x X-Received: by 2002:a17:902:eccd:b0:166:3e34:4d05 with SMTP id a13-20020a170902eccd00b001663e344d05mr31166928plh.75.1654667810742; Tue, 07 Jun 2022 22:56:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667810; cv=none; d=google.com; s=arc-20160816; b=TbMiLg8zVmq00dn6+EefPARm6wSrotYcFjABajVfpR+HVl/DCIoExUtail96pWDxkg DQMMFc/SL1pJ2MQRKHo3Y6rKJkf2UBRMLS5E0qrFolMFkKnREbJUfplo0iehgBclLlXH G+0cNjZ8zPwQ5w9yPeKf8pGTV9AxyHoMZMF4+CsHzOnVQCJBZgy5TEHfp8GiD6KWR7dp fBNWD+i9FSbwFmoZMKEtWHZo0+toJNoYG2RnwevpOK+WJrYvCSIMncshc8CXlHuu2Tao H7GnG4DXDWjfyT7AUfy2lbFhcCTYrjvTLTSecZgmxIwScl1niH7WJo7e6Qkm+LfzhLWz QPsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yKE5Bq8iXMNxt2427O+F+1WcMe8sa2DT1LXBnKJwWF8=; b=f65dj/Aoff1Zobdq72KY1ctCfhYCyZ6IkLAwsdRUfoOiLM9pjfkC50Znq+amnno7U4 t4+juGR2SMNpQ79oVEVaEBa8UR51N0LZorylRDadFYygVIE9oYyXIe+gfw7ay9Fb9q9z iR/pDNddtiuOYeMZjBw8ABeUOTo+F2KW7cjB5jHu/NfRH01nlA3hj1Eil3ojQ5bNq/HN rocLV0pbLC9vqc53zxMV0Stkz3zttXLtFZ7XS7oGlijBJ1jAqxqgxz/CJq06K3ToNigd 69+lhwcAJ3TDzN2qOjFZ/qCIjOy+9HE+dtGyJtps3zh7Gl+eqUBOk/bpLhjFBtNkCPfJ E3TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lxKuu50m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g2-20020a056a000b8200b0051c37a7cfddsi6116058pfj.282.2022.06.07.22.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:56:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lxKuu50m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F04184B3F50; Tue, 7 Jun 2022 22:23:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444011AbiFHBBY (ORCPT + 99 others); Tue, 7 Jun 2022 21:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382604AbiFGWeC (ORCPT ); Tue, 7 Jun 2022 18:34:02 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B76EF27ED8C for ; Tue, 7 Jun 2022 12:29:47 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id w27so24235797edl.7 for ; Tue, 07 Jun 2022 12:29:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yKE5Bq8iXMNxt2427O+F+1WcMe8sa2DT1LXBnKJwWF8=; b=lxKuu50mDkU/0oF/yO+ecrSfjwsRG4gfExEALGlP5/qUx3+Yfpz4hHpOGnHteee7SD 5+AUB224zpBCDlUaUm0OaGN/Uv6sunKvrue5zm3pIU2YE3IS39aBxUPAwFefOc5PzRKu FISZgStjNwkKhqF+gaeesMcMEd6t1hMqUatrU1qVw79NmKqCg/Ezq5z6zIWu4b7hgt4Y Fb9XJ88Lu1Y/8ff3PaDecuJhwM8Qhqc8KnkMUBsvkEDRgnzeLtjnVCNCiyiGxd7oz2eH gvbZbsZfALlHAiMtmJv8vlVPOs+mwMKrTB23F9yOpJGWviIy4hDhT9QIyg86FZIYsiRg nVuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yKE5Bq8iXMNxt2427O+F+1WcMe8sa2DT1LXBnKJwWF8=; b=lqac9jcTIIE4/c3eduSrx6pnR7v9MoN3wxk85/hYDP7nq+ylPvitHZ/lBfKAfA7EpK E9tWX+HW3dmxwwaukt0s55Qx+IhcLl3EkSctqgCa2CTbhjNHbkJYSiukfqqAu9HrFkey TN1ezCz82BV/XM1nZ9EhWQC8y9/hcPzel+JpovwUc0w9JmWvXNIAvksQ7u0iql697yU5 ER8p0Wg1ecPv3k3O0C6xQk7Tfs56Nke/c7ZA2Tvv+5FK8PYxT/8sL3K36mU2Q6L1OCro vUKkNlR/hkd48LzGwMXvxrt92hDk6zEA1Aoao06jzdlWlsgYGSjMWzM+2eMaJkGI+ElF WbYA== X-Gm-Message-State: AOAM533OLN128jKG153a9XNxJmkWUXTLUTN966khVIFmzugHpFko+Ass 2ZAoQc2lt69WnyKITs2yOCdnW/qBUAM= X-Received: by 2002:a05:6402:518b:b0:42d:fe74:98f9 with SMTP id q11-20020a056402518b00b0042dfe7498f9mr35332222edd.371.1654630184913; Tue, 07 Jun 2022 12:29:44 -0700 (PDT) Received: from opensuse.localnet (host-79-13-108-3.retail.telecomitalia.it. [79.13.108.3]) by smtp.gmail.com with ESMTPSA id fg16-20020a1709069c5000b006fe8d8c54a7sm8051501ejc.87.2022.06.07.12.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 12:29:43 -0700 (PDT) From: "Fabio M. De Francesco" To: Phillip Lougher , Matthew Wilcox , Xiongwei Song , Marek Szyprowski , Andrew Morton , Hsin-Yi Wang Cc: 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 Subject: Re: [PATCH v5 3/3] squashfs: implement readahead Date: Tue, 07 Jun 2022 21:29:42 +0200 Message-ID: <1794711.atdPhlSkOF@opensuse> In-Reply-To: <20220606150305.1883410-4-hsinyi@chromium.org> References: <20220606150305.1883410-1-hsinyi@chromium.org> <20220606150305.1883410-4-hsinyi@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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. >=20 > 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. >=20 > v4: https://lore.kernel.org/lkml/20220601103922.1338320-4-hsinyi@chromium= =2Eorg/ > v3: https://lore.kernel.org/lkml/20220523065909.883444-4-hsinyi@chromium.= org/ > v2: https://lore.kernel.org/lkml/20220517082650.2005840-4-hsinyi@chromium= =2Eorg/ > v1: https://lore.kernel.org/lkml/20220516105100.1412740-3-hsinyi@chromium= =2Eorg/ > --- > fs/squashfs/file.c | 124 ++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 123 insertions(+), 1 deletion(-) >=20 > 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" > =20 > /* > * Locate cache slot in range [offset, index] for specified inode. If > @@ -495,7 +496,128 @@ static int squashfs_read_folio(struct file *file,=20 struct folio *folio) > return 0; > } > =20 > +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) -=20 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 -=20 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,=20 block, > + =09 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=20 PAGE_SIZE, offset++) { > + int avail =3D min_t(int, expected,=20 PAGE_SIZE); > + > + squashfs_fill_page(pages[i],=20 buffer, > + offset *=20 PAGE_SIZE, avail); > + unlock_page(pages[i]); > + } > + > + squashfs_cache_put(buffer); > + continue; > + } > + > + res =3D squashfs_read_data(inode->i_sb, block, bsize,=20 NULL, > + actor); > + > + if (res =3D=3D expected) { > + int bytes; > + > + /* Last page may have trailing bytes not=20 filled */ > + bytes =3D res % PAGE_SIZE; > + if (bytes) { > + void *pageaddr; > + > + pageaddr =3D=20 kmap_atomic(pages[nr_pages - 1]); > + memset(pageaddr + bytes, 0,=20 PAGE_SIZE - bytes); > + kunmap_atomic(pageaddr); > + } Hi Hsin-Yi, kmap_atomic() shouldn't be used in new code, unless there are special=20 reasons that I am not able to spot here. Why not use kmap_local_page(), preferably via memzero_page? Thanks, =46abio > + > + 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); > +} > =20 > const struct address_space_operations squashfs_aops =3D { > - .read_folio =3D squashfs_read_folio > + .read_folio =3D squashfs_read_folio, > + .readahead =3D squashfs_readahead > }; > --=20 > 2.36.1.255.ge46751e96f-goog >=20 >=20 >=20