Feature #8015

[patch] tuneable HEAP_GROWTH_FACTOR

Added by Aman Gupta about 1 year ago. Updated about 1 year ago.

[ruby-core:53131]
Status:Closed
Priority:Normal
Assignee:Narihiro Nakamura
Category:core
Target version:2.1.0

Description

diff --git a/gc.c b/gc.c
index 925e496..71f509f 100644
--- a/gc.c
+++ b/gc.c
@@ -71,11 +71,13 @@
#endif
#define HEAPMINSLOTS 10000
#define FREEMIN 4096
+#define HEAP
GROWTH_FACTOR 1.8

typedef struct {
unsigned int initialmalloclimit;
unsigned int initialheapminslots;
unsigned int initial
freemin;
+ double initial
growthfactor;
#if defined(ENABLE
VMOBJSPACE) && ENABLEVMOBJSPACE
int gc
stress;
#endif
@@ -85,6 +87,7 @@ static rubygcparamst initialparams = {
GCMALLOCLIMIT,
HEAPMINSLOTS,
FREEMIN,
+ HEAP
GROWTHFACTOR,
#if defined(ENABLE
VMOBJSPACE) && ENABLEVMOBJSPACE
FALSE,
#endif
@@ -287,6 +290,7 @@ int *ruby
initialgcstressptr = &rbobjspace.gcstress;
#define initial
malloclimit initialparams.initialmalloclimit
#define initialheapminslots initialparams.initialheapminslots
#define initial
freemin initialparams.initialfreemin
+#define initialgrowthfactor initialparams.initialgrowth_factor

#define islazysweeping(objspace) ((objspace)->heap.sweep_slots != 0)

@@ -605,7 +609,7 @@ initialexpandheap(rbobjspacet *objspace)
static void
setheapsincrement(rbobjspacet *objspace)
{
- sizet nextheapslength = (sizet)(heapsused * 1.8);
+ size
t nextheapslength = (sizet)(heapsused * initialgrowthfactor);

 if (next_heaps_length == heaps_used) {
     next_heaps_length++;

@@ -3333,7 +3337,7 @@ rbgcdisable(void)
void
rbgcsetparams(void)
{
- char *malloc
limitptr, *heapminslotsptr, *freeminptr;
+ char *malloclimitptr, *heapminslotsptr, *freeminptr, *growthfactor_ptr;

 if (rb_safe_level() > 0) return;

@@ -3360,6 +3364,16 @@ rbgcset_params(void)
}
}

  • growthfactorptr = getenv("RUBYHEAPSLOTSGROWTHFACTOR");
  • if (growthfactorptr != NULL) {
  • double growthfactorf = atof(growthfactorptr);
  • if (RTEST(ruby_verbose))
  • fprintf(stderr, "growthfactor=%f (%f)\n", growthfactorf, initialgrowth_factor);
  • if (growthfactorf > 0) {
  • initialgrowthfactor = growthfactorf;
  • }
  • } + freeminptr = getenv("RUBYFREEMIN"); if (freeminptr != NULL) { int freemini = atoi(freeminptr);

Related issues

Related to ruby-trunk - Feature #2837: Compile-time constant for HEAP_GROWTH_FACTOR (patch attac... Closed 03/05/2010

Associated revisions

Revision 39746
Added by nari about 1 year ago

  • gc.c: allow to tune growth of heap by environment variable RUBYHEAPSLOTSGROWTHFACTOR. patched by tmm1(Aman Gupta). [Feature #8015]

History

#1 Updated by Motohiro KOSAKI about 1 year ago

The idea seems good.

  • growthfactorptr = getenv("RUBYHEAPSLOTSGROWTHFACTOR");
  • if (growthfactorptr != NULL) {
  • double growthfactorf = atof(growthfactorptr);

atof() don't have proper error check. it should be strtod().

  • if (RTEST(ruby_verbose))
  • fprintf(stderr, "growthfactor=%f (%f)\n", growthfactorf, initialgrowth_factor);
  • if (growthfactorf > 0) {
  • initialgrowthfactor = growthfactorf;
  • }

This seems don't work when growthfactorf is less than 1.

#2 Updated by Aman Gupta about 1 year ago

Thanks for the review. How about this?

@@ -3366,10 +3535,11 @@ rbgcset_params(void)

 growth_factor_ptr = getenv("RUBY_HEAP_SLOTS_GROWTH_FACTOR");
 if (growth_factor_ptr != NULL) {
  • double growthfactorf = atof(growthfactorptr);
  • double growthfactorf = strtod(growthfactorptr, NULL); if (RTEST(ruby_verbose))
  • fprintf(stderr, "growthfactor=%f (%f)\n", growthfactorf, initialgrowth_factor);
  • if (growthfactorf > 0) {
  • fprintf(stderr, "heapslotsgrowth_factor=%f (%f)\n",
  • growthfactorf, initialgrowthfactor);
  • if (growthfactorf > 1) { initialgrowthfactor = growthfactorf; } }

#3 Updated by Aman Gupta about 1 year ago

Are there any objections to this patch?

#4 Updated by Narihiro Nakamura about 1 year ago

  • Assignee set to Narihiro Nakamura

I agree this patch. I'll merge it few days later, if there are no objections.

Thank you!

#5 Updated by Eric Hodel about 1 year ago

  • Category set to core
  • Status changed from Open to Assigned
  • Target version set to 2.1.0

#6 Updated by Narihiro Nakamura about 1 year ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39746.
Aman, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • gc.c: allow to tune growth of heap by environment variable RUBYHEAPSLOTSGROWTHFACTOR. patched by tmm1(Aman Gupta). [Feature #8015]

Also available in: Atom PDF