* [PATCH] vfs: make sure struct filename->iname is word-aligned
@ 2018-02-28 23:19 Rasmus Villemoes
2018-03-18 21:32 ` Rasmus Villemoes
0 siblings, 1 reply; 2+ messages in thread
From: Rasmus Villemoes @ 2018-02-28 23:19 UTC (permalink / raw)
To: Alexander Viro; +Cc: Rasmus Villemoes, linux-fsdevel, linux-kernel
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>
---
fs/namei.c | 2 ++
include/linux/fs.h | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/namei.c b/fs/namei.c
index 921ae32dbc80..5a66e7ca5d60 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -39,6 +39,7 @@
#include <linux/bitops.h>
#include <linux/init_task.h>
#include <linux/uaccess.h>
+#include <linux/build_bug.h>
#include "internal.h"
#include "mount.h"
@@ -130,6 +131,7 @@ getname_flags(const char __user *filename, int flags, int *empty)
struct filename *result;
char *kname;
int len;
+ BUILD_BUG_ON(offsetof(struct filename, iname) % sizeof(long) != 0);
result = audit_reusename(filename);
if (result)
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;
struct filename {
const char *name; /* pointer to actual string */
const __user char *uptr; /* original userland pointer */
- struct audit_names *aname;
int refcnt;
+ struct audit_names *aname;
const char iname[];
};
--
2.15.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] vfs: make sure struct filename->iname is word-aligned
2018-02-28 23:19 [PATCH] vfs: make sure struct filename->iname is word-aligned Rasmus Villemoes
@ 2018-03-18 21:32 ` Rasmus Villemoes
0 siblings, 0 replies; 2+ messages in thread
From: Rasmus Villemoes @ 2018-03-18 21:32 UTC (permalink / raw)
To: Rasmus Villemoes, Alexander Viro; +Cc: linux-fsdevel, linux-kernel
On 2018-03-01 00:19, Rasmus Villemoes wrote:
> 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.
polite ping...
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-18 21:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-28 23:19 [PATCH] vfs: make sure struct filename->iname is word-aligned Rasmus Villemoes
2018-03-18 21:32 ` Rasmus Villemoes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).