From patchwork Tue May 17 08:26:54 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: 12852111 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 B244BC433FE for ; Tue, 17 May 2022 08:28:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F9FF6B0072; Tue, 17 May 2022 04:28:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A9596B0073; Tue, 17 May 2022 04:28:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 399D16B0074; Tue, 17 May 2022 04:28:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2BC7A6B0072 for ; Tue, 17 May 2022 04:28:44 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 0D03C121423 for ; Tue, 17 May 2022 08:28:44 +0000 (UTC) X-FDA: 79474558968.13.B94FA17 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf21.hostedemail.com (Postfix) with ESMTP id 352351C00BA for ; Tue, 17 May 2022 08:28:34 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id q4so16692987plr.11 for ; Tue, 17 May 2022 01:28:43 -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=795DpeL4AVvHI+lpL0joEtH4VZitVLN+aqxdeh6jjYU=; b=ED/whdRh9rUIrpg2gVqOkUlPSLfH+d13dKN6o5qhscZGfYA1wIc36jAYuO2aCcUTME tywwpQRtrhoL7YMncd8uUcl8ldVWCDe8Tvq+4wKthS8GnM6L16HjHx69ofm21fozQ2c1 0gPwozKxl0EWsQf4v0ye2mrWDjOsxXqCxTdjA= 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=795DpeL4AVvHI+lpL0joEtH4VZitVLN+aqxdeh6jjYU=; b=ipH6+rrhWsnYEuUZ7Lta+EOBVRx2cOeK+fE0KGKEPW/MHuUm3ZpLvIjetjikUX756z y2HXM5bHqiXz+CTRuFLeSEFRTs8YvVy/cSEvljAiBpU18ZOb1pgUXwHzBbl+GE9QryjR FID6hf+QOLphZZ1v6VDMRa3CB5jG+jxtkSSTN+ejnP68tfuwoMepMbaihxdck14sYunQ fOFnWOm6KCUWlp1avzZ+dHmMAW92tK6a2zyvi5fFuGL8jLSF42v1MWk+EkpwuPw16BEf I0MLkFiBKSYbyST7BMW96SEuq3ibwR9ktldxgORlW34xT2oAN8yHmowAjf+PPZNJ4gH/ jEKA== X-Gm-Message-State: AOAM533+CyFBu4UU03J9Zt3ZGhxli6X+bAAaUYs/ti0tOvVk1HINHB9h LaihcyzL3W8A0KxUHSwsnNDCOuUm3PY/2w== X-Google-Smtp-Source: ABdhPJw4ZGZtF+d/OR1j0hvEL/B0NPDWxF9N8bLKwYKVOTs7d4kGTcfAco2jqXBr0hSexPHPCcRxIw== X-Received: by 2002:a17:90b:4a02:b0:1dc:4710:c1fe with SMTP id kk2-20020a17090b4a0200b001dc4710c1femr35223567pjb.208.1652776122745; Tue, 17 May 2022 01:28:42 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:beb2:ec58:2159:9a33]) by smtp.gmail.com with ESMTPSA id k9-20020a628409000000b0050dc76281d3sm8615083pfd.173.2022.05.17.01.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:28:42 -0700 (PDT) From: Hsin-Yi Wang To: Phillip Lougher , Matthew Wilcox , Xiongwei Song Cc: Zheng Liang , Zhang Yi , Hou Tao , Miao Xie , Andrew Morton , "linux-mm @ kvack . org" , "squashfs-devel @ lists . sourceforge . net" , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] squashfs: implement readahead Date: Tue, 17 May 2022 16:26:54 +0800 Message-Id: <20220517082650.2005840-4-hsinyi@chromium.org> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog In-Reply-To: <20220517082650.2005840-1-hsinyi@chromium.org> References: <20220517082650.2005840-1-hsinyi@chromium.org> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 352351C00BA Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="ED/whdRh"; spf=pass (imf21.hostedemail.com: domain of hsinyi@chromium.org designates 209.85.214.181 as permitted sender) smtp.mailfrom=hsinyi@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspam-User: X-Stat-Signature: 5bw4c3xzd9phyf4zcstnm9b9gmyf3468 X-HE-Tag: 1652776114-900318 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 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 --- 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 };