From 098f8a0d77ea8f9a8a8fc73e3e7ea29c57fc3afe Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Mon, 2 Sep 2019 13:23:39 +0300 Subject: [PATCH] mdbx: add MDBX_READERS_LIMIT. Change-Id: I2ee97004c084aeb6290c56b8f6415adc464a1bcb --- src/elements/core.c | 4 +-- src/elements/internals.h | 65 +++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/elements/core.c b/src/elements/core.c index bbffedf7..5c797616 100644 --- a/src/elements/core.c +++ b/src/elements/core.c @@ -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) { - if (unlikely(readers < 1 || readers > INT16_MAX)) + if (unlikely(readers < 1 || readers > MDBX_READERS_LIMIT)) return MDBX_EINVAL; if (unlikely(!env)) @@ -6781,7 +6781,7 @@ static int __cold mdbx_setup_lck(MDBX_env *env, char *lck_pathname, const size_t maxreaders = ((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); err = MDBX_PROBLEM; goto bailout; diff --git a/src/elements/internals.h b/src/elements/internals.h index ff2b7810..a1d45faf 100644 --- a/src/elements/internals.h +++ b/src/elements/internals.h @@ -336,37 +336,6 @@ typedef struct MDBX_page { /* Size of the page header, excluding dynamic data at the end */ #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) /* Reader Lock Table @@ -527,6 +496,40 @@ typedef struct MDBX_lockinfo { #define MDBX_ASSUME_MALLOC_OVERHEAD (sizeof(void *) * 2u) #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) */