linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yue Hu <zbestahu@gmail.com>
To: phillip@squashfs.org.uk
Cc: linux-kernel@vger.kernel.org, huyue2@yulong.com, zhangwen@yulong.com
Subject: [PATCH v2] squashfs: avoid to allocate page actor when to read into the page cache
Date: Wed, 17 Jul 2019 20:06:44 +0800	[thread overview]
Message-ID: <20190717120644.11128-1-zbestahu@gmail.com> (raw)

From: Yue Hu <huyue2@yulong.com>

Currently, we will allocate page actor in squashfs_readpage_block() via
kmalloc() if enable SQUASHFS_FILE_DIRECT option. However, the actor size
is small and it will be freed finally in this function. So, use stack
memory will be better for that case to avoid out of memory.

Signed-off-by: Yue Hu <huyue2@yulong.com>
---
v2: fix commit message

 fs/squashfs/file_direct.c | 10 +++-------
 fs/squashfs/page_actor.c  | 10 ++--------
 fs/squashfs/page_actor.h  |  4 ++--
 3 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/fs/squashfs/file_direct.c b/fs/squashfs/file_direct.c
index a4894cc..98c2dd1 100644
--- a/fs/squashfs/file_direct.c
+++ b/fs/squashfs/file_direct.c
@@ -35,7 +35,7 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,
 	int end_index = start_index | mask;
 	int i, n, pages, missing_pages, bytes, res = -ENOMEM;
 	struct page **page;
-	struct squashfs_page_actor *actor;
+	struct squashfs_page_actor actor;
 	void *pageaddr;
 
 	if (end_index > file_end)
@@ -51,9 +51,7 @@ 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(page, pages, 0);
-	if (actor == NULL)
-		goto out;
+	squashfs_page_actor_init_special(&actor, page, pages, 0);
 
 	/* Try to grab all the pages covered by the Squashfs block */
 	for (missing_pages = 0, i = 0, n = start_index; i < pages; i++, n++) {
@@ -90,7 +88,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);
+	res = squashfs_read_data(inode->i_sb, block, bsize, NULL, &actor);
 	if (res < 0)
 		goto mark_errored;
 
@@ -116,7 +114,6 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,
 			put_page(page[i]);
 	}
 
-	kfree(actor);
 	kfree(page);
 
 	return 0;
@@ -135,7 +132,6 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,
 	}
 
 out:
-	kfree(actor);
 	kfree(page);
 	return res;
 }
diff --git a/fs/squashfs/page_actor.c b/fs/squashfs/page_actor.c
index 520d323..0344806 100644
--- a/fs/squashfs/page_actor.c
+++ b/fs/squashfs/page_actor.c
@@ -78,14 +78,9 @@ static void direct_finish_page(struct squashfs_page_actor *actor)
 		kunmap_atomic(actor->pageaddr);
 }
 
-struct squashfs_page_actor *squashfs_page_actor_init_special(struct page **page,
-	int pages, int length)
+void squashfs_page_actor_init_special(struct squashfs_page_actor *actor,
+	struct page **page, int pages, int length)
 {
-	struct squashfs_page_actor *actor = kmalloc(sizeof(*actor), GFP_KERNEL);
-
-	if (actor == NULL)
-		return NULL;
-
 	actor->length = length ? : pages * PAGE_SIZE;
 	actor->page = page;
 	actor->pages = pages;
@@ -94,5 +89,4 @@ struct squashfs_page_actor *squashfs_page_actor_init_special(struct page **page,
 	actor->squashfs_first_page = direct_first_page;
 	actor->squashfs_next_page = direct_next_page;
 	actor->squashfs_finish_page = direct_finish_page;
-	return actor;
 }
diff --git a/fs/squashfs/page_actor.h b/fs/squashfs/page_actor.h
index 2e3073a..ab9d381 100644
--- a/fs/squashfs/page_actor.h
+++ b/fs/squashfs/page_actor.h
@@ -61,8 +61,8 @@ struct squashfs_page_actor {
 };
 
 extern struct squashfs_page_actor *squashfs_page_actor_init(void **, int, int);
-extern struct squashfs_page_actor *squashfs_page_actor_init_special(struct page
-							 **, int, int);
+extern void squashfs_page_actor_init_special(struct squashfs_page_actor *actor,
+				struct page **page, int pages, int length);
 static inline void *squashfs_first_page(struct squashfs_page_actor *actor)
 {
 	return actor->squashfs_first_page(actor);
-- 
1.9.1


                 reply	other threads:[~2019-07-17 12:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190717120644.11128-1-zbestahu@gmail.com \
    --to=zbestahu@gmail.com \
    --cc=huyue2@yulong.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillip@squashfs.org.uk \
    --cc=zhangwen@yulong.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).