lttng-dev.lists.lttng.org archive mirror
 help / color / mirror / Atom feed
* [PATCH lttng-ust] Use MAP_POPULATE to reduce pagefault when available
@ 2019-07-29 18:23 Jonathan Rajotte
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Rajotte @ 2019-07-29 18:23 UTC (permalink / raw)
  To: lttng-dev; +Cc: guoyiteng

Any ring buffer configuration bigger than PAGE_SIZE would result
in increase latency for the first tracepoint hit (1200ns) lending on a
new PAGE_SIZE sized chunk of the mapped memory. This happens at least
for the first ring buffer traversal.

To alleviate this we can use MAP_POPULATE that will "prefault" the page
tables.

A similar flag seems to exists on freebsd (MAP_PREFAULT_READ) but I do
not have access to a system to test it and ensure it does indeed results
in the same effect. It mostly indicate that it prefaults for the
read case so I doubt it is the case.

Default to using MAP_POPULATE on linux only for now. Support of
prefaulting on other platforms will be added as needed.

[1] https://lists.lttng.org/pipermail/lttng-dev/2019-July/029122.html

Tested-by: Yiteng Guo <guoyiteng@gmail.com> [1]
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
---
 libringbuffer/mmap.h | 30 ++++++++++++++++++++++++++++++
 libringbuffer/shm.c  |  5 +++--
 2 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 libringbuffer/mmap.h

diff --git a/libringbuffer/mmap.h b/libringbuffer/mmap.h
new file mode 100644
index 00000000..f195c152
--- /dev/null
+++ b/libringbuffer/mmap.h
@@ -0,0 +1,30 @@
+#ifndef _LTTNG_MMAP_H
+#define _LTTNG_MMAP_H
+
+/*
+ * Copyright (c) 2019 - Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <sys/mman.h>
+
+#if defined(__linux__) && defined(MAP_POPULATE)
+# define LTTNG_MAP_POPULATE MAP_POPULATE
+#else
+# define LTTNG_MAP_POPULATE 0
+#endif /* __linux__ && MAP_POPULATE */
+
+#endif /* _LTTNG_MMAP_H */
diff --git a/libringbuffer/shm.c b/libringbuffer/shm.c
index 10b3bcef..909991ed 100644
--- a/libringbuffer/shm.c
+++ b/libringbuffer/shm.c
@@ -40,6 +40,7 @@
 #endif
 #include <helper.h>
 #include <ust-fd.h>
+#include "mmap.h"
 
 /*
  * Ensure we have the required amount of space available by writing 0
@@ -154,7 +155,7 @@ struct shm_object *_shm_object_table_alloc_shm(struct shm_object_table *table,
 
 	/* memory_map: mmap */
 	memory_map = mmap(NULL, memory_map_size, PROT_READ | PROT_WRITE,
-			  MAP_SHARED, shmfd, 0);
+			  MAP_SHARED | LTTNG_MAP_POPULATE, shmfd, 0);
 	if (memory_map == MAP_FAILED) {
 		PERROR("mmap");
 		goto error_mmap;
@@ -341,7 +342,7 @@ struct shm_object *shm_object_table_append_shm(struct shm_object_table *table,
 
 	/* memory_map: mmap */
 	memory_map = mmap(NULL, memory_map_size, PROT_READ | PROT_WRITE,
-			  MAP_SHARED, shm_fd, 0);
+			  MAP_SHARED | LTTNG_MAP_POPULATE, shm_fd, 0);
 	if (memory_map == MAP_FAILED) {
 		PERROR("mmap");
 		goto error_mmap;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH lttng-ust] Use MAP_POPULATE to reduce pagefault when available
       [not found]   ` <88fc6fd6-bdc1-402b-32c6-f3b48674f931@gydle.com>
@ 2019-07-29 18:44     ` Mathieu Desnoyers
  0 siblings, 0 replies; 5+ messages in thread
From: Mathieu Desnoyers @ 2019-07-29 18:44 UTC (permalink / raw)
  To: Sebastien Boisvert; +Cc: lttng-dev, Yiteng Guo

----- On Jul 29, 2019, at 2:41 PM, Sebastien Boisvert sboisvert@gydle.com wrote:

> nits:
> 
> On 2019-07-29 2:32 p.m., Mathieu Desnoyers wrote:
>>> A similar flag seems to exists on freebsd (MAP_PREFAULT_READ) but I do
>> 
>> exists -> exit
> 
> exist ?

Indeed :)

