From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] fs: ramfs: allocate once instead of twice per ramfs chunk
Date: Wed, 15 May 2024 17:24:10 +0200 [thread overview]
Message-ID: <20240515152410.3386237-1-a.fatoum@pengutronix.de> (raw)
There's no reason to maintain two allocations per chunk, so just collect
them both into the same calloc call.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
I didn't test thoroughly what performance improvement this might bring,
but it looks like a sensible thing to do.
---
fs/ramfs.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/fs/ramfs.c b/fs/ramfs.c
index 117e69b70c0c..3223beba7212 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -28,10 +28,10 @@
#define CHUNK_SIZE (4096 * 2)
struct ramfs_chunk {
- char *data;
unsigned long ofs;
int size;
struct list_head list;
+ char data[];
};
struct ramfs_inode {
@@ -98,19 +98,14 @@ static struct inode *ramfs_get_inode(struct super_block *sb, const struct inode
static struct ramfs_chunk *ramfs_get_chunk(unsigned long size)
{
- struct ramfs_chunk *data = malloc(sizeof(struct ramfs_chunk));
-
- if (!data)
- return NULL;
+ struct ramfs_chunk *data;
if (size < MIN_SIZE)
size = MIN_SIZE;
- data->data = calloc(size, 1);
- if (!data->data) {
- free(data);
+ data = calloc(struct_size(data, data, size), 1);
+ if (!data)
return NULL;
- }
data->size = size;
@@ -119,7 +114,6 @@ static struct ramfs_chunk *ramfs_get_chunk(unsigned long size)
static void ramfs_put_chunk(struct ramfs_chunk *data)
{
- free(data->data);
free(data);
}
--
2.39.2
next reply other threads:[~2024-05-15 15:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-15 15:24 Ahmad Fatoum [this message]
2024-05-16 5:56 ` Sascha Hauer
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=20240515152410.3386237-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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