From a3b6740302459c24a3d406bf86442af035956c27 Mon Sep 17 00:00:00 2001 From: Qian Qian Date: Fri, 31 Mar 2023 15:00:49 +0800 Subject: [PATCH] align buffer at 64-byte boundary so that memcpy can take advantage of simd --- dokan/dokan.c | 4 ++-- sys/public.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dokan/dokan.c b/dokan/dokan.c index ee205a81..5624c01c 100644 --- a/dokan/dokan.c +++ b/dokan/dokan.c @@ -1366,8 +1366,8 @@ VOID DOKANAPI DokanMapKernelToUserCreateFileFlags( } VOID DOKANAPI DokanInit() { - // ensure 64-bit alignment - assert(FIELD_OFFSET(EVENT_INFORMATION, Buffer) % 8 == 0); + // ensure 64-byte alignment, memcpy runs much faster on 64-byte aligned buffer on moden CPU + static_assert(FIELD_OFFSET(EVENT_INFORMATION, Buffer) % 64 == 0, "alignment error"); // this is not as safe as a critical section so to some degree we rely on // the user to do the right thing diff --git a/sys/public.h b/sys/public.h index b7c74be6..1b967404 100644 --- a/sys/public.h +++ b/sys/public.h @@ -388,6 +388,7 @@ typedef struct _EVENT_INFORMATION { ULONG64 Context; ULONG BufferLength; ULONG PullEventTimeoutMs; + UCHAR Padding[24]; // ensure buffer is 64-byte aligned UCHAR Buffer[DOKAN_EVENT_INFO_MIN_BUFFER_SIZE]; } EVENT_INFORMATION, *PEVENT_INFORMATION;