• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3614

14 Feb 2025 09:14AM UTC coverage: 61.4% (-2.1%) from 63.499%
#3614

push

travis-ci

web-flow
Merge pull request #29781 from taosdata/doc/internal

docs: minor changes

142800 of 298998 branches covered (47.76%)

Branch coverage included in aggregate %.

224842 of 299767 relevant lines covered (75.01%)

17915812.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.52
/source/util/src/mpDirect.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define _DEFAULT_SOURCE
17
#include "osMemPool.h"
18
#include "tmempoolInt.h"
19
#include "tlog.h"
20
#include "tutil.h"
21

22
void* mpDirectAlloc(SMemPool* pPool, SMPJob* pJob, int64_t size) {
2,147,483,647✔
23
  MP_CHECK_QUOTA(pPool, pJob, size);
2,147,483,647!
24
  
25
  return taosMemMalloc(size);
2,147,483,647✔
26
}
27

28

29
void* mpDirectAlignAlloc(SMemPool* pPool, SMPJob* pJob, uint32_t alignment, int64_t size) {
302,164,654✔
30
  MP_CHECK_QUOTA(pPool, pJob, size);
302,164,654!
31
  
32
  return taosMemMallocAlign(alignment, size);
302,056,135✔
33
}
34

35

36
void* mpDirectCalloc(SMemPool* pPool, SMPJob* pJob, int64_t num, int64_t size) {
2,147,483,647✔
37
  int64_t tSize = num * size;
2,147,483,647✔
38
  MP_CHECK_QUOTA(pPool, pJob, tSize);
2,147,483,647!
39

40
  return taosMemCalloc(num, size);
2,147,483,647✔
41
}
42

43
void mpDirectFree(SMemPool* pPool, SMPJob* pJob, void *ptr) {
2,147,483,647✔
44
  if (*pPool->cfg.jobQuota > 0) {
2,147,483,647!
45
    (void)atomic_sub_fetch_64(&pJob->job.allocMemSize, taosMemSize(ptr));
×
46
  }
47
  taosMemFree(ptr);
2,147,483,647✔
48
}
2,147,483,647✔
49

50

51
void* mpDirectRealloc(SMemPool* pPool, SMPJob* pJob, void* ptr, int64_t size) {
1,169,194,548✔
52
  int32_t code = TSDB_CODE_SUCCESS;
1,169,194,548✔
53

54
  if (NULL == ptr) {
1,169,194,548✔
55
    return mpDirectAlloc(pPool, pJob, size);
883,792,001✔
56
  }
57

58
  if (0 == size) {
285,402,547!
59
    mpDirectFree(pPool, pJob, ptr);
×
60
    return NULL;
×
61
  }
62

63
  int64_t oSize = taosMemSize(ptr);
285,402,547✔
64

65
  MP_CHECK_QUOTA(pPool, pJob, size - oSize);
288,714,698!
66

67
  return taosMemRealloc(ptr, size);
288,086,036✔
68
}
69

70
void* mpDirectStrdup(SMemPool* pPool, SMPJob* pJob, const void* ptr) {
195,541,428✔
71
  if (NULL == ptr) {
195,541,428!
72
    return NULL;
×
73
  }
74
  
75
  int64_t oSize = strlen(ptr);
195,541,428✔
76
  MP_CHECK_QUOTA(pPool, pJob, oSize);
195,541,428!
77
  
78
  return taosStrdupi(ptr);
195,294,835✔
79
}
80

81
void* mpDirectStrndup(SMemPool* pPool, SMPJob* pJob, const void* ptr, int64_t size) {
499,895,423✔
82
  if (NULL == ptr) {
499,895,423!
83
    return NULL;
×
84
  }
85
  
86
  int64_t oSize = strlen(ptr);
499,895,423✔
87
  MP_CHECK_QUOTA(pPool, pJob, TMIN(oSize, size) + 1);
499,895,423!
88
  
89
  return taosStrndupi(ptr, size);
500,952,116✔
90
}
91

92

93

94

