public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] tunables for glibc
@ 2016-07-02 17:13 Siddhesh Poyarekar
  2016-07-02 17:13 ` [PATCH 2/2] Initialize tunable list with the GLIBC_TUNABLES environment variable Siddhesh Poyarekar
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Siddhesh Poyarekar @ 2016-07-02 17:13 UTC (permalink / raw)
  To: libc-alpha

Hi,

Here's another stab at the tunables patchset.  This patch now gets tunables
working with static binaries as well.

The tunables framework aims to provide a simple and consistent interface for
the library to expose tuning switches in a much more coherent manner to
userspace.  In its initial form, the framework will allow users to tweak
certain parts of the library using an environment variable (or set of
environment variables, depending on where the consensus sends us).  In future,
this could be extended to per-user or even systemwide tuning switches.

The first patch implements a bare framework that moves the environment
variables in the malloc module to the tunables framework without adding any new
user-visible functionality.  The environment variables that were implemented
earlier should work as is.

The second patch adds support for a GLIBC_TUNABLES environment variable, which
users can use to set up tunables instead of using the old environment
variables.  The alternative approach to this is to expose namespace-consistent
environment variables for each tunable for userspace to take advantage of
instead of the earlier environment variables.

Siddhesh Poyarekar (2):
  Add framework for tunables
  Initialize tunable list with the GLIBC_TUNABLES environment variable

 INSTALL                           |   6 +
 Makeconfig                        |  16 +++
 README.tunables                   |  74 ++++++++++++
 config.h.in                       |   3 +
 config.make.in                    |   1 +
 configure                         |  16 +++
 configure.ac                      |  10 ++
 csu/init-first.c                  |   7 ++
 elf/Makefile                      |   5 +
 elf/Versions                      |   3 +
 elf/dl-tunable-types.h            |  45 +++++++
 elf/dl-tunables.c                 | 241 ++++++++++++++++++++++++++++++++++++++
 elf/dl-tunables.h                 |  76 ++++++++++++
 elf/dl-tunables.list              |  50 ++++++++
 elf/rtld.c                        |   8 ++
 malloc/Makefile                   |   3 +
 malloc/arena.c                    |  35 ++++++
 malloc/tst-malloc-usable-static.c |   1 +
 manual/install.texi               |   5 +
 scripts/gen-tunables.awk          | 157 +++++++++++++++++++++++++
 20 files changed, 762 insertions(+)
 create mode 100644 README.tunables
 create mode 100644 elf/dl-tunable-types.h
 create mode 100644 elf/dl-tunables.c
 create mode 100644 elf/dl-tunables.h
 create mode 100644 elf/dl-tunables.list
 create mode 100644 malloc/tst-malloc-usable-static.c
 create mode 100644 scripts/gen-tunables.awk

-- 
2.5.5

^ permalink raw reply	[flat|nested] 29+ messages in thread
* [PATCHv4 0/2] tunables for glibc
@ 2016-08-15 20:05 Siddhesh Poyarekar
  2016-08-15 20:05 ` [PATCH 2/2] Initialize tunable list with the GLIBC_TUNABLES environment variable Siddhesh Poyarekar
  0 siblings, 1 reply; 29+ messages in thread
From: Siddhesh Poyarekar @ 2016-08-15 20:05 UTC (permalink / raw)
  To: libc-alpha; +Cc: carlos, fweimer

Hi,

After another episode of disappearance, here is an updated iteration of the
tunables patch with suggestions from Florian, Carlos and H. J. incorporated.
Changes since the last version:

 - Fixed mallopt behaviour using a set of intermediate functions that the
   callback and __libc_mallopt use.  I did not make them into direct callbacks
   because the callbacks are built only when tunables is enabled.

 - Loads of comment and documentation fixes based on Carlos' and Florian's
   suggestions

 - Call __init_tunables even earlier to ensure that tunables are initialized
   before get_cpu_features is called.

