2019-09-06 18:49:41

by Colin King

[permalink] [raw]
Subject: [PATCH] 9p: make two arrays static const, makes object smaller

From: Colin Ian King <[email protected]>

Don't populate the arrays on the stack but instead make them
static const. Makes the object code smaller by 386 bytes.

Before:
text data bss dec hex filename
17443 2076 0 19519 4c3f fs/9p/vfs_inode_dotl.o

After:
text data bss dec hex filename
16897 2236 0 19133 4abd fs/9p/vfs_inode_dotl.o

(gcc version 9.2.1, amd64)

Signed-off-by: Colin Ian King <[email protected]>
---
fs/9p/vfs_inode_dotl.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c
index 60328b21c5fb..961d8d0fa905 100644
--- a/fs/9p/vfs_inode_dotl.c
+++ b/fs/9p/vfs_inode_dotl.c
@@ -167,7 +167,7 @@ static int v9fs_mapped_dotl_flags(int flags)
{
int i;
int rflags = 0;
- struct dotl_openflag_map dotl_oflag_map[] = {
+ static const struct dotl_openflag_map dotl_oflag_map[] = {
{ O_CREAT, P9_DOTL_CREATE },
{ O_EXCL, P9_DOTL_EXCL },
{ O_NOCTTY, P9_DOTL_NOCTTY },
@@ -512,7 +512,7 @@ static int v9fs_mapped_iattr_valid(int iattr_valid)
{
int i;
int p9_iattr_valid = 0;
- struct dotl_iattr_map dotl_iattr_map[] = {
+ static const struct dotl_iattr_map dotl_iattr_map[] = {
{ ATTR_MODE, P9_ATTR_MODE },
{ ATTR_UID, P9_ATTR_UID },
{ ATTR_GID, P9_ATTR_GID },
--
2.20.1


2019-09-06 19:06:35

by Dominique Martinet

[permalink] [raw]
Subject: Re: [PATCH] 9p: make two arrays static const, makes object smaller

Colin King wrote on Fri, Sep 06, 2019:
> From: Colin Ian King <[email protected]>
>
> Don't populate the arrays on the stack but instead make them
> static const. Makes the object code smaller by 386 bytes.
>
> Before:
> text data bss dec hex filename
> 17443 2076 0 19519 4c3f fs/9p/vfs_inode_dotl.o
>
> After:
> text data bss dec hex filename
> 16897 2236 0 19133 4abd fs/9p/vfs_inode_dotl.o
>
> (gcc version 9.2.1, amd64)
>
> Signed-off-by: Colin Ian King <[email protected]>

Fine with me, I'll pick it up for the next cycle.

There are a couple of static structs in net/9p that aren't const (but
could be); I guess the static is all that matters here?
(I'll try to go through and make the rest const when I have time
though, no harm there)

Thanks,
--
Dominique