> 
> 
>>> [1] https://lists.lttng.org/pipermail/lttng-dev/2019-July/029122.html
>>>
>>> Tested-by: Yiteng Guo <guoyiteng@gmail.com> [1]
>> 
>> I think you might want to add a # before [1] so automated tools don't
>> get confused here. But even better, just describe it has been tested
>> above in the commit message.
> 
> The "Link:" tag can be used for that.

Yes, good point!

Thanks,

Mathieu


-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH lttng-ust] Use MAP_POPULATE to reduce pagefault when available
       [not found] <20190729182356.21025-1-jonathan.rajotte-julien@efficios.com>
  2019-07-29 18:32 ` Mathieu Desnoyers
       [not found] ` <107439491.2361.1564425123412.JavaMail.zimbra@efficios.com>
@ 2019-07-29 18:41 ` Sebastien Boisvert
  2 siblings, 0 replies; 5+ messages in thread
From: Sebastien Boisvert @ 2019-07-29 18:41 UTC (permalink / raw)
  To: Jonathan Rajotte, lttng-dev; +Cc: guoyiteng


On 2019-07-29 2:23 p.m., Jonathan Rajotte wrote:
> Any ring buffer configuration bigger than PAGE_SIZE would result
> in increase latency for the first tracepoint hit (1200ns) lending on a

in an increased latency

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH lttng-ust] Use MAP_POPULATE to reduce pagefault when available
       [not found] ` <107439491.2361.1564425123412.JavaMail.zimbra@efficios.com>
@ 2019-07-29 18:41   ` Sebastien Boisvert
       [not found]   ` <88fc6fd6-bdc1-402b-32c6-f3b48674f931@gydle.com>
  1 sibling, 0 replies; 5+ messages in thread
From: Sebastien Boisvert @ 2019-07-29 18:41 UTC (permalink / raw)
  To: Mathieu Desnoyers, Jonathan Rajotte; +Cc: Yiteng Guo, lttng-dev


nits:

On 2019-07-29 2:32 p.m., Mathieu Desnoyers wrote:
>> A similar flag seems to exists on freebsd (MAP_PREFAULT_READ) but I do
> 
> exists -> exit

exist ?


>> [1] https://lists.lttng.org/pipermail/lttng-dev/2019-July/029122.html
>>
>> Tested-by: Yiteng Guo <guoyiteng@gmail.com> [1]
> 
> I think you might want to add a # before [1] so automated tools don't
> get confused here. But even better, just describe it has been tested
> above in the commit message.

The "Link:" tag can be used for that.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH lttng-ust] Use MAP_POPULATE to reduce pagefault when available
       [not found] <20190729182356.21025-1-jonathan.rajotte-julien@efficios.com>