Siddhesh Poyarekar (2):
  Add framework for tunables
  Initialize tunable list with the GLIBC_TUNABLES environment variable

 INSTALL                                    |   5 +
 Makeconfig                                 |  16 ++
 README.tunables                            |  84 +++++++++
 config.h.in                                |   3 +
 config.make.in                             |   1 +
 configure                                  |  16 ++
 configure.ac                               |  10 +
 csu/init-first.c                           |   7 +
 elf/Makefile                               |   5 +
 elf/Versions                               |   3 +
 elf/dl-sysdep.c                            |   8 +
 elf/dl-tunable-types.h                     |  46 +++++
 elf/dl-tunables.c                          | 284 +++++++++++++++++++++++++++++
 elf/dl-tunables.h                          |  78 ++++++++
 elf/dl-tunables.list                       |  69 +++++++
 malloc/Makefile                            |   7 +-
 malloc/arena.c                             |  54 ++++++
 malloc/malloc.c                            | 126 +++++++++----
 malloc/tst-malloc-usable-static-tunables.c |   1 +
 malloc/tst-malloc-usable-static.c          |   1 +
 malloc/tst-malloc-usable-tunables.c        |   1 +
 manual/install.texi                        |   5 +
 scripts/gen-tunables.awk                   | 157 ++++++++++++++++
 sysdeps/mach/hurd/dl-sysdep.c              |   8 +
 sysdeps/mach/hurd/i386/init-first.c        |   8 +
 25 files changed, 968 insertions(+), 35 deletions(-)
 create mode 100644 README.tunables
 create mode 100644 elf/dl-tunable-types.h
 create mode 100644 elf/dl-tunables.c
 create mode 100644 elf/dl-tunables.h
 create mode 100644 elf/dl-tunables.list
 create mode 100644 malloc/tst-malloc-usable-static-tunables.c
 create mode 100644 malloc/tst-malloc-usable-static.c
 create mode 100644 malloc/tst-malloc-usable-tunables.c
 create mode 100644 scripts/gen-tunables.awk

-- 
2.7.4

^ permalink raw reply	[flat|nested] 29+ messages in thread
* [PATCHv3 0/2] tunables for glibc
@ 2016-07-09 18:49 Siddhesh Poyarekar
  2016-07-09 18:49 ` [PATCH 2/2] Initialize tunable list with the GLIBC_TUNABLES environment variable Siddhesh Poyarekar
  0 siblings, 1 reply; 29+ messages in thread
From: Siddhesh Poyarekar @ 2016-07-09 18:49 UTC (permalink / raw)
  To: libc-alpha

Hi,

Here is another iteration of the tunables patch with some more recommendations
from H. J. Lu incorporated.  I have also added the TUNABLE_TYPE_STRING type to
allow adding of string types easily.  Major changes from the previous version
are:

 - New type TUNABLE_TYPE_STRING
 - Callback now accepts a pointer which will be used to pass the
   tunable value
 - Eliminate the strdup call completely since it won't work for static
   binaries.

Siddhesh Poyarekar (2):
  Add framework for tunables
  Initialize tunable list with the GLIBC_TUNABLES environment variable

 INSTALL                                    |   6 +
 Makeconfig                                 |  16 ++
 README.tunables                            |  74 ++++++++
 config.h.in                                |   3 +
 config.make.in                             |   1 +
 configure                                  |  16 ++
 configure.ac                               |  10 ++
 csu/init-first.c                           |   7 +
 elf/Makefile                               |   5 +
 elf/Versions                               |   3 +
 elf/dl-tunable-types.h                     |  46 +++++
 elf/dl-tunables.c                          | 275 +++++++++++++++++++++++++++++
 elf/dl-tunables.h                          |  76 ++++++++
 elf/dl-tunables.list                       |  50 ++++++
 elf/rtld.c                                 |   8 +
 malloc/Makefile                            |   7 +-
 malloc/arena.c                             |  35 ++++
 malloc/tst-malloc-usable-static-tunables.c |   1 +
 malloc/tst-malloc-usable-static.c          |   1 +
 malloc/tst-malloc-usable-tunables.c        |   1 +
 manual/install.texi                        |   5 +
 scripts/gen-tunables.awk                   | 157 ++++++++++++++++
 22 files changed, 802 insertions(+), 1 deletion(-)
 create mode 100644 README.tunables
 create mode 100644 elf/dl-tunable-types.h
 create mode 100644 elf/dl-tunables.c
 create mode 100644 elf/dl-tunables.h
 create mode 100644 elf/dl-tunables.list
 create mode 100644 malloc/tst-malloc-usable-static-tunables.c
 create mode 100644 malloc/tst-malloc-usable-static.c
 create mode 100644 malloc/tst-malloc-usable-tunables.c
 create mode 100644 scripts/gen-tunables.awk

-- 
2.5.5

^ permalink raw reply	[flat|nested] 29+ messages in thread
* [PATCH 0/2] Tunables for glibc
@ 2016-07-01 18:31 Siddhesh Poyarekar
  2016-07-01 18:31 ` [PATCH 2/2] Initialize tunable list with the GLIBC_TUNABLES environment variable Siddhesh Poyarekar
  0 siblings, 1 reply; 29+ messages in thread
