Changeset: 841d21b018a5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/841d21b018a5
Modified Files:
gdk/gdk.h
gdk/gdk_atoms.c
gdk/gdk_logger.c
gdk/gdk_private.h
gdk/gdk_string.c
gdk/gdk_system.c
gdk/gdk_system_private.h
gdk/gdk_utils.c
geom/monetdb5/geom_atoms.c
monetdb5/modules/atoms/json.c
Branch: resource_management
Log Message:
The atom read functions need to call GDKmalloc when called from the logger.
Also some other fixes and changes, e.g., print allocator info on the
thread-private allocators for the USR1 signal.
diffs (truncated from 499 to 300 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1767,7 +1767,7 @@ gdk_export allocator *ma_get_ta(allocato
#define MA_STRNDUP( sa, s, l) ma_strndup(sa, s, l)
-#if !defined(NDEBUG) && !defined(__COVERITY__) && defined(__GNUC__)
+#if !defined(NDEBUG) && !defined(__COVERITY__) && defined(__GNUC__) &&
!defined(_CLANGD)
#define ma_alloc(sa, sz) \
({ \
allocator *_sa = (sa); \
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -460,9 +460,9 @@ ATOMdup(int t, const void *p)
#define atommem(size) \
do { \
if (*dst == NULL || *len < (size)) { \
- /*GDKfree(*dst);*/ \
+ /*GDKfree(*dst);*/ \
*len = (size); \
- *dst = ma_alloc(ma, *len); \
+ *dst = ma_alloc(ma, *len); \
if (*dst == NULL) { \
*len = 0; \
return -1; \
@@ -887,12 +887,17 @@ hgeFromStr(allocator *ma, const char *sr
#define atom_io(TYPE, NAME, CAST) \
static TYPE * \
-TYPE##Read(allocator *ma, TYPE *A, size_t *dstlen, stream *s, size_t cnt)
\
+TYPE##Read(allocator *ma, TYPE *A, size_t *dstlen, stream *s, size_t cnt) \
{ \
- (void) ma; \
TYPE *a = A; \
if (a == NULL || *dstlen < cnt * sizeof(TYPE)) { \
- if ((a = GDKrealloc(a, cnt * sizeof(TYPE))) == NULL) \
+ if (ma) { \
+ a = ma_realloc(ma, a, cnt * sizeof(TYPE), *dstlen); \
+ } else { \
+ GDKfree(a); \
+ a = GDKmalloc(cnt * sizeof(TYPE)); \
+ } \
+ if (a == NULL) \
return NULL; \
*dstlen = cnt * sizeof(TYPE); \
} \
@@ -924,13 +929,18 @@ mskWrite(const msk *a, stream *s, size_t
static void *
mskRead(allocator *ma, msk *A, size_t *dstlen, stream *s, size_t cnt)
{
- (void) ma;
int8_t v;
msk *a = A;
if (cnt != 1)
return NULL;
if (a == NULL || *dstlen == 0) {
- if ((a = GDKrealloc(a, 1)) == NULL)
+ if (ma) {
+ a = ma_realloc(ma, a, 1, *dstlen);
+ } else {
+ GDKfree(a);
+ a = GDKmalloc(1);
+ }
+ if (a == NULL)
return NULL;
*dstlen = 1;
}
@@ -1361,10 +1371,15 @@ UUIDhash(const void *v)
static void *
UUIDread(allocator *ma, void *U, size_t *dstlen, stream *s, size_t cnt)
{
- (void) ma;
uuid *u = U;
if (u == NULL || *dstlen < cnt * sizeof(uuid)) {
- if ((u = GDKrealloc(u, cnt * sizeof(uuid))) == NULL)
+ if (ma) {
+ u = ma_realloc(ma, u, cnt * sizeof(uuid), *dstlen);
+ } else {
+ GDKfree(u);
+ u = GDKmalloc(cnt * sizeof(uuid));
+ }
+ if (u == NULL)
return NULL;
*dstlen = cnt * sizeof(uuid);
}
@@ -1509,10 +1524,15 @@ INET4hash(const void *v)
static void *
INET4read(allocator *ma, void *U, size_t *dstlen, stream *s, size_t cnt)
{
- (void) ma;
inet4 *u = U;
if (u == NULL || *dstlen < cnt * sizeof(inet4)) {
- if ((u = GDKrealloc(u, cnt * sizeof(inet4))) == NULL)
+ if (ma) {
+ u = ma_realloc(ma, u, cnt * sizeof(inet4), *dstlen);
+ } else {
+ GDKfree(u);
+ u = GDKmalloc(cnt * sizeof(inet4));
+ }
+ if (u == NULL)
return NULL;
*dstlen = cnt * sizeof(inet4);
}
@@ -1724,10 +1744,15 @@ INET6hash(const void *v)
static void *
INET6read(allocator *ma, void *U, size_t *dstlen, stream *s, size_t cnt)
{
- (void) ma;
inet6 *u = U;
if (u == NULL || *dstlen < cnt * sizeof(inet6)) {
- if ((u = GDKrealloc(u, cnt * sizeof(inet6))) == NULL)
+ if (ma) {
+ u = ma_realloc(ma, u, cnt * sizeof(inet6), *dstlen);
+ } else {
+ GDKfree(u);
+ u = GDKmalloc(cnt * sizeof(inet6));
+ }
+ if (u == NULL)
return NULL;
*dstlen = cnt * sizeof(inet6);
}
@@ -1880,7 +1905,13 @@ BLOBread(allocator *ma, void *A, size_t
if (mnstr_readInt(s, &len) != 1 || len < 0)
return NULL;
if (a == NULL || *dstlen < (size_t) len) {
- if ((a = ma_realloc(ma, a, (size_t) len, *dstlen)) == NULL)
+ if (ma) {
+ a = ma_realloc(ma, a, (size_t) len, *dstlen);
+ } else {
+ GDKfree(a);
+ a = GDKmalloc((size_t) len);
+ }
+ if (a == NULL)
return NULL;
*dstlen = (size_t) len;
}
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -385,6 +385,7 @@ log_read_updates(allocator *ma, logger *
bte type_id = -1;
int tpe;
+ (void) ma;
assert(!lg->inmemory);
TRC_DEBUG(WAL, "found %d %s", id, l->flag == LOG_UPDATE ? "update" :
"update_buld");
@@ -452,10 +453,13 @@ log_read_updates(allocator *ma, logger *
/* We have to read the value to update the read
cursor */
size_t tlen = lg->rbufsize;
- void *t = rt(ma, lg->rbuf, &tlen,
lg->input_log, 1);
+ void *t = rt(NULL, lg->rbuf, &tlen,
lg->input_log, 1);
if (t == NULL) {
TRC_CRITICAL(GDK, "read failed\n");
res = LOG_EOF;
+ } else {
+ lg->rbuf = t;
+ lg->rbufsize = tlen;
}
return res;
}
@@ -477,13 +481,14 @@ log_read_updates(allocator *ma, logger *
return LOG_EOF;
}
size_t tlen = lg->rbufsize;
- void *t = rt(ma, lg->rbuf, &tlen,
lg->input_log, 1);
+ void *t = rt(NULL, lg->rbuf, &tlen,
lg->input_log, 1);
if (t == NULL) {
TRC_CRITICAL(GDK, "read
failed\n");
return LOG_EOF;
- } else if (append) {
- lg->rbuf = t;
- lg->rbufsize = tlen;
+ }
+ lg->rbuf = t;
+ lg->rbufsize = tlen;
+ if (append) {
for (BUN p = 0; p < (BUN) nr;
p++)
*c++ = (oid) offset++;
} else
@@ -520,7 +525,7 @@ log_read_updates(allocator *ma, logger *
if (l->flag == LOG_UPDATE_CONST) {
size_t tlen = lg->rbufsize;
- void *t = rt(ma, lg->rbuf, &tlen, lg->input_log, 1);
+ void *t = rt(NULL, lg->rbuf, &tlen, lg->input_log, 1);
if (t == NULL) {
TRC_CRITICAL(GDK, "read failed\n");
res = LOG_EOF;
@@ -557,7 +562,7 @@ log_read_updates(allocator *ma, logger *
return LOG_EOF;
}
size_t tlen = lg->rbufsize;
- void *t = rt(ma, lg->rbuf, &tlen,
lg->input_log, 1);
+ void *t = rt(NULL, lg->rbuf, &tlen,
lg->input_log, 1);
if (t == NULL) {
TRC_CRITICAL(GDK, "read failed\n");
res = LOG_EOF;
@@ -627,7 +632,7 @@ log_read_updates(allocator *ma, logger *
* BUFSIZE/width rows */
for (; res == LOG_OK && snr > 0; snr -=
cnt) {
cnt = snr > tlen ? tlen : snr;
- void *t = rt(ma, lg->rbuf,
&ntlen, lg->input_log, cnt);
+ void *t = rt(NULL, lg->rbuf,
&ntlen, lg->input_log, cnt);
if (t == NULL) {
res = LOG_EOF;
@@ -645,7 +650,7 @@ log_read_updates(allocator *ma, logger *
} else {
for (; res == LOG_OK && nr > 0; nr--) {
size_t tlen = lg->rbufsize;
- void *t = rt(ma, lg->rbuf,
&tlen, lg->input_log, 1);
+ void *t = rt(NULL, lg->rbuf,
&tlen, lg->input_log, 1);
if (t == NULL) {
/* see if failure was
due to
@@ -679,7 +684,7 @@ log_read_updates(allocator *ma, logger *
}
for (; res == LOG_OK && nr > 0; nr--) {
size_t hlen = sizeof(oid);
- void *h = rh(ma, hv, &hlen, lg->input_log, 1);
+ void *h = rh(NULL, hv, &hlen, lg->input_log, 1);
if (h == NULL) {
res = LOG_EOF;
TRC_CRITICAL(GDK, "read failed\n");
@@ -725,7 +730,7 @@ log_read_updates(allocator *ma, logger *
} else {
for (; res == LOG_OK && nr > 0; nr--) {
size_t tlen = lg->rbufsize;
- void *t = rt(ma, lg->rbuf,
&tlen, lg->input_log, 1);
+ void *t = rt(NULL, lg->rbuf,
&tlen, lg->input_log, 1);
if (t == NULL) {
if (strstr(GDKerrbuf,
"malloc") == NULL)
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -39,32 +39,6 @@ enum range_comp_t {
range_inside, /* search range inside bat range */
};
-struct allocator {
- struct allocator *pa;
- struct allocator *ta;
- size_t size; /* size of the allocator in terms of blocks */
- size_t nr; /* number of blocks allocated */
- char **blks;
- char *first_blk;
- size_t used; /* memory used in last block */
- size_t usedmem; /* total used memory */
- size_t blk_size; /* size of the last allocated block */
- size_t objects; /* number of objects */
- size_t inuse; /* number of objects in use*/
- size_t free_obj_hits; /* number of object reuse*/
- void *freelist; /* first free object */
- void *freelist_blks; /* first free blk */
- size_t frees;
- size_t free_blk_hits;
- size_t tmp_used; /* counter for temp usage */
-
- int refcount;
- exception_buffer eb;
- MT_Lock lock; /* lock for thread-safe allocations */
- bool use_lock;
- char name [MT_NAME_LEN]; /* Name (only for display!) */
-};
-
/* checkpoint or snapshot of allocator internal state we can use
* to restore to a point in time */
struct allocator_state {
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -55,9 +55,9 @@
#define atommem(size) \
do { \
if (*dst == NULL || *len < (size)) { \
- /*GDKfree(*dst);*/ \
+ /*GDKfree(*dst);*/ \
*len = (size); \
- *dst = ma_alloc(ma, *len); \
+ *dst = ma_alloc(ma, *len); \
if (*dst == NULL) { \
*len = 0; \
return -1; \
@@ -767,7 +767,13 @@ strRead(allocator *ma, str a, size_t *ds
if (mnstr_readInt(s, &len) != 1 || len < 0)
return NULL;
if (a == NULL || *dstlen < (size_t) len + 1) {
- if ((a = ma_realloc(ma, a, len + 1, *dstlen)) == NULL)
+ if (ma) {
+ a = ma_realloc(ma, a, (size_t) len + 1, *dstlen);
+ } else {
+ GDKfree(a);
+ a = GDKmalloc((size_t) len + 1);
+ }
+ if (a == NULL)
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]