* [PATCH 2/3] lib: improve the performance of memcpy and memmove of the general version
@ 2010-09-01 10:36 Miao Xie
2010-09-03 11:03 ` Florian Weimer
0 siblings, 1 reply; 6+ messages in thread
From: Miao Xie @ 2010-09-01 10:36 UTC (permalink / raw)
To: Ingo Molnar, Andrew Morton, Chris Mason, Theodore Ts'o,
Andreas Dilger
Cc: Linux Kernel, Linux Btrfs, Linux Ext4
the performance of memcpy and memmove of the general version is
very inefficient, this patch improved them.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
lib/string.c | 32 ++++++++++++++------------------
1 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/lib/string.c b/lib/string.c
index f71bead..6cbf6d8 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -23,6 +23,7 @@
#include <linux/string.h>
#include <linux/ctype.h>
#include <linux/module.h>
+#include <linux/memcopy.h>
#ifndef __HAVE_ARCH_STRNICMP
/**
@@ -567,11 +568,12 @@ EXPORT_SYMBOL(memset);
*/
void *memcpy(void *dest, const void *src, size_t count)
{
- char *tmp = dest;
- const char *s = src;
+ unsigned long dstp = (unsigned long)dest;
+ unsigned long srcp = (unsigned long)src;
+
+ /* Copy from the beginning to the end */
+ mem_copy_fwd(dstp, srcp, count);
- while (count--)
- *tmp++ = *s++;
return dest;
}
EXPORT_SYMBOL(memcpy);
@@ -588,21 +590,15 @@ EXPORT_SYMBOL(memcpy);
*/
void *memmove(void *dest, const void *src, size_t count)
{
- char *tmp;
- const char *s;
-
- if (dest <= src) {
- tmp = dest;
- s = src;
- while (count--)
- *tmp++ = *s++;
+ unsigned long dstp = (unsigned long)dest;
+ unsigned long srcp = (unsigned long)src;
+
+ if (dest - src >= count) {
+ /* Copy from the beginning to the end */
+ mem_copy_fwd(dstp, srcp, count);
} else {
- tmp = dest;
- tmp += count;
- s = src;
- s += count;
- while (count--)
- *--tmp = *--s;
+ /* Copy from the end to the beginning */
+ mem_copy_bwd(dstp, srcp, count);
}
return dest;
}
--
1.7.0.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] lib: improve the performance of memcpy and memmove of the general version
@ 2010-09-02 5:46 Miao Xie
0 siblings, 0 replies; 6+ messages in thread
From: Miao Xie @ 2010-09-02 5:46 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Andrew Morton, Theodore Ts'o,
Andreas Dilger
Cc: Linux Kernel, Linux Btrfs, Linux Ext4
the performance of memcpy and memmove of the general version is
very inefficient, this patch improved them.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
lib/string.c | 32 ++++++++++++++------------------
1 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/lib/string.c b/lib/string.c
index f71bead..6cbf6d8 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -23,6 +23,7 @@
#include <linux/string.h>
#include <linux/ctype.h>
#include <linux/module.h>
+#include <linux/memcopy.h>
#ifndef __HAVE_ARCH_STRNICMP
/**
@@ -567,11 +568,12 @@ EXPORT_SYMBOL(memset);
*/
void *memcpy(void *dest, const void *src, size_t count)
{
- char *tmp = dest;
- const char *s = src;
+ unsigned long dstp = (unsigned long)dest;
+ unsigned long srcp = (unsigned long)src;
+
+ /* Copy from the beginning to the end */
+ mem_copy_fwd(dstp, srcp, count);
- while (count--)
- *tmp++ = *s++;
return dest;
}
EXPORT_SYMBOL(memcpy);
@@ -588,21 +590,15 @@ EXPORT_SYMBOL(memcpy);
*/
void *memmove(void *dest, const void *src, size_t count)
{
- char *tmp;
- const char *s;
-
- if (dest <= src) {
- tmp = dest;
- s = src;
- while (count--)
- *tmp++ = *s++;
+ unsigned long dstp = (unsigned long)dest;
+ unsigned long srcp = (unsigned long)src;
+
+ if (dest - src >= count) {
+ /* Copy from the beginning to the end */
+ mem_copy_fwd(dstp, srcp, count);
} else {
- tmp = dest;
- tmp += count;
- s = src;
- s += count;
- while (count--)
- *--tmp = *--s;
+ /* Copy from the end to the beginning */
+ mem_copy_bwd(dstp, srcp, count);
}
return dest;
}
--
1.7.0.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] lib: improve the performance of memcpy and memmove of the general version
2010-09-01 10:36 [PATCH 2/3] lib: improve the performance of memcpy and memmove of the general version Miao Xie
@ 2010-09-03 11:03 ` Florian Weimer
2010-09-03 18:16 ` Andreas Dilger
2010-09-04 12:59 ` Calvin Walton
0 siblings, 2 replies; 6+ messages in thread
From: Florian Weimer @ 2010-09-03 11:03 UTC (permalink / raw)
To: miaox
Cc: Ingo Molnar, Andrew Morton, Chris Mason, Theodore Ts'o,
Andreas Dilger, Linux Kernel, Linux Btrfs, Linux Ext4
* Miao Xie:
> EXPORT_SYMBOL(memcpy);
I think you need to change that to EXPORT_SYMBOL_GPL, because the code
is now licensed under the GPL, and not the GPL plus kernel exceptions
(whatever they are, but they undoubtly exist), unlike the original
implementation.
--
Florian Weimer <fweimer@bfk.de>
BFK edv-consulting GmbH http://www.bfk.de/
Kriegsstraße 100 tel: +49-721-96201-1
D-76133 Karlsruhe fax: +49-721-96201-99
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] lib: improve the performance of memcpy and memmove of the general version
2010-09-03 11:03 ` Florian Weimer
@ 2010-09-03 18:16 ` Andreas Dilger
2010-09-04 12:59 ` Calvin Walton
1 sibling, 0 replies; 6+ messages in thread
From: Andreas Dilger @ 2010-09-03 18:16 UTC (permalink / raw)
To: Florian Weimer
Cc: miaox, Ingo Molnar, Andrew Morton, Chris Mason, Theodore Ts'o,
Linux Kernel, Linux Btrfs, Linux Ext4
On 2010-09-03, at 05:03, Florian Weimer wrote:
> * Miao Xie:
>
>> EXPORT_SYMBOL(memcpy);
>
> I think you need to change that to EXPORT_SYMBOL_GPL, because the code
> is now licensed under the GPL, and not the GPL plus kernel exceptions
> (whatever they are, but they undoubtly exist), unlike the original
> implementation.
Ouch. That would basically make it impossible to implement a non-GPL module. Also, this should only apply to the "lib" version of the memcpy() routine, not the arch-specific ones that are written in assembly (maybe that already is true, I'm not sure).
Lustre is GPL, so it isn't fatal for us, but it definitely seems draconian, and almost a reason not to include this patch into the kernel. Also, given that the original code is LGPL (which allows linking to non-GPL code) this seems counter to the intent of the original authors.
I suspect there isn't anything so brilliant in the glibc memcpy() that it couldn't be re-implemented without copying the code. "implement memcpy with aligned machine-word-sized chunks" would be enough for anyone to reimplement it without ever having come close to the glibc code.
Cheers, Andreas
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] lib: improve the performance of memcpy and memmove of the general version
2010-09-03 11:03 ` Florian Weimer
2010-09-03 18:16 ` Andreas Dilger
@ 2010-09-04 12:59 ` Calvin Walton
2010-09-04 14:41 ` Alan Cox
1 sibling, 1 reply; 6+ messages in thread
From: Calvin Walton @ 2010-09-04 12:59 UTC (permalink / raw)
To: Florian Weimer
Cc: miaox, Ingo Molnar, Andrew Morton, Chris Mason, Theodore Ts'o,
Andreas Dilger, Linux Kernel, Linux Btrfs, Linux Ext4
On Fri, 2010-09-03 at 11:03 +0000, Florian Weimer wrote:
> * Miao Xie:
>
> > EXPORT_SYMBOL(memcpy);
>
> I think you need to change that to EXPORT_SYMBOL_GPL, because the code
> is now licensed under the GPL, and not the GPL plus kernel exceptions
> (whatever they are, but they undoubtly exist), unlike the original
> implementation.
I wouldn't think so - the intent of EXPORT_SYMBOL_GPL is to mark symbols
that make it obvious that a module was derived from the Linux kernel, as
opposed to some sort of generic driver that was just ported to a new
interface. (It's not foolproof, it's more of a warning to developers.)
If you think of it this way, memcpy is a function defined in the C
standard, there's absolutely nothing Linux-specific about using it.
Of course, IANAL; and you should probably grab some more opinions on the
matter.
--
Calvin Walton <calvin.walton@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] lib: improve the performance of memcpy and memmove of the general version
2010-09-04 12:59 ` Calvin Walton
@ 2010-09-04 14:41 ` Alan Cox
0 siblings, 0 replies; 6+ messages in thread
From: Alan Cox @ 2010-09-04 14:41 UTC (permalink / raw)
To: Calvin Walton
Cc: Florian Weimer, miaox, Ingo Molnar, Andrew Morton, Chris Mason,
Theodore Ts'o, Andreas Dilger, Linux Kernel, Linux Btrfs,
Linux Ext4
On Sat, 04 Sep 2010 08:59:02 -0400
Calvin Walton <calvin.walton@gmail.com> wrote:
> On Fri, 2010-09-03 at 11:03 +0000, Florian Weimer wrote:
> > * Miao Xie:
> >
> > > EXPORT_SYMBOL(memcpy);
> >
> > I think you need to change that to EXPORT_SYMBOL_GPL, because the code
> > is now licensed under the GPL, and not the GPL plus kernel exceptions
> > (whatever they are, but they undoubtly exist), unlike the original
> > implementation.
>
> I wouldn't think so - the intent of EXPORT_SYMBOL_GPL is to mark symbols
> that make it obvious that a module was derived from the Linux kernel, as
> opposed to some sort of generic driver that was just ported to a new
> interface. (It's not foolproof, it's more of a warning to developers.)
EXPORT_SYMBOL_GPL was meant for symbols that were clearly internal
workings. EXPORT_SYMBOL() doesn't in any way imply or excuse GPL
compliance for any derivative work.
Using the FSF memcpy seems a good technical idea, and it'll no doubt
liven up the proprietary module makers lawyers as it'll make the FSF a
party to any infringement disputes 8)
Alan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-09-04 14:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-01 10:36 [PATCH 2/3] lib: improve the performance of memcpy and memmove of the general version Miao Xie
2010-09-03 11:03 ` Florian Weimer
2010-09-03 18:16 ` Andreas Dilger
2010-09-04 12:59 ` Calvin Walton
2010-09-04 14:41 ` Alan Cox
-- strict thread matches above, loose matches on Subject: below --
2010-09-02 5:46 Miao Xie
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).