Skip to contentSkip to conversation

9p: make two arrays static const, makes object smaller

PATCH In review Colin King 2 participants 2 messages Sep 6, 2019

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 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)

---
 fs/9p/vfs_inode_dotl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/9p/vfs_inode_dotl.c +2 -2
index 60328b21c5fb..961d8d0fa905 100644
@@ -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 },
Signature · 1 line
2.20.1
#1 lore raw

Colin King wrote on Fri, Sep 06, 2019:

Quoted 9 lines

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

Quoted 7 lines

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

(gcc version 9.2.1, amd64)

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,

Signature · 1 line
Dominique