From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 4DEF021CFA for ; Sat, 25 May 2019 06:44:35 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3ZCkarzLoAZ7 for ; Sat, 25 May 2019 06:44:35 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id DC74A2FD6F for ; Sat, 25 May 2019 06:44:34 -0400 (EDT) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v1 02/21] sql: disable lookaside system Date: Sat, 25 May 2019 13:44:33 +0300 Message-Id: <22314b645abba28c7142b70598aa347b4f4a3327.1558780708.git.imeevma@gmail.com> In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: korablev@tarantool.org Cc: tarantool-patches@freelists.org Since the lookaside system is not currently in use, it must be completely disabled. --- src/box/sql/main.c | 76 ----------------------------------------- src/box/sql/malloc.c | 91 ++++--------------------------------------------- src/box/sql/printf.c | 2 +- src/box/sql/sqlInt.h | 44 +----------------------- src/box/sql/vdbeaux.c | 2 +- src/box/sql/vdbemem.c | 9 +++-- src/box/sql/whereexpr.c | 3 +- 7 files changed, 14 insertions(+), 213 deletions(-) diff --git a/src/box/sql/main.c b/src/box/sql/main.c index 450f7d1..29a7911 100644 --- a/src/box/sql/main.c +++ b/src/box/sql/main.c @@ -173,78 +173,6 @@ sql_initialize(void) return rc; } -/* - * Set up the lookaside buffers for a database connection. - * Return SQL_OK on success. - * If lookaside is already active, return SQL_BUSY. - * - * The sz parameter is the number of bytes in each lookaside slot. - * The cnt parameter is the number of slots. If pStart is NULL the - * space for the lookaside memory is obtained from sql_malloc(). - * If pStart is not NULL then it is sz*cnt bytes of memory to use for - * the lookaside memory. - */ -static int -setupLookaside(sql * db, void *pBuf, int sz, int cnt) -{ -#ifndef SQL_OMIT_LOOKASIDE - void *pStart; - if (db->lookaside.nOut) { - return SQL_BUSY; - } - /* Free any existing lookaside buffer for this handle before - * allocating a new one so we don't have to have space for - * both at the same time. - */ - if (db->lookaside.bMalloced) { - sql_free(db->lookaside.pStart); - } - /* The size of a lookaside slot after ROUNDDOWN8 needs to be larger - * than a pointer to be useful. - */ - sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */ - if (sz <= (int)sizeof(LookasideSlot *)) - sz = 0; - if (cnt < 0) - cnt = 0; - if (sz == 0 || cnt == 0) { - sz = 0; - pStart = 0; - } else if (pBuf == 0) { - sqlBeginBenignMalloc(); - pStart = sqlMalloc(sz * cnt); /* IMP: R-61949-35727 */ - sqlEndBenignMalloc(); - if (pStart) - cnt = sqlMallocSize(pStart) / sz; - } else { - pStart = pBuf; - } - db->lookaside.pStart = pStart; - db->lookaside.pFree = 0; - db->lookaside.sz = (u16) sz; - if (pStart) { - int i; - LookasideSlot *p; - assert(sz > (int)sizeof(LookasideSlot *)); - p = (LookasideSlot *) pStart; - for (i = cnt - 1; i >= 0; i--) { - p->pNext = db->lookaside.pFree; - db->lookaside.pFree = p; - p = (LookasideSlot *) & ((u8 *) p)[sz]; - } - db->lookaside.pEnd = p; - db->lookaside.bDisable = 0; - db->lookaside.bMalloced = pBuf == 0 ? 1 : 0; - } else { - db->lookaside.pStart = db; - db->lookaside.pEnd = db; - db->lookaside.bDisable = 1; - db->lookaside.bMalloced = 0; - } -#endif /* SQL_OMIT_LOOKASIDE */ - return SQL_OK; -} - void sql_row_count(struct sql_context *context, MAYBE_UNUSED int unused1, MAYBE_UNUSED sql_value **unused2) @@ -630,10 +558,6 @@ sql_init_db(sql **out_db) */ sqlRegisterPerConnectionBuiltinFunctions(db); - /* Enable the lookaside-malloc subsystem */ - setupLookaside(db, 0, sqlGlobalConfig.szLookaside, - sqlGlobalConfig.nLookaside); - opendb_out: assert(db != 0 || rc == SQL_NOMEM); if (rc == SQL_NOMEM) diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c index 925ffb2..5c9c8d5 100644 --- a/src/box/sql/malloc.c +++ b/src/box/sql/malloc.c @@ -412,7 +412,6 @@ sqlScratchMalloc(int n) sqlStatusUp(SQL_STATUS_SCRATCH_OVERFLOW, sqlMallocSize(p)); } - sqlMemdebugSetType(p, MEMTYPE_SCRATCH); } #if !defined(NDEBUG) @@ -457,10 +456,6 @@ sqlScratchFree(void *p) sqlStatusDown(SQL_STATUS_SCRATCH_USED, 1); } else { /* Release memory back to the heap */ - assert(sqlMemdebugHasType(p, MEMTYPE_SCRATCH)); - assert(sqlMemdebugNoType - (p, (u8) ~ MEMTYPE_SCRATCH)); - sqlMemdebugSetType(p, MEMTYPE_HEAP); if (sqlGlobalConfig.bMemstat) { int iSize = sqlMallocSize(p); sqlStatusDown @@ -477,55 +472,25 @@ sqlScratchFree(void *p) } /* - * TRUE if p is a lookaside memory allocation from db - */ -#ifndef SQL_OMIT_LOOKASIDE -static int -isLookaside(sql * db, void *p) -{ - return SQL_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd); -} -#else -#define isLookaside(A,B) 0 -#endif - -/* * Return the size of a memory allocation previously obtained from * sqlMalloc() or sql_malloc(). */ int sqlMallocSize(void *p) { - assert(sqlMemdebugHasType(p, MEMTYPE_HEAP)); return sql_sized_sizeof(p); } int -sqlDbMallocSize(sql * db, void *p) +sqlDbMallocSize(void *p) { assert(p != 0); - if (db == 0 || !isLookaside(db, p)) { -#if SQL_DEBUG - if (db == 0) { - assert(sqlMemdebugNoType(p, (u8) ~ MEMTYPE_HEAP)); - assert(sqlMemdebugHasType(p, MEMTYPE_HEAP)); - } else { - assert(sqlMemdebugHasType - (p, (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP))); - assert(sqlMemdebugNoType - (p, (u8) ~ (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP))); - } -#endif - return sql_sized_sizeof(p); - } else - return db->lookaside.sz; + return sql_sized_sizeof(p); } sql_uint64 sql_msize(void *p) { - assert(sqlMemdebugNoType(p, (u8) ~ MEMTYPE_HEAP)); - assert(sqlMemdebugHasType(p, MEMTYPE_HEAP)); return p ? sql_sized_sizeof(p) : 0; } @@ -537,8 +502,6 @@ sql_free(void *p) { if (p == 0) return; /* IMP: R-49053-54554 */ - assert(sqlMemdebugHasType(p, MEMTYPE_HEAP)); - assert(sqlMemdebugNoType(p, (u8) ~ MEMTYPE_HEAP)); if (sqlGlobalConfig.bMemstat) { sqlStatusDown(SQL_STATUS_MEMORY_USED, sqlMallocSize(p)); @@ -555,7 +518,7 @@ sql_free(void *p) static SQL_NOINLINE void measureAllocationSize(sql * db, void *p) { - *db->pnBytesFreed += sqlDbMallocSize(db, p); + *db->pnBytesFreed += sqlDbMallocSize(p); } /* @@ -572,23 +535,7 @@ sqlDbFree(sql * db, void *p) measureAllocationSize(db, p); return; } - if (isLookaside(db, p)) { - LookasideSlot *pBuf = (LookasideSlot *) p; -#if SQL_DEBUG - /* Trash all content in the buffer being freed */ - memset(p, 0xaa, db->lookaside.sz); -#endif - pBuf->pNext = db->lookaside.pFree; - db->lookaside.pFree = pBuf; - db->lookaside.nOut--; - return; - } } - assert(sqlMemdebugHasType(p, (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP))); - assert(sqlMemdebugNoType - (p, (u8) ~ (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP))); - assert(db != 0 || sqlMemdebugNoType(p, MEMTYPE_LOOKASIDE)); - sqlMemdebugSetType(p, MEMTYPE_HEAP); sql_free(p); } @@ -600,8 +547,6 @@ sqlRealloc(void *pOld, u64 nBytes) { int nOld, nNew, nDiff; void *pNew; - assert(sqlMemdebugHasType(pOld, MEMTYPE_HEAP)); - assert(sqlMemdebugNoType(pOld, (u8) ~ MEMTYPE_HEAP)); if (pOld == 0) { return sqlMalloc(nBytes); /* IMP: R-04300-56712 */ } @@ -698,9 +643,6 @@ dbMallocRawFinish(sql * db, u64 n) p = sqlMalloc(n); if (!p) sqlOomFault(db); - sqlMemdebugSetType(p, - (db->lookaside.bDisable == - 0) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP); return p; } @@ -733,7 +675,6 @@ sqlDbMallocRaw(sql * db, u64 n) if (db) return sqlDbMallocRawNN(db, n); p = sqlMalloc(n); - sqlMemdebugSetType(p, MEMTYPE_HEAP); return p; } @@ -785,8 +726,6 @@ sqlDbRealloc(sql * db, void *p, u64 n) assert(db != 0); if (p == 0) return sqlDbMallocRawNN(db, n); - if (isLookaside(db, p) && n <= db->lookaside.sz) - return p; return dbReallocFinish(db, p, n); } @@ -797,27 +736,9 @@ dbReallocFinish(sql * db, void *p, u64 n) assert(db != 0); assert(p != 0); if (db->mallocFailed == 0) { - if (isLookaside(db, p)) { - pNew = sqlDbMallocRawNN(db, n); - if (pNew) { - memcpy(pNew, p, db->lookaside.sz); - sqlDbFree(db, p); - } - } else { - assert(sqlMemdebugHasType - (p, (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP))); - assert(sqlMemdebugNoType - (p, (u8) ~ (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP))); - sqlMemdebugSetType(p, MEMTYPE_HEAP); - pNew = sql_realloc64(p, n); - if (!pNew) { - sqlOomFault(db); - } - sqlMemdebugSetType(pNew, - (db->lookaside.bDisable == - 0 ? MEMTYPE_LOOKASIDE : - MEMTYPE_HEAP)); - } + pNew = sql_realloc64(p, n); + if (!pNew) + sqlOomFault(db); } return pNew; } diff --git a/src/box/sql/printf.c b/src/box/sql/printf.c index 31d21db..c364055 100644 --- a/src/box/sql/printf.c +++ b/src/box/sql/printf.c @@ -874,7 +874,7 @@ sqlStrAccumEnlarge(StrAccum * p, int N) if (!isMalloced(p) && p->nChar > 0) memcpy(zNew, p->zText, p->nChar); p->zText = zNew; - p->nAlloc = sqlDbMallocSize(p->db, zNew); + p->nAlloc = sqlDbMallocSize(zNew); p->printfFlags |= SQL_PRINTF_MALLOCED; } else { sqlStrAccumReset(p); diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index c51a3cc..98a0ccb 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -2998,7 +2998,7 @@ void *sqlDbReallocOrFree(sql *, void *, u64); void *sqlDbRealloc(sql *, void *, u64); void sqlDbFree(sql *, void *); int sqlMallocSize(void *); -int sqlDbMallocSize(sql *, void *); +int sqlDbMallocSize(void *); void *sqlScratchMalloc(int); void sqlScratchFree(void *); void *sqlPageMalloc(int); @@ -4902,48 +4902,6 @@ void sqlVdbeIOTraceSql(Vdbe *); #endif /* - * These routines are available for the mem2.c debugging memory allocator - * only. They are used to verify that different "types" of memory - * allocations are properly tracked by the system. - * - * sqlMemdebugSetType() sets the "type" of an allocation to one of - * the MEMTYPE_* macros defined below. The type must be a bitmask with - * a single bit set. - * - * sqlMemdebugHasType() returns true if any of the bits in its second - * argument match the type set by the previous sqlMemdebugSetType(). - * sqlMemdebugHasType() is intended for use inside assert() statements. - * - * sqlMemdebugNoType() returns true if none of the bits in its second - * argument match the type set by the previous sqlMemdebugSetType(). - * - * Perhaps the most important point is the difference between MEMTYPE_HEAP - * and MEMTYPE_LOOKASIDE. If an allocation is MEMTYPE_LOOKASIDE, that means - * it might have been allocated by lookaside, except the allocation was - * too large or lookaside was already full. It is important to verify - * that allocations that might have been satisfied by lookaside are not - * passed back to non-lookaside free() routines. Asserts such as the - * example above are placed on the non-lookaside free() routines to verify - * this constraint. - * - * All of this is no-op for a production build. It only comes into - * play when the sql_MEMDEBUG compile-time option is used. - */ -#ifdef SQL_MEMDEBUG -void sqlMemdebugSetType(void *, u8); -int sqlMemdebugHasType(void *, u8); -int sqlMemdebugNoType(void *, u8); -#else -#define sqlMemdebugSetType(X,Y) /* no-op */ -#define sqlMemdebugHasType(X,Y) 1 -#define sqlMemdebugNoType(X,Y) 1 -#endif -#define MEMTYPE_HEAP 0x01 /* General heap allocations */ -#define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */ -#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */ -#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */ - -/* * Threading interface */ #if SQL_MAX_WORKER_THREADS>0 diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c index 697dffd..fbe5338 100644 --- a/src/box/sql/vdbeaux.c +++ b/src/box/sql/vdbeaux.c @@ -192,7 +192,7 @@ growOpArray(Vdbe * v, int nOp) assert(nNew >= (p->nOpAlloc + nOp)); pNew = sqlDbRealloc(p->db, v->aOp, nNew * sizeof(Op)); if (pNew) { - p->szOpAlloc = sqlDbMallocSize(p->db, pNew); + p->szOpAlloc = sqlDbMallocSize(pNew); p->nOpAlloc = p->szOpAlloc / sizeof(Op); v->aOp = pNew; } diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index d6375a6..1a0fa75 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -70,7 +70,7 @@ sqlVdbeCheckMemInvariants(Mem * p) /* The szMalloc field holds the correct memory allocation size */ assert(p->szMalloc == 0 - || p->szMalloc == sqlDbMallocSize(p->db, p->zMalloc)); + || p->szMalloc == sqlDbMallocSize(p->zMalloc)); /* If p holds a string or blob, the Mem.z must point to exactly * one of the following: @@ -112,8 +112,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve) testcase(bPreserve && pMem->z == 0); assert(pMem->szMalloc == 0 - || pMem->szMalloc == sqlDbMallocSize(pMem->db, - pMem->zMalloc)); + || pMem->szMalloc == sqlDbMallocSize(pMem->zMalloc)); if (pMem->szMalloc < n) { if (n < 32) n = 32; @@ -133,7 +132,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve) return SQL_NOMEM; } else { pMem->szMalloc = - sqlDbMallocSize(pMem->db, pMem->zMalloc); + sqlDbMallocSize(pMem->zMalloc); } } @@ -993,7 +992,7 @@ sqlVdbeMemSetStr(Mem * pMem, /* Memory cell to set to string value */ } else if (xDel == SQL_DYNAMIC) { sqlVdbeMemRelease(pMem); pMem->zMalloc = pMem->z = (char *)z; - pMem->szMalloc = sqlDbMallocSize(pMem->db, pMem->zMalloc); + pMem->szMalloc = sqlDbMallocSize(pMem->zMalloc); } else { sqlVdbeMemRelease(pMem); pMem->z = (char *)z; diff --git a/src/box/sql/whereexpr.c b/src/box/sql/whereexpr.c index 30017b0..a954b17 100644 --- a/src/box/sql/whereexpr.c +++ b/src/box/sql/whereexpr.c @@ -107,8 +107,7 @@ whereClauseInsert(WhereClause * pWC, Expr * p, u16 wtFlags) if (pOld != pWC->aStatic) { sqlDbFree(db, pOld); } - pWC->nSlot = - sqlDbMallocSize(db, pWC->a) / sizeof(pWC->a[0]); + pWC->nSlot = sqlDbMallocSize(pWC->a) / sizeof(pWC->a[0]); } pTerm = &pWC->a[idx = pWC->nTerm++]; if (p && ExprHasProperty(p, EP_Unlikely)) { -- 2.7.4