serrislew commented on code in PR #13997:
URL: https://github.com/apache/trafficserver/pull/13997#discussion_r4530553160


##########
src/iocore/eventsystem/IOBuffer.cc:
##########
@@ -190,6 +191,113 @@ new_IOBufferData_internal(const char *loc, int64_t 
size_index, AllocType type)
   return d;
 }
 
+namespace
+{
+static_assert(IOBUF_THREAD_CACHE_FIRST_INDEX == BUFFER_SIZE_INDEX_4K);
+static_assert(IOBUF_THREAD_CACHE_LAST_INDEX == BUFFER_SIZE_INDEX_32K);
+
+// Matches the default proxy.config.allocator.thread_freelist_size cap on the 
other per-thread caches.
+constexpr int64_t IOBUF_THREAD_CACHE_MAX_BLOCKS = 512;
+
+// Per-class watermarks for the ioBufCache freelists on each Thread. A high 
watermark of zero
+// disables the cache for that class, which is the state until 
init_iobuf_thread_cache() runs.
+int iobuf_thread_cache_high[IOBUF_THREAD_CACHE_CLASSES];
+int iobuf_thread_cache_low[IOBUF_THREAD_CACHE_CLASSES];
+
+// The per-thread cache for @a size_index on the current thread, or nullptr if 
the block
+// should go to the global allocator.
+ProxyAllocator *
+iobuf_thread_cache(int64_t size_index)
+{
+  int const cls = size_index - IOBUF_THREAD_CACHE_FIRST_INDEX;
+  if (cls < 0 || cls >= IOBUF_THREAD_CACHE_CLASSES || 
iobuf_thread_cache_high[cls] == 0 || cmd_disable_pfreelist) {
+    return nullptr;
+  }
+  Thread *t = this_thread();
+  return t ? &t->ioBufCache[cls] : nullptr;
+}
+
+// Return blocks from the head of @a l to the global freelist until @a keep 
remain. The blocks
+// were counted as freed when they entered the cache, so this must not touch 
the metrics,
+// which free_void_bulk() does not.
+void
+iobuf_thread_cache_trim(int64_t size_index, ProxyAllocator &l, int keep)
+{
+  void  *head  = l.freelist;
+  void  *tail  = l.freelist;
+  size_t count = 0;
+
+  while (l.freelist && l.allocated > keep) {
+    tail       = l.freelist;
+    l.freelist = *static_cast<void **>(l.freelist);
+    --l.allocated;
+    ++count;
+  }
+  if (count > 0) {
+    ioBufAllocator[size_index].free_void_bulk(head, tail, count);

Review Comment:
   Not a blocker but now with `free_void_bulk` and `-f (cmd_disable_freelist)`, 
this ends up in `malloc_bulkfree()` which always calls `ats_free()`. This is 
unlike `malloc_free()` which conditionalizes on `f->alignment`
   
   This predates the PR but this PR makes it reachable for IOBuffers so I 
wanted to make note of it



-- 
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