Repository: trafodion Updated Branches: refs/heads/master 279ef7bc6 -> 8b6a6bbeb
[TRAFOFION-2731] CodeCleanup: Removed the obsolete code in NAMemory and CliGlobals classes Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/806e93b2 Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/806e93b2 Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/806e93b2 Branch: refs/heads/master Commit: 806e93b2ca81e6172f0a210ab852c3d4c2af59c2 Parents: 3dbfa89 Author: selvaganesang <[email protected]> Authored: Wed Jan 10 23:13:31 2018 +0000 Committer: selvaganesang <[email protected]> Committed: Thu Jan 11 04:39:21 2018 +0000 ---------------------------------------------------------------------- core/sql/arkcmp/CmpContext.cpp | 2 +- core/sql/arkcmp/CmpStatement.cpp | 2 +- core/sql/cli/Globals.cpp | 68 +------- core/sql/cli/Globals.h | 71 -------- core/sql/common/NAAssert.h | 7 - core/sql/common/NAMemory.cpp | 291 ++++++++------------------------ core/sql/common/NAMemory.h | 135 +++------------ core/sql/runtimestats/SqlStats.cpp | 5 +- core/sql/runtimestats/SqlStats.h | 1 - 9 files changed, 97 insertions(+), 485 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafodion/blob/806e93b2/core/sql/arkcmp/CmpContext.cpp ---------------------------------------------------------------------- diff --git a/core/sql/arkcmp/CmpContext.cpp b/core/sql/arkcmp/CmpContext.cpp index 1b30b3d..6df3ddc 100644 --- a/core/sql/arkcmp/CmpContext.cpp +++ b/core/sql/arkcmp/CmpContext.cpp @@ -211,7 +211,7 @@ CmpContext::CmpContext(UInt32 f, CollHeap * h) memLimit = (size_t) 1024 * CmpCommon::getDefaultLong(MEMORY_LIMIT_HISTCACHE_UPPER_KB); const Lng32 initHeapSize = 16 * 1024; // ## 16K NAHeap *histogramCacheHeap = new (heap_) - NAHeap("HistogramCache Heap", + NAHeap((const char *)"HistogramCache Heap", heap_, initHeapSize, memLimit); http://git-wip-us.apache.org/repos/asf/trafodion/blob/806e93b2/core/sql/arkcmp/CmpStatement.cpp ---------------------------------------------------------------------- diff --git a/core/sql/arkcmp/CmpStatement.cpp b/core/sql/arkcmp/CmpStatement.cpp index f352876..d1b8e22 100644 --- a/core/sql/arkcmp/CmpStatement.cpp +++ b/core/sql/arkcmp/CmpStatement.cpp @@ -165,7 +165,7 @@ CmpStatement::CmpStatement(CmpContext* context, { // set up statement heap with 32 KB allocation units size_t memLimit = (size_t) 1024 * CmpCommon::getDefaultLong(MEMORY_LIMIT_CMPSTMT_UPPER_KB); - heap_ = new (context_->heap()) NAHeap("Cmp Statement Heap", + heap_ = new (context_->heap()) NAHeap((const char *)"Cmp Statement Heap", context_->heap(), (Lng32)32768, memLimit); http://git-wip-us.apache.org/repos/asf/trafodion/blob/806e93b2/core/sql/cli/Globals.cpp ---------------------------------------------------------------------- diff --git a/core/sql/cli/Globals.cpp b/core/sql/cli/Globals.cpp index b9dd6e5..e6f64eb 100644 --- a/core/sql/cli/Globals.cpp +++ b/core/sql/cli/Globals.cpp @@ -74,14 +74,8 @@ CLISemaphore globalSemaphore ; CliGlobals::CliGlobals(NABoolean espProcess) : inConstructor_(TRUE), - executorMemory_("Global Executor Memory",0,0, - 0,0,0, &segGlobals_), + executorMemory_((const char *)"Global Executor Memory"), contextList_(NULL), - defaultVolSeed_(0), - listOfVolNames_(NULL), - listOfAuditedVols_(NULL), - listOfVolNamesCacheTime_(-1), - sysVolNameInitialized_(FALSE), envvars_(NULL), envvarsContext_(0), sharedArkcmp_(NULL), @@ -90,16 +84,10 @@ CliGlobals::CliGlobals(NABoolean espProcess) totalCliCalls_(0), savedCompilerVersion_ (COM_VERS_COMPILER_VERSION), globalSbbCount_(0), - // sessionDefaults_(NULL), priorityChanged_(FALSE), currRootTcb_(NULL), processStats_(NULL), savedPriority_(148), // Set it to some valid priority to start with - qualifyingVolsPerNode_(NULL), - cpuNumbers_(NULL), - capacities_(NULL), - freespaces_(NULL), - largestFragments_(NULL), tidList_(NULL), cliSemaphore_(NULL), defaultContext_(NULL), @@ -134,7 +122,6 @@ void CliGlobals::init( NABoolean espProcess, _sqptr = new (&executorMemory_) char[10]; numCliCalls_ = 0; - logEmsEvents_ = TRUE; nodeName_[0] = '\0'; breakEnabled_ = FALSE; @@ -181,10 +168,6 @@ void CliGlobals::init( NABoolean espProcess, // Create the process global ARKCMP server. sharedArkcmp_ = NULL; nextUniqueContextHandle = DEFAULT_CONTEXT_HANDLE; - - arlibHeap_ = new (&executorMemory_) NAHeap("MXARLIB Cache Heap", - &executorMemory_, - (Lng32) 32768); lastUniqueNumber_ = 0; sessionUniqueNumber_ = 0; // It is not thread safe to set the globals cli_globals @@ -243,11 +226,6 @@ void CliGlobals::init( NABoolean espProcess, tidList_ = new(&executorMemory_) HashQueue(&executorMemory_); SQLCTX_HANDLE ch = defaultContext_->getContextHandle(); contextList_->insert((char*)&ch, sizeof(SQLCTX_HANDLE), (void*)defaultContext_); - qualifyingVolsPerNode_.setHeap(defaultContext_->exCollHeap()); - cpuNumbers_.setHeap(defaultContext_->exCollHeap()); - capacities_.setHeap(defaultContext_->exCollHeap()); - freespaces_.setHeap(defaultContext_->exCollHeap()); - largestFragments_.setHeap(defaultContext_->exCollHeap()); if (statsGlobals_ != NULL) memMonitor_ = statsGlobals_->getMemoryMonitor(); else @@ -307,11 +285,6 @@ CliGlobals::~CliGlobals() delete sharedArkcmp_; sharedArkcmp_ = NULL; } - if (arlibHeap_) - { - delete arlibHeap_; - arlibHeap_ = NULL; - } if (statsGlobals_ != NULL) { error = statsGlobals_->getStatsSemaphore(semId_, myPin_); @@ -894,45 +867,6 @@ Lng32 CliGlobals::resetContext(ContextCli *theContext, void *contextMsg) return SUCCESS; } -void CliGlobals::clearQualifiedDiskInfo() -{ - CollHeap *heap = defaultContext_->exCollHeap(); - - nodeName_[0] = '\0'; - - while (!qualifyingVolsPerNode_.isEmpty()) - { - char *volume; - // getFirst() removes and returns the first element in - // the container. - qualifyingVolsPerNode_.getFirst(volume); - NADELETEBASIC(volume, heap); // Allocated in addQualifiedDiskInfo() - } - - cpuNumbers_.clear(); - capacities_.clear(); - freespaces_.clear(); - largestFragments_.clear(); -} - -void CliGlobals::addQualifiedDiskInfo( - const char *volumeName, - Lng32 primaryCpu, - Lng32 capacity, - Lng32 freeSpace, - Lng32 largestFragment) -{ - CollHeap *heap = defaultContext_->exCollHeap(); - char *volName = new(heap) char[9]; // deleted in clearQualifiedDiskInfo() - strcpy(volName, volumeName); - - qualifyingVolsPerNode_.insert(volName); - cpuNumbers_.insert(primaryCpu); - capacities_.insert(capacity); - freespaces_.insert(freeSpace); - largestFragments_.insert(largestFragment); -} - NAHeap *CliGlobals::getCurrContextHeap() { return currContext()->exHeap(); http://git-wip-us.apache.org/repos/asf/trafodion/blob/806e93b2/core/sql/cli/Globals.h ---------------------------------------------------------------------- diff --git a/core/sql/cli/Globals.h b/core/sql/cli/Globals.h index ce9ecb0..284d992 100644 --- a/core/sql/cli/Globals.h +++ b/core/sql/cli/Globals.h @@ -159,46 +159,10 @@ public: inline void setMemoryMonitor(MemoryMonitor *memMon) { memMonitor_ = memMon; } inline NAHeap * getExecutorMemory() { return &executorMemory_; } - inline NAHeap * getNoWaitHeap() { return noWaitSQLHeap_; } - - inline short getSegId(Lng32 &index) - { return segGlobals_.getSegId(index); } - inline const NASegGlobals * getSegGlobals() const - - { return &segGlobals_; } - inline UInt32 getDefaultVolSeed() { return defaultVolSeed_; } - inline void setDefaultVolSeed( UInt32 seed) - { defaultVolSeed_ = seed; } - inline char ** getListOfVolNames() { return listOfVolNames_; } - inline void setListOfVolNames( char ** pVols) - { listOfVolNames_ = pVols; } - inline void * getListOfAuditedVols() { return listOfAuditedVols_; } - inline void setListOfAuditedVols( void *p) - { listOfAuditedVols_ = p; } - inline Int64 getListOfVolNamesCacheTime() // 64-bit - { return listOfVolNamesCacheTime_; } - inline void setListOfVolNamesCacheTime(Int64 cacheTime) - { listOfVolNamesCacheTime_ = cacheTime; } - inline NABoolean isSysVolNameInitialized() - { return sysVolNameInitialized_; } - inline void setSysVolNameIsInitialized() - { sysVolNameInitialized_ = TRUE; } - inline char * getSysVolName() { return sysVolName_; } - - void clearQualifiedDiskInfo(); - void addQualifiedDiskInfo(const char *volumeName, Lng32 primaryCpu, - Lng32 capacity, Lng32 freeSpace, Lng32 largestFragment); inline void setNodeName(const char *nodeName) { strncpy(nodeName_, nodeName, sizeof(nodeName_)); } inline char *getNodeName() { return nodeName_; } - inline Lng32 getNumOfQualifyingVols() { return qualifyingVolsPerNode_.entries(); } - inline char *getQualifyingVolume(Lng32 i) { return qualifyingVolsPerNode_[i]; } - inline Lng32 getCpuNumberForVol(Lng32 i) { return cpuNumbers_[i]; } - inline Lng32 getCapacityForVol(Lng32 i) { return capacities_[i]; } - inline Lng32 getFreespaceForVol(Lng32 i) { return freespaces_[i]; } - inline Lng32 getLargestFragmentForVol(Lng32 i) { return largestFragments_[i]; } - inline Lng32 incrNumOfCliCalls() { return ++numCliCalls_; } inline Lng32 decrNumOfCliCalls() { @@ -439,39 +403,12 @@ private: // executor memory that maintains all heap memory for this executor NAHeap executorMemory_; - // Object that contains: 1) attributes of the first flat segment - // 2) array of secondary segment ids - NASegGlobals segGlobals_; - // heap used by the IPC procedures NAHeap * ipcHeap_; // memory monitor for this process MemoryMonitor *memMonitor_; - // heap used by no-wait SQL procedures - NAHeap * noWaitSQLHeap_; - - // Cache of descriptive table information from resource forks. Used - // in the audit reading CLI procedures called by utilities and by - // TMFARLB2. Code for these audit reading procedures is in - // CliMxArLib.cpp. - NAHeap *arlibHeap_; - // - // used by the catalog manager get-default-volume algorithm - // - UInt32 defaultVolSeed_; - char ** listOfVolNames_; - void * listOfAuditedVols_; - Int64 listOfVolNamesCacheTime_; // 64-bit - - // - // cache the Tandem System Volume name - // - NABoolean sysVolNameInitialized_; - char sysVolName_[ 18 ]; // '$' + VOLNAME + '.' + - // SUBVOL + null-terminator - // copy of the oss envvars char ** envvars_; @@ -515,8 +452,6 @@ private: // location of the application program which is calling SQL. // Fully qualified oss pathname for OSS processes. - // \sys.$vol.subvol for guardian processes. Currently, programDir_ - // is not set or used for guardian processes. char * programDir_; short processType_; // 0, oss process. 1, guardian process. NABoolean logReclaimEventDone_; @@ -550,13 +485,7 @@ private: // EMS event descriptor SQLMXLoggingArea::ExperienceLevel emsEventExperienceLevel_; - // these vars are used by GetListOfQualifyingVolumes.. methods. char nodeName_[9]; - LIST(char *) qualifyingVolsPerNode_; - LIST(Lng32) cpuNumbers_; - LIST(Lng32) capacities_; - LIST(Lng32) freespaces_; - LIST(Lng32) largestFragments_; StatsGlobals *statsGlobals_; // heap used for the Stats collection http://git-wip-us.apache.org/repos/asf/trafodion/blob/806e93b2/core/sql/common/NAAssert.h ---------------------------------------------------------------------- diff --git a/core/sql/common/NAAssert.h b/core/sql/common/NAAssert.h index 4c37de7..7121060 100644 --- a/core/sql/common/NAAssert.h +++ b/core/sql/common/NAAssert.h @@ -97,18 +97,11 @@ public: inline jmp_buf *getJmpBuf() { return &longJmpTgt_; } inline jmp_buf *getJmpBufPtr() { return longJmpTgtPtr_; } inline void setJmpBufPtr(jmp_buf *longJmpTgtPtr) { longJmpTgtPtr_ = longJmpTgtPtr; } - inline NABoolean getLogEmsEvents() const { return logEmsEvents_; } - inline void setLogEmsEvents(NABoolean logEmsEvents) { logEmsEvents_ = logEmsEvents; } - inline void setQfoProcessing() { qfoProcessing_ = TRUE; } - inline void clearQfoProcessing() { qfoProcessing_ = FALSE; } - inline NABoolean isQfoProcessing() { return qfoProcessing_; } protected: NABoolean globalsAreInitialized_; jmp_buf *longJmpTgtPtr_; jmp_buf longJmpTgt_; long numCliCalls_; - NABoolean logEmsEvents_; - NABoolean qfoProcessing_; }; NAAssertGlobals * GetNAAssertGlobals(NABoolean *logEmsEvents = NULL); http://git-wip-us.apache.org/repos/asf/trafodion/blob/806e93b2/core/sql/common/NAMemory.cpp ---------------------------------------------------------------------- diff --git a/core/sql/common/NAMemory.cpp b/core/sql/common/NAMemory.cpp index d96351a..0c13caa 100644 --- a/core/sql/common/NAMemory.cpp +++ b/core/sql/common/NAMemory.cpp @@ -852,7 +852,7 @@ NAMemory::sysFreeBlock(NABlock *blk) #ifndef MUSE NAMemory::NAMemory(const char * name) : - type_(NO_MEMORY_TYPE), + type_(EXECUTOR_MEMORY), maximumSize_((size_t)-1), // no maximum parent_(NULL), firstBlk_(NULL), @@ -864,7 +864,6 @@ NAMemory::NAMemory(const char * name) totalSize_(0), blockCnt_(0), thBlockCnt_(DEFAULT_THRESHOLD_BLOCK_COUNT), - segGlobals_(0), memoryList_(NULL), lastListEntry_(NULL), nextEntry_(NULL), @@ -879,6 +878,7 @@ NAMemory::NAMemory(const char * name) , maxVmSize_(0l) , sharedMemory_(FALSE) { + setType(type_, 0); #if ( defined(_DEBUG) || defined(NSK_MEMDEBUG) ) char * debugLevel = getenv("MEMDEBUG"); if (debugLevel) @@ -915,7 +915,6 @@ NAMemory::NAMemory(const char * name, NAHeap * parent, size_t blockSize, totalSize_(0), blockCnt_(0), thBlockCnt_(DEFAULT_THRESHOLD_BLOCK_COUNT), - segGlobals_(0), memoryList_(NULL), lastListEntry_(NULL), nextEntry_(NULL), @@ -972,7 +971,6 @@ NAMemory::NAMemory(const char * name, NAMemoryType type, size_t blockSize, totalSize_(0), blockCnt_(0), thBlockCnt_(DEFAULT_THRESHOLD_BLOCK_COUNT), - segGlobals_(0), memoryList_(NULL), lastListEntry_(NULL), nextEntry_(NULL), @@ -1008,13 +1006,10 @@ NAMemory::NAMemory(const char * name, NAMemoryType type, size_t blockSize, } NAMemory::NAMemory(const char * name, - SEG_ID extFirstSegId, - void * extFirstSegStart, - off_t extFirstSegOffset, - size_t extFirstSegLen, - size_t extFirstSegMaxLen, - NASegGlobals *segGlobals, - Lng32 extMaxSecSegCount) + SEG_ID segmentId, + void * baseAddr, + off_t heapStartOffset, + size_t maxSize) : type_(EXECUTOR_MEMORY), parent_(NULL), @@ -1027,7 +1022,6 @@ NAMemory::NAMemory(const char * name, totalSize_(0), blockCnt_(0), thBlockCnt_(DEFAULT_THRESHOLD_BLOCK_COUNT), - segGlobals_(segGlobals), memoryList_(NULL), lastListEntry_(NULL), nextEntry_(NULL), @@ -1042,13 +1036,6 @@ NAMemory::NAMemory(const char * name, , maxVmSize_(0l) , sharedMemory_(FALSE) { - segGlobals_->setFirstSegInfo(extFirstSegId, - extFirstSegStart, - extFirstSegOffset, - extFirstSegLen, - extFirstSegMaxLen); - segGlobals_->setMaxSecSegCount(extMaxSecSegCount); - // call setType to initialize the values of all the sizes setType(type_, 0); @@ -1068,18 +1055,19 @@ NAMemory::NAMemory(const char * name, // space in the segment, then initialize the firstBlk_ within // the passed in memory. The NAHeap constructor will initialize // the top NAHeapFragment. - if (extFirstSegStart != NULL) { + if (baseAddr != NULL) { blockCnt_ = 1; - size_t tsize = extFirstSegLen - extFirstSegOffset - BLOCK_OVERHEAD; + size_t tsize = maxSize - heapStartOffset - BLOCK_OVERHEAD; if (tsize > (8 * sizeof(size_t))) { - firstBlk_ = (NABlock*)((char*)extFirstSegStart + extFirstSegOffset); - firstBlk_->size_ = extFirstSegLen - extFirstSegOffset; + firstBlk_ = (NABlock*)((char*)baseAddr + heapStartOffset); + firstBlk_->size_ = maxSize - heapStartOffset; firstBlk_->sflags_ = NABlock::EXTERN_BIT; firstBlk_->next_ = NULL; - firstBlk_->segmentId_ = extFirstSegId; + firstBlk_->segmentId_ = segmentId; + totalSize_ = initialSize_ = maximumSize_ = firstBlk_->size_; } } - + upperLimit_ = maxSize; // need to initialize an NAStringRef object "on top" of the array // (don't touch this unless you know what you're doing!) NAStringRef * tmp = @@ -1087,6 +1075,7 @@ NAMemory::NAMemory(const char * name, NAStringRef (NAStringRef::NULL_CTOR, this) ; } + void NAMemory::reInitialize() { // delete all blocks allocated for this heap and re-set the heap @@ -1131,9 +1120,7 @@ void NAMemory::reInitialize() // This code provides mutual exclusion for the runtime stats shared // memory segment. short semRetcode = 0; - if (parent_->getType() == EXECUTOR_MEMORY && - parent_->getSegGlobals() != NULL && - parent_->getSegGlobals()->getFirstSegId() == getStatsSegmentId()) { + if (parent_->getType() == EXECUTOR_MEMORY && getSharedMemory()) { semRetcode = getRTSSemaphore(); } while (p) { @@ -1174,7 +1161,7 @@ void NAMemory::reInitialize() firstBlk_ = externSegment; firstBlk_->next_ = NULL; blockCnt_ = 1; - totalSize_ = firstBlk_->size_ - segGlobals_->getFirstSegOffset(); + totalSize_ = firstBlk_->size_ ; } // If this is an NAHeap, then call reInitializeHeap() to reinitialize @@ -1207,24 +1194,9 @@ void NAMemory::setType(NAMemoryType type, Lng32 blockSize) switch(type_) { case EXECUTOR_MEMORY: - // input parameter blockSize is ignored - // this is an NAMemory using flat segments on NSK - if (segGlobals_ && segGlobals_->getFirstSegStart()) - { - // take the segment size and max. size from the externally - // provided // segment - totalSize_ = initialSize_ = segGlobals_->getFirstSegLen() - - segGlobals_->getFirstSegOffset(); - maximumSize_ = segGlobals_->getFirstSegMaxLen() - - segGlobals_->getFirstSegOffset(); - } - else - { - initialSize_ = DEFAULT_NT_HEAP_INIT_SIZE ; - maximumSize_ = DEFAULT_NT_HEAP_MAX_SIZE ; // no maximum - incrementSize_ = DEFAULT_NT_HEAP_INCR_SIZE ; - } - + initialSize_ = DEFAULT_NT_HEAP_INIT_SIZE ; + maximumSize_ = DEFAULT_NT_HEAP_MAX_SIZE ; // no maximum + incrementSize_ = DEFAULT_NT_HEAP_INCR_SIZE ; break; case SYSTEM_MEMORY: @@ -1972,9 +1944,7 @@ NAHeap::deallocateFreeBlock(NAHeapFragment *p) HEAPLOG_OFF() // no recursive logging. // This code provides mutual exclusion for the runtime stats shared // memory segment. - if (parent_->getType() == EXECUTOR_MEMORY && - parent_->getSegGlobals() != NULL && - parent_->getSegGlobals()->getFirstSegId() == getStatsSegmentId()) { + if (parent_->getType() == EXECUTOR_MEMORY && getSharedMemory()) { short retcode = getRTSSemaphore(); parent_->deallocateHeapMemory((void*)curr); if (retcode == 1) @@ -2218,7 +2188,7 @@ NAHeap::allocateBlock(size_t size, NABoolean failureIsFatal) // This could be either Global Executor Memory or Stats Globals // Don't add a block if Stats Globals! - if (getSegGlobals()->getFirstSegId() == getStatsSegmentId()) + if (getSharedMemory()) return NULL; // Try to allocate the NABlock using mmap(). If it succeeds return the @@ -2276,9 +2246,7 @@ NAHeap::allocateBlock(size_t size, NABoolean failureIsFatal) // semaphore is obtained in allocateHeapMemory or deallocateHeapMemory // for both global and process stats heap. But leaving it now // since it won't hurt other than extra cpu cycles - if (getSharedMemory() || (parent_->getType() == EXECUTOR_MEMORY && - parent_->getSegGlobals() != NULL && - parent_->getSegGlobals()->getFirstSegId() == getStatsSegmentId())) { + if (getSharedMemory()) { short retcode = getRTSSemaphore(); p = (NABlock*)parent_->allocateHeapMemory(blockSize, FALSE); @@ -2455,146 +2423,6 @@ NABoolean NAMemory::checkSize(size_t size, NABoolean failureIsFatal) } // --------------------------------------------------------------------------- -// NASegGlobals methods -// --------------------------------------------------------------------------- -void NASegGlobals::setFirstSegInfo(SEG_ID firstSegId, - void * firstSegStart, - off_t firstSegOffset, - size_t firstSegLen, - size_t firstSegMaxLen) -{ - firstSegId_ = firstSegId; - firstSegStart_ = firstSegStart; - firstSegOffset_ = firstSegOffset; - firstSegLen_ = firstSegLen; - firstSegMaxLen_ = firstSegMaxLen; - addedSegCount_ = 0; - lowWaterMark_ = firstSegStart; - highWaterMark_ = (void *) ((char *)firstSegStart + firstSegLen); - for (Int32 i = 0; i < NA_MAX_SECONDARY_SEGS; i++) - { - addedSegId_[i] = 0; - startAddresses_[i] = 0; - lengths_[i] = 0; - } -} - -Int32 NASegGlobals::addSegId(short segId, void *start, size_t len) -{ - if (addedSegCount_ == NA_MAX_SECONDARY_SEGS) - { - return 0; - } - else - { - Int32 segOffset = (Int32)(segId - firstSegId_ - 1); - addedSegId_[segOffset] = segId; - startAddresses_[segOffset] = start; - lengths_[segOffset] = len; - addedSegCount_++; - } - - void *end = (void *) ((char *)start + len); - if (lowWaterMark_ > start) - lowWaterMark_ = start; - if (highWaterMark_ < end) - highWaterMark_ = end; - return 1; -} - -void NASegGlobals::deleteSegId(short segId) -{ - Lng32 addedSegCount, i; - void *start, *end; - Int32 segOffset = (Int32)(segId - firstSegId_ -1); - assert (--addedSegCount_ >= 0); - addedSegId_[segOffset] = 0; - startAddresses_[segOffset] = 0; - lengths_[segOffset] = 0; - lowWaterMark_ = firstSegStart_; - highWaterMark_ = (void *) ((char *)firstSegStart_ + firstSegLen_); - for (addedSegCount = 0, i = 0; addedSegCount < addedSegCount_; i++) { - if (addedSegId_[i] != 0) - { - addedSegCount += 1; - start = startAddresses_[i]; - end = (void *) ((char *)start + lengths_[i]); - if (lowWaterMark_ > start) - lowWaterMark_ = start; - if (highWaterMark_ < end) - highWaterMark_ = end; - } - } -} - -void NASegGlobals::resizeSeg(short segId, void *start, size_t newLen) -{ - Lng32 addedSegCount, i; - void *end = (void *) ((char *)start + newLen); - if (lowWaterMark_ > start) - lowWaterMark_ = start; - if (highWaterMark_ < end) - highWaterMark_ = end; - - if (segId == firstSegId_) - { - firstSegLen_ = newLen; - } - else - { - for (addedSegCount = 0, i = 0; addedSegCount < addedSegCount_; i++) - { - if (addedSegId_[i] != 0) - { - addedSegCount += 1; - if (segId == addedSegId_[i]) - { - lengths_[i] = newLen; - return; - } - } - } - } -} - -NABoolean NASegGlobals::overlaps(void *start, size_t len) const -{ - // check the easy things first, performance of this method is critical - // because it is used in boundscheck routines that are frequently called - Lng32 addedSegCount, i; - void *end = (void *) ((char *)start + len); - - // sanity check, does the provided memory range wrap around the end - // of the 32 bit addressing range (refuse to deal with such ranges - // and just return an overlap) - if (start > end) - return TRUE; - - // quick check, using low and high water marks - if (end <= lowWaterMark_ || start >= highWaterMark_) - return FALSE; - - // quick check won't work, loop over each executor segment separately - // in case the memory range lies between two executor segments. - for (addedSegCount = 0, i = 0; addedSegCount < addedSegCount_; i++) - { - if (addedSegId_[i] != 0) - { - addedSegCount += 1; - void *startSeg = startAddresses_[i]; - void *endSeg = (void *) ((char *)startSeg + lengths_[i]); - - // if the start address of the segment or its last byte lie - // in the range then there is an overlap - if (start <= startSeg && end > startSeg || - start < endSeg && end >= endSeg) - return TRUE; - } - } - return FALSE; -} - -// --------------------------------------------------------------------------- // NAHeap methods // --------------------------------------------------------------------------- #ifndef MUSE @@ -2623,7 +2451,7 @@ NAHeap::NAHeap() NAHeap::NAHeap(const char * name, NAHeap * parent, Lng32 blockSize, - Lng32 upperLimit) + size_t upperLimit) : NAMemory(name, parent, blockSize, upperLimit), smallmap_(0), treemap_(0), @@ -2653,7 +2481,7 @@ NAHeap::NAHeap(const char * name, NAHeap::NAHeap(const char * name, NAMemoryType type, Lng32 blockSize, - Lng32 upperLimit) + size_t upperLimit) : NAMemory(name, type, blockSize, upperLimit), smallmap_(0), treemap_(0), @@ -2675,17 +2503,51 @@ NAHeap::NAHeap(const char * name, #endif // _DEBUG } -NAHeap::NAHeap(const char * name, - SEG_ID extFirstSegId, - void * extFirstSegStart, - Lng32 extFirstSegOffset, - Lng32 extFirstSegLen, - Lng32 extFirstSegMaxLen, - NASegGlobals *segGlobals, - Lng32 extMaxSecSegCount) - : NAMemory(name, extFirstSegId, extFirstSegStart, extFirstSegOffset, - extFirstSegLen, extFirstSegMaxLen, segGlobals, - extMaxSecSegCount), +NAHeap::NAHeap(const char * name) + : NAMemory(name), + smallmap_(0), + treemap_(0), + dvsize_(0), + topsize_(0), + least_addr_(0), + dv_(NULL), + top_(NULL), + errCallback_(NULL) +{ + initBins(); + derivedClass_ = NAHEAP_CLASS; + + if (firstBlk_) { + initTop(firstBlk_); + least_addr_ = (char*)firstBlk_; + } + + if (deallocTraceArray == 0) + { + char *deallocTraceEnvvar = getenv("EXE_DEALLOC_MEM_TRACE"); + if (deallocTraceEnvvar != NULL) + { + deallocTraceArray = + (DeallocTraceEntry (*) [deallocTraceEntries])malloc(sizeof(DeallocTraceEntry) * deallocTraceEntries); + memset((void *)deallocTraceArray, '\0', sizeof(DeallocTraceEntry) * deallocTraceEntries); + } + } + + threadSafe_ = false; + memset(&mutex_, '\0', sizeof(mutex_)); + +#ifdef _DEBUG + setAllocTrace(); +#endif // _DEBUG +} + +// Constructor that imposes the NAHeap struture on already allocated memory +NAHeap::NAHeap(const char * name, + SEG_ID segmentId, + void * baseAddr, + off_t heapStartOffset, + size_t maxSize) + : NAMemory(name, segmentId, baseAddr, heapStartOffset, maxSize), smallmap_(0), treemap_(0), dvsize_(0), @@ -2806,8 +2668,6 @@ void NAHeap::reInitializeHeap() // That code frees the NABlocks and will reinitialize the firstBlk_ // if it was allocated externally. if (firstBlk_ != NULL) { - assert((char*)firstBlk_ == (char*)segGlobals_->getFirstSegStart() - + segGlobals_->getFirstSegOffset()); least_addr_ = (char*)firstBlk_; initTop(firstBlk_); } @@ -2902,9 +2762,7 @@ void * NAHeap::allocateHeapMemory(size_t userSize, NABoolean failureIsFatal) // getSharedMemory() check alone is enough since it will return for both // global and process stats heap. Leaving the rest of the condition here // - if (getSharedMemory() || (parent_ && parent_->getType() == EXECUTOR_MEMORY && - parent_->getSegGlobals() != NULL && - parent_->getSegGlobals()->getFirstSegId() == getStatsSegmentId())) + if (getSharedMemory()) { // Check if you are within semaphore if (! checkIfRTSSemaphoreLocked()) @@ -2949,10 +2807,7 @@ void * NAHeap::allocateHeapMemory(size_t userSize, NABoolean failureIsFatal) // then allocate a NABlock using mmap(). This prevents any changes // to the "top_" fragment and allows the memory used by the request to // be returned to the operating system when the user frees it. - if (additionalUserSize >= MIN_MMAP_ALLOC_SIZE && parent_ == NULL - && (getSegGlobals() == NULL || - getSegGlobals()->getFirstSegId() != getStatsSegmentId()) - ) + if (additionalUserSize >= MIN_MMAP_ALLOC_SIZE && parent_ == NULL && (! getSharedMemory())) { nb = PAD_REQUEST(additionalUserSize); @@ -3231,9 +3086,7 @@ void NAHeap::deallocateHeapMemory(void* addr) NAMutex mutex(threadSafe_, &mutex_); - if (getSharedMemory() || (parent_ && parent_->getType() == EXECUTOR_MEMORY && - parent_->getSegGlobals() != NULL && - parent_->getSegGlobals()->getFirstSegId() == getStatsSegmentId())) + if (getSharedMemory()) { // Check if you are within semaphore if (! checkIfRTSSemaphoreLocked()) http://git-wip-us.apache.org/repos/asf/trafodion/blob/806e93b2/core/sql/common/NAMemory.h ---------------------------------------------------------------------- diff --git a/core/sql/common/NAMemory.h b/core/sql/common/NAMemory.h index 78ad279..009ec1a 100644 --- a/core/sql/common/NAMemory.h +++ b/core/sql/common/NAMemory.h @@ -73,7 +73,6 @@ typedef uid_t SEG_ID; // contents of this file: class NAMemory; -class NASegGlobals; class NABlock; class NAHeap; class NAHeapFragment; @@ -107,84 +106,6 @@ private: // 17 - all objects > 2 MB }; -//////////////////////////////////////////////////////////////////////////// -// One NASegGlobals object exists in the executor as a member variable -// of CliGlobals. Information about the first executor flat segment, as well -// as the address of the NASegGlobals object in which the information is -// stored, is passed as arguments to the setFirstSegInfo function, and used -// by NAMEMORY::allocateBlock. addSegId is called by NAMemory::allocateBlock -// to maintain an array of secondary (allocated after the first) flat segment -// ids. getSegId is called on MIPS by switchToPriv and switchToNonPriv to -// obtain the flat segment ids to hide and reveal. On Yosemite, the -// segments are not hidden and revealed. -//////////////////////////////////////////////////////////////////////////// -class NASegGlobals { -public: - inline short getSegId(Lng32 &index) const - { - Lng32 i, addedSegCount; - for (i = 0, addedSegCount = 0; addedSegCount < addedSegCount_; i++) - { - if (addedSegId_[i] != 0) - { - addedSegCount += 1; - if (i >= index) - { - index = i; - return addedSegId_[i]; - } - } - } - return 0; - } - - short getSegInfo(Lng32 index, void **startAddr) const - { - *startAddr = startAddresses_[index]; - return addedSegId_[index]; - } - void setFirstSegInfo( - SEG_ID firstSegId, - void *firstSegStart, - off_t firstSegOffset, - size_t firstSegLen, - size_t firstSegMaxLen); - void setMaxSecSegCount(Lng32 maxSecSegCount) - { maxSecSegCount_ = maxSecSegCount; } - NABoolean reachedMaxSegCnt() const - { return addedSegCount_ >= maxSecSegCount_; } - Lng32 addSegId(short segId, void *start, size_t len); - void deleteSegId(short segId); - SEG_ID getFirstSegId() const { return firstSegId_; } - void * getFirstSegStart() const { return firstSegStart_; } - off_t getFirstSegOffset() const { return firstSegOffset_; } - size_t getFirstSegLen() const { return firstSegLen_; } - size_t getFirstSegMaxLen() const { return firstSegMaxLen_; } - void resizeSeg(short segId, void *start, size_t newLen); - - // check whether a specified range of memory overlaps any of the segments - NABoolean overlaps(void *start, size_t len) const; - - enum { NA_MAX_SECONDARY_SEGS=28 }; // Seg IDs 2111 - 2138 -private: - SEG_ID firstSegId_; - void *firstSegStart_; // starting addr of segment - off_t firstSegOffset_; // offset of free space in the segment - size_t firstSegLen_; // length of external segment - size_t firstSegMaxLen_; // max. len the segment can be resized to - Lng32 addedSegCount_; // number of additional segments - Lng32 maxSecSegCount_; // Maximum number of secondary segments - short addedSegId_ [NA_MAX_SECONDARY_SEGS]; // array of secondary seg ids - void *startAddresses_ [NA_MAX_SECONDARY_SEGS]; // start addresses of segs - size_t lengths_[NA_MAX_SECONDARY_SEGS]; // lengths of segments - - // total range of memory spanned by the segments (may have other - // things or holes between those water marks) - void *lowWaterMark_; - void *highWaterMark_; -}; - - //////////////////////////////////////////////////////////////////////////// // A NABlock is the basic allocation unit, i.e., we always request Blocks @@ -263,15 +184,6 @@ public: // time. Before a memory can be used, the type_ has to be set via // setType() or setParent() // - // The number of NAMemory objects of NAMemoryType SYSTEM_MEMORY or IPC_MEMORY - // is currently restricted to one because the assignment of flat segment ids - // (NSK) for SYSTEM/IPC_MEMORY is not managed globally. If one such object - // already exists, an assertion failure will occur following an attempt to - // to allocate a segment with an id that was previously used. This is not - // a problem because only the compiler's main statement heap resides in - // SYSTEM_MEMORY, and only ESPs use IPC_Memory. If needed in the future, - // multiple SYSTEM/IPC _MEMORY heaps could be supported by keeping track of - // SYSTEM_MEMORY/IPC segment ids in the NASegGlobals object. enum NAMemoryType { NO_MEMORY_TYPE = 0, EXECUTOR_MEMORY = 2, @@ -304,22 +216,18 @@ public: NAMemory(const char * name, NAMemoryType type, size_t blockSize, size_t upperLimit); - // an NAMemory of type EXECUTOR_MEMORY that uses a first flat segment - // that is allocated by the caller (on NSK, uses malloc on NT and ignores - // the parameters after the first one) - NAMemory(const char * name, - SEG_ID extFirstSegId, - void * extFirstSegStart, - off_t extFirstSegOffset, - size_t extFirstSegLen, - size_t extFirstSegMaxLen, - NASegGlobals * segGlobals, - Lng32 extMaxSecSegCount = NASegGlobals::NA_MAX_SECONDARY_SEGS); - // DERIVED_MEMORY NAMemory(const char * name, NAHeap * parent, size_t blockSize, size_t upperLimit); + // an NAMemory of type EXECUTOR_MEMORY that imposes the NAMemory struture + // on already allocated memory + NAMemory(const char * name, + SEG_ID segmentId, + void * baseAddr, + off_t heapStartOffset, + size_t maxSize); + ~NAMemory(); void reInitialize(); @@ -374,7 +282,6 @@ public: inline void resetIntervalWaterMark() { intervalWaterMark_ = allocSize_;}; - inline NASegGlobals * getSegGlobals() { return segGlobals_; } char *getName() { return name_; } NAMemoryType getType() { return type_; } @@ -451,8 +358,6 @@ private: // that was allocated before this memory // was created (allows to put the memory // itself and other info into the segment) - NASegGlobals *segGlobals_; // Executor flat segment globals object - NAMemory *memoryList_; // list of memory directly derived from this NAMemory *lastListEntry_; // last entry of this list NAMemory *nextEntry_; // pointer if this memory is on a memoryList_ @@ -531,17 +436,19 @@ public: NAHeap(const char * name, NAHeap * parent, Lng32 blockSize = 0, - Lng32 upperLimit =0); - NAHeap(const char * name, NAMemoryType type = DERIVED_FROM_SYS_HEAP, - Lng32 blockSize = 0, Lng32 upperLimit = 0); - NAHeap(const char * name, - SEG_ID extFirstSegId, - void * extFirstSegStart, - Lng32 extFirstSegOffset, - Lng32 extFirstSegLen, - Lng32 extFirstSegMaxLen, - NASegGlobals *segGlobals, - Lng32 extMaxSecSegCount = NASegGlobals::NA_MAX_SECONDARY_SEGS); + size_t upperLimit =0); + NAHeap(const char * name, NAMemoryType type, + Lng32 blockSize = 0, size_t upperLimit = 0); + + // Constructor that imposes the NAHeap struture on already allocated memory + NAHeap(const char * name, + SEG_ID segmentId, + void * baseAddr, + off_t heapStartOffset, + size_t maxSize); + + NAHeap(const char * name); + ~NAHeap(); void destroy(); void reInitializeHeap(); http://git-wip-us.apache.org/repos/asf/trafodion/blob/806e93b2/core/sql/runtimestats/SqlStats.cpp ---------------------------------------------------------------------- diff --git a/core/sql/runtimestats/SqlStats.cpp b/core/sql/runtimestats/SqlStats.cpp index 4e5a4a7..0b64e02 100644 --- a/core/sql/runtimestats/SqlStats.cpp +++ b/core/sql/runtimestats/SqlStats.cpp @@ -64,10 +64,7 @@ StatsGlobals::StatsGlobals(void *baseAddr, short envType, Lng32 maxSegSize) getStatsSegmentId(), baseAddr, ((sizeof(StatsGlobals)+16-1)/16)*16, - maxSegSize, - maxSegSize, - &segGlobals_, - 0), // Zero secondary segments + maxSegSize), recentSikeys_(NULL), newestRevokeTimestamp_(0), // all new compilers are current. statsArray_(NULL) http://git-wip-us.apache.org/repos/asf/trafodion/blob/806e93b2/core/sql/runtimestats/SqlStats.h ---------------------------------------------------------------------- diff --git a/core/sql/runtimestats/SqlStats.h b/core/sql/runtimestats/SqlStats.h index acb75fc..0377c3d 100644 --- a/core/sql/runtimestats/SqlStats.h +++ b/core/sql/runtimestats/SqlStats.h @@ -507,7 +507,6 @@ private: short cpu_; pid_t semPid_; // Pid of the process that holds semaphore lock - This element is used for debugging purpose only Int64 semPidCreateTime_; // Creation timestamp - pid recycle workaround. - NASegGlobals segGlobals_; NAHeap statsHeap_; NABoolean isSscpInitialized_; short rtsEnvType_; // 1 - Global Environment