From: Siddhesh Poyarekar @ 2016-07-01 18:31 UTC (permalink / raw)
  To: libc-alpha

Hi,

Here's another swipe at the tunables.  As usual, I'll start with an apology for
the very slow turnaround time and especially my tendency to come to this around
freeze time.

This version takes a completely different approach for a couple of reasons and
ends up making the tunables interface simpler to use.  Firstly, the tunables
are now much richer as Florian requested.  A tunable now has a data type
associated with it, with the ability to attach attributes like type, minimum
and maximum values to it as well as calling a callback function.  Additionally,
I got rid of the compatibility interface and included that in the tunable
structure since that is much easier to deal with.

Finally, I've moved the tunables out of the tunables directory and into elf/.
This is because I had overlooked the fact that if we had to control ifuncs
using tunables, they would have to be initialized much earlier.  They are now
initialized along with the LD_* environment variables.  In fact, it might not
be a bad idea to move the LD_* variables under the tunables mechanism as well.

Like last time, the first patch adds a framework for tunables, moving the old
environment variables into the tunables infrastructure and reads them all in
early.  The module (malloc is the example in this case) only has to get the
initialized value (if it has been initialized that is) and optionally call a
function to do additional work based on whether the value has been set via the
envvar.

Patch 2 then introduces the GLIBC_TUNABLES environment variable, which can be
set to a colon-separated list of name=value pairs of tunables.  This is the
contentious bit because there isn't agreement yet on what the final interface
should look like.

Siddhesh Poyarekar (2):
  Add framework for tunables
  Initialize tunable list with the GLIBC_TUNABLES environment variable

 INSTALL                  |   6 ++
 Makeconfig               |  16 ++++
 README.tunables          |  74 +++++++++++++++
 config.h.in              |   3 +
 config.make.in           |   1 +
 configure                |  16 ++++
 configure.ac             |  10 ++
 elf/Makefile             |   5 +
 elf/Versions             |   3 +
 elf/dl-tunable-types.h   |  45 +++++++++
 elf/dl-tunables.c        | 241 +++++++++++++++++++++++++++++++++++++++++++++++
 elf/dl-tunables.h        |  76 +++++++++++++++
 elf/dl-tunables.list     |  50 ++++++++++
 elf/rtld.c               |   8 ++
 malloc/arena.c           |  28 ++++++
 manual/install.texi      |   5 +
 scripts/gen-tunables.awk | 157 ++++++++++++++++++++++++++++++
 17 files changed, 744 insertions(+)
 create mode 100644 README.tunables
 create mode 100644 elf/dl-tunable-types.h
 create mode 100644 elf/dl-tunables.c
 create mode 100644 elf/dl-tunables.h
 create mode 100644 elf/dl-tunables.list
 create mode 100644 scripts/gen-tunables.awk

