Commit d8b3acdf authored by jonas@eel.(none)'s avatar jonas@eel.(none)

ndb dd

  - add resource limit to buddy allocator
parent af6688dc
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "SimBlockList.hpp" #include "SimBlockList.hpp"
#include "EmulatorData.hpp"
#include <SimulatedBlock.hpp> #include <SimulatedBlock.hpp>
#include <Cmvmi.hpp> #include <Cmvmi.hpp>
#include <Ndbfs.hpp> #include <Ndbfs.hpp>
...@@ -69,7 +70,7 @@ void * operator new (size_t sz, SIMBLOCKLIST_DUMMY dummy){ ...@@ -69,7 +70,7 @@ void * operator new (size_t sz, SIMBLOCKLIST_DUMMY dummy){
#endif #endif
void void
SimBlockList::load(Configuration & conf){ SimBlockList::load(EmulatorData& data){
noOfBlocks = NO_OF_BLOCKS; noOfBlocks = NO_OF_BLOCKS;
theList = new SimulatedBlock * [noOfBlocks]; theList = new SimulatedBlock * [noOfBlocks];
Dbdict* dbdict = 0; Dbdict* dbdict = 0;
...@@ -79,7 +80,7 @@ SimBlockList::load(Configuration & conf){ ...@@ -79,7 +80,7 @@ SimBlockList::load(Configuration & conf){
Tsman* ts = 0; Tsman* ts = 0;
Block_context ctx = Block_context ctx =
{ conf, * (Ndbd_mem_manager*)0 }; { *data.theConfiguration, *data.m_mem_manager };
SimulatedBlock * fs = 0; SimulatedBlock * fs = 0;
{ {
......
...@@ -17,17 +17,6 @@ ...@@ -17,17 +17,6 @@
#ifndef KERNEL_RECORDS_HPP #ifndef KERNEL_RECORDS_HPP
#define KERNEL_RECORDS_HPP #define KERNEL_RECORDS_HPP
/**
* Record types
*/
#define PGMAN_PAGE_REQUEST 1
#define LGMAN_LOG_BUFFER_WAITER 2
#define LGMAN_LOG_SYNC_WAITER 3
#define DBTUP_PAGE_REQUEST 4
#define DBTUP_EXTENT_INFO 5
/** /**
* Resource groups * Resource groups
*/ */
...@@ -47,4 +36,21 @@ ...@@ -47,4 +36,21 @@
*/ */
#define RG_DISK_RECORDS 2 #define RG_DISK_RECORDS 2
/**
*
*/
#define RG_RESERVED 0
#define RG_COUNT 3
/**
* Record types
*/
#define PGMAN_PAGE_REQUEST MAKE_TID(1, RG_DISK_OPERATIONS)
#define LGMAN_LOG_BUFFER_WAITER MAKE_TID(2, RG_DISK_OPERATIONS)
#define LGMAN_LOG_SYNC_WAITER MAKE_TID(3, RG_DISK_OPERATIONS)
#define DBTUP_PAGE_REQUEST MAKE_TID(4, RG_DISK_OPERATIONS)
#define DBTUP_EXTENT_INFO MAKE_TID(5, RG_DISK_RECORDS)
#endif #endif
...@@ -406,7 +406,7 @@ int main(int argc, char** argv) ...@@ -406,7 +406,7 @@ int main(int argc, char** argv)
systemInfo(* theConfig, * theConfig->m_logLevel); systemInfo(* theConfig, * theConfig->m_logLevel);
// Load blocks // Load blocks
globalEmulatorData.theSimBlockList->load(* theConfig); globalEmulatorData.theSimBlockList->load(globalEmulatorData);
// Set thread concurrency for Solaris' light weight processes // Set thread concurrency for Solaris' light weight processes
int status; int status;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "SimBlockList.hpp" #include "SimBlockList.hpp"
#include <NodeState.hpp> #include <NodeState.hpp>
#include "ndbd_malloc_impl.hpp"
#include <NdbMem.h> #include <NdbMem.h>
#include <NdbMutex.h> #include <NdbMutex.h>
...@@ -77,6 +78,7 @@ EmulatorData::EmulatorData(){ ...@@ -77,6 +78,7 @@ EmulatorData::EmulatorData(){
theSimBlockList = 0; theSimBlockList = 0;
theShutdownMutex = 0; theShutdownMutex = 0;
m_socket_server = 0; m_socket_server = 0;
m_mem_manager = 0;
} }
void void
...@@ -93,6 +95,7 @@ EmulatorData::create(){ ...@@ -93,6 +95,7 @@ EmulatorData::create(){
theThreadConfig = new ThreadConfig(); theThreadConfig = new ThreadConfig();
theSimBlockList = new SimBlockList(); theSimBlockList = new SimBlockList();
m_socket_server = new SocketServer(); m_socket_server = new SocketServer();
m_mem_manager = new Ndbd_mem_manager();
theShutdownMutex = NdbMutex_Create(); theShutdownMutex = NdbMutex_Create();
...@@ -111,6 +114,9 @@ EmulatorData::destroy(){ ...@@ -111,6 +114,9 @@ EmulatorData::destroy(){
delete theSimBlockList; theSimBlockList = 0; delete theSimBlockList; theSimBlockList = 0;
if(m_socket_server) if(m_socket_server)
delete m_socket_server; m_socket_server = 0; delete m_socket_server; m_socket_server = 0;
if (m_mem_manager)
delete m_mem_manager; m_mem_manager = 0;
NdbMem_Destroy(); NdbMem_Destroy();
} }
......
...@@ -56,6 +56,7 @@ struct EmulatorData { ...@@ -56,6 +56,7 @@ struct EmulatorData {
class ThreadConfig * theThreadConfig; class ThreadConfig * theThreadConfig;
class SimBlockList * theSimBlockList; class SimBlockList * theSimBlockList;
class SocketServer * m_socket_server; class SocketServer * m_socket_server;
class Ndbd_mem_manager * m_mem_manager;
/** /**
* Constructor * Constructor
......
...@@ -19,7 +19,7 @@ libkernel_a_SOURCES = \ ...@@ -19,7 +19,7 @@ libkernel_a_SOURCES = \
SectionReader.cpp \ SectionReader.cpp \
Mutex.cpp SafeCounter.cpp \ Mutex.cpp SafeCounter.cpp \
Rope.cpp \ Rope.cpp \
ndbd_malloc.cpp ndbd_malloc_impl.cpp ndbd_malloc.cpp ndbd_malloc_impl.cpp Pool.cpp
INCLUDES_LOC = -I$(top_srcdir)/storage/ndb/src/mgmapi INCLUDES_LOC = -I$(top_srcdir)/storage/ndb/src/mgmapi
......
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "Pool.hpp"
#include "SimulatedBlock.hpp"
void*
Pool_context::alloc_page(Uint32 type_id, Uint32 *i)
{
return m_block->m_ctx.m_mm.alloc_page(type_id, i);
}
void
Pool_context::release_page(Uint32 type_id, Uint32 i, void* p)
{
m_block->m_ctx.m_mm.release_page(type_id, i, p);
}
void
Pool_context::handle_abort(const AbortArg &)
{
}
...@@ -19,6 +19,22 @@ ...@@ -19,6 +19,22 @@
#include <kernel_types.h> #include <kernel_types.h>
/**
* Type id is 11 bits record type, and 5 bits resource id
* -> 2048 different kind of records and 32 different resource groups
*
* Resource id is used to handle configuration parameters
*
* see blocks/records_types.hpp
*/
#define RG_BITS 5
#define RG_MASK ((1 << RG_BITS) - 1)
#define MAKE_TID(TID,RG) ((TID << RG_BITS) | RG)
/**
* Record_info
*
*/
struct Record_info struct Record_info
{ {
Uint16 m_size; Uint16 m_size;
...@@ -27,6 +43,9 @@ struct Record_info ...@@ -27,6 +43,9 @@ struct Record_info
Uint16 m_offset_magic; Uint16 m_offset_magic;
}; };
/**
* Resource_limit
*/
struct Resource_limit struct Resource_limit
{ {
Uint32 m_min; Uint32 m_min;
...@@ -38,7 +57,6 @@ struct Resource_limit ...@@ -38,7 +57,6 @@ struct Resource_limit
struct Pool_context struct Pool_context
{ {
class SimulatedBlock* m_block; class SimulatedBlock* m_block;
struct Resource_limit* m_resource_limit;
/** /**
* Alloc consekutive pages * Alloc consekutive pages
...@@ -48,7 +66,7 @@ struct Pool_context ...@@ -48,7 +66,7 @@ struct Pool_context
* *
* Will handle resource limit * Will handle resource limit
*/ */
void* alloc_page(Uint32 *i); void* alloc_page(Uint32 type_id, Uint32 *i);
/** /**
* Release pages * Release pages
...@@ -56,7 +74,7 @@ struct Pool_context ...@@ -56,7 +74,7 @@ struct Pool_context
* @param i : in : i value of first page * @param i : in : i value of first page
* @param p : in : pointer to first page * @param p : in : pointer to first page
*/ */
void release_page(Uint32 i, void* p); void release_page(Uint32 type_id, Uint32 i, void* p);
/** /**
* Alloc consekutive pages * Alloc consekutive pages
...@@ -70,7 +88,7 @@ struct Pool_context ...@@ -70,7 +88,7 @@ struct Pool_context
* *
* Will handle resource limit * Will handle resource limit
*/ */
void* alloc_pages(Uint32 *i, Uint32 *cnt, Uint32 min = 1); void* alloc_pages(Uint32 type_id, Uint32 *i, Uint32 *cnt, Uint32 min =1);
/** /**
* Release pages * Release pages
...@@ -79,7 +97,7 @@ struct Pool_context ...@@ -79,7 +97,7 @@ struct Pool_context
* @param p : in : pointer to first page * @param p : in : pointer to first page
* @param cnt : in : no of pages to release * @param cnt : in : no of pages to release
*/ */
void release_pages(Uint32 i, void* p, Uint32 cnt); void release_pages(Uint32 type_id, Uint32 i, void* p, Uint32 cnt);
/** /**
* Pool abort * Pool abort
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <SimulatedBlock.hpp> #include <SimulatedBlock.hpp>
class Configuration; class EmulatorData;
class SimBlockList class SimBlockList
{ {
...@@ -27,7 +27,7 @@ public: ...@@ -27,7 +27,7 @@ public:
SimBlockList(); SimBlockList();
~SimBlockList(); ~SimBlockList();
void load(Configuration & conf); void load(EmulatorData&);
void unload(); void unload();
private: private:
int noOfBlocks; int noOfBlocks;
......
...@@ -91,6 +91,7 @@ class SimulatedBlock { ...@@ -91,6 +91,7 @@ class SimulatedBlock {
friend class Page_cache_client; friend class Page_cache_client;
friend class Lgman; friend class Lgman;
friend class Logfile_client; friend class Logfile_client;
friend struct Pool_context;
public: public:
friend class BlockComponent; friend class BlockComponent;
virtual ~SimulatedBlock(); virtual ~SimulatedBlock();
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <kernel_types.h> #include <kernel_types.h>
#include <Bitmask.hpp> #include <Bitmask.hpp>
#include <assert.h> #include <assert.h>
#include "Pool.hpp"
/** /**
* 13 -> 8192 words -> 32768 bytes * 13 -> 8192 words -> 32768 bytes
...@@ -51,25 +52,22 @@ struct Free_page_data ...@@ -51,25 +52,22 @@ struct Free_page_data
class Ndbd_mem_manager class Ndbd_mem_manager
{ {
public: public:
Ndbd_mem_manager(Uint32 default_grow = 32); Ndbd_mem_manager();
void set_resource_limit(const Resource_limit& rl);
bool init(bool allow_alloc_less_than_requested = true);
void grow(Uint32 start, Uint32 cnt);
void* get_memroot() const { return (void*)m_base_page;}
void alloc(Uint32* ret, Uint32 *pages, Uint32 min_requested); void alloc(Uint32* ret, Uint32 *pages, Uint32 min_requested);
void release(Uint32 start, Uint32 cnt); void release(Uint32 start, Uint32 cnt);
Uint32 get_no_allocated_pages() const;
Uint32 get_no_used_pages() const;
Uint32 get_no_free_pages() const;
bool init(Uint32 pages = 0);
bool grow(Uint32 pages = 0);
void dump() const ; void dump() const ;
void* get_memroot() const { return (void*)m_base_page;} void* alloc_page(Uint32 type, Uint32* i);
void release_page(Uint32 type, Uint32 i, void * p);
void* alloc(Uint32 * pages, Uint32 min_requested);
void release(void* ptr, Uint32 cnt);
/** /**
* Compute 2log of size * Compute 2log of size
* @note size = 0 -> 0 * @note size = 0 -> 0
...@@ -78,18 +76,15 @@ public: ...@@ -78,18 +76,15 @@ public:
static Uint32 log2(Uint32 size); static Uint32 log2(Uint32 size);
private: private:
#define XX_RL_COUNT 3
/** /**
* Return pointer to free page data on page * Return pointer to free page data on page
*/ */
static Free_page_data* get_free_page_data(Alloc_page*, Uint32 idx); static Free_page_data* get_free_page_data(Alloc_page*, Uint32 idx);
Bitmask<1> m_used_bitmap_pages;
Uint32 m_pages_alloc;
Uint32 m_pages_used;
Uint32 m_grow_size;
Uint32 m_buddy_lists[16]; Uint32 m_buddy_lists[16];
Resource_limit m_resource_limit[XX_RL_COUNT]; // RG_COUNT in record_types.hpp
void * m_base;
Alloc_page * m_base_page; Alloc_page * m_base_page;
void release_impl(Uint32 start, Uint32 cnt); void release_impl(Uint32 start, Uint32 cnt);
...@@ -121,7 +116,7 @@ Ndbd_mem_manager::set(Uint32 first, Uint32 last) ...@@ -121,7 +116,7 @@ Ndbd_mem_manager::set(Uint32 first, Uint32 last)
#if ((SPACE_PER_BMP_2LOG < 32) && (SIZEOF_CHARP == 4)) || (SIZEOF_CHARP == 8) #if ((SPACE_PER_BMP_2LOG < 32) && (SIZEOF_CHARP == 4)) || (SIZEOF_CHARP == 8)
Uint32 bmp = first & ~((1 << BPP_2LOG) - 1); Uint32 bmp = first & ~((1 << BPP_2LOG) - 1);
assert((first >> BPP_2LOG) == (last >> BPP_2LOG)); assert((first >> BPP_2LOG) == (last >> BPP_2LOG));
assert(bmp < m_pages_alloc); assert(bmp < m_resource_limit[0].m_resource_id);
first -= bmp; first -= bmp;
last -= bmp; last -= bmp;
...@@ -139,7 +134,7 @@ Ndbd_mem_manager::clear(Uint32 first, Uint32 last) ...@@ -139,7 +134,7 @@ Ndbd_mem_manager::clear(Uint32 first, Uint32 last)
#if ((SPACE_PER_BMP_2LOG < 32) && (SIZEOF_CHARP == 4)) || (SIZEOF_CHARP == 8) #if ((SPACE_PER_BMP_2LOG < 32) && (SIZEOF_CHARP == 4)) || (SIZEOF_CHARP == 8)
Uint32 bmp = first & ~((1 << BPP_2LOG) - 1); Uint32 bmp = first & ~((1 << BPP_2LOG) - 1);
assert((first >> BPP_2LOG) == (last >> BPP_2LOG)); assert((first >> BPP_2LOG) == (last >> BPP_2LOG));
assert(bmp < m_pages_alloc); assert(bmp < m_resource_limit[0].m_resource_id);
first -= bmp; first -= bmp;
last -= bmp; last -= bmp;
...@@ -157,7 +152,7 @@ Ndbd_mem_manager::clear_and_set(Uint32 first, Uint32 last) ...@@ -157,7 +152,7 @@ Ndbd_mem_manager::clear_and_set(Uint32 first, Uint32 last)
#if ((SPACE_PER_BMP_2LOG < 32) && (SIZEOF_CHARP == 4)) || (SIZEOF_CHARP == 8) #if ((SPACE_PER_BMP_2LOG < 32) && (SIZEOF_CHARP == 4)) || (SIZEOF_CHARP == 8)
Uint32 bmp = first & ~((1 << BPP_2LOG) - 1); Uint32 bmp = first & ~((1 << BPP_2LOG) - 1);
assert((first >> BPP_2LOG) == (last >> BPP_2LOG)); assert((first >> BPP_2LOG) == (last >> BPP_2LOG));
assert(bmp < m_pages_alloc); assert(bmp < m_resource_limit[0].m_resource_id);
first -= bmp; first -= bmp;
last -= bmp; last -= bmp;
...@@ -177,7 +172,7 @@ Ndbd_mem_manager::check(Uint32 first, Uint32 last) ...@@ -177,7 +172,7 @@ Ndbd_mem_manager::check(Uint32 first, Uint32 last)
#if ((SPACE_PER_BMP_2LOG < 32) && (SIZEOF_CHARP == 4)) || (SIZEOF_CHARP == 8) #if ((SPACE_PER_BMP_2LOG < 32) && (SIZEOF_CHARP == 4)) || (SIZEOF_CHARP == 8)
Uint32 bmp = first & ~((1 << BPP_2LOG) - 1); Uint32 bmp = first & ~((1 << BPP_2LOG) - 1);
assert((first >> BPP_2LOG) == (last >> BPP_2LOG)); assert((first >> BPP_2LOG) == (last >> BPP_2LOG));
assert(bmp < m_pages_alloc); assert(bmp < m_resource_limit[0].m_resource_id);
first -= bmp; first -= bmp;
last -= bmp; last -= bmp;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment