From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19EA1C433EF for ; Tue, 31 May 2022 20:47:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 67F346B0071; Tue, 31 May 2022 16:47:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 629F26B0073; Tue, 31 May 2022 16:47:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F3226B0074; Tue, 31 May 2022 16:47:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3C6496B0071 for ; Tue, 31 May 2022 16:47:44 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E860A205E3 for ; Tue, 31 May 2022 20:47:43 +0000 (UTC) X-FDA: 79527224406.24.BE60CA4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 28CD040053 for ; Tue, 31 May 2022 20:47:34 +0000 (UTC) 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 247A361301; 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-Stat-Signature: scey5jap19omdz5jr3fhdhtdfynz7txz X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=XT2pd6nB; dmarc=none; spf=pass (imf11.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 28CD040053 X-HE-Tag: 1654030054-625288 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 > };