| 139 | } |
| 140 | |
| 141 | void GcTcmalloc() { |
| 142 | TRACE_EVENT0("process", "GcTcmalloc"); |
| 143 | |
| 144 | // Number of bytes in the 'NORMAL' free list (i.e reserved by tcmalloc but |
| 145 | // not in use). |
| 146 | int64_t bytes_overhead = GetTCMallocProperty("tcmalloc.pageheap_free_bytes"); |
| 147 | // Bytes allocated by the application. |
| 148 | int64_t bytes_used = GetTCMallocCurrentAllocatedBytes(); |
| 149 | |
| 150 | int64_t max_overhead = bytes_used * FLAGS_tcmalloc_max_free_bytes_percentage / 100.0; |
| 151 | if (bytes_overhead > max_overhead) { |
| 152 | int64_t extra = bytes_overhead - max_overhead; |
| 153 | while (extra > 0) { |
| 154 | // Release 1MB at a time, so that tcmalloc releases its page heap lock |
| 155 | // allowing other threads to make progress. This still disrupts the current |
| 156 | // thread, but is better than disrupting all. |
| 157 | MallocExtension::instance()->ReleaseToSystem(1024 * 1024); |
| 158 | extra -= 1024 * 1024; |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | #endif // TCMALLOC_ENABLED |
| 163 | |
| 164 |
no test coverage detected