List:Commits« Previous MessageNext Message »
From:kpettersson Date:March 18 2008 9:45am
Subject:bk commit into 5.1 tree (thek:1.2558) BUG#25175
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of thek.  When thek does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-03-18 10:45:36+01:00, thek@adventure.(none) +3 -0
  Bug#25175 Too much memory used by MySQL grant system
  
  Each time the server reloads privileges containing table grants, the 
  system will allocate too much memory than needed because of badly
  chosen growth prediction in the underlying dynamic arrays.
  
  This patch introduces a new signature to the hash container initializer
  which enables a much more pessimistic approach in favour for more
  efficient memory useage.
  
  This patch was supplied by Google Inc.

  include/hash.h@stripped, 2008-03-18 10:45:32+01:00, thek@adventure.(none) +4 -3
    * New signature for _hash_init.
    * Defined new function hash_init2 which takes growth_size argument.

  mysys/hash.c@stripped, 2008-03-18 10:45:32+01:00, thek@adventure.(none) +3 -2
    * New signature for _hash_init.

  sql/sql_acl.cc@stripped, 2008-03-18 10:45:32+01:00, thek@adventure.(none) +2 -2
    * Changed hash_init signature so that it takes a 'growth_size' smaller
    than the default. Each time a GRANT_TABLE is allocated a pre-allocated
    dynamic array is instantiated. A large growth size can result in too
    many unused hash-entries per table-entry and thus be a waste of free
    memory.

diff -Nrup a/include/hash.h b/include/hash.h
--- a/include/hash.h	2007-05-24 12:24:27 +02:00
+++ b/include/hash.h	2008-03-18 10:45:32 +01:00
@@ -47,8 +47,9 @@ typedef struct st_hash {
 /* A search iterator state */
 typedef uint HASH_SEARCH_STATE;
 
-#define hash_init(A,B,C,D,E,F,G,H) _hash_init(A,B,C,D,E,F,G, H CALLER_INFO)
-my_bool _hash_init(HASH *hash, CHARSET_INFO *charset,
+#define hash_init(A,B,C,D,E,F,G,H) _hash_init(A,0,B,C,D,E,F,G,H CALLER_INFO)
+#define hash_init2(A,B,C,D,E,F,G,H,I) _hash_init(A,B,C,D,E,F,G,H,I CALLER_INFO)
+my_bool _hash_init(HASH *hash, uint growth_size,CHARSET_INFO *charset,
 		   ulong default_array_elements, size_t key_offset,
 		   size_t key_length, hash_get_key get_key,
 		   void (*free_element)(void*), uint flags CALLER_INFO_PROTO);
@@ -69,7 +70,7 @@ my_bool hash_check(HASH *hash);			/* Onl
 #define hash_clear(H) bzero((char*) (H),sizeof(*(H)))
 #define hash_inited(H) ((H)->array.buffer != 0)
 #define hash_init_opt(A,B,C,D,E,F,G,H) \
-          (!hash_inited(A) && _hash_init(A,B,C,D,E,F,G, H CALLER_INFO))
+          (!hash_inited(A) && _hash_init(A,0,B,C,D,E,F,G, H CALLER_INFO))
 
 #ifdef	__cplusplus
 }
diff -Nrup a/mysys/hash.c b/mysys/hash.c
--- a/mysys/hash.c	2007-07-30 10:33:41 +02:00
+++ b/mysys/hash.c	2008-03-18 10:45:32 +01:00
@@ -46,7 +46,7 @@ static uint calc_hash(const HASH *hash, 
 }
 
 my_bool
-_hash_init(HASH *hash,CHARSET_INFO *charset,
+_hash_init(HASH *hash,uint growth_size, CHARSET_INFO *charset,
 	   ulong size, size_t key_offset, size_t key_length,
 	   hash_get_key get_key,
 	   void (*free_element)(void*),uint flags CALLER_INFO_PROTO)
@@ -55,7 +55,8 @@ _hash_init(HASH *hash,CHARSET_INFO *char
   DBUG_PRINT("enter",("hash: 0x%lx  size: %u", (long) hash, (uint) size));
 
   hash->records=0;
-  if (my_init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0))
+  if (my_init_dynamic_array_ci(&hash->array, sizeof(HASH_LINK), size,
+                               growth_size))
   {
     hash->free=0;				/* Allow call to hash_free */
     DBUG_RETURN(1);
diff -Nrup a/sql/sql_acl.cc b/sql/sql_acl.cc
--- a/sql/sql_acl.cc	2008-02-19 13:57:59 +01:00
+++ b/sql/sql_acl.cc	2008-03-18 10:45:32 +01:00
@@ -2281,7 +2281,7 @@ GRANT_TABLE::GRANT_TABLE(const char *h, 
                 	 const char *t, ulong p, ulong c)
   :GRANT_NAME(h,d,u,t,p), cols(c)
 {
-  (void) hash_init(&hash_columns,system_charset_info,
+  (void) hash_init2(&hash_columns,4,system_charset_info,
                    0,0,0, (hash_get_key) get_key_column,0,0);
 }
 
@@ -2329,7 +2329,7 @@ GRANT_TABLE::GRANT_TABLE(TABLE *form, TA
   cols= (ulong) form->field[7]->val_int();
   cols =  fix_rights_for_column(cols);
 
-  (void) hash_init(&hash_columns,system_charset_info,
+  (void) hash_init2(&hash_columns,4,system_charset_info,
                    0,0,0, (hash_get_key) get_key_column,0,0);
   if (cols)
   {
Thread
bk commit into 5.1 tree (thek:1.2558) BUG#25175kpettersson18 Mar