-- 
2.5.5

^ permalink raw reply	[flat|nested] 29+ messages in thread
* [PATCH 2/2] Initialize tunable list with the GLIBC_TUNABLES environment variable
@ 2016-01-11 11:17 Siddhesh Poyarekar
  2016-01-11 13:51 ` Andreas Schwab
  2016-01-11 21:26 ` Paul E. Murphy
  0 siblings, 2 replies; 29+ messages in thread
From: Siddhesh Poyarekar @ 2016-01-11 11:17 UTC (permalink / raw)
  To: libc-alpha; +Cc: roland, carlos, Paul E. Murphy, Andi Kleen

Read tunables values from the users using the GLIBC_TUNABLES
environment variable.  The value of this variable is a colon-separated
list of name=value pairs.  So a typical string would look like this:

GLIBC_TUNABLES=glibc.malloc.mmap_threshold=2048:glibc.malloc.trim_threshold=1024

	* tunables/tunables.c: Include sys/mman.h and libc-internals.h.
	(GLIBC_TUNABLES): New macro.
	(t_strdup): New function.
	(__tunables_init): Implement initializer.
---
 tunables/tunables.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 98 insertions(+), 5 deletions(-)

diff --git a/tunables/tunables.c b/tunables/tunables.c
index 2ae1050..ddd1934 100644
--- a/tunables/tunables.c
+++ b/tunables/tunables.c
@@ -24,12 +24,16 @@
 #include <stdbool.h>
 #include <unistd.h>
 #include <sys/param.h>
+#include <sys/mman.h>
+#include <libc-internal.h>
 
 extern char **__environ;
 
 #define TUNABLES_INTERNAL 1
 #include "tunables.h"
 
+#define GLIBC_TUNABLES "GLIBC_TUNABLES"
+
 static int
 t_strncmp (const char *a, const char *b, size_t len)
 {
@@ -46,6 +50,31 @@ t_strncmp (const char *a, const char *b, size_t len)
   return 0;
 }
 
