AsyncIO::initializeContext() should provide more debug output when io_queue_init...
authorAltan Alpay <nerd@fb.com>
Thu, 12 Sep 2013 21:08:01 +0000 (14:08 -0700)
committerJordan DeLong <jdelong@fb.com>
Sun, 22 Sep 2013 23:40:13 +0000 (16:40 -0700)
Summary: It would be good idea to provide more information if the io_queue_init() failed due to resource allocation.

Test Plan:
Run standart tests + manual testing
1. fbconfig -r folly/experimental/ && fbmake runtests
2. Ask a capacity larger than aio_max_nr and check failure messages

Reviewed By: agartrell@fb.com

FB internal diff: D965260

folly/experimental/io/AsyncIO.cpp

index 83558e83b1b6f6ef506ee9a7e363116b2998d57c..3ad69a057a6acd23f95b88dd2a3d00d15448abc5 100644 (file)
@@ -21,6 +21,7 @@
 #include <cerrno>
 #include <stdexcept>
 #include <string>
+#include <fstream>
 
 #include <boost/intrusive/parent_from_member.hpp>
 #include <glog/logging.h>
@@ -139,6 +140,22 @@ void AsyncIO::initializeContext() {
     if (!ctxSet_.load(std::memory_order_relaxed)) {
       int rc = io_queue_init(capacity_, &ctx_);
       // returns negative errno
+      if (rc == -EAGAIN) {
+        long aio_nr, aio_max;
+        std::unique_ptr<FILE, int(*)(FILE*)>
+          fp(fopen("/proc/sys/fs/aio-nr", "r"), fclose);
+        PCHECK(fp);
+        CHECK_EQ(fscanf(fp.get(), "%ld", &aio_nr), 1);
+
+        std::unique_ptr<FILE, int(*)(FILE*)>
+          aio_max_fp(fopen("/proc/sys/fs/aio-max-nr", "r"), fclose);
+        PCHECK(aio_max_fp);
+        CHECK_EQ(fscanf(aio_max_fp.get(), "%ld", &aio_max), 1);
+
+        LOG(ERROR) << "No resources for requested capacity of " << capacity_;
+        LOG(ERROR) << "aio_nr " << aio_nr << ", aio_max_nr " << aio_max;
+      }
+
       checkKernelError(rc, "AsyncIO: io_queue_init failed");
       DCHECK(ctx_);
       ctxSet_.store(true, std::memory_order_release);