Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3635891iob; Tue, 17 May 2022 04:28:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjcl5vc8LvrzS509CfpBud6bddKirnr1+WDSzSfY1nOmtTwIEFXsoFtzJ9fLfcb2cMJWaL X-Received: by 2002:a63:a4d:0:b0:3db:7de7:58b0 with SMTP id z13-20020a630a4d000000b003db7de758b0mr19513464pgk.128.1652786937190; Tue, 17 May 2022 04:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652786937; cv=none; d=google.com; s=arc-20160816; b=eOS5EenQHfwDaUiNFoivN80EjMQ8WSEAiXKwRnnmaNUD6+Xnz4yU0RPLoxJsV5PCWW 9eqAu8TBJxzPMZRhcZM/8C0zOefG1xGN8nytsC4Jv62VLVOviSwpiJV5D979tiK1p7Ea V57Y1Hf8ppWXoXMbX5V91AErgb85ZeWCUUy5TN/1noqL9vl8MIyqzqsjd/q6TpaGoRDM HXy4Fl8lr25kr+uxkknJhgRRBxr+Ef68NJrke5/BFuniuPLwNPsbj+2GEUvNVvTQZTXi F8xk1Uks5PBu84UTwyVs1OuGf/Ugr+wAFWs9WIp318zaodP23GQGuvgamSyNoCuDUFen g7vw== 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=795DpeL4AVvHI+lpL0joEtH4VZitVLN+aqxdeh6jjYU=; b=p2giT2VSsXh9/2vsoIcbA2tYbuNTZ0Bdepb19ovHOxFAlIgsvUZszsMPp9J3NMA8/c GQojf7SMdxdM5YWhTkbcz7+1t1wKzh0wRdxGzPfz51Yj4A5mpjKbJIG4JCXUq+bbH/Sl p/JfF9u5FGuvJ3jLr2qX2/bragIwyqhUaibwpwFd+nxwLFQWM3Rm5Eg13Q3iuuJ0SIAT vv9hPC890wWpaYaG0BZbPPoAZ5i0MrFQ9AvQrB8Lr3AyMzOTlccMltpZ8aS8zG3L+Mlb DGR5/WdRihjMmsPspayNQPKk+MsejbEXqnYnwZkXyy4w6awh3ySkcRDcigPlcN3L+w2y N+tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="ED/whdRh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w22-20020a63fb56000000b003c6b96fbd91si16013298pgj.434.2022.05.17.04.28.44; Tue, 17 May 2022 04:28:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="ED/whdRh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243300AbiEQI3V (ORCPT + 99 others); Tue, 17 May 2022 04:29:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243189AbiEQI27 (ORCPT ); Tue, 17 May 2022 04:28:59 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B304134BB2 for ; Tue, 17 May 2022 01:28:43 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id z7-20020a17090abd8700b001df78c7c209so1765145pjr.1 for ; Tue, 17 May 2022 01:28:43 -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=795DpeL4AVvHI+lpL0joEtH4VZitVLN+aqxdeh6jjYU=; b=ED/whdRh9rUIrpg2gVqOkUlPSLfH+d13dKN6o5qhscZGfYA1wIc36jAYuO2aCcUTME tywwpQRtrhoL7YMncd8uUcl8ldVWCDe8Tvq+4wKthS8GnM6L16HjHx69ofm21fozQ2c1 0gPwozKxl0EWsQf4v0ye2mrWDjOsxXqCxTdjA= 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=795DpeL4AVvHI+lpL0joEtH4VZitVLN+aqxdeh6jjYU=; b=T50XU1eDzJKMrVHoctaCws7G31iheG9pa8nYUH/6IGHL5PW+G14GrexufAjxLY6WuD 4nYFZEO93nbL1UKcRHvtzjhawRgT/7xb3Zy6LYhWlVHBbqazxBXP5IhFylM+8hBzF4D+ wYCMr5eWmi6qQ504UzY5u1LUI/YwVn9/RgKvKHpV74mB2MJ3H8egZgWMx/pyDqdDutf1 x8xUnlEBfEbvcgzlTiC/CgJLqaawW6oBsdu2lmugzPyQJEFZlwvW5XqZdJGbUsxHL9EW c0bZoyzMHFsCkF1dZ3r9p84fjrDjOpygLr0lTe8SYsE0aokBayB7bATQKqihlKPd9+LP +zBw== X-Gm-Message-State: AOAM5303G3HRGcUmpi7RuwinR4YVkoI+Q6NGuDVAFPCjC10ImRMh260z 9c/q9NgYUOIzV9fhE6AJoM4OeA== X-Received: by 2002:a17:90b:4a02:b0:1dc:4710:c1fe with SMTP id kk2-20020a17090b4a0200b001dc4710c1femr35223567pjb.208.1652776122745; Tue, 17 May 2022 01:28:42 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:beb2:ec58:2159:9a33]) by smtp.gmail.com with ESMTPSA id k9-20020a628409000000b0050dc76281d3sm8615083pfd.173.2022.05.17.01.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:28:42 -0700 (PDT) From: Hsin-Yi Wang To: Phillip Lougher , Matthew Wilcox , Xiongwei Song Cc: Zheng Liang , Zhang Yi , Hou Tao , Miao Xie , Andrew Morton , "linux-mm @ kvack . org" , "squashfs-devel @ lists . sourceforge . net" , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] squashfs: implement readahead Date: Tue, 17 May 2022 16:26:54 +0800 Message-Id: <20220517082650.2005840-4-hsinyi@chromium.org> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog In-Reply-To: <20220517082650.2005840-1-hsinyi@chromium.org> References: <20220517082650.2005840-1-hsinyi@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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 or not enough in a datablock. 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 --- v1->v2: remove unused check on readahead_expand(). v1: https://lore.kernel.org/lkml/20220516105100.1412740-3-hsinyi@chromium.org/ --- fs/squashfs/file.c | 77 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index a8e495d8eb86..e10a55c5b1eb 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,81 @@ 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; + size_t 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; + u64 block = 0; + int bsize, res, i, index; + int 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 (;;) { + nr_pages = __readahead_batch(ractl, pages, max_pages); + if (!nr_pages) + break; + + if (readahead_pos(ractl) >= i_size_read(inode) || + nr_pages < max_pages) + goto skip_pages; + + index = pages[0]->index >> shift; + if ((pages[nr_pages - 1]->index >> shift) != index) + goto skip_pages; + + bsize = read_blocklist(inode, index, &block); + if (bsize == 0) + goto skip_pages; + + res = squashfs_read_data(inode->i_sb, block, bsize, NULL, + actor); + + if (res >= 0) + for (i = 0; i < nr_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.0.550.gb090851708-goog