Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp249606iog; Mon, 13 Jun 2022 01:39:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGnJwAF/ezyvU5/uXdA77fDtgTXzQE/1DJ1IbtDqrGJdKJZCGBaD2PWkjrkOpSZb1eL5cb X-Received: by 2002:a50:8e58:0:b0:433:2d3b:ed5 with SMTP id 24-20020a508e58000000b004332d3b0ed5mr26198749edx.246.1655109579831; Mon, 13 Jun 2022 01:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655109579; cv=none; d=google.com; s=arc-20160816; b=A+tSgEZv+He6rhKIxOo3wzMtLn5ng2KWENbapivazQW6WJcEAArEmALmHrz3fN3DgL jBl/UubnBsT7QeJA+AeGW5JSQXFl8RVRsleAecgBEp9GEiq1zt9ux85noJBCZgbQlba2 GJkzuCnZnpJGop0NPWFH1xMA4H5PV2IcYnkGL8Poa7hEQ9S9Qj5bsn4Wyfmi28D54Ccv kocaIL4Po4umC3nwoq0x5kDGNNYvVJlofDufCZktfADHstkPmXp2S69WHJIdfcqQj4Qr AGN6Fi6uiMv3KaATNvv1aYEqZYrdyoEHY1+tcy7ZNYb97hPAhFiTpky4K+yQnXmjat5o Xpmw== 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=ykDR2Uk4CbOQ3wM0PXuQC4oxDGLqvfs6LYo+jnOevDY=; b=nMKV0NrC0pxAzH0gpMdPGIlSMbL2oJ3G/f0vAnwzfnBsi6EVBxKmNhW7G+53ZyDrDp gtmli2887FdShDy1TGeCg5wYfQCfu7LcIsQ07Vama78pJrKJuFUK5qtsqywpUIPrWvwM 0Qo5ywgMexXBrkFwrkZQALMzXT1V9TpsU/P1UpXUODZEjlAj5ULieU6dBVSYeBnKrk46 FYqxyBdoW4fzUebERXNaEFi2s/G6Qo4OWMmi694RHCjQsyIfp/PeFTyjtyQSngmcsd8y X/C273cm7TMZ2iKT0YBajkajREkA6fgmPiAG46VemGEHGAElzO80BUyB+xLRkqJf9WXX /oqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iBEsynkr; 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 cr19-20020a170906d55300b0071212933e05si7501802ejc.433.2022.06.13.01.39.15; Mon, 13 Jun 2022 01:39:39 -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=iBEsynkr; 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 S229603AbiFMI2t (ORCPT + 99 others); Mon, 13 Jun 2022 04:28:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240161AbiFMI23 (ORCPT ); Mon, 13 Jun 2022 04:28:29 -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 1F26612757 for ; Mon, 13 Jun 2022 01:28:26 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d5so1895915plo.12 for ; Mon, 13 Jun 2022 01:28:26 -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=ykDR2Uk4CbOQ3wM0PXuQC4oxDGLqvfs6LYo+jnOevDY=; b=iBEsynkrqKiDNFcZ/2PPp1KD827bEZaQ/fOYwNHs93fW8/auD7Uf41sOsHATyyeNgu v4qiBS0sWa2faVOaBotB267Qu1DkblzSW3vCivrWnXT0Lg4RmDx1p1XW/fyBzBH98cz/ k0ud7NQUACMOVgBADm0y8FMttNspzpifAnudU= 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=ykDR2Uk4CbOQ3wM0PXuQC4oxDGLqvfs6LYo+jnOevDY=; b=3P1m9YfX4RIxuLt/BbnpRmB/a8JMSauUg1oZNd6QTdF7p9kTkuVuzaM2SP0Mm7SU6s E/x47VNcQJh0uHlLfOazPCvDZx+da/QgkJ08QFpSf90ghifRdbTsFxz0V1Mqdj3Q04DK 1WfDGyCHUckwkon9UuKUck22iHHc3He3rrwrGPuPuq9qT/R4cSFkhQAZLCCOgxFo9CKb IV5D62nfc82ddeXXAGDtwl7o9cWU+o+7AkMCkNGMFwjlli6p3/FYHAQy2GrcTLoil5lt KVq4SzBv4JIwI71p3IFUzIGvwpuAKa83/SsnnsxBw5mmPeTo6oRWTaq63fE6XYzlvvzu EiGw== X-Gm-Message-State: AOAM530/VFyya9vyNizRoMnnNXkiRWoLfksOGYJ6JTEExFcgZ81YUAOu yfacD/B8NH+1lkeBqE0z+Sf/VSMuDjxpWg== X-Received: by 2002:a05:6a00:2341:b0:51b:dd96:c7c1 with SMTP id j1-20020a056a00234100b0051bdd96c7c1mr53913886pfj.14.1655108895352; Mon, 13 Jun 2022 01:28:15 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:79ca:e1d9:ad5:dc9e]) by smtp.gmail.com with ESMTPSA id br8-20020a056a00440800b00518a473265csm4624906pfb.217.2022.06.13.01.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 01:28:14 -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 v6 3/3] squashfs: implement readahead Date: Mon, 13 Jun 2022 16:28:02 +0800 Message-Id: <20220613082802.1301238-4-hsinyi@chromium.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220613082802.1301238-1-hsinyi@chromium.org> References: <20220613082802.1301238-1-hsinyi@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.3 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. - 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 --- v5->v6: - use the new squashfs_page_actor_init_special() to handle short file cases as well. - use memzero_page(). v5: https://lore.kernel.org/lkml/20220606150305.1883410-4-hsinyi@chromium.org/ v4: https://lore.kernel.org/lkml/20220601103922.1338320-4-hsinyi@chromium.org/ v3: https://lore.kernel.org/lkml/20220523065909.883444-4-hsinyi@chromium.org/ v2: https://lore.kernel.org/lkml/20220517082650.2005840-4-hsinyi@chromium.org/ v1: https://lore.kernel.org/lkml/20220516105100.1412740-3-hsinyi@chromium.org/ --- 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" /* * Locate cache slot in range [offset, index] for specified inode. If @@ -496,7 +497,96 @@ static int squashfs_read_folio(struct file *file, struct folio *folio) return res; } +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; + unsigned short 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; + int i, 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; + + for (;;) { + pgoff_t index; + int res, bsize; + u64 block = 0; + unsigned int expected; + + nr_pages = __readahead_batch(ractl, pages, max_pages); + if (!nr_pages) + break; + + if (readahead_pos(ractl) >= i_size_read(inode)) + goto skip_pages; + + index = pages[0]->index >> shift; + if ((pages[nr_pages - 1]->index >> shift) != index) + goto skip_pages; + + expected = index == file_end ? + (i_size_read(inode) & (msblk->block_size - 1)) : + msblk->block_size; + + bsize = read_blocklist(inode, index, &block); + if (bsize == 0) + goto skip_pages; + + actor = squashfs_page_actor_init_special(msblk, pages, nr_pages, + expected); + if (!actor) + goto skip_pages; + + res = squashfs_read_data(inode->i_sb, block, bsize, NULL, actor); + + kfree(actor); + + if (res == expected) { + int bytes; + + /* Last page (if present) may have trailing bytes not filled */ + bytes = res % PAGE_SIZE; + if (pages[nr_pages - 1]->index == file_end && bytes) + memzero_page(pages[nr_pages - 1], bytes, + PAGE_SIZE - bytes); + + for (i = 0; i < nr_pages; i++) { + flush_dcache_page(pages[i]); + SetPageUptodate(pages[i]); + } + } + + for (i = 0; i < nr_pages; i++) { + unlock_page(pages[i]); + put_page(pages[i]); + } + } + + kfree(pages); + return; + +skip_pages: + for (i = 0; i < nr_pages; i++) { + unlock_page(pages[i]); + put_page(pages[i]); + } + kfree(pages); +} const struct address_space_operations squashfs_aops = { - .read_folio = squashfs_read_folio + .read_folio = squashfs_read_folio, + .readahead = squashfs_readahead }; -- 2.36.1.476.g0c4daa206d-goog