From patchwork Fri Jun 17 08:38:13 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: 12885295 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 9C738C433EF for ; Fri, 17 Jun 2022 08:39:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B6836B0083; Fri, 17 Jun 2022 04:39:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 33F436B0085; Fri, 17 Jun 2022 04:39:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 192366B0087; Fri, 17 Jun 2022 04:39:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 05C146B0083 for ; Fri, 17 Jun 2022 04:39:05 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D4B03214AF for ; Fri, 17 Jun 2022 08:39:04 +0000 (UTC) X-FDA: 79587077808.26.A10559A Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf21.hostedemail.com (Postfix) with ESMTP id 7CC4C1C00A5 for ; Fri, 17 Jun 2022 08:39:04 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id r1so3311111plo.10 for ; Fri, 17 Jun 2022 01:39:04 -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=OcQHcF0Ot6zJHxJE6BCq0SLAaPt9Vdx4j9mbahe8wSE=; b=gKMzClnTDfI8SUjMNX6fH7fhxMRMio7/lnouINYXTknvlSQGrGJcKIAZtWflN/Bohq qoxPsXVblEwF/jvueaJK163tba46YMu4zx8a5mAiAXDZn+N5vtObxQ9xc8Q6AghEOMJD W5f5AraAVihtPahuek9K4ljUWRatX40WkUMuA= 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=OcQHcF0Ot6zJHxJE6BCq0SLAaPt9Vdx4j9mbahe8wSE=; b=QKLkoOX7STaio5LtT63NNwmmDCmaaou3KqGRewgSEnUisgaNJQWLMTkExaFEXH10Nq qIiWdUmOyPbc54PnmFh8Lk/m7Dn3XxIcGbTQnufsgsNrtgNbcK4pyMvDzjEqLvPqOp/4 07Zzix9/KovkbgTd2gi4xyhwqiO8AbzQlh5eKxDh4RVzQWZMBdUmFkQxkH5LcJblQV78 H+KSwPsdNr4ylR96/G9+7y4upM6OhP8hnmc1suZ1L4XjYHfnFdxkR49pvY3Uo0emSrWm qsTVrarxtTWFqFtfypAJWVeoG4SVcaOuIk8MW3HhwDIAVLQrYUElSKYKZJzWK6RUVpyC dlMQ== X-Gm-Message-State: AJIora+f+GpfF7si1AXWQGswYICkjzun6XX7xKDSr6XD9U64DNB79+Jp oqRHQr0AzKcbEt1Y1d6mmXPl9g== X-Google-Smtp-Source: AGRyM1vXrobSvy6fvBmTMguR7jdxWtClLv8yNDivQ52V+DQBP9+yRJ7i0flqk2jWsoX1tcsWCsKVUA== X-Received: by 2002:a17:902:d50e:b0:16a:13d:30ab with SMTP id b14-20020a170902d50e00b0016a013d30abmr3915658plg.31.1655455143450; Fri, 17 Jun 2022 01:39:03 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:a0dc:9427:fea8:f78a]) by smtp.gmail.com with ESMTPSA id d12-20020a62f80c000000b005185407eda5sm3154103pfh.44.2022.06.17.01.39.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 01:39:03 -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 v7 3/4] squashfs: implement readahead Date: Fri, 17 Jun 2022 16:38:13 +0800 Message-Id: <20220617083810.337573-4-hsinyi@chromium.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220617083810.337573-1-hsinyi@chromium.org> References: <20220617083810.337573-1-hsinyi@chromium.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=gKMzClnT; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf21.hostedemail.com: domain of hsinyi@chromium.org designates 209.85.214.174 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=1655455144; 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=OcQHcF0Ot6zJHxJE6BCq0SLAaPt9Vdx4j9mbahe8wSE=; b=fyklneiTiSPAOo+FZfnUksn8n6ySj0epGUm4BwuWMCLUn31Q1N1p+YpZShw6+KahAYHkfA p5HRIX4Wa63d6KVzkYEy8HV24s5frPkg7ZwMFBuNLmzYL7P1PRJsu5OrB0z1fgSBkvuv0D MUKQWek21pAO7ViUrLv9zm9DEMcBsms= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655455144; a=rsa-sha256; cv=none; b=fW/7tOLRMoMPP0FwlU/3yClrg+UjctT2CH8jYHB6+dBV7+B+3/5E9zqMKj3l4LwyceEC6M T6jcLxTTOjsZStdn8mhTL25rbB2185DDb+8yl4GRqLYW0A2e6PUGsdqjhA28CxCY0COm3E fVHsPP9zrJytaJVMDLCB2sbEryGsPo0= X-Stat-Signature: qip9e4toauf3t33skthj4okfc35tt5cb X-Rspamd-Queue-Id: 7CC4C1C00A5 X-Rspam-User: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=gKMzClnT; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf21.hostedemail.com: domain of hsinyi@chromium.org designates 209.85.214.174 as permitted sender) smtp.mailfrom=hsinyi@chromium.org X-Rspamd-Server: rspam10 X-HE-Tag: 1655455144-928291 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 --- 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 };