mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 17:54:13 +08:00
mdbx: add MDBX_READERS_LIMIT.
Change-Id: I2ee97004c084aeb6290c56b8f6415adc464a1bcb
This commit is contained in:
parent
6f39d8228d
commit
098f8a0d77
@ -6323,7 +6323,7 @@ int __cold mdbx_env_set_maxdbs(MDBX_env *env, MDBX_dbi dbs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int __cold mdbx_env_set_maxreaders(MDBX_env *env, unsigned readers) {
|
int __cold mdbx_env_set_maxreaders(MDBX_env *env, unsigned readers) {
|
||||||
if (unlikely(readers < 1 || readers > INT16_MAX))
|
if (unlikely(readers < 1 || readers > MDBX_READERS_LIMIT))
|
||||||
return MDBX_EINVAL;
|
return MDBX_EINVAL;
|
||||||
|
|
||||||
if (unlikely(!env))
|
if (unlikely(!env))
|
||||||
@ -6781,7 +6781,7 @@ static int __cold mdbx_setup_lck(MDBX_env *env, char *lck_pathname,
|
|||||||
|
|
||||||
const size_t maxreaders =
|
const size_t maxreaders =
|
||||||
((size_t)size - sizeof(MDBX_lockinfo)) / sizeof(MDBX_reader) + 1;
|
((size_t)size - sizeof(MDBX_lockinfo)) / sizeof(MDBX_reader) + 1;
|
||||||
if (maxreaders < 2 || maxreaders > UINT16_MAX) {
|
if (maxreaders < 2 || maxreaders > MDBX_READERS_LIMIT) {
|
||||||
mdbx_error("lck-size too big (up to %" PRIuPTR " readers)", maxreaders);
|
mdbx_error("lck-size too big (up to %" PRIuPTR " readers)", maxreaders);
|
||||||
err = MDBX_PROBLEM;
|
err = MDBX_PROBLEM;
|
||||||
goto bailout;
|
goto bailout;
|
||||||
|
@ -336,37 +336,6 @@ typedef struct MDBX_page {
|
|||||||
/* Size of the page header, excluding dynamic data at the end */
|
/* Size of the page header, excluding dynamic data at the end */
|
||||||
#define PAGEHDRSZ ((unsigned)offsetof(MDBX_page, mp_data))
|
#define PAGEHDRSZ ((unsigned)offsetof(MDBX_page, mp_data))
|
||||||
|
|
||||||
/* The maximum size of a database page.
|
|
||||||
*
|
|
||||||
* It is 64K, but value-PAGEHDRSZ must fit in MDBX_page.mp_upper.
|
|
||||||
*
|
|
||||||
* MDBX will use database pages < OS pages if needed.
|
|
||||||
* That causes more I/O in write transactions: The OS must
|
|
||||||
* know (read) the whole page before writing a partial page.
|
|
||||||
*
|
|
||||||
* Note that we don't currently support Huge pages. On Linux,
|
|
||||||
* regular data files cannot use Huge pages, and in general
|
|
||||||
* Huge pages aren't actually pageable. We rely on the OS
|
|
||||||
* demand-pager to read our data and page it out when memory
|
|
||||||
* pressure from other processes is high. So until OSs have
|
|
||||||
* actual paging support for Huge pages, they're not viable. */
|
|
||||||
#define MAX_PAGESIZE 0x10000u
|
|
||||||
#define MIN_PAGESIZE 512u
|
|
||||||
|
|
||||||
#define MIN_MAPSIZE (MIN_PAGESIZE * MIN_PAGENO)
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
|
||||||
#define MAX_MAPSIZE32 UINT32_C(0x38000000)
|
|
||||||
#else
|
|
||||||
#define MAX_MAPSIZE32 UINT32_C(0x7ff80000)
|
|
||||||
#endif
|
|
||||||
#define MAX_MAPSIZE64 (MAX_PAGENO * (uint64_t)MAX_PAGESIZE)
|
|
||||||
|
|
||||||
#if MDBX_WORDBITS >= 64
|
|
||||||
#define MAX_MAPSIZE MAX_MAPSIZE64
|
|
||||||
#else
|
|
||||||
#define MAX_MAPSIZE MAX_MAPSIZE32
|
|
||||||
#endif /* MDBX_WORDBITS */
|
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
/* Reader Lock Table
|
/* Reader Lock Table
|
||||||
@ -527,6 +496,40 @@ typedef struct MDBX_lockinfo {
|
|||||||
#define MDBX_ASSUME_MALLOC_OVERHEAD (sizeof(void *) * 2u)
|
#define MDBX_ASSUME_MALLOC_OVERHEAD (sizeof(void *) * 2u)
|
||||||
#endif /* MDBX_ASSUME_MALLOC_OVERHEAD */
|
#endif /* MDBX_ASSUME_MALLOC_OVERHEAD */
|
||||||
|
|
||||||
|
/* The maximum size of a database page.
|
||||||
|
*
|
||||||
|
* It is 64K, but value-PAGEHDRSZ must fit in MDBX_page.mp_upper.
|
||||||
|
*
|
||||||
|
* MDBX will use database pages < OS pages if needed.
|
||||||
|
* That causes more I/O in write transactions: The OS must
|
||||||
|
* know (read) the whole page before writing a partial page.
|
||||||
|
*
|
||||||
|
* Note that we don't currently support Huge pages. On Linux,
|
||||||
|
* regular data files cannot use Huge pages, and in general
|
||||||
|
* Huge pages aren't actually pageable. We rely on the OS
|
||||||
|
* demand-pager to read our data and page it out when memory
|
||||||
|
* pressure from other processes is high. So until OSs have
|
||||||
|
* actual paging support for Huge pages, they're not viable. */
|
||||||
|
#define MAX_PAGESIZE 0x10000u
|
||||||
|
#define MIN_PAGESIZE 512u
|
||||||
|
|
||||||
|
#define MIN_MAPSIZE (MIN_PAGESIZE * MIN_PAGENO)
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
#define MAX_MAPSIZE32 UINT32_C(0x38000000)
|
||||||
|
#else
|
||||||
|
#define MAX_MAPSIZE32 UINT32_C(0x7ff80000)
|
||||||
|
#endif
|
||||||
|
#define MAX_MAPSIZE64 (MAX_PAGENO * (uint64_t)MAX_PAGESIZE)
|
||||||
|
|
||||||
|
#if MDBX_WORDBITS >= 64
|
||||||
|
#define MAX_MAPSIZE MAX_MAPSIZE64
|
||||||
|
#define MDBX_READERS_LIMIT \
|
||||||
|
((65536 - sizeof(MDBX_lockinfo)) / sizeof(MDBX_reader) + 1)
|
||||||
|
#else
|
||||||
|
#define MDBX_READERS_LIMIT 1024
|
||||||
|
#define MAX_MAPSIZE MAX_MAPSIZE32
|
||||||
|
#endif /* MDBX_WORDBITS */
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Two kind lists of pages (aka PNL) */
|
/* Two kind lists of pages (aka PNL) */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user