On 9/25/16 6:59 PM, Chet Ramey wrote:
> On 9/25/16 3:51 PM, Sean Zha wrote:
> 
>> Bash Version: 4.4
>> Patch Level: 0
>> Release Status: release
>>
>> Description:
>>      I use a huge value for HISTSIZE (=999999999) to enable infinite
>>      history items. The actural size of ~/.bash_history is only 4MB now.
>>      Everything worked fine before the lastest upgrade. Now bash refuse
>>      me to login due to memory allocation failure. After choosing
>>      a smaller HISTSIZE, bash still eatup too much unnesssary memory.
>>
>> Repeat-By:
>>      open a workable terminal with small HISTSIZE setting,
>>      $ echo HISTSIZE=999999999 > ~/test.rc
>>      $ bash --rcfile ~/test.rc
>>        bash: xmalloc: cannot allocate 8000000008 bytes (114688 bytes 
>> allocated)
> 
> Since you've specified the desired history size, bash tries to allocate
> enough entries to hold all of the entries.  The assumption is that this
> will reduce the number of allocations/reallocations and the number of
> times the history list has to be copied as it's reallocated.  I suppose
> I should cap the maximum value for which that occurs instead of trusting
> the supplied max number of entries.

Try the attached patch and see whether or not it improves things.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/
*** ../bash-4.4/lib/readline/history.c	2015-12-28 13:50:31.000000000 -0500
--- lib/readline/history.c	2016-09-30 14:28:40.000000000 -0400
***************
*** 58,61 ****
--- 58,63 ----
  #define DEFAULT_HISTORY_INITIAL_SIZE	502
  
+ #define MAX_HISTORY_INITIAL_SIZE	8192
+ 
  /* The number of slots to increase the_history by. */
  #define DEFAULT_HISTORY_GROW_SIZE 50
***************
*** 308,312 ****
  	{
  	  if (history_stifled && history_max_entries > 0)
! 	    history_size = history_max_entries + 2;
  	  else
  	    history_size = DEFAULT_HISTORY_INITIAL_SIZE;
--- 310,316 ----
  	{
  	  if (history_stifled && history_max_entries > 0)
! 	    history_size = (history_max_entries > MAX_HISTORY_INITIAL_SIZE)
! 				? MAX_HISTORY_INITIAL_SIZE
! 				: history_max_entries + 2;
  	  else
  	    history_size = DEFAULT_HISTORY_INITIAL_SIZE;

Reply via email to