From nobody Mon Apr 27 04:37:06 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DC6CC43334 for ; Fri, 17 Jun 2022 08:38:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380462AbiFQIiy (ORCPT ); Fri, 17 Jun 2022 04:38:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380589AbiFQIiu (ORCPT ); Fri, 17 Jun 2022 04:38:50 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27AC5692BA for ; Fri, 17 Jun 2022 01:38:42 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id h34-20020a17090a29a500b001eb01527d9eso2724707pjd.3 for ; Fri, 17 Jun 2022 01:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZkbtHcgR5KA0zD+x9oTUHYVWwacT9VRypGcZ4wLZpOg=; b=IQFp5xvBUij3vF6RFgONUsdI4F7LxAqN3ZtrQJPeUNxo+8zjmXF0j0NLkeatzKk0Mu Defn/MOopf+Tt0LZJhZgRZHPpDV16Far+cgOJxrI7ZBIjwr2nsEfcGhxQyeciQWOJJk9 92AbvVtuk7PzI/PoFh5iu1MlFb2Rm7mCnC7lc= 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=ZkbtHcgR5KA0zD+x9oTUHYVWwacT9VRypGcZ4wLZpOg=; b=kDXT5zJkwFVohODJt+aKBPerLV/L/cjxYJYMFhoz8nFol0RdIV9fu09k/q/VH188WG n20LDP1qVjOWjjiBxr7+2HnlAvJUuL9lo+yFzxFscgf1YX9OrM7mSlNOgtrbRd34st6r sh02SI6yMDC1w57uty2FwGZgIvgFloVVrzrNJFCiD1PSOpdHH4ksOgn4F4mJcu+abXbQ Hau3Dz7ok/0wKca6v4qJW6vjuyUoMrgKtZ4ByO1kYoU7dWplXGCHrj3+6bzVieInfYg5 QO+QuYGIco/eJChq18jNaJuDfiJ9RaGTaQRUVAgveZXq3zc+Dac9aL0jwsUstcXrUIUM nV3A== X-Gm-Message-State: AJIora9gPbHMMNczc2og4w+nvWsih96Xb4j057flbl72GtwVeSjCGBl5 IhiYzO6FT8ZMSrO2qQBTAscEFA== X-Google-Smtp-Source: AGRyM1s7VdOCGqUQpIDER4YWqjxPf/Ek4KvwYv/N24Zykvnrz2Rw2pxH86XQrvXmIMf1TkI7KpHZxg== X-Received: by 2002:a17:902:930c:b0:167:8960:2c39 with SMTP id bc12-20020a170902930c00b0016789602c39mr8426893plb.33.1655455121565; Fri, 17 Jun 2022 01:38:41 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:a0dc:9427:fea8:f78a]) by smtp.gmail.com with ESMTPSA id d12-20020a62f80c000000b005185407eda5sm3154103pfh.44.2022.06.17.01.38.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 01:38:41 -0700 (PDT) From: Hsin-Yi Wang To: Phillip Lougher , Matthew Wilcox , Marek Szyprowski , Andrew Morton Cc: Xiongwei Song , Zheng Liang , Zhang Yi , Hou Tao , Miao Xie , "linux-mm @ kvack . org" , "squashfs-devel @ lists . sourceforge . net" , linux-kernel@vger.kernel.org Subject: [PATCH v7 1/4] Revert "squashfs: provide backing_dev_info in order to disable read-ahead" Date: Fri, 17 Jun 2022 16:38:09 +0800 Message-Id: <20220617083810.337573-2-hsinyi@chromium.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220617083810.337573-1-hsinyi@chromium.org> References: <20220617083810.337573-1-hsinyi@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This reverts commit 9eec1d897139e5de287af5d559a02b811b844d82. Revert closing the readahead to squashfs since the readahead callback for squashfs is implemented. Suggested-by: Xiongwei Song Signed-off-by: Hsin-Yi Wang --- fs/squashfs/super.c | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c index 6d594ba2ed28f..32565dafa7f3b 100644 --- a/fs/squashfs/super.c +++ b/fs/squashfs/super.c @@ -29,7 +29,6 @@ #include #include #include -#include =20 #include "squashfs_fs.h" #include "squashfs_fs_sb.h" @@ -113,24 +112,6 @@ static const struct squashfs_decompressor *supported_s= quashfs_filesystem( return decompressor; } =20 -static int squashfs_bdi_init(struct super_block *sb) -{ - int err; - unsigned int major =3D MAJOR(sb->s_dev); - unsigned int minor =3D MINOR(sb->s_dev); - - bdi_put(sb->s_bdi); - sb->s_bdi =3D &noop_backing_dev_info; - - err =3D super_setup_bdi_name(sb, "squashfs_%u_%u", major, minor); - if (err) - return err; - - sb->s_bdi->ra_pages =3D 0; - sb->s_bdi->io_pages =3D 0; - - return 0; -} =20 static int squashfs_fill_super(struct super_block *sb, struct fs_context *= fc) { @@ -146,20 +127,6 @@ static int squashfs_fill_super(struct super_block *sb,= struct fs_context *fc) =20 TRACE("Entered squashfs_fill_superblock\n"); =20 - /* - * squashfs provides 'backing_dev_info' in order to disable read-ahead. F= or - * squashfs, I/O is not deferred, it is done immediately in read_folio, - * which means the user would always have to wait their own I/O. So the e= ffect - * of readahead is very weak for squashfs. squashfs_bdi_init will set - * sb->s_bdi->ra_pages and sb->s_bdi->io_pages to 0 and close readahead f= or - * squashfs. - */ - err =3D squashfs_bdi_init(sb); - if (err) { - errorf(fc, "squashfs init bdi failed"); - return err; - } - sb->s_fs_info =3D kzalloc(sizeof(*msblk), GFP_KERNEL); if (sb->s_fs_info =3D=3D NULL) { ERROR("Failed to allocate squashfs_sb_info\n"); --=20 2.36.1.476.g0c4daa206d-goog From nobody Mon Apr 27 04:37:06 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5BD1C43334 for ; Fri, 17 Jun 2022 08:39:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380759AbiFQIjI (ORCPT ); Fri, 17 Jun 2022 04:39:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380589AbiFQIiz (ORCPT ); Fri, 17 Jun 2022 04:38:55 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9A1669486 for ; Fri, 17 Jun 2022 01:38:54 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id w21so3644906pfc.0 for ; Fri, 17 Jun 2022 01:38:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zopK+BvSuamYvb8kkpPXiSJpoMOkgUyTWgxXUH/cCsw=; b=GpjdkIbTWWbrZUCBW7rlQQdUuuBvKFDKBuLlaoY5VjEUH10jMZXq59WS6tJnFqEgfL c2058J9vJgcrlylt8KFriWP/rA4D2Tzv8GF0nE7LdoNrmnUfvxYWAlDgXRm62NqnITvI SgKeEyr4pOBraKH9bjFC+FgB/1ZzI5FGuLBG4= 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=zopK+BvSuamYvb8kkpPXiSJpoMOkgUyTWgxXUH/cCsw=; b=7cvpRwHFDlrW0+x+Nci/Rb+UlFUjjTIflbagZK/Iqe+s3oozSeZ9apNNejmy5IlxMW UzoeSfwOzuZJ4KALQjtDr4aqaFCkh+BuOgSet5eAKU6DxTbk0RpJmcOO8tFNNbMN/R4S Vh8/vKtSAEUEL7F4FD5YgzNaEod0kgMafKAsu/WJvk6EhLw+Hlmw2Ql+E+ws0smfUuK+ EC/cJFH1nons05MinxNcW8tdPor7jyqKMb0Auw8N7osR9RcZUEsVyKHh2WvKh7t5MRzS DxT+YLtPirChLl95hXCKXiei6JtZ9Mz3rNb97UYRa+Hg+dNmpBraRLu1xUhSb4HIHLGi natQ== X-Gm-Message-State: AJIora+AlPajBTc8rGpxN8OoLzle80/ceIXNnBWNFlGP+i6fA+upwldq 8//TU98YhwaeMujgLqmnFsDp9Q== X-Google-Smtp-Source: AGRyM1uPYLhqbv/0uKLCtUWT/6Sgfvzcvfo4kaPqSj6W9uUwVrFuRA9YUyKPuKXoe5ttY3bo9JJPng== X-Received: by 2002:a05:6a00:1502:b0:51c:2991:f1c with SMTP id q2-20020a056a00150200b0051c29910f1cmr8765805pfu.37.1655455134146; Fri, 17 Jun 2022 01:38:54 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:a0dc:9427:fea8:f78a]) by smtp.gmail.com with ESMTPSA id d12-20020a62f80c000000b005185407eda5sm3154103pfh.44.2022.06.17.01.38.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 01:38:53 -0700 (PDT) From: Hsin-Yi Wang To: Phillip Lougher , Matthew Wilcox , Marek Szyprowski , Andrew Morton Cc: Xiongwei Song , Zheng Liang , Zhang Yi , Hou Tao , Miao Xie , "linux-mm @ kvack . org" , "squashfs-devel @ lists . sourceforge . net" , linux-kernel@vger.kernel.org Subject: [PATCH v7 2/4] squashfs: always build "file direct" version of page actor Date: Fri, 17 Jun 2022 16:38:11 +0800 Message-Id: <20220617083810.337573-3-hsinyi@chromium.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220617083810.337573-1-hsinyi@chromium.org> References: <20220617083810.337573-1-hsinyi@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Phillip Lougher Squashfs_readahead uses the "file direct" version of the page actor, and so build it unconditionally. Reported-by: kernel test robot Signed-off-by: Phillip Lougher Signed-off-by: Hsin-Yi Wang --- fs/squashfs/Makefile | 4 ++-- fs/squashfs/page_actor.h | 46 ---------------------------------------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile index 7bd9b8b856d0b..477c89a519ee8 100644 --- a/fs/squashfs/Makefile +++ b/fs/squashfs/Makefile @@ -5,9 +5,9 @@ =20 obj-$(CONFIG_SQUASHFS) +=3D squashfs.o squashfs-y +=3D block.o cache.o dir.o export.o file.o fragment.o id.o inod= e.o -squashfs-y +=3D namei.o super.o symlink.o decompressor.o +squashfs-y +=3D namei.o super.o symlink.o decompressor.o page_actor.o squashfs-$(CONFIG_SQUASHFS_FILE_CACHE) +=3D file_cache.o -squashfs-$(CONFIG_SQUASHFS_FILE_DIRECT) +=3D file_direct.o page_actor.o +squashfs-$(CONFIG_SQUASHFS_FILE_DIRECT) +=3D file_direct.o squashfs-$(CONFIG_SQUASHFS_DECOMP_SINGLE) +=3D decompressor_single.o squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI) +=3D decompressor_multi.o squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU) +=3D decompressor_multi_pe= rcpu.o diff --git a/fs/squashfs/page_actor.h b/fs/squashfs/page_actor.h index 37523c54256fa..24841d28bc0fb 100644 --- a/fs/squashfs/page_actor.h +++ b/fs/squashfs/page_actor.h @@ -6,51 +6,6 @@ * Phillip Lougher */ =20 -#ifndef CONFIG_SQUASHFS_FILE_DIRECT -struct squashfs_page_actor { - void **page; - int pages; - int length; - int next_page; -}; - -static inline struct squashfs_page_actor *squashfs_page_actor_init(void **= page, - int pages, int length) -{ - struct squashfs_page_actor *actor =3D kmalloc(sizeof(*actor), GFP_KERNEL); - - if (actor =3D=3D NULL) - return NULL; - - actor->length =3D length ? : pages * PAGE_SIZE; - actor->page =3D page; - actor->pages =3D pages; - actor->next_page =3D 0; - return actor; -} - -static inline void *squashfs_first_page(struct squashfs_page_actor *actor) -{ - actor->next_page =3D 1; - return actor->page[0]; -} - -static inline void *squashfs_next_page(struct squashfs_page_actor *actor) -{ - return actor->next_page =3D=3D actor->pages ? NULL : - actor->page[actor->next_page++]; -} - -static inline void squashfs_finish_page(struct squashfs_page_actor *actor) -{ - /* empty */ -} - -static inline void squashfs_actor_nobuff(struct squashfs_page_actor *actor) -{ - /* empty */ -} -#else struct squashfs_page_actor { union { void **buffer; @@ -91,4 +46,3 @@ static inline void squashfs_actor_nobuff(struct squashfs_= page_actor *actor) actor->alloc_buffer =3D 0; } #endif -#endif --=20 2.36.1.476.g0c4daa206d-goog From nobody Mon Apr 27 04:37:06 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B4F3C43334 for ; Fri, 17 Jun 2022 08:39:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381151AbiFQIjY (ORCPT ); Fri, 17 Jun 2022 04:39:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381141AbiFQIjK (ORCPT ); Fri, 17 Jun 2022 04:39:10 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F93C69B4C for ; Fri, 17 Jun 2022 01:39:04 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id y13-20020a17090a154d00b001eaaa3b9b8dso3581828pja.2 for ; Fri, 17 Jun 2022 01:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OcQHcF0Ot6zJHxJE6BCq0SLAaPt9Vdx4j9mbahe8wSE=; b=gKMzClnTDfI8SUjMNX6fH7fhxMRMio7/lnouINYXTknvlSQGrGJcKIAZtWflN/Bohq qoxPsXVblEwF/jvueaJK163tba46YMu4zx8a5mAiAXDZn+N5vtObxQ9xc8Q6AghEOMJD W5f5AraAVihtPahuek9K4ljUWRatX40WkUMuA= 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=OcQHcF0Ot6zJHxJE6BCq0SLAaPt9Vdx4j9mbahe8wSE=; b=AD5c2nL118BZZNVtAUpi/wL6UwotBh6bhj//897KmAdwKHca4V5H8ml38eCrgYlnlG GhkvoYqUQHjhxbs2z+4XfTYdi31eusJc7UenoTMCEhKnKCDnXxwMU4YxwJidkQHL2Nh1 bhWHJK4DQ1JcujWEJochsN2sqcDPdrvSfSn6prAy4pFHA+R7cdK5sSvvEDyJVQHqUb0D HaJGj6ypmbZwtBeOkJCS1ZbqImiapUhFgEQFZBpBfTv9MAK+rM0bbcOv7KqY1zOE5os4 AJ9rvoDW51R9gc2Olp402qZzYQy+pT3z1JkyUWgqwVdwrFW7wcW1DZDJwDxwIAq9CYHc TQHQ== X-Gm-Message-State: AJIora9TRzVPe3KDlNA4UzBk47SFwaBNC+wads+2MwjMxXIs3BRA2yxh 3s+Sj2cqaO7Qkx0NphKwJ90xtA== X-Google-Smtp-Source: AGRyM1vXrobSvy6fvBmTMguR7jdxWtClLv8yNDivQ52V+DQBP9+yRJ7i0flqk2jWsoX1tcsWCsKVUA== X-Received: by 2002:a17:902:d50e:b0:16a:13d:30ab with SMTP id b14-20020a170902d50e00b0016a013d30abmr3915658plg.31.1655455143450; Fri, 17 Jun 2022 01:39:03 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:a0dc:9427:fea8:f78a]) by smtp.gmail.com with ESMTPSA id d12-20020a62f80c000000b005185407eda5sm3154103pfh.44.2022.06.17.01.39.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 01:39:03 -0700 (PDT) From: Hsin-Yi Wang To: Phillip Lougher , Matthew Wilcox , Marek Szyprowski , Andrew Morton Cc: Xiongwei Song , Zheng Liang , Zhang Yi , Hou Tao , Miao Xie , "linux-mm @ kvack . org" , "squashfs-devel @ lists . sourceforge . net" , linux-kernel@vger.kernel.org Subject: [PATCH v7 3/4] squashfs: implement readahead Date: Fri, 17 Jun 2022 16:38:13 +0800 Message-Id: <20220617083810.337573-4-hsinyi@chromium.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220617083810.337573-1-hsinyi@chromium.org> References: <20220617083810.337573-1-hsinyi@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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: Andrew Morton --- fs/squashfs/file.c | 92 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index 7f0904b203294..f0c64ee272d5d 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 @@ -496,7 +497,96 @@ static int squashfs_read_folio(struct file *file, stru= ct folio *folio) return res; } =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) - 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; + + 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; + + actor =3D squashfs_page_actor_init_special(msblk, pages, nr_pages, + expected); + if (!actor) + goto skip_pages; + + res =3D squashfs_read_data(inode->i_sb, block, bsize, NULL, actor); + + kfree(actor); + + if (res =3D=3D expected) { + int bytes; + + /* Last page (if present) may have trailing bytes not filled */ + bytes =3D res % PAGE_SIZE; + if (pages[nr_pages - 1]->index =3D=3D file_end && bytes) + memzero_page(pages[nr_pages - 1], bytes, + PAGE_SIZE - bytes); + + 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(pages); + return; + +skip_pages: + for (i =3D 0; i < nr_pages; i++) { + unlock_page(pages[i]); + put_page(pages[i]); + } + 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.476.g0c4daa206d-goog From nobody Mon Apr 27 04:37:06 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2E79C433EF for ; Fri, 17 Jun 2022 08:39:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381230AbiFQIjx (ORCPT ); Fri, 17 Jun 2022 04:39:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381199AbiFQIjb (ORCPT ); Fri, 17 Jun 2022 04:39:31 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E7D969730 for ; Fri, 17 Jun 2022 01:39:16 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id o6so3330506plg.2 for ; Fri, 17 Jun 2022 01:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G086Dnit23XcYgqGZXR8d4QAiX5I5zPq+4/SqclxxJs=; b=VdbwQ4cd6v433oanoE0oyHKGpgJ6Sqwso/c30X2vOYB5aA4/iAtfKKyfVWc0dmgiXu CWjpdg0Kc8jVXkJVDW8W21xhw0scR/bhN55J5YUHztOeynl60wnyx6Yav+WWA1iL1NKy BrkUYqeLHVQqTyDE2xNlZuADrrmCANFnZj9WU= 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=G086Dnit23XcYgqGZXR8d4QAiX5I5zPq+4/SqclxxJs=; b=Fv5sxBpX7FldpH94LKUrBUSDDmToWmMJPU93F2C2YutdQNKbT2RvOnUfjEYiVEyQ3m l6KIJnCstNb73AineKZdNspSc0VJrRB2+kcWnPqAAINqUAICb+coPRW44RvgVvbnkUOT ldBVPFNF71xO4lrK0JFHvsF7AmQ0a0P0E3dH7JVMct1UdS08kZYkc31ISglipjyrQU5t asywondtSxjC4ciWmbqyH4kiYwNEWxI6INTjRqkzsBatU6zY58wa3eWmYNiVITmkGYms HL4CkupUZKvLW2CKN5DBt5nSt+GKOaggOB2SsvG2ZCcrPxo5rMV2TSJ2yc8CaPX8U8wZ uDtA== X-Gm-Message-State: AJIora8Dj21Tg7jrP5G05Di3e7gWyDPnnPxHVMuYmvLdZm7wTIuMNGNz GB2tvuqmWqh2gSV+LMid63wi+Q== X-Google-Smtp-Source: AGRyM1tPpQfuwZvZz9Xp+OlNElXn9z7cg7Ee0CHxsdUetFEHC3NVB1yjPycl87pTn/NmxdJo4O59hw== X-Received: by 2002:a17:90b:388c:b0:1e2:f376:b8d with SMTP id mu12-20020a17090b388c00b001e2f3760b8dmr20205301pjb.148.1655455152985; Fri, 17 Jun 2022 01:39:12 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:a0dc:9427:fea8:f78a]) by smtp.gmail.com with ESMTPSA id d12-20020a62f80c000000b005185407eda5sm3154103pfh.44.2022.06.17.01.39.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 01:39:12 -0700 (PDT) From: Hsin-Yi Wang To: Phillip Lougher , Matthew Wilcox , Marek Szyprowski , Andrew Morton Cc: Xiongwei Song , Zheng Liang , Zhang Yi , Hou Tao , Miao Xie , "linux-mm @ kvack . org" , "squashfs-devel @ lists . sourceforge . net" , linux-kernel@vger.kernel.org Subject: [PATCH v7 4/4] squashfs: support reading fragments in readahead call Date: Fri, 17 Jun 2022 16:38:15 +0800 Message-Id: <20220617083810.337573-5-hsinyi@chromium.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220617083810.337573-1-hsinyi@chromium.org> References: <20220617083810.337573-1-hsinyi@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Phillip Lougher This patch adds a function which can be used to read fragments in the readahead call. This function is necessary because filesystems built with the -tailends (or -always-use-fragments) option may have fragments present which cannot be currently handled. Signed-off-by: Phillip Lougher Signed-off-by: Hsin-Yi Wang --- fs/squashfs/file.c | 47 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index f0c64ee272d5d..98e64fec75b77 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -497,6 +497,41 @@ static int squashfs_read_folio(struct file *file, stru= ct folio *folio) return res; } =20 +static int squashfs_readahead_fragment(struct page **page, + unsigned int pages, unsigned int expected) +{ + struct inode *inode =3D page[0]->mapping->host; + struct squashfs_cache_entry *buffer =3D squashfs_get_fragment(inode->i_sb, + squashfs_i(inode)->fragment_block, + squashfs_i(inode)->fragment_size); + struct squashfs_sb_info *msblk =3D inode->i_sb->s_fs_info; + unsigned int n, mask =3D (1 << (msblk->block_log - PAGE_SHIFT)) - 1; + + if (buffer->error) + goto out; + + expected +=3D squashfs_i(inode)->fragment_offset; + + for (n =3D 0; n < pages; n++) { + unsigned int base =3D (page[n]->index & mask) << PAGE_SHIFT; + unsigned int offset =3D base + squashfs_i(inode)->fragment_offset; + + if (expected > offset) { + unsigned int avail =3D min_t(unsigned int, expected - + offset, PAGE_SIZE); + + squashfs_fill_page(page[n], buffer, offset, avail); + } + + unlock_page(page[n]); + put_page(page[n]); + } + +out: + squashfs_cache_put(buffer); + return buffer->error; +} + static void squashfs_readahead(struct readahead_control *ractl) { struct inode *inode =3D ractl->mapping->host; @@ -513,9 +548,6 @@ static void squashfs_readahead(struct readahead_control= *ractl) =20 readahead_expand(ractl, start, (len | mask) + 1); =20 - if (file_end =3D=3D 0) - return; - pages =3D kmalloc_array(max_pages, sizeof(void *), GFP_KERNEL); if (!pages) return; @@ -541,6 +573,15 @@ static void squashfs_readahead(struct readahead_contro= l *ractl) (i_size_read(inode) & (msblk->block_size - 1)) : msblk->block_size; =20 + if (index =3D=3D file_end && squashfs_i(inode)->fragment_block !=3D + SQUASHFS_INVALID_BLK) { + res =3D squashfs_readahead_fragment(pages, nr_pages, + expected); + if (res) + goto skip_pages; + continue; + } + bsize =3D read_blocklist(inode, index, &block); if (bsize =3D=3D 0) goto skip_pages; --=20 2.36.1.476.g0c4daa206d-goog