From: imeevma@tarantool.org To: korablev@tarantool.org Cc: tarantool-patches@freelists.org Subject: [tarantool-patches] [PATCH v1 02/21] sql: disable lookaside system Date: Sat, 25 May 2019 13:44:33 +0300 [thread overview] Message-ID: <22314b645abba28c7142b70598aa347b4f4a3327.1558780708.git.imeevma@gmail.com> (raw) In-Reply-To: <cover.1558780708.git.imeevma@gmail.com> 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
next prev parent reply other threads:[~2019-05-25 10:44 UTC|newest] Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 01/21] sql: remove unused functions of " imeevma 2019-05-25 10:44 ` imeevma [this message] 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 03/21] sql: remove SQL_OK error/status code imeevma 2019-05-25 14:45 ` [tarantool-patches] " n.pettik 2019-05-26 9:39 ` Mergen Imeev 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 04/21] sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes imeevma 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 05/21] sql: remove SQL_CANTOPEN errcode imeevma 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 06/21] sql: remove SQL_NOTFOUND error/status code imeevma 2019-05-25 14:58 ` [tarantool-patches] " n.pettik 2019-05-25 20:26 ` Konstantin Osipov 2019-05-26 16:07 ` n.pettik 2019-05-26 9:45 ` Mergen Imeev 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 07/21] sql: remove SQL_LOCKED errcode imeevma 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 08/21] sql: remove SQL_FULL errcode imeevma 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 09/21] sql: remove SQL_MISUSE errcode imeevma 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 10/21] sql: remove SQL_RANGE errcode imeevma 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 11/21] sql: remove SQL_SCHEMA errcode imeevma 2019-05-25 16:18 ` [tarantool-patches] " n.pettik 2019-05-26 9:46 ` Mergen Imeev 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 12/21] sql: remove SQL_TOOBIG errcode imeevma 2019-05-25 16:11 ` [tarantool-patches] " n.pettik 2019-05-26 12:12 ` Mergen Imeev 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 13/21] sql: remove SQL_BUSY errcode imeevma 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 14/21] sql: remove SQL_CONSTRAINT errcode imeevma 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 15/21] sql: remove SQL_ERROR errcode imeevma 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 16/21] sql: remove SQL_NOMEM errcode imeevma 2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 17/21] sql: remove SQL_IOERR errcode imeevma 2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 18/21] sql: remove SQL_TARANTOOL_ERROR errcode imeevma 2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 19/21] sql: remove field errMask from struct sql imeevma 2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 20/21] sql: replace rc by is_aborted in struct Parse imeevma 2019-05-25 15:46 ` [tarantool-patches] " n.pettik 2019-05-26 9:49 ` Mergen Imeev 2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 21/21] sql: remove sql_log() imeevma 2019-05-25 16:36 ` [tarantool-patches] Re: [PATCH v1 00/21] sql: remove SQL error system n.pettik 2019-05-28 11:12 ` Mergen Imeev
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=22314b645abba28c7142b70598aa347b4f4a3327.1558780708.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH v1 02/21] sql: disable lookaside system' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox