List:Commits« Previous MessageNext Message »
From:knielsen Date:November 9 2007 9:54am
Subject:bk commit into 5.1 tree (knielsen:1.2618)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of knielsen. When knielsen 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, 2007-11-09 10:54:08+01:00, knielsen@ymer.(none) +7 -0
  WL#1498: Multi-threaded ndbd.
  
  Move global memory manager initialization from CMVMI into main().
  Use global memory manager for ndbmtd job buffers.
  Remove job buffer packing, it's no longer used anyway.
  Small cleanup.

  storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp@stripped, 2007-11-09 10:54:00+01:00, knielsen@ymer.(none) +0 -47
    Move global memory manager initialization from CMVMI into main().

  storage/ndb/src/kernel/blocks/record_types.hpp@stripped, 2007-11-09 10:54:00+01:00, knielsen@ymer.(none) +8 -1
    Use global memory manager for ndbmtd job buffers.

  storage/ndb/src/kernel/main.cpp@stripped, 2007-11-09 10:54:00+01:00, knielsen@ymer.(none) +64 -0
    Move global memory manager initialization from CMVMI into main().

  storage/ndb/src/kernel/vm/ThreadConfig.cpp@stripped, 2007-11-09 10:54:01+01:00, knielsen@ymer.(none) +5 -0
    Move global memory manager initialization from CMVMI into main().

  storage/ndb/src/kernel/vm/ThreadConfig.hpp@stripped, 2007-11-09 10:54:01+01:00, knielsen@ymer.(none) +1 -0
    Move global memory manager initialization from CMVMI into main().

  storage/ndb/src/kernel/vm/mt/mt.cpp@stripped, 2007-11-09 10:54:01+01:00, knielsen@ymer.(none) +33 -48
    Use global memory manager for ndbmtd job buffers.
    Remove job buffer packing, it's no longer used anyway.
    Small cleanup.

  storage/ndb/src/kernel/vm/ndbd_malloc_impl.hpp@stripped, 2007-11-09 10:54:01+01:00, knielsen@ymer.(none) +1 -1
    Use global memory manager for ndbmtd job buffers.