95
int64_t mpDirectGetMemSize(SMemPool* pPool, SMPSession* pSession, void *ptr) {
×
96
  return taosMemSize(ptr);
×
97
}
98

99
void mpDirectFullFree(SMemPool* pPool, SMPSession* pSession, void *ptr, int64_t* origSize) {
×
100
  int64_t oSize = taosMemSize(ptr);
×
101
  if (origSize) {
×
102
    *origSize = oSize;
×
103
  }
104
  
105
  MP_LOCK(MP_READ, &pPool->cfgLock); // tmp test
×
106

107
  taosMemFree(ptr);
×
108

109
  if (NULL != pSession) {
×
110
    (void)atomic_sub_fetch_64(&pSession->allocMemSize, oSize);
×
111
    (void)atomic_sub_fetch_64(&pSession->pJob->job.allocMemSize, oSize);
×
112
  }
113
  
114
  (void)atomic_sub_fetch_64(&pPool->allocMemSize, oSize);
×
115

116
  MP_UNLOCK(MP_READ, &pPool->cfgLock);
×
117
}
×
118

119

120

121
int32_t mpDirectFullAlloc(SMemPool* pPool, SMPSession* pSession, int64_t* size, uint32_t alignment, void** ppRes) {
×
122
  int32_t code = TSDB_CODE_SUCCESS;
×
123
  void* res = NULL;
×
124
  int64_t nSize = *size;
×
125
  
126
  MP_LOCK(MP_READ, &pPool->cfgLock);
×
127

128
  MP_ERR_JRET(mpChkFullQuota(pPool, pSession, *size));
×
129
  
130
  res = alignment ? taosMemMallocAlign(alignment, *size) : taosMemMalloc(*size);
×
131
  if (NULL != res) {
×
132
    nSize = taosMemSize(res);
×
133
    mpUpdateAllocSize(pPool, pSession, nSize, nSize - *size);
×
134
  } else {
135
    if (NULL != pSession) {
×
136
      (void)atomic_sub_fetch_64(&pSession->pJob->job.allocMemSize, *size);
×
137
    }
138
    
139
    (void)atomic_sub_fetch_64(&pPool->allocMemSize, *size);
×
140
    
141
    uError("malloc %" PRId64 " alignment %d failed, code: 0x%x", *size, alignment, terrno);
×
142

143
    code = terrno;
×
144
  }
145

146
_return:
×
147

148
  MP_UNLOCK(MP_READ, &pPool->cfgLock);
×
149
  
150
  *ppRes = res;
×
151
  *size = nSize;
×
152
  
153
  MP_RET(code);
×
154
}
155

156
int32_t mpDirectFullRealloc(SMemPool* pPool, SMPSession* pSession, void **pPtr, int64_t* size, int64_t* origSize) {
×
157
  int32_t code = TSDB_CODE_SUCCESS;
×
158
  int64_t nSize = *size;
×
159

160
  MP_LOCK(MP_READ, &pPool->cfgLock);
×
161

162
  MP_ERR_JRET(mpChkFullQuota(pPool, pSession, *size - *origSize));
×
163
  
164
  *pPtr = taosMemRealloc(*pPtr, *size);
×
165
  if (NULL != *pPtr) {
×
166
    nSize = taosMemSize(*pPtr);
×
167
    mpUpdateAllocSize(pPool, pSession, nSize - *origSize, nSize - *size + *origSize);
×
168
  } else {
169
    MP_ERR_JRET(terrno);
×
170
  }
171

172
_return:
×
173

174
  MP_UNLOCK(MP_READ, &pPool->cfgLock);
×
175

176
  if (code) {
×
177
    mpDirectFullFree(pPool, pSession, *pPtr, origSize);
×
178
    *pPtr = NULL;
×
179
  }
180

181
  *size = nSize;
×
182
  
183
  return TSDB_CODE_SUCCESS;
×
184
}
185

186
int32_t mpDirectTrim(SMemPool* pPool, SMPSession* pSession, int32_t size, bool* trimed) {
×
187
  return taosMemTrim(size, trimed);
×
188
}
189

190

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc