Skip to contentSkip to conversation

perf, tools, bench: Fix memcpy benchmark for large sizes

PATCH Kirill A. Shutemov 3 participants 5 messages Jul 15, 2013 – Jul 16, 2013 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Kirill A. Shutemov

author Acked-by
#1 lore raw
Quoted 6 lines · Andi Kleen

From: Andi Kleen <[email protected]>

glibc calloc() has an optimization to not explicitely memset() very large calloc allocations that just came from mmap(), because they are known to be zero.

Quoted 8 lines

This could result in the perf memcpy benchmark reading only from the zero page, which gives unrealistic results.

Always call memset explicitly on the source area to avoid this problem.

Quoted 19 lines
---
 tools/perf/bench/mem-memcpy.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/bench/mem-memcpy.c +2 -0
index 93c83e3..690f75f 100644
@@ -117,6 +117,8 @@ static void alloc_mem(void **dst, void **src, size_t length)
 	*src = zalloc(length);
 	if (!src)
 		die("memory allocation failed - maybe length is too large?\n");
+	/* Make sure to always replace the zero pages even if MMAP_THRESH is crossed */
+	memset(src, 0, length);
 }
 
 static u64 do_memcpy_cycle(memcpy_t fn, size_t len, bool prefault)
Signature · 1 line
1.8.1.4
Signature · 1 line
 Kirill A. Shutemov
#2 lore raw

At Mon, 15 Jul 2013 11:15:32 +0300 (EEST),

Quoted 11 lines · Kirill A. Shutemov
Quoted 9 lines · Andi Kleen

From: Andi Kleen <[email protected]>

glibc calloc() has an optimization to not explicitely memset() very large calloc allocations that just came from mmap(), because they are known to be zero.

This could result in the perf memcpy benchmark reading only from the zero page, which gives unrealistic results.

Quoted 7 lines
Quoted 5 lines

Always call memset explicitly on the source area to avoid this problem.

Thanks for this fix, Andi.

Quoted 28 lines
Quoted 20 lines
---
 tools/perf/bench/mem-memcpy.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/bench/mem-memcpy.c +2 -0
index 93c83e3..690f75f 100644
@@ -117,6 +117,8 @@ static void alloc_mem(void **dst, void **src, size_t length)
 	*src = zalloc(length);
 	if (!src)
 		die("memory allocation failed - maybe length is too large?\n");
+	/* Make sure to always replace the zero pages even if MMAP_THRESH is crossed */
+	memset(src, 0, length);
 }
 
 static u64 do_memcpy_cycle(memcpy_t fn, size_t len, bool prefault)
Signature · 1 line
1.8.1.4
Signature · 6 lines
 Kirill A. Shutemov
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#3 lore raw
In reply to a message not in the archive
Quoted 23 lines · Andi Kleen

From: Andi Kleen <[email protected]>

glibc calloc() has an optimization to not explicitely memset() very large calloc allocations that just came from mmap(), because they are known to be zero.

This could result in the perf memcpy benchmark reading only from the zero page, which gives unrealistic results.

Always call memset explicitly on the source area to avoid this problem.

---
 tools/perf/bench/mem-memcpy.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/bench/mem-memcpy.c +0 -0
index 93c83e3..690f75f 100644

tools/perf/bench/mem-memcpy.c static void alloc_mem(void **dst, void **src, size_t length) · line 121

Quoted 5 lines
tools/perf/bench/mem-memcpy.c +2 -0
@@ -117,6 +117,8 @@ static void alloc_mem(void **dst, void **src, size_t length)
 	*src = zalloc(length);
 	if (!src)
 		die("memory allocation failed - maybe length is too large?\n");
+	/* Make sure to always replace the zero pages even if MMAP_THRESH is crossed */
+	memset(src, 0, length);

It should be memset(*src, 0, length) instead.

There's fix for wrong memory allocation fail check in v3.11-rc1.

Signature · 1 line
 Kirill A. Shutemov
#4 lore raw

At Tue, 16 Jul 2013 13:11:00 +0300 (EEST),

Quoted 33 lines · Kirill A. Shutemov
Quoted 23 lines · Andi Kleen

From: Andi Kleen <[email protected]>

glibc calloc() has an optimization to not explicitely memset() very large calloc allocations that just came from mmap(), because they are known to be zero.

This could result in the perf memcpy benchmark reading only from the zero page, which gives unrealistic results.

Always call memset explicitly on the source area to avoid this problem.

---
 tools/perf/bench/mem-memcpy.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/bench/mem-memcpy.c +0 -0
index 93c83e3..690f75f 100644

tools/perf/bench/mem-memcpy.c static void alloc_mem(void **dst, void **src, size_t length) · line 121

Quoted 5 lines
tools/perf/bench/mem-memcpy.c +2 -0
@@ -117,6 +117,8 @@ static void alloc_mem(void **dst, void **src, size_t length)
 	*src = zalloc(length);
 	if (!src)
 		die("memory allocation failed - maybe length is too large?\n");
+	/* Make sure to always replace the zero pages even if MMAP_THRESH is crossed */
+	memset(src, 0, length);

It should be memset(*src, 0, length) instead.

Quoted 1 line

There's fix for wrong memory allocation fail check in v3.11-rc1.

I couldn't catch it, thanks. The memset() should be fixed.

Thanks,
Hitoshi

#5 lore raw
In reply to Kirill A. Shutemov
Quoted 8 lines

Review static void alloc_mem(void **dst, void **src, size_t length) · line 121

Quoted 6 lines
(quoted diff) +2 -0
@@ -117,6 +117,8 @@ static void alloc_mem(void **dst, void **src, size_t length)
 	*src = zalloc(length);
 	if (!src)
 		die("memory allocation failed - maybe length is too large?\n");
+	/* Make sure to always replace the zero pages even if MMAP_THRESH is crossed */
+	memset(src, 0, length);

It should be memset(*src, 0, length) instead.

Thanks for catching. I wonder why it fixed the problem for me.

Quoted 1 line

There's fix for wrong memory allocation fail check in v3.11-rc1.

Doubt it matters.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only