| 243 | // to return. |
| 244 | template<typename T> |
| 245 | Try<Nothing> writeJemallocSetting(const char* name, const T& value) |
| 246 | { |
| 247 | #ifdef LIBPROCESS_ALLOW_JEMALLOC |
| 248 | if (!detectJemalloc()) { |
| 249 | return Error(JEMALLOC_NOT_DETECTED_MESSAGE); |
| 250 | } |
| 251 | |
| 252 | int error = mallctl( |
| 253 | name, nullptr, nullptr, const_cast<T*>(&value), sizeof(value)); |
| 254 | |
| 255 | if (error) { |
| 256 | return Error(strings::format( |
| 257 | "Couldn't write value %s for option %s: %s", |
| 258 | stringify(value), name, ::strerror(error)).get()); |
| 259 | } |
| 260 | |
| 261 | return Nothing(); |
| 262 | #else |
| 263 | UNREACHABLE(); |
| 264 | #endif |
| 265 | } |
| 266 | |
| 267 | |
| 268 | // All generated disk artifacts, i.e. profiles and graph files, are stored |