mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 04:34:12 +08:00
mdbx: преимущественное использование size_t
для уменьшения накладных расходов на платформе Эльбрус.
This commit is contained in:
parent
bcd5bad74a
commit
143e3dfb77
1508
src/core.c
1508
src/core.c
File diff suppressed because it is too large
Load Diff
@ -570,7 +570,7 @@ typedef struct MDBX_page {
|
||||
: PAGETYPE_WHOLE(p))
|
||||
|
||||
/* Size of the page header, excluding dynamic data at the end */
|
||||
#define PAGEHDRSZ ((unsigned)offsetof(MDBX_page, mp_ptrs))
|
||||
#define PAGEHDRSZ offsetof(MDBX_page, mp_ptrs)
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
@ -860,7 +860,7 @@ typedef struct MDBX_dp {
|
||||
MDBX_page *ptr;
|
||||
pgno_t pgno;
|
||||
union {
|
||||
unsigned extra;
|
||||
uint32_t extra;
|
||||
__anonymous_struct_extension__ struct {
|
||||
unsigned multi : 1;
|
||||
unsigned lru : 31;
|
||||
@ -870,10 +870,10 @@ typedef struct MDBX_dp {
|
||||
|
||||
/* An DPL (dirty-page list) is a sorted array of MDBX_DPs. */
|
||||
typedef struct MDBX_dpl {
|
||||
unsigned sorted;
|
||||
unsigned length;
|
||||
unsigned pages_including_loose; /* number of pages, but not an entries. */
|
||||
unsigned detent; /* allocated size excluding the MDBX_DPL_RESERVE_GAP */
|
||||
size_t sorted;
|
||||
size_t length;
|
||||
size_t pages_including_loose; /* number of pages, but not an entries. */
|
||||
size_t detent; /* allocated size excluding the MDBX_DPL_RESERVE_GAP */
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
|
||||
(!defined(__cplusplus) && defined(_MSC_VER))
|
||||
MDBX_dp items[] /* dynamic size with holes at zero and after the last */;
|
||||
@ -892,11 +892,17 @@ typedef struct MDBX_dpl {
|
||||
((1u << 17) - 2 - MDBX_ASSUME_MALLOC_OVERHEAD / sizeof(txnid_t))
|
||||
|
||||
#define MDBX_PNL_ALLOCLEN(pl) ((pl)[-1])
|
||||
#define MDBX_PNL_SIZE(pl) ((pl)[0])
|
||||
#define MDBX_PNL_GETSIZE(pl) ((size_t)((pl)[0]))
|
||||
#define MDBX_PNL_SETSIZE(pl, size) \
|
||||
do { \
|
||||
const size_t __size = size; \
|
||||
assert(__size < INT_MAX); \
|
||||
(pl)[0] = (pgno_t)__size; \
|
||||
} while (0)
|
||||
#define MDBX_PNL_FIRST(pl) ((pl)[1])
|
||||
#define MDBX_PNL_LAST(pl) ((pl)[MDBX_PNL_SIZE(pl)])
|
||||
#define MDBX_PNL_LAST(pl) ((pl)[MDBX_PNL_GETSIZE(pl)])
|
||||
#define MDBX_PNL_BEGIN(pl) (&(pl)[1])
|
||||
#define MDBX_PNL_END(pl) (&(pl)[MDBX_PNL_SIZE(pl) + 1])
|
||||
#define MDBX_PNL_END(pl) (&(pl)[MDBX_PNL_GETSIZE(pl) + 1])
|
||||
|
||||
#if MDBX_PNL_ASCENDING
|
||||
#define MDBX_PNL_LEAST(pl) MDBX_PNL_FIRST(pl)
|
||||
@ -906,8 +912,8 @@ typedef struct MDBX_dpl {
|
||||
#define MDBX_PNL_MOST(pl) MDBX_PNL_FIRST(pl)
|
||||
#endif
|
||||
|
||||
#define MDBX_PNL_SIZEOF(pl) ((MDBX_PNL_SIZE(pl) + 1) * sizeof(pgno_t))
|
||||
#define MDBX_PNL_IS_EMPTY(pl) (MDBX_PNL_SIZE(pl) == 0)
|
||||
#define MDBX_PNL_SIZEOF(pl) ((MDBX_PNL_GETSIZE(pl) + 1) * sizeof(pgno_t))
|
||||
#define MDBX_PNL_IS_EMPTY(pl) (MDBX_PNL_GETSIZE(pl) == 0)
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Internal structures */
|
||||
@ -1013,13 +1019,13 @@ struct MDBX_txn {
|
||||
#if MDBX_ENABLE_REFUND
|
||||
pgno_t loose_refund_wl /* FIXME: describe */;
|
||||
#endif /* MDBX_ENABLE_REFUND */
|
||||
/* a sequence to spilling dirty page with LRU policy */
|
||||
unsigned dirtylru;
|
||||
/* dirtylist room: Dirty array size - dirty pages visible to this txn.
|
||||
* Includes ancestor txns' dirty pages not hidden by other txns'
|
||||
* dirty/spilled pages. Thus commit(nested txn) has room to merge
|
||||
* dirtylist into mt_parent after freeing hidden mt_parent pages. */
|
||||
unsigned dirtyroom;
|
||||
/* a sequence to spilling dirty page with LRU policy */
|
||||
unsigned dirtylru;
|
||||
size_t dirtyroom;
|
||||
/* For write txns: Modified pages. Sorted when not MDBX_WRITEMAP. */
|
||||
MDBX_dpl *dirtylist;
|
||||
/* The list of reclaimed txns from GC */
|
||||
@ -1030,8 +1036,8 @@ struct MDBX_txn {
|
||||
* in this transaction, linked through `mp_next`. */
|
||||
MDBX_page *loose_pages;
|
||||
/* Number of loose pages (tw.loose_pages) */
|
||||
unsigned loose_count;
|
||||
unsigned spill_least_removed;
|
||||
size_t loose_count;
|
||||
size_t spill_least_removed;
|
||||
/* The sorted list of dirty pages we temporarily wrote to disk
|
||||
* because the dirty list was full. page numbers in here are
|
||||
* shifted left by 1, deleted slots have the LSB set. */
|
||||
|
@ -583,7 +583,7 @@ static size_t osal_iov_max;
|
||||
|
||||
MDBX_INTERNAL_FUNC int osal_ioring_create(osal_ioring_t *ior,
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
unsigned flags,
|
||||
uint8_t flags,
|
||||
#endif /* Windows */
|
||||
mdbx_filehandle_t fd) {
|
||||
memset(ior, 0, sizeof(osal_ioring_t));
|
||||
@ -1480,14 +1480,14 @@ MDBX_INTERNAL_FUNC int osal_write(mdbx_filehandle_t fd, const void *buf,
|
||||
}
|
||||
}
|
||||
|
||||
int osal_pwritev(mdbx_filehandle_t fd, struct iovec *iov, int sgvcnt,
|
||||
int osal_pwritev(mdbx_filehandle_t fd, struct iovec *iov, size_t sgvcnt,
|
||||
uint64_t offset) {
|
||||
size_t expected = 0;
|
||||
for (int i = 0; i < sgvcnt; ++i)
|
||||
for (size_t i = 0; i < sgvcnt; ++i)
|
||||
expected += iov[i].iov_len;
|
||||
#if !MDBX_HAVE_PWRITEV
|
||||
size_t written = 0;
|
||||
for (int i = 0; i < sgvcnt; ++i) {
|
||||
for (size_t i = 0; i < sgvcnt; ++i) {
|
||||
int rc = osal_pwrite(fd, iov[i].iov_base, iov[i].iov_len, offset);
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
return rc;
|
||||
|
@ -352,7 +352,7 @@ typedef struct osal_ioring {
|
||||
/* Actually this is not ioring for now, but on the way. */
|
||||
MDBX_INTERNAL_FUNC int osal_ioring_create(osal_ioring_t *,
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
unsigned flags,
|
||||
uint8_t flags,
|
||||
#endif /* Windows */
|
||||
mdbx_filehandle_t fd);
|
||||
MDBX_INTERNAL_FUNC int osal_ioring_resize(osal_ioring_t *, size_t items);
|
||||
@ -380,11 +380,11 @@ static inline unsigned osal_ioring_used(const osal_ioring_t *ior) {
|
||||
return ior->allocated - ior->slots_left;
|
||||
}
|
||||
|
||||
static inline int osal_ioring_reserve(osal_ioring_t *ior, unsigned items,
|
||||
static inline int osal_ioring_reserve(osal_ioring_t *ior, size_t items,
|
||||
size_t bytes) {
|
||||
items = (items > 32) ? items : 32;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
const unsigned npages = (unsigned)(bytes >> ior->pagesize_ln2);
|
||||
const size_t npages = bytes >> ior->pagesize_ln2;
|
||||
items = (items > npages) ? items : npages;
|
||||
#else
|
||||
(void)bytes;
|
||||
@ -468,7 +468,7 @@ MDBX_INTERNAL_FUNC int osal_fastmutex_release(osal_fastmutex_t *fastmutex);
|
||||
MDBX_INTERNAL_FUNC int osal_fastmutex_destroy(osal_fastmutex_t *fastmutex);
|
||||
|
||||
MDBX_INTERNAL_FUNC int osal_pwritev(mdbx_filehandle_t fd, struct iovec *iov,
|
||||
int sgvcnt, uint64_t offset);
|
||||
size_t sgvcnt, uint64_t offset);
|
||||
MDBX_INTERNAL_FUNC int osal_pread(mdbx_filehandle_t fd, void *buf, size_t count,
|
||||
uint64_t offset);
|
||||
MDBX_INTERNAL_FUNC int osal_pwrite(mdbx_filehandle_t fd, const void *buf,
|
||||
|
Loading…
x
Reference in New Issue
Block a user