diff options
author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2018-02-28 18:19:21 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2018-03-19 01:07:04 -0400 |
commit | 1c94984396dc7bc40b4f6899674eaa41f29a4f6e (patch) | |
tree | a111ee94fffcd116066eb92572e2658bd2a9d101 /include/linux/fs.h | |
parent | 304ec482f562885b178b370cd50340447585d1c0 (diff) |
vfs: make sure struct filename->iname is word-aligned
I noticed that offsetof(struct filename, iname) is actually 28 on 64
bit platforms, so we always pass an unaligned pointer to
strncpy_from_user. This is mostly a problem for those 64 bit platforms
without HAVE_EFFICIENT_UNALIGNED_ACCESS, but even on x86_64, unaligned
accesses carry a penalty.
A user-space microbenchmark doing nothing but strncpy_from_user from the
same (aligned) source string runs about 5% faster when the destination
is aligned. That number increases to 20% when the string is long
enough (~32 bytes) that we cross a cache line boundary - that's for
example the case for about half the files a "git status" in a kernel
tree ends up stat'ing.
This won't make any real-life workloads 5%, or even 1%, faster, but path
lookup is common enough that cutting even a few cycles should be
worthwhile. So ensure we always pass an aligned destination pointer to
strncpy_from_user. Instead of explicit padding, simply swap the refcnt
and aname members, as suggested by Al Viro.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'include/linux/fs.h')
-rw-r--r-- | include/linux/fs.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h index 2a815560fda0..d7b2caadb292 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -2380,8 +2380,8 @@ struct audit_names; | |||
2380 | struct filename { | 2380 | struct filename { |
2381 | const char *name; /* pointer to actual string */ | 2381 | const char *name; /* pointer to actual string */ |
2382 | const __user char *uptr; /* original userland pointer */ | 2382 | const __user char *uptr; /* original userland pointer */ |
2383 | struct audit_names *aname; | ||
2384 | int refcnt; | 2383 | int refcnt; |
2384 | struct audit_names *aname; | ||
2385 | const char iname[]; | 2385 | const char iname[]; |
2386 | }; | 2386 | }; |
2387 | 2387 | ||