Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp139905iob; Tue, 17 May 2022 21:35:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9iU5Hxv9RSvmXhU3Bud90dD7OhC2EQA0uHQmhpgG46bjPf3V4/7xpg0mMFM6PA1UFI/Fd X-Received: by 2002:a05:6a00:1252:b0:50e:9fc:d5b7 with SMTP id u18-20020a056a00125200b0050e09fcd5b7mr25706908pfi.85.1652848525052; Tue, 17 May 2022 21:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652848525; cv=none; d=google.com; s=arc-20160816; b=GZXUXhswypTRqIiaBd0yKRVoJ/ZRP45FDT1+tXuDjXIlvFXiIW+vIwiqZwnQxQxM46 hK3vqtHuP1yQJwIA0Cke4uJNn+RUo4/F7vt0zO2jkvEXpZ63A3R3RNntMClrWmvBqfOA lrgs/JvhMVc1gKnV6wKGhYf7719rjtMnSHZhd4kCO+CtKaRPtMkGJOG4S3eumImB0g/W YRiu+f2lVkqXPNW7fzwc7qIOLBPb+ipb4+H37E/CepfYKUpDZOIUk9/l05DUmcBori0w Qx1402VKxw3IG+QELz9ZNgkGTIJ7uizNF4tS5RoYFxrvFIZC0gSMcD1eli5NIxbH14JS Ygzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=E8YGWSWWojih1VKbtgTaPJ1Z6S4eE96LyrRQW+VNJuo=; b=Y5ob1Ak/ORFClxN6KWCdDn3CTX5PcQ6BztQIvpAHpwqfkPhTPYbREwXtZ52uFvZ9h+ RLK/etUBlMJcGsxcha6VSFnSAKAjBT0djPTjqeDDQ5hck5svFBp2zOCt/pfO2Wcfekg/ qVx5TLMrhdW2RK4GvNlrtDtPn5Bwr1qbsfwRf/t6mIYtEjKoOn7VDTv4MYJ7HZ6c9t69 1rzQpSGBr7pNgMj5t5jPslwZktnIZWzoys5aKvErYC1ovSckRcKOMoi/2QAbavQObXzD eLmm1guw+ZjNpoTiv5+kkp7BuNjDI27XalSF4PFE3f4j0dTjjYEZVsgfTLpn7zcp637T ecWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="JI/N/9lY"; 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 t19-20020a170902d29300b00158d0436f45si1140659plc.76.2022.05.17.21.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 21:35:25 -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="JI/N/9lY"; 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4C8F1B82CE; Tue, 17 May 2022 20:53:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244654AbiEQJSc (ORCPT + 99 others); Tue, 17 May 2022 05:18:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243266AbiEQJSR (ORCPT ); Tue, 17 May 2022 05:18:17 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 126E833A0B for ; Tue, 17 May 2022 02:17:09 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id 202so16402441pgc.9 for ; Tue, 17 May 2022 02:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=E8YGWSWWojih1VKbtgTaPJ1Z6S4eE96LyrRQW+VNJuo=; b=JI/N/9lYrny+vGuuJmW/Mz1EwloPiEjhN5PZon9WeBaiDjglsT4Enu5a5xHVRZowOg 9f3A17ll9qIQChEyLVLsVampoZaCPeLaG4XBeilDJhXBWZbrmNaGpxkZOVLYFaQLD6yh /m2bw9s2rGOy5vAk+xOFwaw/t8tuyJV2+DyDH+XizMJ6Gm5RhK7wbA1qpyUv7p3SdWZr DHfk71IEAw0lPD8PMXyKfPLy8XSSFX2sAnqmA9/yObH9mgCAlICK9Y2fzSydlVHpzxhR 9KZFz/lLG0hIcoEFXrFxC6O06kxPgggx5ocXTGPVirYrnk1XPOE+jT9zbPorcmfYK9q2 2h3A== 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; bh=E8YGWSWWojih1VKbtgTaPJ1Z6S4eE96LyrRQW+VNJuo=; b=Fa4cbPqVox4nJxdZ3meuh45lcuVfLi6yGRXIWjUt32CuSOPdhjxjcpHSDh6WiW2CNx ZuxC3Q1mnJ+qwrDVfQwEnVLA3KTN0RXliu1Diyzdne59DtCutQmtnCLlLPIlBONop2LL aaRinb8d6ZsQVD43scYpLz/6hZgEH3wgexSx5QMw29IOwcp3HXRiVxLaOSByaUgOjPv8 Ekw9FzR+q0zufY6Y4HXDV6RnlT8rrs+312k5hjgY6R/zhsmTHZlI4vMMucrgEjGrl69U grPAumA29vJAsMkFri9uIiW3UFxteY8JRaPZ3eoMFJA3J1iJjQmET1hhDGqhNPzz2CKN 9aDg== X-Gm-Message-State: AOAM533H1cf1WMwpAeFZODkW2VVQdZ0EKb5W/q+AFlIor5S4BvLC2gXn lbFI/zdiXTbmIrWItColPtBr0ZniQYXc9NWCZvo= X-Received: by 2002:a05:6a00:244a:b0:4fa:ebf9:75de with SMTP id d10-20020a056a00244a00b004faebf975demr21562526pfj.73.1652779028918; Tue, 17 May 2022 02:17:08 -0700 (PDT) MIME-Version: 1.0 References: <20220517082650.2005840-1-hsinyi@chromium.org> <20220517082650.2005840-4-hsinyi@chromium.org> In-Reply-To: <20220517082650.2005840-4-hsinyi@chromium.org> From: Xiongwei Song Date: Tue, 17 May 2022 17:16:42 +0800 Message-ID: Subject: Re: [PATCH v2 3/3] squashfs: implement readahead To: Hsin-Yi Wang Cc: Phillip Lougher , Matthew Wilcox , Xiongwei Song , Zheng Liang , Zhang Yi , Hou Tao , Miao Xie , Andrew Morton , "linux-mm @ kvack . org" , "squashfs-devel @ lists . sourceforge . net" , Linux Kernel Mailing List 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 Tue, May 17, 2022 at 4:28 PM 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 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 "xiongwei.song@windriver.com" too. > --- > 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 > >