diff -Nrup a/storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp b/storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp
--- a/storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp	2007-10-12 13:25:02 +02:00
+++ b/storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp	2007-11-09 10:54:00 +01:00
@@ -349,53 +349,6 @@ Cmvmi::execREAD_CONFIG_REQ(Signal* signa
   pages += page_buffer / GLOBAL_PAGE_SIZE; // in pages
   pages += LCP_RESTORE_BUFFER;
   m_global_page_pool.setSize(pages + 64, true);
-  
-  Uint64 shared_mem = 8*1024*1024;
-  ndb_mgm_get_int64_parameter(p, CFG_DB_SGA, &shared_mem);
-  shared_mem /= GLOBAL_PAGE_SIZE;
-
-  Uint32 tupmem = 0;
-  ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_TUP_PAGE, &tupmem));
-  if (tupmem)
-  {
-    Resource_limit rl;
-    rl.m_min = tupmem;
-    rl.m_max = tupmem;
-    rl.m_resource_id = 3;
-    m_ctx.m_mm.set_resource_limit(rl);
-  }
-
-  if (shared_mem+tupmem)
-  {
-    Resource_limit rl;
-    rl.m_min = 0;
-    rl.m_max = shared_mem + tupmem;
-    rl.m_resource_id = 0;
-    m_ctx.m_mm.set_resource_limit(rl);
-  }
-  
-  if (!m_ctx.m_mm.init())
-  {
-    char buf[255];
-
-    struct ndb_mgm_param_info dm;
-    struct ndb_mgm_param_info sga;
-    size_t size = sizeof(ndb_mgm_param_info);
-    
-    ndb_mgm_get_db_parameter_info(CFG_DB_DATA_MEM, &dm, &size);
-    size = sizeof(ndb_mgm_param_info);
-    ndb_mgm_get_db_parameter_info(CFG_DB_SGA, &sga, &size);
-
-    BaseString::snprintf(buf, sizeof(buf), 
-			 "Malloc (%lld bytes) for %s and %s failed", 
-			 Uint64(shared_mem + tupmem) * 32768,
-			 dm.m_name, sga.m_name);
-    
-    ErrorReporter::handleAssert(buf,
-				__FILE__, __LINE__, NDBD_EXIT_MEMALLOC);
-    
-    ndbrequire(false);
-  }
 
   {
     void* ptr = m_ctx.m_mm.get_memroot();
diff -Nrup a/storage/ndb/src/kernel/blocks/record_types.hpp b/storage/ndb/src/kernel/blocks/record_types.hpp
--- a/storage/ndb/src/kernel/blocks/record_types.hpp	2007-05-01 21:52:47 +02:00
+++ b/storage/ndb/src/kernel/blocks/record_types.hpp	2007-11-09 10:54:00 +01:00
@@ -40,10 +40,15 @@
 #define RG_DATAMEM              3
 
 /**
+ * Records for job buffers (multi-threaded ndbd only).
+ */
+#define RG_JOBBUFFER            4
+
+/**
  * 
  */
 #define RG_RESERVED             0
-#define RG_COUNT                4
+#define RG_COUNT                5
 
 /**
  * Record types
@@ -62,5 +67,7 @@
 
 #define RT_DBTUP_PAGE              MAKE_TID( 1, RG_DATAMEM)
 #define RT_DBTUP_PAGE_MAP          MAKE_TID( 2, RG_DATAMEM)
+
+#define RT_JOB_BUFFER              MAKE_TID( 1, RG_JOBBUFFER)
 
 #endif
diff -Nrup a/storage/ndb/src/kernel/main.cpp b/storage/ndb/src/kernel/main.cpp
--- a/storage/ndb/src/kernel/main.cpp	2007-10-12 13:25:02 +02:00
+++ b/storage/ndb/src/kernel/main.cpp	2007-11-09 10:54:00 +01:00
@@ -226,6 +226,65 @@ do_next:
   return 0;
 }
 
+static int
+init_global_memory_manager(EmulatorData &ed)
+{
+  const ndb_mgm_configuration_iterator * p =
+    ed.theConfiguration->getOwnConfigIterator();
+  if (p == 0)
+  {
+    abort();
+  }
+
+  Uint64 shared_mem = 8*1024*1024;
+  ndb_mgm_get_int64_parameter(p, CFG_DB_SGA, &shared_mem);
+  shared_mem /= GLOBAL_PAGE_SIZE;
+
+  Uint32 tupmem = 0;
+  if (ndb_mgm_get_int_parameter(p, CFG_TUP_PAGE, &tupmem))
+  {
+    g_eventLogger.alert("Failed to get CFG_TUP_PAGE parameter from "
+                        "config, exiting.");
+    return -1;
+  }
+  if (tupmem)
+  {
+    Resource_limit rl;
+    rl.m_min = tupmem;
+    rl.m_max = tupmem;
+    rl.m_resource_id = 3;
+    ed.m_mem_manager->set_resource_limit(rl);
+  }
+
+  if (shared_mem+tupmem)
+  {
+    Resource_limit rl;
+    rl.m_min = 0;
+    rl.m_max = shared_mem + tupmem;
+    rl.m_resource_id = 0;
+    ed.m_mem_manager->set_resource_limit(rl);
+  }
+
+  if (!ed.m_mem_manager->init())
+  {
+    struct ndb_mgm_param_info dm;
+    struct ndb_mgm_param_info sga;
+    size_t size;
+
+    size = sizeof(ndb_mgm_param_info);
+    ndb_mgm_get_db_parameter_info(CFG_DB_DATA_MEM, &dm, &size);
+    size = sizeof(ndb_mgm_param_info);
+    ndb_mgm_get_db_parameter_info(CFG_DB_SGA, &sga, &size);
+
+    g_eventLogger.alert("Malloc (%lld bytes) for %s and %s failed, exiting",
+                        Uint64(shared_mem + tupmem) * 32768,
+                        dm.m_name, sga.m_name);
+    return -1;
+  }
+
+  return 0;                     // Success
+}
+
 int main(int argc, char** argv)
 {
   NDB_INIT(argv[0]);
@@ -405,6 +464,11 @@ int main(int argc, char** argv)
   theConfig->setupConfiguration();
   systemInfo(* theConfig, * theConfig->m_logLevel); 
   
+  if (init_global_memory_manager(globalEmulatorData))
+    return 1;
+
+  globalEmulatorData.theThreadConfig->init(&globalEmulatorData);
+
     // Load blocks
   globalEmulatorData.theSimBlockList->load(globalEmulatorData);
     
diff -Nrup a/storage/ndb/src/kernel/vm/ThreadConfig.cpp b/storage/ndb/src/kernel/vm/ThreadConfig.cpp
--- a/storage/ndb/src/kernel/vm/ThreadConfig.cpp	2007-10-12 13:34:01 +02:00
+++ b/storage/ndb/src/kernel/vm/ThreadConfig.cpp	2007-11-09 10:54:01 +01:00
@@ -39,6 +39,11 @@ ThreadConfig::~ThreadConfig()
 {
 }
 
+void
+ThreadConfig::init(EmulatorData *emulatorData)
+{
+}
+
 /**
  * For each millisecond that has passed since this function was last called:
  *   Scan the job buffer and increment the internalMillisecCounter 
diff -Nrup a/storage/ndb/src/kernel/vm/ThreadConfig.hpp b/storage/ndb/src/kernel/vm/ThreadConfig.hpp
--- a/storage/ndb/src/kernel/vm/ThreadConfig.hpp	2007-10-11 14:55:28 +02:00
+++ b/storage/ndb/src/kernel/vm/ThreadConfig.hpp	2007-11-09 10:54:01 +01:00
@@ -27,6 +27,7 @@ class ThreadConfig
 public:
   ThreadConfig();
   ~ThreadConfig();
+  void init(EmulatorData *emulatorData);
 
   void ipControlLoop(Uint32 thread_index);
 
diff -Nrup a/storage/ndb/src/kernel/vm/mt/mt.cpp b/storage/ndb/src/kernel/vm/mt/mt.cpp
--- a/storage/ndb/src/kernel/vm/mt/mt.cpp	2007-11-07 13:11:32 +01:00
+++ b/storage/ndb/src/kernel/vm/mt/mt.cpp	2007-11-09 10:54:01 +01:00
@@ -260,7 +260,12 @@ trylock(struct thr_mutex * sl)
 }
 
 /**
+ * Signal buffers.
  *
+ * Each thread job queue contains a list of these buffers with signals.
+ *
+ * There is an underlying assumption that the size of this structure is the
+ * same as the global memory manager page size.
  */
 struct thr_job_buffer // 32k
 {
@@ -281,7 +286,7 @@ struct thr_job_buffer // 32k
 
 struct thr_job_queue
 {
-  static const unsigned SIZE = 62;
+  static const unsigned SIZE = 30;
 
   unsigned m_read_index; // Read/written by consumer, read by producer
   unsigned m_write_index; // Read/written by producer, read by consumer
@@ -441,9 +446,6 @@ struct thr_data
 #endif
 };
 
-#define DBG_MALLOC 0
-#define THR_TO_REP(selfptr) &g_thr_repository
-
 template<typename T>
 struct thr_safe_pool
 {
@@ -451,6 +453,7 @@ struct thr_safe_pool
 
   thr_spin_lock m_lock;
   T* m_free_list;
+  Ndbd_mem_manager *m_mm;
 
   T* seize() {
     T* ret = 0;
@@ -459,12 +462,17 @@ struct thr_safe_pool
     {
       ret = m_free_list;
       m_free_list = *reinterpret_cast<T**>(m_free_list);
+      unlock(&m_lock);
     }
     else
     {
-      ret = reinterpret_cast<T*>(malloc(sizeof(T)));
+      Uint32 dummy;
+      unlock(&m_lock);
+      ret = reinterpret_cast<T*>(m_mm->alloc_page(RT_JOB_BUFFER, &dummy));
+      // ToDo: How to deal with failed allocation?!?
+      // I think in this case we need to start grabbing buffers kept for signal
+      // trace.
     }
-    unlock(&m_lock);
     return ret;
   }
 
@@ -564,44 +572,10 @@ release_buffer(struct thr_repository* re
   struct thr_data* selfptr = rep->m_thread + thr_no;
   Uint32 first_free = selfptr->m_first_free;
   Uint32 first_unused = selfptr->m_first_unused;
-  Uint32 last_free = (first_unused ? first_unused : THR_FREE_BUF_MAX) - 1;
-  thr_job_buffer *last_jb = selfptr->m_free_fifo[last_free];
-  Uint32 len1, len2;
-
-  if (!jb->m_prioa &&
-      first_free != first_unused &&
-      !last_jb->m_prioa &&
-      (len2 = jb->m_len) <= (thr_job_buffer::SIZE / 4) &&
-      (len1 = last_jb->m_len) + len2 <= thr_job_buffer::SIZE)
-  {
-    /*
-     * The buffer being release is fairly empty, and what data it contains fit
-     * in the previously released buffer.
-     *
-     * We want to avoid too many almost-empty buffers in the free fifo, as that
-     * makes signal traces less useful due to too little data available. So in
-     * this case we move the data from the buffer to be released into the
-     * previous buffer, and place the to-be-released buffer at the head of the
-     * fifo (to be immediately reused).
-     *
-     * This is only done for prio B buffers, as we must not merge prio A and B
-     * data (or dumps would be incorrect), and prio A buffers are in any case
-     * full when released.
-     */
-    memcpy(last_jb->m_data + len1, jb->m_data, len2*sizeof(jb->m_data[0]));
-    last_jb->m_len = len1 + len2;
-    jb->m_len = 0;
-    first_free = (first_free ? first_free : THR_FREE_BUF_MAX) - 1;
-    selfptr->m_free_fifo[first_free] = jb;
-    selfptr->m_first_free = first_free;
-  }
-  else
-  {
-    /* Just insert at the end of the fifo. */
-    selfptr->m_free_fifo[first_unused] = jb;
-    first_unused = (first_unused + 1) % THR_FREE_BUF_MAX;
-    selfptr->m_first_unused = first_unused;
-  }
+
+  selfptr->m_free_fifo[first_unused] = jb;
+  first_unused = (first_unused + 1) % THR_FREE_BUF_MAX;
+  selfptr->m_first_unused = first_unused;
 
   if (unlikely(first_unused == first_free))
   {
@@ -1544,8 +1518,10 @@ init2(struct thr_repository* rep, struct
 
 static
 void
-init(struct thr_repository* rep, unsigned int cnt)
+init(struct thr_repository* rep, unsigned int cnt, Ndbd_mem_manager *mm)
 {
+  rep->m_free_list.m_mm = mm;
+
   rep->m_thread_count = cnt;
   for (unsigned int i = 0; i<cnt; i++)
   {
@@ -1571,13 +1547,21 @@ init(struct thr_repository* rep, unsigne
 
 ThreadConfig::ThreadConfig()
 {
-  init(&g_thr_repository, NUM_THREADS);
 }
 
 ThreadConfig::~ThreadConfig()
 {
 }
 
+/*
+ * We must do the init here rather than in the constructor, since at
+ * constructor time the global memory manager is not available.
+ */
+void
+ThreadConfig::init(EmulatorData *emulatorData)
+{
+  ::init(&g_thr_repository, NUM_THREADS, emulatorData->m_mem_manager);
+}
 
 void ThreadConfig::ipControlLoop(Uint32 thread_index)
 {
@@ -1789,6 +1773,7 @@ FastScheduler::dumpSignalMemory(Uint32 t
 {
   void *value= NdbThread_GetTlsKey(NDB_THREAD_TLS_THREAD);
   const thr_data *selfptr = reinterpret_cast<const thr_data *>(value);
+  const thr_repository *rep = &g_thr_repository;
   /*
    * The selfptr might be NULL, or pointer to thread that is doing the crash
    * jump.
@@ -1826,7 +1811,7 @@ FastScheduler::dumpSignalMemory(Uint32 t
   Uint32 seq_start = 0;
   Uint32 seq_end = 0;
 
-  const thr_data *thr_ptr = &g_thr_repository.m_thread[thr_no];
+  const thr_data *thr_ptr = &rep->m_thread[thr_no];
   if (watchDogCounter)
     *watchDogCounter = 4;
 
@@ -1868,7 +1853,7 @@ FastScheduler::dumpSignalMemory(Uint32 t
     idx = (idx + 1) % THR_FREE_BUF_MAX;
   }
   /* Load any active prio B buffers. */
-  for (Uint32 thr_no = 0; thr_no < g_thr_repository.m_thread_count; thr_no++)
+  for (Uint32 thr_no = 0; thr_no < rep->m_thread_count; thr_no++)
   {
     const thr_job_queue *q = thr_ptr->m_in_queue + thr_no;
     const thr_jb_read_state *r = thr_ptr->m_read_states + thr_no;
diff -Nrup a/storage/ndb/src/kernel/vm/ndbd_malloc_impl.hpp b/storage/ndb/src/kernel/vm/ndbd_malloc_impl.hpp
--- a/storage/ndb/src/kernel/vm/ndbd_malloc_impl.hpp	2007-03-08 15:41:45 +01:00
+++ b/storage/ndb/src/kernel/vm/ndbd_malloc_impl.hpp	2007-11-09 10:54:01 +01:00
@@ -78,7 +78,7 @@ public:
 private:
   void grow(Uint32 start, Uint32 cnt);
 
-#define XX_RL_COUNT 4
+#define XX_RL_COUNT 5
   /**
    * Return pointer to free page data on page
    */
Thread
bk commit into 5.1 tree (knielsen:1.2618)knielsen9 Nov