2010-12-25 19:36:47

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH] befs: Don't pass huge structs by value.

Hi there,

'struct befs_disk_data_stream' is huge (~144 bytes) and it's being passed
by value in fs/befs/endian.h::cpu_to_fsrun().

It seems to me that it would be better to pass a pointer, no?
This patch changes the function to take a pointer to the large struct.

Signed-off-by: Jesper Juhl <[email protected]>
---
endian.h | 16 ++++++++--------
linuxvfs.c | 2 +-
2 files changed, 9 insertions(+), 9 deletions(-)

Compile tested only. I have no way to test this.

diff --git a/fs/befs/endian.h b/fs/befs/endian.h
index 6cb84d8..a99caa0 100644
--- a/fs/befs/endian.h
+++ b/fs/befs/endian.h
@@ -102,22 +102,22 @@ cpu_to_fsrun(const struct super_block *sb, befs_block_run n)
}

static inline befs_data_stream
-fsds_to_cpu(const struct super_block *sb, befs_disk_data_stream n)
+fsds_to_cpu(const struct super_block *sb, befs_disk_data_stream *n)
{
befs_data_stream data;
int i;

for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; ++i)
- data.direct[i] = fsrun_to_cpu(sb, n.direct[i]);
+ data.direct[i] = fsrun_to_cpu(sb, n->direct[i]);

- data.max_direct_range = fs64_to_cpu(sb, n.max_direct_range);
- data.indirect = fsrun_to_cpu(sb, n.indirect);
- data.max_indirect_range = fs64_to_cpu(sb, n.max_indirect_range);
- data.double_indirect = fsrun_to_cpu(sb, n.double_indirect);
+ data.max_direct_range = fs64_to_cpu(sb, n->max_direct_range);
+ data.indirect = fsrun_to_cpu(sb, n->indirect);
+ data.max_indirect_range = fs64_to_cpu(sb, n->max_indirect_range);
+ data.double_indirect = fsrun_to_cpu(sb, n->double_indirect);
data.max_double_indirect_range = fs64_to_cpu(sb,
- n.
+ n->
max_double_indirect_range);
- data.size = fs64_to_cpu(sb, n.size);
+ data.size = fs64_to_cpu(sb, n->size);

return data;
}
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index aa4e7c7..d5fbc09 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -384,7 +384,7 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
int num_blks;

befs_ino->i_data.ds =
- fsds_to_cpu(sb, raw_inode->data.datastream);
+ fsds_to_cpu(sb, &raw_inode->data.datastream);

num_blks = befs_count_blocks(sb, &befs_ino->i_data.ds);
inode->i_blocks =



--
Jesper Juhl <[email protected]> http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.


2010-12-26 01:26:06

by Will Dyson

[permalink] [raw]
Subject: Re: [PATCH] befs: Don't pass huge structs by value.

On Sat, Dec 25, 2010 at 2:27 PM, Jesper Juhl <[email protected]> wrote:
> Hi there,
>
> 'struct befs_disk_data_stream' is huge (~144 bytes) and it's being passed
> by value in fs/befs/endian.h::cpu_to_fsrun().
>
> It seems to me that it would be better to pass a pointer, no?
> This patch changes the function to take a pointer to the large struct.
>
> Signed-off-by: Jesper Juhl <[email protected]>

Seems very reasonable to me. Unfortunately, I have no longer have any
befs filesystems to test on either.

--
Will Dyson

2010-12-26 08:48:41

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] befs: Don't pass huge structs by value.

On Sat, Dec 25, 2010 at 20:27, Jesper Juhl <[email protected]> wrote:
> 'struct befs_disk_data_stream' is huge (~144 bytes) and it's being passed
> by value in fs/befs/endian.h::cpu_to_fsrun().
>
> It seems to me that it would be better to pass a pointer, no?
> This patch changes the function to take a pointer to the large struct.
>
> Signed-off-by: Jesper Juhl <[email protected]>
> ---
>  endian.h   |   16 ++++++++--------
>  linuxvfs.c |    2 +-
>  2 files changed, 9 insertions(+), 9 deletions(-)
>
>  Compile tested only. I have no way to test this.
>
> diff --git a/fs/befs/endian.h b/fs/befs/endian.h
> index 6cb84d8..a99caa0 100644
> --- a/fs/befs/endian.h
> +++ b/fs/befs/endian.h
> @@ -102,22 +102,22 @@ cpu_to_fsrun(const struct super_block *sb, befs_block_run n)
>  }
>
>  static inline befs_data_stream
> -fsds_to_cpu(const struct super_block *sb, befs_disk_data_stream n)
> +fsds_to_cpu(const struct super_block *sb, befs_disk_data_stream *n)