@ 2019-07-29 18:32 ` Mathieu Desnoyers
       [not found] ` <107439491.2361.1564425123412.JavaMail.zimbra@efficios.com>
  2019-07-29 18:41 ` Sebastien Boisvert
  2 siblings, 0 replies; 5+ messages in thread
From: Mathieu Desnoyers @ 2019-07-29 18:32 UTC (permalink / raw)
  To: Jonathan Rajotte; +Cc: Yiteng Guo, lttng-dev

----- On Jul 29, 2019, at 2:23 PM, Jonathan Rajotte jonathan.rajotte-julien@efficios.com wrote:

> Any ring buffer configuration bigger than PAGE_SIZE would result
> in increase latency for the first tracepoint hit (1200ns) lending on a

landing

> new PAGE_SIZE sized chunk of the mapped memory. This happens at least
> for the first ring buffer traversal.
> 
> To alleviate this we can use MAP_POPULATE that will "prefault" the page
> tables.
> 
> A similar flag seems to exists on freebsd (MAP_PREFAULT_READ) but I do

exists -> exit

> not have access to a system to test it and ensure it does indeed results
> in the same effect. It mostly indicate that it prefaults for the

indicate -> indicates

> read case so I doubt it is the case.
> 
> Default to using MAP_POPULATE on linux only for now. Support of

linux -> Linux

> prefaulting on other platforms will be added as needed.
> 
> [1] https://lists.lttng.org/pipermail/lttng-dev/2019-July/029122.html
> 
> Tested-by: Yiteng Guo <guoyiteng@gmail.com> [1]

I think you might want to add a # before [1] so automated tools don't
get confused here. But even better, just describe it has been tested
above in the commit message.

The rest of the patch looks good, can you re-submit with the commit message
changes ?

Thanks,

Mathieu


> Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
> ---
> libringbuffer/mmap.h | 30 ++++++++++++++++++++++++++++++
> libringbuffer/shm.c  |  5 +++--
> 2 files changed, 33 insertions(+), 2 deletions(-)
> create mode 100644 libringbuffer/mmap.h
> 
> diff --git a/libringbuffer/mmap.h b/libringbuffer/mmap.h
> new file mode 100644
> index 00000000..f195c152
> --- /dev/null
> +++ b/libringbuffer/mmap.h
> @@ -0,0 +1,30 @@
> +#ifndef _LTTNG_MMAP_H
> +#define _LTTNG_MMAP_H
> +
> +/*
> + * Copyright (c) 2019 - Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; only
> + * version 2.1 of the License.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include <sys/mman.h>
> +
> +#if defined(__linux__) && defined(MAP_POPULATE)
> +# define LTTNG_MAP_POPULATE MAP_POPULATE
> +#else
> +# define LTTNG_MAP_POPULATE 0
> +#endif /* __linux__ && MAP_POPULATE */
> +
> +#endif /* _LTTNG_MMAP_H */
> diff --git a/libringbuffer/shm.c b/libringbuffer/shm.c
> index 10b3bcef..909991ed 100644
> --- a/libringbuffer/shm.c
> +++ b/libringbuffer/shm.c
> @@ -40,6 +40,7 @@
> #endif
> #include <helper.h>
> #include <ust-fd.h>
> +#include "mmap.h"
> 
> /*
>  * Ensure we have the required amount of space available by writing 0
> @@ -154,7 +155,7 @@ struct shm_object *_shm_object_table_alloc_shm(struct
> shm_object_table *table,
> 
> 	/* memory_map: mmap */
> 	memory_map = mmap(NULL, memory_map_size, PROT_READ | PROT_WRITE,
> -			  MAP_SHARED, shmfd, 0);
> +			  MAP_SHARED | LTTNG_MAP_POPULATE, shmfd, 0);
> 	if (memory_map == MAP_FAILED) {
> 		PERROR("mmap");
> 		goto error_mmap;
> @@ -341,7 +342,7 @@ struct shm_object *shm_object_table_append_shm(struct
> shm_object_table *table,
> 
> 	/* memory_map: mmap */
> 	memory_map = mmap(NULL, memory_map_size, PROT_READ | PROT_WRITE,
> -			  MAP_SHARED, shm_fd, 0);
> +			  MAP_SHARED | LTTNG_MAP_POPULATE, shm_fd, 0);
> 	if (memory_map == MAP_FAILED) {
> 		PERROR("mmap");
> 		goto error_mmap;
> --
> 2.17.1

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-07-29 18:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-29 18:23 [PATCH lttng-ust] Use MAP_POPULATE to reduce pagefault when available Jonathan Rajotte
     [not found] <20190729182356.21025-1-jonathan.rajotte-julien@efficios.com>
2019-07-29 18:32 ` Mathieu Desnoyers
     [not found] ` <107439491.2361.1564425123412.JavaMail.zimbra@efficios.com>
2019-07-29 18:41   ` Sebastien Boisvert
     [not found]   ` <88fc6fd6-bdc1-402b-32c6-f3b48674f931@gydle.com>
2019-07-29 18:44     ` Mathieu Desnoyers
2019-07-29 18:41 ` Sebastien Boisvert

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).