Added the sqlite3_soft_heap_limit64() interface. Deprecate the older
sqlite3_soft_heap_limit() interface. FossilOrigin-Name: 82268a2c3d75431cd40de6ad09d398729de32a29
This commit is contained in:
parent
2969a58790
commit
f82ccf6437
30
manifest
30
manifest
@ -1,5 +1,8 @@
|
||||
C Add\strivial\stest\scase\sto\smake\ssure\sshared-cache\smode\sdoes\snot\sautomatically\sturn\son\sexclusive-locking\smode.
|
||||
D 2010-09-15T11:42:04
|
||||
-----BEGIN PGP SIGNED MESSAGE-----
|
||||
Hash: SHA1
|
||||
|
||||
C Added\sthe\ssqlite3_soft_heap_limit64()\sinterface.\s\sDeprecate\sthe\solder\nsqlite3_soft_heap_limit()\sinterface.
|
||||
D 2010-09-15T17:54:31
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -140,7 +143,7 @@ F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f
|
||||
F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e
|
||||
F src/loadext.c 6d422ea91cf3d2d00408c5a8f2391cd458da85f8
|
||||
F src/main.c da74b2269470d97a702d2956eeeb691a5e3a68c3
|
||||
F src/malloc.c 579a6eee344a63c607c4b2933e9258708d0f6cc7
|
||||
F src/malloc.c babecbdfc62279cbcd0d16d275584aded02b6cb3
|
||||
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
|
||||
F src/mem1.c 00bd8265c81abb665c48fea1e0c234eb3b922206
|
||||
F src/mem2.c e307323e86b5da1853d7111b68fd6b84ad6f09cf
|
||||
@ -174,14 +177,14 @@ F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706
|
||||
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
|
||||
F src/select.c b0b124781474e4e0c8f64022875e5e2009e13443
|
||||
F src/shell.c 8517fc1f9c59ae4007e6cc8b9af91ab231ea2056
|
||||
F src/sqlite.h.in 105ccc5426705d40d426c5c015334fdb6fa7de71
|
||||
F src/sqlite.h.in f12039ff7abd1de321a799023e9611747a25cbf8
|
||||
F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
|
||||
F src/sqliteInt.h 81343db96497aebf81dff9c695dfd29699b377b3
|
||||
F src/sqliteInt.h ef7ed8746759c09edd87e5550de973a4da3e4ca7
|
||||
F src/sqliteLimit.h a17dcd3fb775d63b64a43a55c54cb282f9726f44
|
||||
F src/status.c 496913d4e8441195f6f2a75b1c95993a45b9b30b
|
||||
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
|
||||
F src/tclsqlite.c e91019fb6787166abca23a81b16c07fecc2ed751
|
||||
F src/test1.c c1b74b15b55051e7004ede9233e4b2b323e8ba65
|
||||
F src/test1.c a0f135000894cb5a3d32d23fd74a83939ca854fa
|
||||
F src/test2.c 80d323d11e909cf0eb1b6fbb4ac22276483bcf31
|
||||
F src/test3.c 056093cfef69ff4227a6bdb9108564dc7f45e4bc
|
||||
F src/test4.c 0528360b5025688002a5feb6be906ddce52eaaee
|
||||
@ -857,7 +860,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
P a0f01ebab9bd42fca9ce5d97f8cbf44afd803f4e
|
||||
R 3b07812fa7ffe651e3d23f156f91296a
|
||||
U dan
|
||||
Z c0451ba7dfb3514907a6c35a2fc14f3d
|
||||
P a0ab3902f1431c962a5d034647ef3c6876dc0e75
|
||||
R 7da6d31c36a2050258d528b89799ab10
|
||||
U drh
|
||||
Z aa3b892a44c4e00e79837aea29531379
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
Version: GnuPG v1.4.6 (GNU/Linux)
|
||||
|
||||
iD8DBQFMkQhboxKgR168RlERAm4cAJ4w9wAFqHb6joB5SxErUJy8jkJxDQCePAMm
|
||||
nGkIpE/aZAZjrCs5c2HTHyI=
|
||||
=Qtkd
|
||||
-----END PGP SIGNATURE-----
|
||||
|
@ -1 +1 @@
|
||||
a0ab3902f1431c962a5d034647ef3c6876dc0e75
|
||||
82268a2c3d75431cd40de6ad09d398729de32a29
|
148
src/malloc.c
148
src/malloc.c
@ -15,46 +15,6 @@
|
||||
#include "sqliteInt.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
/*
|
||||
** This routine runs when the memory allocator sees that the
|
||||
** total memory allocation is about to exceed the soft heap
|
||||
** limit.
|
||||
*/
|
||||
static void softHeapLimitEnforcer(
|
||||
void *NotUsed,
|
||||
sqlite3_int64 NotUsed2,
|
||||
int allocSize
|
||||
){
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
sqlite3_release_memory(allocSize);
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the soft heap-size limit for the library. Passing a zero or
|
||||
** negative value indicates no limit.
|
||||
*/
|
||||
void sqlite3_soft_heap_limit(int n){
|
||||
sqlite3_uint64 iLimit;
|
||||
int overage;
|
||||
if( n<0 ){
|
||||
iLimit = 0;
|
||||
}else{
|
||||
iLimit = n;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTOINIT
|
||||
sqlite3_initialize();
|
||||
#endif
|
||||
if( iLimit>0 ){
|
||||
sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, iLimit);
|
||||
}else{
|
||||
sqlite3MemoryAlarm(0, 0, 0);
|
||||
}
|
||||
overage = (int)(sqlite3_memory_used() - (i64)n);
|
||||
if( overage>0 ){
|
||||
sqlite3_release_memory(overage);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to release up to n bytes of non-essential memory currently
|
||||
** held by SQLite. An example of non-essential memory is memory used to
|
||||
@ -115,6 +75,81 @@ static SQLITE_WSD struct Mem0Global {
|
||||
|
||||
#define mem0 GLOBAL(struct Mem0Global, mem0)
|
||||
|
||||
/*
|
||||
** This routine runs when the memory allocator sees that the
|
||||
** total memory allocation is about to exceed the soft heap
|
||||
** limit.
|
||||
*/
|
||||
static void softHeapLimitEnforcer(
|
||||
void *NotUsed,
|
||||
sqlite3_int64 NotUsed2,
|
||||
int allocSize
|
||||
){
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
sqlite3_release_memory(allocSize);
|
||||
}
|
||||
|
||||
/*
|
||||
** Change the alarm callback
|
||||
*/
|
||||
static int sqlite3MemoryAlarm(
|
||||
void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
|
||||
void *pArg,
|
||||
sqlite3_int64 iThreshold
|
||||
){
|
||||
int nUsed;
|
||||
sqlite3_mutex_enter(mem0.mutex);
|
||||
mem0.alarmCallback = xCallback;
|
||||
mem0.alarmArg = pArg;
|
||||
mem0.alarmThreshold = iThreshold;
|
||||
nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
|
||||
mem0.nearlyFull = (iThreshold>0 && iThreshold<=nUsed);
|
||||
sqlite3_mutex_leave(mem0.mutex);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
/*
|
||||
** Deprecated external interface. Internal/core SQLite code
|
||||
** should call sqlite3MemoryAlarm.
|
||||
*/
|
||||
int sqlite3_memory_alarm(
|
||||
void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
|
||||
void *pArg,
|
||||
sqlite3_int64 iThreshold
|
||||
){
|
||||
return sqlite3MemoryAlarm(xCallback, pArg, iThreshold);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Set the soft heap-size limit for the library. Passing a zero or
|
||||
** negative value indicates no limit.
|
||||
*/
|
||||
sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){
|
||||
sqlite3_int64 priorLimit;
|
||||
sqlite3_int64 excess;
|
||||
#ifndef SQLITE_OMIT_AUTOINIT
|
||||
sqlite3_initialize();
|
||||
#endif
|
||||
sqlite3_mutex_enter(mem0.mutex);
|
||||
priorLimit = mem0.alarmThreshold;
|
||||
sqlite3_mutex_leave(mem0.mutex);
|
||||
if( n<0 ) return priorLimit;
|
||||
if( n>0 ){
|
||||
sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, n);
|
||||
}else{
|
||||
sqlite3MemoryAlarm(0, 0, 0);
|
||||
}
|
||||
excess = sqlite3_memory_used() - n;
|
||||
if( excess>0 ) sqlite3_release_memory(excess & 0x7fffffff);
|
||||
return priorLimit;
|
||||
}
|
||||
void sqlite3_soft_heap_limit(int n){
|
||||
if( n<0 ) n = 0;
|
||||
sqlite3_soft_heap_limit64(n);
|
||||
}
|
||||
|
||||
/*
|
||||
** Initialize the memory allocation subsystem.
|
||||
*/
|
||||
@ -200,39 +235,6 @@ sqlite3_int64 sqlite3_memory_highwater(int resetFlag){
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
** Change the alarm callback
|
||||
*/
|
||||
int sqlite3MemoryAlarm(
|
||||
void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
|
||||
void *pArg,
|
||||
sqlite3_int64 iThreshold
|
||||
){
|
||||
int nUsed;
|
||||
sqlite3_mutex_enter(mem0.mutex);
|
||||
mem0.alarmCallback = xCallback;
|
||||
mem0.alarmArg = pArg;
|
||||
mem0.alarmThreshold = iThreshold;
|
||||
nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
|
||||
mem0.nearlyFull = (iThreshold>0 && iThreshold<=nUsed);
|
||||
sqlite3_mutex_leave(mem0.mutex);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
/*
|
||||
** Deprecated external interface. Internal/core SQLite code
|
||||
** should call sqlite3MemoryAlarm.
|
||||
*/
|
||||
int sqlite3_memory_alarm(
|
||||
void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
|
||||
void *pArg,
|
||||
sqlite3_int64 iThreshold
|
||||
){
|
||||
return sqlite3MemoryAlarm(xCallback, pArg, iThreshold);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Trigger the alarm
|
||||
*/
|
||||
|
@ -1249,7 +1249,7 @@ struct sqlite3_mem_methods {
|
||||
** <ul>
|
||||
** <li> [sqlite3_memory_used()]
|
||||
** <li> [sqlite3_memory_highwater()]
|
||||
** <li> [sqlite3_soft_heap_limit()]
|
||||
** <li> [sqlite3_soft_heap_limit64()]
|
||||
** <li> [sqlite3_status()]
|
||||
** </ul>)^
|
||||
** ^Memory allocation statistics are enabled by default unless SQLite is
|
||||
@ -3897,16 +3897,19 @@ void sqlite3_activate_cerod(
|
||||
/*
|
||||
** CAPI3REF: Suspend Execution For A Short Time
|
||||
**
|
||||
** ^The sqlite3_sleep() function causes the current thread to suspend execution
|
||||
** The sqlite3_sleep() function causes the current thread to suspend execution
|
||||
** for at least a number of milliseconds specified in its parameter.
|
||||
**
|
||||
** ^If the operating system does not support sleep requests with
|
||||
** If the operating system does not support sleep requests with
|
||||
** millisecond time resolution, then the time will be rounded up to
|
||||
** the nearest second. ^The number of milliseconds of sleep actually
|
||||
** the nearest second. The number of milliseconds of sleep actually
|
||||
** requested from the operating system is returned.
|
||||
**
|
||||
** ^SQLite implements this interface by calling the xSleep()
|
||||
** method of the default [sqlite3_vfs] object.
|
||||
** method of the default [sqlite3_vfs] object. If the xSleep() method
|
||||
** of the default VFS is not implemented correctly, or not implemented at
|
||||
** all, then the behavior of sqlite3_sleep() may deviate from the description
|
||||
** in the previous paragraphs.
|
||||
*/
|
||||
int sqlite3_sleep(int);
|
||||
|
||||
@ -4136,34 +4139,65 @@ int sqlite3_release_memory(int);
|
||||
/*
|
||||
** CAPI3REF: Impose A Limit On Heap Size
|
||||
**
|
||||
** ^The sqlite3_soft_heap_limit() interface places a "soft" limit
|
||||
** on the amount of heap memory that may be allocated by SQLite.
|
||||
** ^If an internal allocation is requested that would exceed the
|
||||
** soft heap limit, [sqlite3_release_memory()] is invoked one or
|
||||
** more times to free up some space before the allocation is performed.
|
||||
** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
|
||||
** soft limit on the amount of heap memory that may be allocated by SQLite.
|
||||
** ^SQLite strives to keep heap memory utilization below the soft heap
|
||||
** limit by reducing the number of pages held in the page cache
|
||||
** as heap memory usages approaches the limit.
|
||||
** ^The soft heap limit is "soft" because even though SQLite strives to stay
|
||||
** below the limit, it will exceed the limit rather than generate
|
||||
** an [SQLITE_NOMEM] error. In other words, the soft heap limit
|
||||
** is advisory only.
|
||||
**
|
||||
** ^The limit is called "soft" because if [sqlite3_release_memory()]
|
||||
** cannot free sufficient memory to prevent the limit from being exceeded,
|
||||
** the memory is allocated anyway and the current operation proceeds.
|
||||
** ^The return value from sqlite3_soft_heap_limit64() is the size of
|
||||
** the soft heap limit prior to the call. ^If the argument N is negative
|
||||
** then no change is made to the soft heap limit. Hence, the current
|
||||
** size of the soft heap limit can be determined by invoking
|
||||
** sqlite3_soft_heap_limit64() with a negative argument.
|
||||
**
|
||||
** ^A negative or zero value for N means that there is no soft heap limit and
|
||||
** [sqlite3_release_memory()] will only be called when memory is exhausted.
|
||||
** ^The default value for the soft heap limit is zero.
|
||||
** ^If the argument N is zero then the soft heap limit is disabled.
|
||||
**
|
||||
** ^(SQLite makes a best effort to honor the soft heap limit.
|
||||
** But if the soft heap limit cannot be honored, execution will
|
||||
** continue without error or notification.)^ This is why the limit is
|
||||
** called a "soft" limit. It is advisory only.
|
||||
** ^(The soft heap limit is not enforced in the current implementation
|
||||
** if one or more of following conditions are true:
|
||||
**
|
||||
** Prior to SQLite version 3.5.0, this routine only constrained the memory
|
||||
** allocated by a single thread - the same thread in which this routine
|
||||
** runs. Beginning with SQLite version 3.5.0, the soft heap limit is
|
||||
** applied to all threads. The value specified for the soft heap limit
|
||||
** is an upper bound on the total memory allocation for all threads. In
|
||||
** version 3.5.0 there is no mechanism for limiting the heap usage for
|
||||
** individual threads.
|
||||
** <ul>
|
||||
** <li> The soft heap limit is set to zero.
|
||||
** <li> Memory accounting is disabled using a combination of the
|
||||
** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
|
||||
** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
|
||||
** <li> An alternative page cache implementation is specifed using
|
||||
** [sqlite3_config]([SQLITE_CONFIG_PCACHE],...).
|
||||
** <li> The page cache allocates from its own memory pool supplied
|
||||
** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
|
||||
** from the heap.
|
||||
** </ul>)^
|
||||
**
|
||||
** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
|
||||
** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
|
||||
** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
|
||||
** the soft heap limit is enforced on every memory allocation. Without
|
||||
** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
|
||||
** when memory is allocated by the page cache. Testing suggests that because
|
||||
** the page cache is the predominate memory user in SQLite, most
|
||||
** applications will achieve adequate soft heap limit enforcement without
|
||||
** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
|
||||
**
|
||||
** The circumstances under which SQLite will enforce the soft heap limit may
|
||||
** changes in future releases of SQLite.
|
||||
*/
|
||||
void sqlite3_soft_heap_limit(int);
|
||||
sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Deprecated Soft Heap Limit Interface
|
||||
** DEPRECATED
|
||||
**
|
||||
** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
|
||||
** interface. This routine is provided for historical compatibility
|
||||
** only. All new applications should use the
|
||||
** [sqlite3_soft_heap_limit64()] interface rather than this one.
|
||||
*/
|
||||
SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
|
||||
|
||||
|
||||
/*
|
||||
** CAPI3REF: Extract Metadata About A Column Of A Table
|
||||
|
@ -2530,7 +2530,6 @@ void *sqlite3PageMalloc(int);
|
||||
void sqlite3PageFree(void*);
|
||||
void sqlite3MemSetDefault(void);
|
||||
void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
|
||||
int sqlite3MemoryAlarm(void (*)(void*, sqlite3_int64, int), void*, sqlite3_int64);
|
||||
int sqlite3HeapNearlyFull(void);
|
||||
|
||||
/*
|
||||
|
13
src/test1.c
13
src/test1.c
@ -4390,20 +4390,17 @@ static int test_soft_heap_limit(
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
static int softHeapLimit = 0;
|
||||
int amt;
|
||||
sqlite3_int64 amt;
|
||||
sqlite3_int64 N = -1;
|
||||
if( objc!=1 && objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "?N?");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
amt = softHeapLimit;
|
||||
if( objc==2 ){
|
||||
int N;
|
||||
if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR;
|
||||
sqlite3_soft_heap_limit(N);
|
||||
softHeapLimit = N;
|
||||
if( Tcl_GetWideIntFromObj(interp, objv[1], &N) ) return TCL_ERROR;
|
||||
}
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(amt));
|
||||
amt = sqlite3_soft_heap_limit64(N);
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(amt));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user