Skip to contentSkip to conversation

xen/arm32: Get rid of __memzero()

PATCH In review Julien Grall 3 participants 4 messages Nov 27, 2024 – Dec 2, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm32: Get rid of __memzero()

From: Julien Grall <[email protected]>

All the code in arch/arm32/lib/ where copied from Linux 3.16 and never re-synced since then.

A few years ago, Linux got rid of __memzero() because the implementation is very similar to memset(p,0,n) and the current use of __memzero() interferes with optimization. See full commit message from Linux below.

So it makes sense to get rid of __memzero in Xen as well.

From ff5fdafc9e9702846480e0cea55ba861f72140a2 Mon Sep 17 00:00:00 2001
From: Nicolas Pitre <[email protected]>
Date: Fri, 19 Jan 2018 18:17:46 +0100
Subject: [PATCH] ARM: 8745/1: get rid of __memzero()

The __memzero assembly code is almost identical to memset's except for two orr instructions. The runtime performance of __memset(p, n) and memset(p, 0, n) is accordingly almost identical.

However, the memset() macro used to guard against a zero length and to call __memzero at compile time when the fill value is a constant zero interferes with compiler optimizations.

Arnd found tha the test against a zero length brings up some new warnings with gcc v8:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82103

And successively rremoving the test against a zero length and the call to __memzero optimization produces the following kernel sizes for defconfig with gcc 6:

text data bss dec hex filename
12248142 6278960 413588 18940690 1210312 vmlinux.orig
12244474 6278960 413588 18937022 120f4be vmlinux.no_zero_test
12239160 6278960 413588 18931708 120dffc vmlinux.no_memzero

So it is probably not worth keeping __memzero around given that the compiler can do a better job at inlining trivial memset(p,0,n) on its own. And the memset code already handles a zero length just fine.

Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ff5fdafc9e97

---
 xen/arch/arm/README.LinuxPrimitives |   3 +-
 xen/arch/arm/arm32/lib/Makefile     |   2 +-
 xen/arch/arm/arm32/lib/memzero.S    | 124 ----------------------------
 xen/arch/arm/include/asm/string.h   |  18 ----
 4 files changed, 2 insertions(+), 145 deletions(-)
 delete mode 100644 xen/arch/arm/arm32/lib/memzero.S
xen/arch/arm/README.LinuxPrimitives +1 -2
index 301c0271bbe4..107a01aab743 100644
@@ -108,10 +108,9 @@ linux/arch/arm/lib/memchr.S             xen/arch/arm/arm32/lib/memchr.S
 linux/arch/arm/lib/memcpy.S             xen/arch/arm/arm32/lib/memcpy.S
 linux/arch/arm/lib/memmove.S            xen/arch/arm/arm32/lib/memmove.S
 linux/arch/arm/lib/memset.S             xen/arch/arm/arm32/lib/memset.S
-linux/arch/arm/lib/memzero.S            xen/arch/arm/arm32/lib/memzero.S
 
 for i in copy_template.S memchr.S memcpy.S memmove.S memset.S \
-         memzero.S ; do
+        ; do
     diff -u linux/arch/arm/lib/$i xen/arch/arm/arm32/lib/$i
 done
 
xen/arch/arm/arm32/lib/Makefile +1 -1
index b1457c89dc66..18326b284e3b 100644
@@ -1,4 +1,4 @@
-obj-y += memcpy.o memmove.o memset.o memchr.o memzero.o
+obj-y += memcpy.o memmove.o memset.o memchr.o
 obj-y += findbit.o
 obj-y += bitops.o
 obj-y += strchr.o strrchr.o
xen/arch/arm/arm32/lib/memzero.S deleted +0 -124

124 lines not on this page · raw message

xen/arch/arm/include/asm/string.h +0 -18
index b485e4904419..7cbc8ecc7600 100644
@@ -24,24 +24,6 @@
 #define __HAVE_ARCH_MEMSET
 #define __HAVE_ARCH_MEMCHR
 
