aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Möllmann2025-09-06 06:16:11 +0200
committerGerd Möllmann2025-09-06 06:16:11 +0200
commitabd7e62a5564a6ae7c8590d2c932b5423ecc6ee4 (patch)
tree522cee848d97484aef6a2041e1fefb9c83e7bdb8
parent09736f2679a18d59855c3bd17672e3310199901d (diff)
downloademacs-scratch/igc2.tar.gz
emacs-scratch/igc2.zip
Read GC parameters from environmentscratch/igc2
* src/igc.c (read_gens, read_pause_time, read_commit_limit): New. (make_arena): Use them.
-rw-r--r--src/igc.c99
1 files changed, 97 insertions, 2 deletions
diff --git a/src/igc.c b/src/igc.c
index 55fd133b954..5ec0ebde854 100644
--- a/src/igc.c
+++ b/src/igc.c
@@ -4885,19 +4885,114 @@ really know what you are doing! */)
4885 return Qnil; 4885 return Qnil;
4886} 4886}
4887 4887
4888/* Read GC generation settings from environment variable
4889 EMACS_IGC_GENS. Value must be a string consisting of pairs SIZE
4890 MORTALITY, where SIZE Is the size of the generation in KB, and
4891 mortality is a floating-point number between 0 and 1. All numbers are
4892 separated by spaces. Example:
4893
4894 export EMACS_IGC_GENS="256000 0.8 256000 0.6 256000 0.4 512000 0.2"
4895
4896 specifies to use 4 generations. The first three have a sizeof 256 MB,
4897 with mortality 0.8, 0.6, and 0.4. The fourth generation has a size of
4898 512 MB and a mortality of 0.2. */
4899
4900static bool
4901read_gens (mps_gen_param_s **gens, int *ngens)
4902{
4903 const char *env = getenv ("EMACS_IGC_GENS");
4904 if (env == NULL)
4905 return false;
4906 const char *end = env + strlen (env);
4907 static struct mps_gen_param_s parms[10];
4908 *ngens = 0;
4909 *gens = parms;
4910 for (int i = 0; i < ARRAYELTS (parms) && env < end; ++i)
4911 {
4912 int nchars;
4913 if (sscanf (env, "%zu %lf%n", &parms[i].mps_capacity,
4914 &parms[i].mps_mortality, &nchars) == 2)
4915 {
4916 env += nchars;
4917 ++*ngens;
4918 }
4919 }
4920
4921 return true;
4922}
4923
4924/* Read GC maximum pause time from environment variable
4925 EMACS_IGC_PAUSE_TIME. Value must be a floating point number
4926 specifying the pause time in seconds. Example:
4927
4928 export EMACS_IGC_PAUSE_TIME=0.05
4929
4930 says to use 50ms maximum pause time. */
4931
4932static bool
4933read_pause_time (double *time)
4934{
4935 const char *env = getenv ("EMACS_IGC_PAUSE_TIME");
4936 if (env == NULL)
4937 return false;
4938 return sscanf (env, "%lf", time) == 1;
4939}
4940
4941/* Read GC commit limit from environment variable
4942 EMACS_IGC_COMMIT_LIMIT. Value must be an integer number specifying
4943 the commit limit in bytes. Example:
4944
4945 export EMACS_IGC_COMMIT_LIMIT=1000000000
4946
4947 Do not use this, except for testing. */
4948
4949static bool
4950read_commit_limit (size_t *limit)
4951{
4952 const char *env = getenv ("EMACS_IGC_COMMIT_LIMIT");
4953 if (env == NULL)
4954 return false;
4955 return sscanf (env, "%zu", limit) == 1;
4956}
4957
4888static void 4958static void
4889make_arena (struct igc *gc) 4959make_arena (struct igc *gc)
4890{ 4960{
4891 mps_res_t res; 4961 mps_res_t res;
4892 MPS_ARGS_BEGIN (args) 4962 MPS_ARGS_BEGIN (args)
4893 { 4963 {
4964 double pause_time;
4965 if (read_pause_time (&pause_time))
4966 MPS_ARGS_ADD (args, MPS_KEY_PAUSE_TIME, pause_time);
4967
4968 size_t commit_limit;
4969 if (read_commit_limit (&commit_limit))
4970 MPS_ARGS_ADD (args, MPS_KEY_COMMIT_LIMIT, commit_limit);
4971
4894 res = mps_arena_create_k (&gc->arena, mps_arena_class_vm (), args); 4972 res = mps_arena_create_k (&gc->arena, mps_arena_class_vm (), args);
4895 } 4973 }
4896 MPS_ARGS_END (args); 4974 MPS_ARGS_END (args);
4897 IGC_CHECK_RES (res); 4975 IGC_CHECK_RES (res);
4898 4976
4899 mps_gen_param_s gens[] = { { 128000, 0.8 }, { 5 * 128000, 0.4 } }; 4977 mps_gen_param_s *gens;
4900 res = mps_chain_create (&gc->chain, gc->arena, ARRAYELTS (gens), gens); 4978 int ngens;
4979 if (!read_gens (&gens, &ngens))
4980 {
4981 static mps_gen_param_s default_gens[] = { { 128000, 0.8 }, { 5 * 128000, 0.4 } };
4982 gens = default_gens;
4983 ngens = ARRAYELTS (default_gens);
4984 }
4985
4986 if (getenv ("EMACS_IGC_VERBOSE"))
4987 {
4988 for (int i = 0; i < ngens; ++i)
4989 fprintf (stderr, "gen %d: %zu %lf\n", i, gens[i].mps_capacity,
4990 gens[i].mps_mortality);
4991 fprintf (stderr, "pause time %lf\n", mps_arena_pause_time (gc->arena));
4992 fprintf (stderr, "commit limit %zu\n", mps_arena_commit_limit (gc->arena));
4993 }
4994
4995 res = mps_chain_create (&gc->chain, gc->arena, ngens, gens);
4901 IGC_CHECK_RES (res); 4996 IGC_CHECK_RES (res);
4902} 4997}
4903 4998