rok commented on code in PR #14194:
URL: https://github.com/apache/arrow/pull/14194#discussion_r976792240


##########
cpp/src/arrow/memory_pool_jemalloc.cc:
##########
@@ -167,16 +166,31 @@ Result<int64_t> jemalloc_get_stat(const char* name) {
       std::strcmp(name, "stats.mapped") == 0 ||
       std::strcmp(name, "stats.retained") == 0) {
     uint64_t epoch;
+    sz = sizeof(epoch);
     mallctl("epoch", &epoch, &sz, &epoch, sz);
   }
 
-  err = mallctl(name, &value, &sz, nullptr, 0);
-
-  if (err) {
-    return arrow::internal::IOErrorFromErrno(err, "Failed retrieving ", &name);
+  // Depending on the stat being queried and on the platform, we could need
+  // to pass a uint32_t or uint64_t pointer. Try both.
+  {
+    uint32_t value = 0;
+    sz = sizeof(value);
+    err = mallctl(name, &value, &sz, nullptr, 0);
+    if (!err) {
+      return value;
+    }
+  }
+  // EINVAL means the given value length (`sz`) was incorrect.
+  if (err == EINVAL) {
+    uint64_t value = 0;
+    sz = sizeof(value);
+    err = mallctl(name, &value, &sz, nullptr, 0);
+    if (!err) {
+      return value;
+    }

Review Comment:
   ```suggestion
     // Depending on the stat being queried and on the platform, we could need
     // to pass a uint64_t or uint32_t pointer. Try both.
     {
       uint64_t value = 0;
       sz = sizeof(value);
       err = mallctl(name, &value, &sz, nullptr, 0);
       if (!err) {
         return value;
       }
     }
     // EINVAL means the given value length (`sz`) was incorrect.
     if (err == EINVAL) {
       uint32_t value = 0;
       sz = sizeof(value);
       err = mallctl(name, &value, &sz, nullptr, 0);
       if (!err) {
         return value;
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to