bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Curious... on readline history patch -- round up memory allocs?


From: L. A. Walsh
Subject: Curious... on readline history patch -- round up memory allocs?
Date: Tue, 15 Nov 2016 13:16:38 -0800
User-agent: Thunderbird

Saw the bit about bash-4.4 changing things to reduce reallocs/copies,
and wondered if you'd thought about rounding up the allocations
to the nearest page size (at least on linux):

Something along the lines of:
Ishtar:tools/bash/readline-7.0> diff -u history.c.orig history.c
--- history.c 2015-12-28 10:50:31.000000000 -0800
+++ history.c 2016-11-15 12:36:51.452105223 -0800
@@ -57,6 +57,12 @@
/* How big to make the_history when we first allocate it. */
#define DEFAULT_HISTORY_INITIAL_SIZE 502

+#define MAX_HISTORY_INITIAL_SIZE 8192
+
+#define DEFAULT_PAGE_SIZE 8192
+
+#define ROUND_UP_TO_PAGE_SIZE(x) ( x + DEFAULT_PAGE_SIZE-1) & ~(DEFAULT_PAGE_SIZE-1)
+
/* The number of slots to increase the_history by. */
#define DEFAULT_HISTORY_GROW_SIZE 50

@@ -310,16 +316,19 @@
     history_size = history_max_entries + 2;
   else
     history_size = DEFAULT_HISTORY_INITIAL_SIZE;
- the_history = (HIST_ENTRY **)xmalloc (history_size * sizeof (HIST_ENTRY *)); + the_history = (HIST_ENTRY **)xmalloc (ROUND_UP_TO_PAGE_SIZE(history_size * sizeof (HIST_ENTRY *)));
   history_length = 1;
 }
      else
 {
   if (history_length == (history_size - 1))
     {
-       history_size += DEFAULT_HISTORY_GROW_SIZE;
+       history_size = (history_max_entries > MAX_HISTORY_INITIAL_SIZE)
+         ? MAX_HISTORY_INITIAL_SIZE
+         : history_max_entries + 2;
       the_history = (HIST_ENTRY **)
-   xrealloc (the_history, history_size * sizeof (HIST_ENTRY *));
+ xrealloc (the_history, ROUND_UP_TO_PAGE_SIZE(history_size * sizeof (HIST_ENTRY *)));
+
     }
   history_length++;
 }

----
Note, since I'm having probs building bash right now, the above
isn't execution tested, but it does compile!  ;-)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]