Please make befs_disk_data_stream const, so people don't accidentally modify it.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

2010-12-26 19:14:00

by Jesper Juhl

[permalink] [raw]
Subject: Re: [PATCH] befs: Don't pass huge structs by value.

On Sun, 26 Dec 2010, Geert Uytterhoeven wrote:

> On Sat, Dec 25, 2010 at 20:27, Jesper Juhl <[email protected]> wrote:
> > 'struct befs_disk_data_stream' is huge (~144 bytes) and it's being passed
> > by value in fs/befs/endian.h::cpu_to_fsrun().
> >
> > It seems to me that it would be better to pass a pointer, no?
> > This patch changes the function to take a pointer to the large struct.
> >
> > Signed-off-by: Jesper Juhl <[email protected]>
> > ---
> >  endian.h   |   16 ++++++++--------
> >  linuxvfs.c |    2 +-
> >  2 files changed, 9 insertions(+), 9 deletions(-)
> >
> >  Compile tested only. I have no way to test this.
> >
> > diff --git a/fs/befs/endian.h b/fs/befs/endian.h
> > index 6cb84d8..a99caa0 100644
> > --- a/fs/befs/endian.h
> > +++ b/fs/befs/endian.h
> > @@ -102,22 +102,22 @@ cpu_to_fsrun(const struct super_block *sb, befs_block_run n)
> >  }
> >
> >  static inline befs_data_stream
> > -fsds_to_cpu(const struct super_block *sb, befs_disk_data_stream n)
> > +fsds_to_cpu(const struct super_block *sb, befs_disk_data_stream *n)
>
> Please make befs_disk_data_stream const, so people don't accidentally modify it.
>
Certainly.

Signed-off-by: Jesper Juhl <[email protected]>
---
endian.h | 16 ++++++++--------
linuxvfs.c | 2 +-
2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/fs/befs/endian.h b/fs/befs/endian.h
index 6cb84d8..2722387 100644
--- a/fs/befs/endian.h
+++ b/fs/befs/endian.h
@@ -102,22 +102,22 @@ cpu_to_fsrun(const struct super_block *sb, befs_block_run n)
}

static inline befs_data_stream
-fsds_to_cpu(const struct super_block *sb, befs_disk_data_stream n)
+fsds_to_cpu(const struct super_block *sb, const befs_disk_data_stream *n)
{
befs_data_stream data;
int i;

for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; ++i)
- data.direct[i] = fsrun_to_cpu(sb, n.direct[i]);
+ data.direct[i] = fsrun_to_cpu(sb, n->direct[i]);

- data.max_direct_range = fs64_to_cpu(sb, n.max_direct_range);
- data.indirect = fsrun_to_cpu(sb, n.indirect);
- data.max_indirect_range = fs64_to_cpu(sb, n.max_indirect_range);
- data.double_indirect = fsrun_to_cpu(sb, n.double_indirect);
+ data.max_direct_range = fs64_to_cpu(sb, n->max_direct_range);
+ data.indirect = fsrun_to_cpu(sb, n->indirect);
+ data.max_indirect_range = fs64_to_cpu(sb, n->max_indirect_range);
+ data.double_indirect = fsrun_to_cpu(sb, n->double_indirect);
data.max_double_indirect_range = fs64_to_cpu(sb,
- n.
+ n->
max_double_indirect_range);
- data.size = fs64_to_cpu(sb, n.size);
+ data.size = fs64_to_cpu(sb, n->size);

return data;
}
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index aa4e7c7..d5fbc09 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -384,7 +384,7 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
int num_blks;

befs_ino->i_data.ds =
- fsds_to_cpu(sb, raw_inode->data.datastream);
+ fsds_to_cpu(sb, &raw_inode->data.datastream);

num_blks = befs_count_blocks(sb, &befs_ino->i_data.ds);
inode->i_blocks =


--
Jesper Juhl <[email protected]> http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.