This is an automated email from the ASF dual-hosted git repository.
kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new de3bdd9c0cb GH-55362: [C++] Fix jemalloc ReleaseUnused implementation
(#55363)
de3bdd9c0cb is described below
commit de3bdd9c0cbd8f091c6045ffd86a669ff2cdbfb4
Author: Adam Reeve <[email protected]>
AuthorDate: Wed Nov 4 10:28:19 2026 +1300
GH-55362: [C++] Fix jemalloc ReleaseUnused implementation (#55363)
### Rationale for this change
Makes ReleaseUnused no longer an unintentional no-op with Jemalloc.
### What changes are included in this PR?
Correctly builds the `mallctl` argument when calling
`JemallocAllocator::ReleaseUnused`, and adds a debug-check of the error code.
### Are these changes tested?
Yes. I tested that without the fix, the `DCHECK_EQ` raised an error for
`Jemalloc/TestMemoryPool/0.ReleaseUnused`:
```
Check failed: (err) == (0) Failed to purge jemalloc arenas: No such file or
directory
```
With the fix, the tests pass.
I also ran an extra test that dirty pages were now released successfully
and reduced to 0, when before they weren't. But I'm not sure this is worth
committing as it could be affected by changes to jemalloc internals.
### Are there any user-facing changes?
No.
### Was AI used for this PR?
In accordance to the [AI generation
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
please disclose below whether and how AI was used in this PR.
**PR code and description written by:**
- [x] Human
- [x] AI
**Reviewed before submission by:**
- [x] Human
- [ ] AI
- [ ] Not reviewed
* GitHub Issue: #55362
Authored-by: Adam Reeve <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
cpp/src/arrow/memory_pool_jemalloc.cc | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/cpp/src/arrow/memory_pool_jemalloc.cc
b/cpp/src/arrow/memory_pool_jemalloc.cc
index bb428272146..fb35c50d88e 100644
--- a/cpp/src/arrow/memory_pool_jemalloc.cc
+++ b/cpp/src/arrow/memory_pool_jemalloc.cc
@@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.
+#include <cstring>
+#include <string>
+
#include "arrow/memory_pool_internal.h"
#include "arrow/util/io_util.h"
#include "arrow/util/logging_internal.h" // IWYU pragma: keep
@@ -128,7 +131,9 @@ void JemallocAllocator::DeallocateAligned(uint8_t* ptr,
int64_t size, int64_t al
}
void JemallocAllocator::ReleaseUnused() {
- mallctl("arena." ARROW_STRINGIFY(MALLCTL_ARENAS_ALL) ".purge", NULL, NULL,
NULL, 0);
+ const std::string purge_name = "arena." + std::to_string(MALLCTL_ARENAS_ALL)
+ ".purge";
+ int err = mallctl(purge_name.c_str(), nullptr, nullptr, nullptr, 0);
+ DCHECK_EQ(err, 0) << "Failed to purge jemalloc arenas: " <<
std::strerror(err);
}
void JemallocAllocator::PrintStats() {