+static char *
+t_strdup (const char *in)
+{
+  size_t len = 0;
+
+  while (in[len] != '\0')
+    len++;
+
+  /* Allocate enough number of pages.  Given the number of tunables this should
+     not exceed a single page but we err on the conservative side and try to
+     allocate space as needed.  */
+  size_t alloclen = ALIGN_UP (len + 1, __getpagesize ());
+
+  char *out = __mmap (NULL, alloclen, PROT_READ | PROT_WRITE,
+		      MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+
+  if (__glibc_unlikely (out == MAP_FAILED))
+    return NULL;
+  else
+    {
+      memcpy (out, in, len);
+      return out;
+    }
+}
+
 static bool
 get_next_env (char ***envp, char **name, size_t *namelen, char **val)
 {
@@ -74,14 +103,78 @@ get_next_env (char ***envp, char **name, size_t *namelen, char **val)
   return false;
 }
 
-/* This is where tunables will be read in from either an environment variable,
-   a set of environment variables or some other source and then initialized.
-   Caller should pass it the environment variable; __environ may not be
-   reliable if it is called earlier than libc.so initialization.  */
+/* Initialize tunables from the GLIBC_TUNABLES environment variable.  The
+   variable is set as colon separated name=value pairs.  */
 void
 __tunables_init (char **envp)
 {
-  /* Empty for now.  */
+  static bool initialized = false;
+
+  if (__glibc_likely (initialized))
+    return;
+
+  char **evp = envp;
+  char *p = NULL;
+
+  char *envname;
+  size_t envnamelen;
+  char *envval;
+
+  while (get_next_env (&evp, &envname, &envnamelen, &envval))
+    {
+      if (!t_strncmp (envname, GLIBC_TUNABLES, sizeof (GLIBC_TUNABLES)))
+	{
+	  p = t_strdup (envval);
+	  break;
+	}
+    }
+
+  if (p == NULL || *p == '\0')
+    goto out;
+
+  while (true)
+    {
+      char *name = p;
+      size_t len = 0;
+
+      /* First, find where the name ends.  */
+      while (p[len] != '=' && p[len] != '\0')
+	len++;
+
+      /* If we reach the end of the string before getting a valid name-value
+	 pair, bail out.  */
+      if (p[len] == '\0')
+	goto out;
+
+      p[len] = '\0';
+      p += len + 1;
+
+      char *value = p;
+      len = 0;
+
+      while (p[len] != ':' && p[len] != '\0')
+	len++;
+
+      char end = p[len];
+      p[len] = '\0';
+
+      /* Add the tunable if it exists.  */
+      for (size_t i = 0; i < sizeof (tunable_list) / sizeof (tunable_t); i++)
+	{
+	  if (t_strncmp (name, tunable_list[i].name, SIZE_MAX) == 0)
+	    {
+	      tunable_list[i].val = value;
+	      break;
+	    }
+	}
+
+      if (end == ':')
+	p += len + 1;
+      else
+	goto out;
+    }
+out:
+  initialized = true;
 }
 strong_alias (__tunables_init, tunables_init)
 
-- 
2.5.0

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

end of thread, other threads:[~2016-08-15 20:05 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-02 17:13 [PATCH 0/2] tunables for glibc Siddhesh Poyarekar
2016-07-02 17:13 ` [PATCH 2/2] Initialize tunable list with the GLIBC_TUNABLES environment variable Siddhesh Poyarekar
2016-07-03 14:39   ` H.J. Lu
2016-07-03 17:15     ` Siddhesh Poyarekar
2016-07-03 15:53   ` H.J. Lu
2016-07-03 17:18     ` Siddhesh Poyarekar
2016-07-02 17:13 ` [PATCH 1/2] Add framework for tunables Siddhesh Poyarekar
2016-07-03 14:30   ` H.J. Lu
2016-07-03 17:08     ` Siddhesh Poyarekar
2016-07-03 14:44   ` H.J. Lu
2016-07-03 17:14     ` Siddhesh Poyarekar
2016-07-03 17:41       ` H.J. Lu
2016-07-03 15:13   ` H.J. Lu
2016-07-03 17:43     ` H.J. Lu
2016-07-03 18:20       ` Siddhesh Poyarekar
2016-07-03  0:24 ` [PATCH 0/2] tunables for glibc H.J. Lu
2016-07-03  3:08   ` Siddhesh Poyarekar
  -- strict thread matches above, loose matches on Subject: below --
2016-08-15 20:05 [PATCHv4 " Siddhesh Poyarekar
2016-08-15 20:05 ` [PATCH 2/2] Initialize tunable list with the GLIBC_TUNABLES environment variable Siddhesh Poyarekar
2016-07-09 18:49 [PATCHv3 0/2] tunables for glibc Siddhesh Poyarekar
2016-07-09 18:49 ` [PATCH 2/2] Initialize tunable list with the GLIBC_TUNABLES environment variable Siddhesh Poyarekar
2016-07-01 18:31 [PATCH 0/2] Tunables for glibc Siddhesh Poyarekar
2016-07-01 18:31 ` [PATCH 2/2] Initialize tunable list with the GLIBC_TUNABLES environment variable Siddhesh Poyarekar
2016-01-11 11:17 Siddhesh Poyarekar
2016-01-11 13:51 ` Andreas Schwab
2016-01-11 14:45   ` Siddhesh Poyarekar
2016-01-13  2:44     ` Carlos O'Donell
2016-01-13  3:27       ` Siddhesh Poyarekar
2016-01-13  8:38         ` Andreas Schwab
2016-01-13 15:37           ` Carlos O'Donell
2016-01-11 21:26 ` Paul E. Murphy
2016-01-12 12:28   ` Siddhesh Poyarekar

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 read-only IMAP folder(s) and NNTP newsgroup(s).