From patchwork Sun Aug 18 23:58:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Lougher X-Patchwork-Id: 13767678 Received: from sxb1plsmtpa01-06.prod.sxb1.secureserver.net (sxb1plsmtpa01-06.prod.sxb1.secureserver.net [188.121.53.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88C281A291 for ; Sun, 18 Aug 2024 23:58:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.121.53.61 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025537; cv=none; b=KR7nhaJwE7AEfSwi0PyudqYwS1+lRDBitz7FCFQ+RHPBXKcGSp1mfkeUrHrmcAtu3l7OO8FroLhNJtgM87mEPzc3ohDQ4h1WNOHaaV3jbKMZjhGyKcboPQk9ZnSYHdxsCC5WIn9ry8MUUASSxM1p/gmCwIPr8VxMnqYADrPWcRQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025537; c=relaxed/simple; bh=G73OEgJWv98tJ1N7a3jIpsciRVOfJTKmyNgrnC4lwWY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GWKkxLfdpCaJbTcfYQjmSKY3LH+4jMqTXiNVZcB+xUPjJ2NvOsZOzapk5LtSzdqHq5gw7qpYf+ugdXXmQzwAWvzzF4g+49XxkAEWnFYHLNkhLdujbyHB5mtzHmSCdWSanMvuJKxnlnkqq3a/wNn7H8+Uu4ACUnkSCgHPYxsSYOo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=squashfs.org.uk; spf=pass smtp.mailfrom=squashfs.org.uk; arc=none smtp.client-ip=188.121.53.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=squashfs.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=squashfs.org.uk Received: from phoenix.fritz.box ([82.69.79.175]) by :SMTPAUTH: with ESMTPA id fpn7sTYC0QGHUfpnKsxSIV; Sun, 18 Aug 2024 16:58:47 -0700 X-CMAE-Analysis: v=2.4 cv=LJ6tQ4W9 c=1 sm=1 tr=0 ts=66c28ab7 a=84ok6UeoqCVsigPHarzEiQ==:117 a=84ok6UeoqCVsigPHarzEiQ==:17 a=FXvPX3liAAAA:8 a=anrbtZqQEueed_iD4xoA:9 a=UObqyxdv-6Yh2QiB9mM_:22 X-SECURESERVER-ACCT: phillip@squashfs.org.uk From: Phillip Lougher To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: willy@infradead.org, lizetao1@huawei.com, Phillip Lougher Subject: [PATCH 1/4] Squashfs: Update page_actor to not use page->index Date: Mon, 19 Aug 2024 00:58:44 +0100 Message-Id: <20240818235847.170468-2-phillip@squashfs.org.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240818235847.170468-1-phillip@squashfs.org.uk> References: <20240818235847.170468-1-phillip@squashfs.org.uk> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CMAE-Envelope: MS4xfFSx/F/6C0Y7TeC/JaJpJkGg+I37+UT52v5GqI7/FTbq0zwkBaiVIG/Mo4HU28wok1h3/vD2rspnh6hAyd8rkSz9PAU1tpLlGA5MzG7WuOQCh4/yv/hD E3ljf9rAmfPBwjjm5HRgF5B1E7BhTJfnz4msf8TTjr6mrHs9ZvlzfbsldzFVMi9CRGFHkZgXgeNrD6PNHupxtD096C5h+OiYekKKDPueQIFlu96rHWzJD2Zy b8u6/26klW5FGcBzTyP553KjBXMYDTC6w2El51ntvM+BzC+Yj0MILn9I70bcrL6jOUtgpuaWgxs0e+UQ8LZMucPC+cL1cNpX1rJ2+q1DiPg0SWH4eIoW1mm5 oNz0pfbZhrCx0SaEDeUPMlbN67C8aHouB4mT3rKtJZ6Jv0eO9rQ= This commit removes an unnecessary use of page->index, and moves the other use over to folio->index. Signed-off-by: Phillip Lougher --- fs/squashfs/file.c | 2 +- fs/squashfs/file_direct.c | 3 ++- fs/squashfs/page_actor.c | 11 ++++++++--- fs/squashfs/page_actor.h | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index a8c1e7f9a609..2b6b63f4ccd1 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -589,7 +589,7 @@ static void squashfs_readahead(struct readahead_control *ractl) goto skip_pages; actor = squashfs_page_actor_init_special(msblk, pages, nr_pages, - expected); + expected, start); if (!actor) goto skip_pages; diff --git a/fs/squashfs/file_direct.c b/fs/squashfs/file_direct.c index 2a689ce71de9..0586e6ba94bf 100644 --- a/fs/squashfs/file_direct.c +++ b/fs/squashfs/file_direct.c @@ -67,7 +67,8 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize, * Create a "page actor" which will kmap and kunmap the * page cache pages appropriately within the decompressor */ - actor = squashfs_page_actor_init_special(msblk, page, pages, expected); + actor = squashfs_page_actor_init_special(msblk, page, pages, expected, + start_index << PAGE_SHIFT); if (actor == NULL) goto out; diff --git a/fs/squashfs/page_actor.c b/fs/squashfs/page_actor.c index 81af6c4ca115..2b3e807d4dea 100644 --- a/fs/squashfs/page_actor.c +++ b/fs/squashfs/page_actor.c @@ -60,6 +60,11 @@ struct squashfs_page_actor *squashfs_page_actor_init(void **buffer, } /* Implementation of page_actor for decompressing directly into page cache. */ +static loff_t page_next_index(struct squashfs_page_actor *actor) +{ + return page_folio(actor->page[actor->next_page])->index; +} + static void *handle_next_page(struct squashfs_page_actor *actor) { int max_pages = (actor->length + PAGE_SIZE - 1) >> PAGE_SHIFT; @@ -68,7 +73,7 @@ static void *handle_next_page(struct squashfs_page_actor *actor) return NULL; if ((actor->next_page == actor->pages) || - (actor->next_index != actor->page[actor->next_page]->index)) { + (actor->next_index != page_next_index(actor))) { actor->next_index++; actor->returned_pages++; actor->last_page = NULL; @@ -103,7 +108,7 @@ static void direct_finish_page(struct squashfs_page_actor *actor) } struct squashfs_page_actor *squashfs_page_actor_init_special(struct squashfs_sb_info *msblk, - struct page **page, int pages, int length) + struct page **page, int pages, int length, loff_t start_index) { struct squashfs_page_actor *actor = kmalloc(sizeof(*actor), GFP_KERNEL); @@ -125,7 +130,7 @@ struct squashfs_page_actor *squashfs_page_actor_init_special(struct squashfs_sb_ actor->pages = pages; actor->next_page = 0; actor->returned_pages = 0; - actor->next_index = page[0]->index & ~((1 << (msblk->block_log - PAGE_SHIFT)) - 1); + actor->next_index = start_index >> PAGE_SHIFT; actor->pageaddr = NULL; actor->last_page = NULL; actor->alloc_buffer = msblk->decompressor->alloc_buffer; diff --git a/fs/squashfs/page_actor.h b/fs/squashfs/page_actor.h index 97d4983559b1..c6d837f0e9ca 100644 --- a/fs/squashfs/page_actor.h +++ b/fs/squashfs/page_actor.h @@ -29,7 +29,8 @@ extern struct squashfs_page_actor *squashfs_page_actor_init(void **buffer, int pages, int length); extern struct squashfs_page_actor *squashfs_page_actor_init_special( struct squashfs_sb_info *msblk, - struct page **page, int pages, int length); + struct page **page, int pages, int length, + loff_t start_index); static inline struct page *squashfs_page_actor_free(struct squashfs_page_actor *actor) { struct page *last_page = actor->last_page; From patchwork Sun Aug 18 23:58:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Lougher X-Patchwork-Id: 13767679 Received: from sxb1plsmtpa01-06.prod.sxb1.secureserver.net (sxb1plsmtpa01-06.prod.sxb1.secureserver.net [188.121.53.63]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9547C1BC59 for ; Sun, 18 Aug 2024 23:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.121.53.63 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025538; cv=none; b=X/NQ48lFgt+H343k8DGyviMbVUKGjexPj4xxGKvpqcNBujLM5Lzj59FjjWI8TjiTN2PBId/j/HdBofr0hHm4iwWA7ODjPHX8f8adc6b/+LV88UITw5eLvWE63Cr5sm/Fy4zUJ0wMSvc7QfoU+Rgs09tIKFyCnko4fEnpwxFfLtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025538; c=relaxed/simple; bh=AZ57LPeQ04mzM+QuuWSVbk/W3te3QhYFAyBfKK3jk9I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MykPCmIJxQ5k3KJzfT8FJhFuIgbZ37KqN++oiXnz37oSXlx3TJkFJQlUfwxT1faHjEeF7sBbG+tly8ofuK3HmgDepemzY+8JK0Hm+EZRTAr0FEq9HWd84/5M5JoD5GPQQdRUcW/jFciOhzAV4JUbexwRkfvEmdhuHK/rv/hZl8M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=squashfs.org.uk; spf=pass smtp.mailfrom=squashfs.org.uk; arc=none smtp.client-ip=188.121.53.63 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=squashfs.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=squashfs.org.uk Received: from phoenix.fritz.box ([82.69.79.175]) by :SMTPAUTH: with ESMTPA id fpn7sTYC0QGHUfpnLsxSIc; Sun, 18 Aug 2024 16:58:48 -0700 X-CMAE-Analysis: v=2.4 cv=LJ6tQ4W9 c=1 sm=1 tr=0 ts=66c28ab8 a=84ok6UeoqCVsigPHarzEiQ==:117 a=84ok6UeoqCVsigPHarzEiQ==:17 a=FXvPX3liAAAA:8 a=zvuxCLvZWVJikxbZp60A:9 a=UObqyxdv-6Yh2QiB9mM_:22 X-SECURESERVER-ACCT: phillip@squashfs.org.uk From: Phillip Lougher To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: willy@infradead.org, lizetao1@huawei.com, Phillip Lougher Subject: [PATCH 2/4] Squashfs: Update squashfs_readahead() to not use page->index Date: Mon, 19 Aug 2024 00:58:45 +0100 Message-Id: <20240818235847.170468-3-phillip@squashfs.org.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240818235847.170468-1-phillip@squashfs.org.uk> References: <20240818235847.170468-1-phillip@squashfs.org.uk> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CMAE-Envelope: MS4xfFb2ovMBOh8BLMyp5LuvcpONdolk5ZxlPm3dw/0yXCFT9HYtOK8GhpUQKtPX8DJpbXCfsaSFc5Tcuf9G1s3nIil/jU5CC0PlhIhECCK5zW3bJfoaNM4Y M3Rq61j4sHsz4lnW1U0bmkKsGVBNorkUDnoG9yKnp8Ayj9gIWUCfjNnO5VgU2EhkVfURNTCSqlnsvtu/137uSsy/mCOXbzwBaWA7SH4YeIOlxtMXM5URuVbx Em8Q+akYJwoWeU0tWjAYvY3kxaDzEWmlVpXeA3n5RO9DIbM48tZ1r/6go+5oaeZHgCwZINJphtdaxghkyV6FUR/L9wPDrhF5GpqsW7flIfoEcJi/X19TtcG/ n5nIDXSX2Cq6hzKREbsLDOBtiUV2AFZfxFZjfoItUU90FoWCeUY= This commit removes references to page->index in the pages returned from __readahead_batch(), and instead uses the 'start' variable. This does reveal a bug in the previous code in that 'start' was not updated every time around the loop. This is fixed in this commit. Signed-off-by: Phillip Lougher --- fs/squashfs/file.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index 2b6b63f4ccd1..50fe5a078b83 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -551,7 +551,6 @@ static void squashfs_readahead(struct readahead_control *ractl) return; for (;;) { - pgoff_t index; int res, bsize; u64 block = 0; unsigned int expected; @@ -570,13 +569,8 @@ static void squashfs_readahead(struct readahead_control *ractl) 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; - - if (index == file_end && squashfs_i(inode)->fragment_block != - SQUASHFS_INVALID_BLK) { + if (start >> msblk->block_log == file_end && + squashfs_i(inode)->fragment_block != SQUASHFS_INVALID_BLK) { res = squashfs_readahead_fragment(pages, nr_pages, expected); if (res) @@ -584,7 +578,7 @@ static void squashfs_readahead(struct readahead_control *ractl) continue; } - bsize = read_blocklist(inode, index, &block); + bsize = read_blocklist(inode, start >> msblk->block_log, &block); if (bsize == 0) goto skip_pages; @@ -602,7 +596,7 @@ static void squashfs_readahead(struct readahead_control *ractl) /* Last page (if present) may have trailing bytes not filled */ bytes = res % PAGE_SIZE; - if (index == file_end && bytes && last_page) + if (start >> msblk->block_log == file_end && bytes && last_page) memzero_page(last_page, bytes, PAGE_SIZE - bytes); @@ -616,6 +610,8 @@ static void squashfs_readahead(struct readahead_control *ractl) unlock_page(pages[i]); put_page(pages[i]); } + + start += readahead_batch_length(ractl); } kfree(pages); From patchwork Sun Aug 18 23:58:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Lougher X-Patchwork-Id: 13767683 Received: from sxb1plsmtpa01-06.prod.sxb1.secureserver.net (sxb1plsmtpa01-06.prod.sxb1.secureserver.net [92.204.81.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E555BE46 for ; Mon, 19 Aug 2024 00:06:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=92.204.81.206 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025984; cv=none; b=Utnnvx9++bHPGHbIVc1Mlkjz/yl7KuVEX9yTkvyS3j8YwepKFw/avcCenKu5zTp8e+GjmrweaaenGWk5OZ4cxXL6w58q5brV4285KbigFZhQkl8G38sJu/VrYehzU32U3CN6t3tC+dhZY2N0hxI3sFgWMKPu2ZHzdd25bCzgy9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025984; c=relaxed/simple; bh=CLxWQbrGLeGhf8m0jbFA8flJFaDPvmVHoBNH0fNSN8I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jwObJ/QxxAzpKnrfD8q2jmIXBYPDLreNJyr163E1CqZIJCc7oTTXsdff8hwnZzaza5DjhFLXl3dQ12FIT3NvBqdstXKHCQO3NsA3idnqz+e0KURRQ8Q/5Me2PSt3W7HSJM24bZWKSMiMVgAhOO6Lcepp/f/IUuVi+PC8wNPi6g4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=squashfs.org.uk; spf=pass smtp.mailfrom=squashfs.org.uk; arc=none smtp.client-ip=92.204.81.206 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=squashfs.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=squashfs.org.uk Received: from phoenix.fritz.box ([82.69.79.175]) by :SMTPAUTH: with ESMTPA id fpn7sTYC0QGHUfpnNsxSIj; Sun, 18 Aug 2024 16:58:49 -0700 X-CMAE-Analysis: v=2.4 cv=LJ6tQ4W9 c=1 sm=1 tr=0 ts=66c28ab9 a=84ok6UeoqCVsigPHarzEiQ==:117 a=84ok6UeoqCVsigPHarzEiQ==:17 a=FXvPX3liAAAA:8 a=pK5tc-4CcGVY2xxucFwA:9 a=UObqyxdv-6Yh2QiB9mM_:22 X-SECURESERVER-ACCT: phillip@squashfs.org.uk From: Phillip Lougher To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: willy@infradead.org, lizetao1@huawei.com, Phillip Lougher Subject: [PATCH 3/4] Squashfs: Update squashfs_readpage_block() to not use page->index Date: Mon, 19 Aug 2024 00:58:46 +0100 Message-Id: <20240818235847.170468-4-phillip@squashfs.org.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240818235847.170468-1-phillip@squashfs.org.uk> References: <20240818235847.170468-1-phillip@squashfs.org.uk> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CMAE-Envelope: MS4xfC4EVImtNchewiNRgGU1EmOg2S2bEAhPfYB7xYHZx62zj16rW1wXEiGhBHJb2pZyWqgHuUiMHBnuoaKse3n4P2iplaSfLA0GibD8z3UEo6VMJ13xHzzz ZX6qikiQjekYxDy8K9wjlydyXOTI2NFtR4pBSHVOH4IkX17/CpV4gCGK0OpFxCdqKwexPg40XbH4IYz482sZ1vFm1LqUq7zxgiRQ4ClJFMu8O7bqWFnb5zLm 8tQihrRuTqnIlsu+JHWGh8003TV7ajTlm9iop1Uwi6rQBAbSNdOLhKrAyitgrrB2rsNXrIZ9hK0uxORY4hHZQNsuogHHSvRARbAmX2RkLRXc8bNuJm76nWbw pUGtse+x32VYdUY34ruG5RBzUKAK8WwNmkMBoCxGrkn74mHR8kQ= This commit replaces references to page->index to folio->index or their equivalent. Signed-off-by: Phillip Lougher --- fs/squashfs/file_direct.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/squashfs/file_direct.c b/fs/squashfs/file_direct.c index 0586e6ba94bf..646d4d421f99 100644 --- a/fs/squashfs/file_direct.c +++ b/fs/squashfs/file_direct.c @@ -23,15 +23,15 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize, int expected) { + struct folio *folio = page_folio(target_page); struct inode *inode = target_page->mapping->host; struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info; - loff_t file_end = (i_size_read(inode) - 1) >> PAGE_SHIFT; int mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1; - loff_t start_index = target_page->index & ~mask; + loff_t start_index = folio->index & ~mask; loff_t end_index = start_index | mask; int i, n, pages, bytes, res = -ENOMEM; - struct page **page; + struct page **page, *last_page; struct squashfs_page_actor *actor; void *pageaddr; @@ -46,7 +46,7 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize, /* Try to grab all the pages covered by the Squashfs block */ for (i = 0, n = start_index; n <= end_index; n++) { - page[i] = (n == target_page->index) ? target_page : + page[i] = (n == folio->index) ? target_page : grab_cache_page_nowait(target_page->mapping, n); if (page[i] == NULL) @@ -75,7 +75,7 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize, /* Decompress directly into the page cache buffers */ res = squashfs_read_data(inode->i_sb, block, bsize, NULL, actor); - squashfs_page_actor_free(actor); + last_page = squashfs_page_actor_free(actor); if (res < 0) goto mark_errored; @@ -87,8 +87,8 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize, /* Last page (if present) may have trailing bytes not filled */ bytes = res % PAGE_SIZE; - if (page[pages - 1]->index == end_index && bytes) { - pageaddr = kmap_local_page(page[pages - 1]); + if (end_index == file_end && last_page && bytes) { + pageaddr = kmap_local_page(last_page); memset(pageaddr + bytes, 0, PAGE_SIZE - bytes); kunmap_local(pageaddr); } From patchwork Sun Aug 18 23:58:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Lougher X-Patchwork-Id: 13767681 Received: from sxb1plsmtpa01-06.prod.sxb1.secureserver.net (sxb1plsmtpa01-06.prod.sxb1.secureserver.net [92.204.81.207]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FDE23BBF2 for ; Mon, 19 Aug 2024 00:01:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=92.204.81.207 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025682; cv=none; b=tJEDO/FUTtYhIfTe7N8t/XMPiy3W07ksCQRBsHxrN/SzDS2TGDwymuDquu0Xv7pUBTeAJZSmLqDmN9ONDXGOTC7WAAdw/Of9NSAPc9iFrl6uWSH1t7DbAj8ewr3iZZmXSVrU+LNRiTCnsd3Qq/Rbnmv5ITfbvRpRXMvPaFnALJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724025682; c=relaxed/simple; bh=VMbsSCwl8BRhNBMKYMjgjw4ce4B36fAYx4tZYgbpdIc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d2wI4WSv2gXmlbu9AmNH5mVV5uPsNpRtQUnfar4YOIoYhWvpdTL/9bJmaaRVAZIE4/Ez6jtViAldf7pk2PbZwVciuYi/SNbJyEqBgqKWmsc+mdVATQp8mqrspdW2D6lXYRYgBfIip0mylc63x13eIE+TXk2xOTEp4e+fWXxUsio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=squashfs.org.uk; spf=pass smtp.mailfrom=squashfs.org.uk; arc=none smtp.client-ip=92.204.81.207 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=squashfs.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=squashfs.org.uk Received: from phoenix.fritz.box ([82.69.79.175]) by :SMTPAUTH: with ESMTPA id fpn7sTYC0QGHUfpnOsxSIr; Sun, 18 Aug 2024 16:58:51 -0700 X-CMAE-Analysis: v=2.4 cv=LJ6tQ4W9 c=1 sm=1 tr=0 ts=66c28abb a=84ok6UeoqCVsigPHarzEiQ==:117 a=84ok6UeoqCVsigPHarzEiQ==:17 a=FXvPX3liAAAA:8 a=9tSg9AYEYi0W0Z4Y8GAA:9 a=UObqyxdv-6Yh2QiB9mM_:22 X-SECURESERVER-ACCT: phillip@squashfs.org.uk From: Phillip Lougher To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: willy@infradead.org, lizetao1@huawei.com, Phillip Lougher Subject: [PATCH 4/4] Squashfs: Rewrite and update squashfs_readahead_fragment() to not use page->index Date: Mon, 19 Aug 2024 00:58:47 +0100 Message-Id: <20240818235847.170468-5-phillip@squashfs.org.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240818235847.170468-1-phillip@squashfs.org.uk> References: <20240818235847.170468-1-phillip@squashfs.org.uk> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CMAE-Envelope: MS4xfJrHU6NXhXbqHmipeh76Mhj9TxdPQEZUIwgjTedAZz55OJAQAGvHE6zLaMdETM4u2qYG8Ks0sRIclrYqajWNlwKi0jTtbp1KVEaqNN4ktOtuMMYAbQIS apd4NfiShAp/E+sNRpfNDUbfwU0pNKmiTFgZG+I2Bbgu7C7EuWUQIm2tFVAFANw5I9Mrxe2gl/UoCuSUMEZ98PuEeFUvRX99T8RukU5vCvqJpPrsKEePxIyt I0GNu8edEyFbtHsr8JallWSpp46NqPhbeHNPxW9ZClcW0kVGsNlkiGchTGVI9CIhM/OmOxzA1qbvnt8nLF0lzIXCdqLQo5RKTSdervWw6xEq/jorZRbQmRzU rCZ6m90kvn18KijJpoPE1mYS0L40jbtpmGheKf4/VUp83Ac2+Ak= The previous implementation lacked error checking (e.g. the bytes returned by squashfs_fill_page() is not checked), and the use of page->index could not be removed without substantially rewriting the routine to use the page actor abstraction used elsewhere. Signed-off-by: Phillip Lougher --- fs/squashfs/file.c | 66 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index 50fe5a078b83..5a3745e52025 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -494,39 +494,73 @@ static int squashfs_read_folio(struct file *file, struct folio *folio) } static int squashfs_readahead_fragment(struct page **page, - unsigned int pages, unsigned int expected) + unsigned int pages, unsigned int expected, loff_t start) { struct inode *inode = page[0]->mapping->host; struct squashfs_cache_entry *buffer = squashfs_get_fragment(inode->i_sb, squashfs_i(inode)->fragment_block, squashfs_i(inode)->fragment_size); struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info; - unsigned int n, mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1; - int error = buffer->error; + int i, bytes, copied; + struct squashfs_page_actor *actor; + unsigned int offset; + void *addr; + struct page *last_page; - if (error) + if (buffer->error) goto out; - expected += squashfs_i(inode)->fragment_offset; + actor = squashfs_page_actor_init_special(msblk, page, pages, + expected, start); + if (!actor) + goto out; - for (n = 0; n < pages; n++) { - unsigned int base = (page[n]->index & mask) << PAGE_SHIFT; - unsigned int offset = base + squashfs_i(inode)->fragment_offset; + squashfs_actor_nobuff(actor); + addr = squashfs_first_page(actor); - if (expected > offset) { - unsigned int avail = min_t(unsigned int, expected - - offset, PAGE_SIZE); + for (copied = offset = 0; offset < expected; offset += PAGE_SIZE) { + int avail = min_t(int, expected - offset, PAGE_SIZE); - squashfs_fill_page(page[n], buffer, offset, avail); + if (!IS_ERR(addr)) { + bytes = squashfs_copy_data(addr, buffer, offset + + squashfs_i(inode)->fragment_offset, avail); + + if (bytes != avail) + goto failed; } - unlock_page(page[n]); - put_page(page[n]); + copied += avail; + addr = squashfs_next_page(actor); } + last_page = squashfs_page_actor_free(actor); + + if (copied == expected) { + /* Last page (if present) may have trailing bytes not filled */ + bytes = copied % PAGE_SIZE; + if (bytes && last_page) + memzero_page(last_page, bytes, PAGE_SIZE - bytes); + + for (i = 0; i < pages; i++) { + flush_dcache_page(page[i]); + SetPageUptodate(page[i]); + } + } + + for (i = 0; i < pages; i++) { + unlock_page(page[i]); + put_page(page[i]); + } + + squashfs_cache_put(buffer); + return 0; + +failed: + squashfs_page_actor_free(actor); + out: squashfs_cache_put(buffer); - return error; + return 1; } static void squashfs_readahead(struct readahead_control *ractl) @@ -572,7 +606,7 @@ static void squashfs_readahead(struct readahead_control *ractl) if (start >> msblk->block_log == file_end && squashfs_i(inode)->fragment_block != SQUASHFS_INVALID_BLK) { res = squashfs_readahead_fragment(pages, nr_pages, - expected); + expected, start); if (res) goto skip_pages; continue;