From patchwork Mon Jun 13 08:28:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 12879171 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 E7359C433EF for ; Mon, 13 Jun 2022 08:28:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 818958D0169; Mon, 13 Jun 2022 04:28:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A0DA6B025B; Mon, 13 Jun 2022 04:28:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61AE68D0169; Mon, 13 Jun 2022 04:28:27 -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 4C4C86B025A for ; Mon, 13 Jun 2022 04:28:27 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2CE5120E5D for ; Mon, 13 Jun 2022 08:28:27 +0000 (UTC) X-FDA: 79572535854.29.9F00D54 Received: from mail-vs1-f46.google.com (mail-vs1-f46.google.com [209.85.217.46]) by imf16.hostedemail.com (Postfix) with ESMTP id CE9F3180088 for ; Mon, 13 Jun 2022 08:28:26 +0000 (UTC) Received: by mail-vs1-f46.google.com with SMTP id x9so5155195vsg.13 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=ctZdWQFeCUeccMxB6d3a12znUPNSIjKxHoXYkyKfJ1Kb+otEOEozwWEA/Q5BEgpt4/ 4k511Ls8OE63/CXWWfkhDzpXw8dKUNyWgcNIlL+R0QVq2sxMQxIeSGFG76VtOzZKiC+x oQtOJPVJ/vAW/ONXVplvFtGAjLKuImllH/Jgm9lVEV+Ne1k6+BMUWHxk+/pZDTlMCi2r hHiuew8FyPKmsWfYpbdbbHep/PqY9hK2PAINzqUusmGj3GoEEfb9/+4VdARQi6EksYht yACUnGUspqbZ3/aW0+Z50o/4Xo8TM80UaduNsCKfBeYdhlAqrKj/oNSN/vq/Ic7JYDDM WsuA== X-Gm-Message-State: AOAM531kBbwmKB6XUWj032/O7g5Hau9Jlv5b8PowoHDiB9KKt4o8I0/V uXo8YvABz722pGn+9TT/rXcAoVKtavdbYQ== X-Google-Smtp-Source: ABdhPJygjTGKX6O7iWUY8qOD+wjhd0VACZB/J2Z7QNA2jWpF+iXgT4YvK1K2bcNxt+9/tu+2hettsA== 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655108906; a=rsa-sha256; cv=none; b=krmZ3r//HD6sB1nl+RPJJOV5ge1SeDm7IWavaP7Ay+1wDx/GZ7V06g0BzpBN1aa/HZ3KbU qYVZrq7OvQKKM+cd8aJ8KPUuL9gnL89NrlMlY80Vx0Kvsl6Ej10oXnfCaepCRjrKylKmya /Mr3pT7eLoqRyGmHozZw0C9NH6yWBKc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=iBEsynkr; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf16.hostedemail.com: domain of hsinyi@chromium.org designates 209.85.217.46 as permitted sender) smtp.mailfrom=hsinyi@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655108906; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ykDR2Uk4CbOQ3wM0PXuQC4oxDGLqvfs6LYo+jnOevDY=; b=7Vs86GwG4CELLXkQ1mCqDkVqIaK/Wh33oetRTS2NWUQviZfUz2XUbMH3ISXNVabCZASswD edpX64C9rfhuGT/ZGZQztohaBBE6xRrO0WRvNJLL77fvD/pAhddDAwiv1xL3o7a6X3Icju MUnXlh1P/geXmr4E3glDYQbZjAP4u4M= X-Stat-Signature: adx3tszxkr7o5816689zajhy8ucofwfq X-Rspam-User: X-Rspamd-Queue-Id: CE9F3180088 X-Rspamd-Server: rspam07 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=iBEsynkr; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf16.hostedemail.com: domain of hsinyi@chromium.org designates 209.85.217.46 as permitted sender) smtp.mailfrom=hsinyi@chromium.org X-HE-Tag: 1655108906-523876 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: 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 };