Defrag helper for generic allocations. * * returns NULL in case the allocation wasn't moved. * when it returns a non-null value, the old pointer was already released * and should NOT be accessed. */
| 54 | * when it returns a non-null value, the old pointer was already released |
| 55 | * and should NOT be accessed. */ |
| 56 | void* activeDefragAlloc(void *ptr) { |
| 57 | size_t size; |
| 58 | void *newptr; |
| 59 | if(!je_get_defrag_hint(ptr)) { |
| 60 | server.stat_active_defrag_misses++; |
| 61 | return NULL; |
| 62 | } |
| 63 | /* move this allocation to a new allocation. |
| 64 | * make sure not to use the thread cache. so that we don't get back the same |
| 65 | * pointers we try to free */ |
| 66 | size = zmalloc_size(ptr); |
| 67 | newptr = zmalloc_no_tcache(size); |
| 68 | memcpy(newptr, ptr, size); |
| 69 | zfree_no_tcache(ptr); |
| 70 | return newptr; |
| 71 | } |
| 72 | |
| 73 | /*Defrag helper for sds strings |
| 74 | * |
no test coverage detected