-#if defined(CONFIG_ARM_32)
-
-void __memzero(void *ptr, size_t n);
-
-#define memset(p, v, n)                                                 \
-        ({                                                              \
-                void *__p = (p); size_t __n = n;                        \
-                if ((__n) != 0) {                                       \
-                        if (__builtin_constant_p((v)) && (v) == 0)      \
-                                __memzero((__p),(__n));                 \
-                        else                                            \
-                                memset((__p),(v),(__n));                \
-                }                                                       \
-                (__p);                                                  \
-        })
-
-#endif
-
 #endif /* __ARM_STRING_H__ */
 /*
  * Local variables:
Signature · 1 line
2.40.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 42 lines · Julien Grall

From: Julien Grall <[email protected]>

All the code in arch/arm32/lib/ where copied from Linux 3.16 and never re-synced since then.

A few years ago, Linux got rid of __memzero() because the implementation is very similar to memset(p,0,n) and the current use of __memzero() interferes with optimization. See full commit message from Linux below.

So it makes sense to get rid of __memzero in Xen as well.

From ff5fdafc9e9702846480e0cea55ba861f72140a2 Mon Sep 17 00:00:00 2001
From: Nicolas Pitre <[email protected]>
Date: Fri, 19 Jan 2018 18:17:46 +0100
Subject: [PATCH] ARM: 8745/1: get rid of __memzero()

The __memzero assembly code is almost identical to memset's except for two orr instructions. The runtime performance of __memset(p, n) and memset(p, 0, n) is accordingly almost identical.

However, the memset() macro used to guard against a zero length and to call __memzero at compile time when the fill value is a constant zero interferes with compiler optimizations.

Arnd found tha the test against a zero length brings up some new warnings with gcc v8:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82103

And successively rremoving the test against a zero length and the call to __memzero optimization produces the following kernel sizes for defconfig with gcc 6:

text data bss dec hex filename
12248142 6278960 413588 18940690 1210312 vmlinux.orig
12244474 6278960 413588 18937022 120f4be vmlinux.no_zero_test
12239160 6278960 413588 18931708 120dffc vmlinux.no_memzero

So it is probably not worth keeping __memzero around given that the compiler can do a better job at inlining trivial memset(p,0,n) on its own. And the memset code already handles a zero length just fine.

Quoted 8 lines

Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ff5fdafc9e97

with a suggestion:

xen/arch/arm/README.LinuxPrimitives linux/arch/arm/lib/memchr.S xen/arch/arm/arm32/lib/memchr.S · line 115

Quoted 13 lines
xen/arch/arm/README.LinuxPrimitives +1 -2
@@ -108,10 +108,9 @@ linux/arch/arm/lib/memchr.S             xen/arch/arm/arm32/lib/memchr.S
 linux/arch/arm/lib/memcpy.S             xen/arch/arm/arm32/lib/memcpy.S
 linux/arch/arm/lib/memmove.S            xen/arch/arm/arm32/lib/memmove.S
 linux/arch/arm/lib/memset.S             xen/arch/arm/arm32/lib/memset.S
-linux/arch/arm/lib/memzero.S            xen/arch/arm/arm32/lib/memzero.S
 
 for i in copy_template.S memchr.S memcpy.S memmove.S memset.S \
-         memzero.S ; do
+        ; do
     diff -u linux/arch/arm/lib/$i xen/arch/arm/arm32/lib/$i
 done

Also do away with the line continuation at the same time? E.g.

for i in copy_template.S memchr.S memcpy.S memmove.S memset.S; do

    diff -u linux/arch/arm/lib/$i xen/arch/arm/arm32/lib/$i

done

or

for i in copy_template.S memchr.S memcpy.S memmove.S memset.S do

    diff -u linux/arch/arm/lib/$i xen/arch/arm/arm32/lib/$i

done

?

Jan

#2 lore raw

Hi Jan,

Quoted 49 lines · Jan Beulich
Quoted 48 lines · Julien Grall

From: Julien Grall <[email protected]>

All the code in arch/arm32/lib/ where copied from Linux 3.16 and never re-synced since then.

A few years ago, Linux got rid of __memzero() because the implementation is very similar to memset(p,0,n) and the current use of __memzero() interferes with optimization. See full commit message from Linux below.

So it makes sense to get rid of __memzero in Xen as well.

From ff5fdafc9e9702846480e0cea55ba861f72140a2 Mon Sep 17 00:00:00 2001
From: Nicolas Pitre <[email protected]>
Date: Fri, 19 Jan 2018 18:17:46 +0100
Subject: [PATCH] ARM: 8745/1: get rid of __memzero()

The __memzero assembly code is almost identical to memset's except for two orr instructions. The runtime performance of __memset(p, n) and memset(p, 0, n) is accordingly almost identical.

However, the memset() macro used to guard against a zero length and to call __memzero at compile time when the fill value is a constant zero interferes with compiler optimizations.

Arnd found tha the test against a zero length brings up some new warnings with gcc v8:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82103

And successively rremoving the test against a zero length and the call to __memzero optimization produces the following kernel sizes for defconfig with gcc 6:

text data bss dec hex filename
12248142 6278960 413588 18940690 1210312 vmlinux.orig
12244474 6278960 413588 18937022 120f4be vmlinux.no_zero_test
12239160 6278960 413588 18931708 120dffc vmlinux.no_memzero

So it is probably not worth keeping __memzero around given that the compiler can do a better job at inlining trivial memset(p,0,n) on its own. And the memset code already handles a zero length just fine.

Quoted 4 lines
Quoted 2 lines

Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ff5fdafc9e97

Thanks!

Quoted 18 lines

with a suggestion:

xen/arch/arm/README.LinuxPrimitives linux/arch/arm/lib/memchr.S xen/arch/arm/arm32/lib/memchr.S · line 115

Quoted 13 lines
xen/arch/arm/README.LinuxPrimitives +1 -2
@@ -108,10 +108,9 @@ linux/arch/arm/lib/memchr.S             xen/arch/arm/arm32/lib/memchr.S
  linux/arch/arm/lib/memcpy.S             xen/arch/arm/arm32/lib/memcpy.S
  linux/arch/arm/lib/memmove.S            xen/arch/arm/arm32/lib/memmove.S
  linux/arch/arm/lib/memset.S             xen/arch/arm/arm32/lib/memset.S
-linux/arch/arm/lib/memzero.S            xen/arch/arm/arm32/lib/memzero.S
 
  for i in copy_template.S memchr.S memcpy.S memmove.S memset.S \
-         memzero.S ; do
+        ; do
      diff -u linux/arch/arm/lib/$i xen/arch/arm/arm32/lib/$i
  done

Also do away with the line continuation at the same time? E.g.

Quoted 3 lines

for i in copy_template.S memchr.S memcpy.S memmove.S memset.S; do

     diff -u linux/arch/arm/lib/$i xen/arch/arm/arm32/lib/$i

done

I will go with this version because I don't expect the number of files to increase.

Cheers,

Signature · 1 line
Julien Grall
Acked-by on v1 1/1
#3 lore raw
In reply to Julien Grall
Quoted 44 lines · Julien Grall

From: Julien Grall <[email protected]>

All the code in arch/arm32/lib/ where copied from Linux 3.16 and never re-synced since then.

A few years ago, Linux got rid of __memzero() because the implementation is very similar to memset(p,0,n) and the current use of __memzero() interferes with optimization. See full commit message from Linux below.

So it makes sense to get rid of __memzero in Xen as well.

From ff5fdafc9e9702846480e0cea55ba861f72140a2 Mon Sep 17 00:00:00 2001
From: Nicolas Pitre <[email protected]>
Date: Fri, 19 Jan 2018 18:17:46 +0100
Subject: [PATCH] ARM: 8745/1: get rid of __memzero()

The __memzero assembly code is almost identical to memset's except for two orr instructions. The runtime performance of __memset(p, n) and memset(p, 0, n) is accordingly almost identical.

However, the memset() macro used to guard against a zero length and to call __memzero at compile time when the fill value is a constant zero interferes with compiler optimizations.

Arnd found tha the test against a zero length brings up some new warnings with gcc v8:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82103

And successively rremoving the test against a zero length and the call to __memzero optimization produces the following kernel sizes for defconfig with gcc 6:

text data bss dec hex filename
12248142 6278960 413588 18940690 1210312 vmlinux.orig
12244474 6278960 413588 18937022 120f4be vmlinux.no_zero_test
12239160 6278960 413588 18931708 120dffc vmlinux.no_memzero

So it is probably not worth keeping __memzero around given that the compiler can do a better job at inlining trivial memset(p,0,n) on its own. And the memset code already handles a zero length just fine.

Quoted 8 lines

Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ff5fdafc9e97

In case you need Arm's ack apart from Jan's Rb:

~Michal