Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5864894ioo; Wed, 1 Jun 2022 14:25:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaxPM0Zp5EoX6HS+jqqeGbpFDUE+HMJMIpyZt3WBXElOmW7gy4+jDkbev5moDXx6JSFAic X-Received: by 2002:a17:903:25c1:b0:164:1517:e8c3 with SMTP id jc1-20020a17090325c100b001641517e8c3mr1445572plb.116.1654118724297; Wed, 01 Jun 2022 14:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654118724; cv=none; d=google.com; s=arc-20160816; b=Oa9Y1Ng3+zcpwVy985aiFZqXnlyeHQQ1fTJvpxTpRB2sRsbx+9I/llo8lXfvA9OGFA JwAzx4K+acHENWSW1O6Dhl4XGl9H7mk2M9XLAX+XC+xmrSylfRsHKdyaIfmM47T7H4fw w7wHIs+NXSkmQzsdyxhjpUZrxGdWTOmf7qvX2GocP8GEnTxcWLnmdc2usKG4Wil9bQre JZnPGPyIojonqfEL0rwIvX8FSg9iNd8JYT51tVEXoObP6dAweJOFnpq3lIR78r92bUcF 3+nCx2ETd6zDkMERQLxq40lIGKeOh7O2UXS+J8nBYd5P8is1uf100DZHe1AaZ3OkpyWq vj9w== 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:subject:cc:to:from:date :dkim-signature; bh=ZY6clv8308bTKGLaBYKGBZw3L1mGR5FDHPObelAdtQE=; b=PsUa2sg7Ztq5ifeAJz05XkCLScP/F5uIcB5u8haCi58mfK5nKgLy64sXHTOscLhmOU CpRE7oaodVU35ZAPPSYWxUx2W0BNiXxJtATYox+vZchBQsRYvd8N18gxf5CPiSPr6I3B 8FE1iQmpfdzJUpJQIUGr6oIWQKnLgkxfAC9h+H3QujJqJ7mZ4GQbafoWBqzTc//1bV/y 1e2na6S8zb1X9ZWnUcPvVLeWKrp9P27K7yoT2xY/DMfokJF7f9YGGKaj9KtEfo8nKEAf +AYsdkA4xhJ2oXp3cQsUxuniIAcOsL1Xh2ahucfT2+oX1VnDAFi+TOAhkZYBYIRQYKXZ QdYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=XT2pd6nB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 123-20020a630181000000b003fca77a36e1si3697640pgb.201.2022.06.01.14.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 14:25:24 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=XT2pd6nB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A9EF423BC35; Wed, 1 Jun 2022 13:16:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237511AbiEaUrp (ORCPT + 99 others); Tue, 31 May 2022 16:47:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347857AbiEaUrn (ORCPT ); Tue, 31 May 2022 16:47:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9228F33E33 for ; Tue, 31 May 2022 13:47:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2B10861309 for ; Tue, 31 May 2022 20:47:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A9D1C385A9; Tue, 31 May 2022 20:47:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1654030061; bh=fzrQx5AYSFavOiUDERP8KYImhoo/bZrSeE+sPb05Gxw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=XT2pd6nBD2ZUibRo5HLGsXDK0DYHXIz/ZJEYSYmiHtRI6GvB5VFLpGgBu/StnzLR8 Z24TA09jTeG+htfqQvOEjT07aUdREe5b0xwxJBKH4EvU9aihE9FwC+TfKu2dAa+unH EiZT4/A9G7Pa90bZ390dRUQ00NWJyh/P9Fwkg0nY= Date: Tue, 31 May 2022 13:47:40 -0700 From: Andrew Morton To: Hsin-Yi Wang Cc: Phillip Lougher , Matthew Wilcox , 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: Re: [PATCH v3 3/3] squashfs: implement readahead Message-Id: <20220531134740.91ae4dcea1e06640ba1bfc12@linux-foundation.org> In-Reply-To: <20220523065909.883444-4-hsinyi@chromium.org> References: <20220523065909.883444-1-hsinyi@chromium.org> <20220523065909.883444-4-hsinyi@chromium.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Mon, 23 May 2022 14:59:13 +0800 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. > - decompressor error. > Otherwise pages will be marked as uptodate. The unhandled pages will be > updated by readpage later. > > ... > The choice of types seems somewhat confused. > @@ -495,7 +496,95 @@ 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; block_log is unsigned short. Why size_t? > + 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; OK. > + struct page **pages; > + u64 block = 0; > + int bsize, res, i, index, bytes, expected; `res' could be local to the inner loop. `i' is used in situations where an unsigned type would be more appropriate. If it is made unsigned then `i' is no longer a suitable identifier. Doesn't matter much. `index' is from page.index, which is pgoff_t. `bytes' could be local to the innermost loop. `expected' is inappropriately a signed type and could be local to the inner loop. > + int file_end = i_size_read(inode) >> msblk->block_log; > + unsigned int max_pages = 1UL << shift; > + void *pageaddr; > + > + 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; > + > + 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; > + > + res = squashfs_read_data(inode->i_sb, block, bsize, NULL, > + actor); > + > + if (res == expected) { > + /* Last page may have trailing bytes not filled */ > + bytes = res % PAGE_SIZE; > + if (bytes) { > + pageaddr = kmap_atomic(pages[nr_pages - 1]); > + memset(pageaddr + bytes, 0, PAGE_SIZE - bytes); > + kunmap_atomic(pageaddr); > + } > + > + for (i = 0; i < nr_pages; i++) > + SetPageUptodate(pages[i]); > + } res == -EIO is unhandled? > + 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 > };