Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp131436iol; Fri, 10 Jun 2022 23:56:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcoQrlC3BcK697LjHr5FuBCoCSWQAzbStDZNtFhlyNQ5etm7RSruarCZD5Xeqo2c1UwwlT X-Received: by 2002:a17:90b:1bcd:b0:1e2:c8da:7c29 with SMTP id oa13-20020a17090b1bcd00b001e2c8da7c29mr3749593pjb.4.1654930564691; Fri, 10 Jun 2022 23:56:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654930564; cv=none; d=google.com; s=arc-20160816; b=B7Jdnn9gNBzybeWv9RrLRboLMsoCmLRx9r7dfPpgjPSvJzlYv9SVw1DhbO8lQuyl6Y j8LzGXWP+Vym0IEH60VSrf2izABISsw4GrscRMQrVKc2vOFOjtLHY6bA1spBG8Y2ide3 0pNi8B+ANGIFCCyII+79DxjSBM8S1IAmurW6SZmHPff0y4OOctW1vcUpV39mRM1NIaUV UA2xVtZY/zW2fzh9hWktKMp5IdEmm4skj9xkM81rbXPoM0BnJ69tammt2pruaOvoUuPx OSgIlPaffAy7owLshfXAZcHukyfUTxYHKnnnCtnc5pN0+FuCzwNZ3buK72+WrXrLOCuI kuSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=iBlplB3iWTffq+yqtPO+GO5mYtl+OM5cofSlR1oHORY=; b=lPntTgc+tws4drxiQYsgv8avAqeayfMnl7Zk7cvUJE2IWROqMXAm59LWJiAyrC3bwz GCVAPm9GK3V0KdmmwWtBOdXJNGw+wS7N2Nyb/xp1HX1rIXdGVeUyk410MnvD9qFo73Ms Vn5aJqBC+VAqJQ89FfpwdBoo1misFlaApv+XtZ/E3Bwk0Ivp0airxvhF5rkvARj24IWa AQhp2k7qXvfUT6YQiHeel/LWPmnuuXfECyBYgv5onQ0oeOgS4OGiSG8++dfR5fR51xI4 LlnWi/ywjkJTaVHou/ZNS/ctwWLOqUu3tftMHvmSRBEutswFRX5gqWGUZcyTlb0u7Y0c 8O6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 20-20020a631354000000b003f9d5d48e42si1650302pgt.99.2022.06.10.23.55.52; Fri, 10 Jun 2022 23:56:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244610AbiFKFXy (ORCPT + 99 others); Sat, 11 Jun 2022 01:23:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348597AbiFKFXu (ORCPT ); Sat, 11 Jun 2022 01:23:50 -0400 Received: from p3plwbeout16-02.prod.phx3.secureserver.net (p3plsmtp16-02-2.prod.phx3.secureserver.net [173.201.193.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31062CE19 for ; Fri, 10 Jun 2022 22:23:49 -0700 (PDT) Received: from mailex.mailcore.me ([94.136.40.141]) by :WBEOUT: with ESMTP id ztb9ne2lHJglUztbAnMfyU; Fri, 10 Jun 2022 22:23:48 -0700 X-CMAE-Analysis: v=2.4 cv=cNIlDnSN c=1 sm=1 tr=0 ts=62a426e4 a=bheWAUFm1xGnSTQFbH9Kqg==:117 a=84ok6UeoqCVsigPHarzEiQ==:17 a=ggZhUymU-5wA:10 a=IkcTkHD0fZMA:10 a=JPEYwPQDsx4A:10 a=VwQbUJbxAAAA:8 a=FXvPX3liAAAA:8 a=9JzQIcLJ2qe6kJ3kX6oA:9 a=QEXdDO2ut3YA:10 a=AjGcO6oz07-iQ99wixmX:22 a=UObqyxdv-6Yh2QiB9mM_:22 X-SECURESERVER-ACCT: phillip@squashfs.org.uk X-SID: ztb9ne2lHJglU Received: from 82-69-79-175.dsl.in-addr.zen.co.uk ([82.69.79.175] helo=[192.168.178.33]) by smtp13.mailcore.me with esmtpa (Exim 4.94.2) (envelope-from ) id 1nztb8-0001Si-QI; Sat, 11 Jun 2022 06:23:47 +0100 Message-ID: Date: Sat, 11 Jun 2022 06:23:42 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v5 3/3] squashfs: implement readahead To: Hsin-Yi Wang , Matthew Wilcox , Xiongwei Song , Marek Szyprowski , Andrew Morton Cc: Zheng Liang , Zhang Yi , Hou Tao , Miao Xie , "linux-mm @ kvack . org" , "squashfs-devel @ lists . sourceforge . net" , linux-kernel@vger.kernel.org References: <20220606150305.1883410-1-hsinyi@chromium.org> <20220606150305.1883410-4-hsinyi@chromium.org> From: Phillip Lougher In-Reply-To: <20220606150305.1883410-4-hsinyi@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailcore-Auth: 439999529 X-Mailcore-Domain: 1394945 X-123-reg-Authenticated: phillip@squashfs.org.uk X-Originating-IP: 82.69.79.175 X-CMAE-Envelope: MS4xfPHKJUs+goLUlS+bzKd7bc9a7BmLEYRAKPgBEW6ECFSaRTyFj7tAg+Dk3PENztaETHfY9BYa6YaRVsN+7zByXGHh8r2Z/sLkrOThVtB336PRDQ1CemZb RuXxyvrovgerqGyvAqGHPKqEDIHPRJ/8xt50I2RN4B2FCk/JMDgs4He78Ktx+aEbVjWq1cV92cSILpX0UQjjBn9s6z/e9LWjH5I= X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 06/06/2022 16:03, 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. > - decompressor error. > Otherwise pages will be marked as uptodate. The unhandled pages will be > updated by readpage later. > Hi Hsin-Yi, I have reviewed, tested and instrumented the following patch. There are a number of problems with the patch including performance, unhandled issues, and bugs. In this email I'll concentrate on the performance aspects. The major change between this V5 patch and the previous patches (V4 etc), is that it now handles the case where + nr_pages = __readahead_batch(ractl, pages, max_pages); returns an "nr_pages" less than "max_pages". What this means is that the readahead code has returned a set of page cache pages which does not fully map the datablock to be decompressed. If this is passed to squashfs_read_data() using the current "page actor" code, the decompression will fail on the missing pages. In recognition of that fact, your V5 patch falls back to using the earlier intermediate buffer method, with squashfs_get_datablock() returning a buffer, which is then memcopied into the page cache pages. This is currently what is also done in the existing squashfs_readpage_block() function if the entire set of pages cannot be obtained. The problem with this fallback intermediate buffer is it is slow, both due to the additional memcopies, but, more importantly because it introduces contention on a single shared buffer. I have long had the intention to fix this performance issue in squashfs_readpage_block(), but, due it being a rare issue there, the additional work has seemed to be nice but not essential. The problem is we don't want the readahead code to be using this slow method, because the scenario will probably happen much more often, and for a performance improvement patch, falling back to an old slow method isn't very useful. So I have finally done the work to make the "page actor" code handle missing pages. This I have sent out in the following patch-set updating the squashfs_readpage_block() function to use it. https://lore.kernel.org/lkml/20220611032133.5743-1-phillip@squashfs.org.uk/ You can use this updated "page actor" code to eliminate the "nr_pages < max_pages" special case in your patch. With the benefit that decompression is done directly into the page cache. I have updated your patch to use the new functionality. The diff including a bug fix I have appended to this email. Phillip diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index b86b2f9d9ae6..721d35ecfca9 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -519,10 +519,6 @@ static void squashfs_readahead(struct readahead_control *ractl) if (!pages) return; - actor = squashfs_page_actor_init_special(pages, max_pages, 0); - if (!actor) - goto out; - for (;;) { pgoff_t index; int res, bsize; @@ -548,41 +544,21 @@ static void squashfs_readahead(struct readahead_control *ractl) if (bsize == 0) goto skip_pages; - if (nr_pages < max_pages) { - struct squashfs_cache_entry *buffer; - unsigned int block_mask = max_pages - 1; - int offset = pages[0]->index - (pages[0]->index & ~block_mask); - - buffer = squashfs_get_datablock(inode->i_sb, block, - bsize); - if (buffer->error) { - squashfs_cache_put(buffer); - goto skip_pages; - } - - expected -= offset * PAGE_SIZE; - for (i = 0; i < nr_pages && expected > 0; i++, - expected -= PAGE_SIZE, offset++) { - int avail = min_t(int, expected, PAGE_SIZE); - - squashfs_fill_page(pages[i], buffer, - offset * PAGE_SIZE, avail); - unlock_page(pages[i]); - } - - squashfs_cache_put(buffer); - continue; - } + actor = squashfs_page_actor_init_special(msblk, pages, nr_pages, expected); + if (!actor) + goto out; res = squashfs_read_data(inode->i_sb, block, bsize, NULL, actor); + kfree(actor); + if (res == expected) { int bytes; - /* Last page may have trailing bytes not filled */ + /* Last page (if present) may have trailing bytes not filled */ bytes = res % PAGE_SIZE; - if (bytes) { + if (pages[nr_pages - 1]->index == file_end && bytes) { void *pageaddr; pageaddr = kmap_atomic(pages[nr_pages - 1]); @@ -602,7 +578,6 @@ static void squashfs_readahead(struct readahead_control *ractl) } } - kfree(actor); kfree(pages); return; @@ -612,7 +587,6 @@ static void squashfs_readahead(struct readahead_control *ractl) put_page(pages[i]); } - kfree(actor); out: kfree(pages); } -- 2.34.1