You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "cmcfarlen (via GitHub)" <gi...@apache.org> on 2023/03/01 17:27:56 UTC

[GitHub] [trafficserver] cmcfarlen commented on a diff in pull request #9479: Hugepage config cleanup

cmcfarlen commented on code in PR #9479:
URL: https://github.com/apache/trafficserver/pull/9479#discussion_r1122090641


##########
iocore/eventsystem/IOBuffer.cc:
##########
@@ -73,6 +74,80 @@ init_buffer_allocators(int iobuffer_advice)
   init_buffer_allocators(iobuffer_advice, chunk_sizes, false);
 }
 
+auto
+make_buffer_size_parser()
+{
+  return [l = swoc::Lexicon<int>{
+            {{0, {"128"}},
+             {1, {"256"}},
+             {2, {"512"}},
+             {3, {"1k", "1024"}},
+             {4, {"2k", "2048"}},
+             {5, {"4k", "4096"}},
+             {6, {"8k", "8192"}},
+             {7, {"16k"}},
+             {8, {"32k"}},
+             {9, {"64k"}},
+             {10, {"128k"}},
+             {11, {"256k"}},
+             {12, {"512k"}},
+             {13, {"1M", "1024k"}},
+             {14, {"2M", "2048k"}}},
+            -1
+  }](ts::TextView esize) -> std::optional<int> {
+    int result = l[esize];
+    if (result == -1) {
+      return std::nullopt;
+    }
+    return result;
+  };
+}
+
+bool
+parse_buffer_chunk_sizes(const char *chunk_sizes_string, int chunk_sizes[DEFAULT_BUFFER_SIZES])
+{
+  const ts::TextView delimiters(", ");
+  if (chunk_sizes_string != nullptr) {
+    ts::TextView src(chunk_sizes_string, ts::TextView::npos);
+    auto parser = make_buffer_size_parser();
+    int n       = 0;
+    while (!src.empty()) {
+      ts::TextView token{src.take_prefix_at(delimiters)};
+
+      ts::TextView esize = token.take_prefix_at(':');
+      if (!token.empty()) {
+        auto parsed = parser(esize);
+        if (parsed) {
+          n = *parsed;
+        } else {
+          Error("Failed to parse size for %.*s", static_cast<int>(esize.size()), esize.data());
+          return false;
+        }
+      } else {
+        // element didn't have a colon so its just a chunk size
+        token = esize;
+      }
+
+      // Check if n goes out of bounds
+      if (n >= DEFAULT_BUFFER_SIZES) {
+        Error("Invalid IO buffer chunk sizes string");
+        return false;
+      }
+
+      auto x = ts::svto_radix<10>(token);
+      if (token.empty() && x <= std::numeric_limits<int>::max()) {

Review Comment:
   oops, unfixed!  Thanks!



-- 
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: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org