Skip to content

Commit 3e88a95

Browse files
committed
Issue#6850 - Customize Max IOBuffer Size for each usecase.
Allow callers explicitly configure and pass in the max buffer sizes when asking for unknown sized memory chunks depending on the usecase instead of relying on a common/global default config.
1 parent c20125e commit 3e88a95

File tree

12 files changed

+50
-18
lines changed

12 files changed

+50
-18
lines changed

iocore/hostdb/HostDB.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ int hostdb_max_count = DEFAULT_HOST_DB_SIZE;
6262
char hostdb_hostfile_path[PATH_NAME_MAX] = "";
6363
int hostdb_sync_frequency = 0;
6464
int hostdb_disable_reverse_lookup = 0;
65+
int hostdb_max_iobuf_index = BUFFER_SIZE_INDEX_32K;
6566

6667
ClassAllocator<HostDBContinuation> hostDBContAllocator("hostDBContAllocator");
6768

@@ -325,6 +326,8 @@ HostDBCache::start(int flags)
325326
// how often to sync hostdb to disk
326327
REC_EstablishStaticConfigInt32(hostdb_sync_frequency, "proxy.config.cache.hostdb.sync_frequency");
327328

329+
REC_EstablishStaticConfigInt32(hostdb_max_iobuf_index, "proxy.config.hostdb.io.max_buffer_index");
330+
328331
if (hostdb_max_size == 0) {
329332
Fatal("proxy.config.hostdb.max_size must be a non-zero number");
330333
}

iocore/hostdb/I_HostDBProcessor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ extern unsigned int hostdb_ip_fail_timeout_interval;
6262
extern unsigned int hostdb_serve_stale_but_revalidate;
6363
extern unsigned int hostdb_round_robin_max_count;
6464

65+
extern int hostdb_max_iobuf_index;
66+
6567
static inline unsigned int
6668
makeHostHash(const char *string)
6769
{
@@ -142,7 +144,7 @@ struct HostDBInfo : public RefCountObj {
142144
alloc(int size = 0)
143145
{
144146
size += sizeof(HostDBInfo);
145-
int iobuffer_index = iobuffer_size_to_index(size);
147+
int iobuffer_index = iobuffer_size_to_index(size, hostdb_max_iobuf_index);
146148
ink_release_assert(iobuffer_index >= 0);
147149
void *ptr = ioBufAllocator[iobuffer_index].alloc_void();
148150
memset(ptr, 0, size);

iocore/net/QUICNetVConnection.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ QUICNetVConnection::_state_common_send_packet()
13441344

13451345
Ptr<IOBufferBlock> udp_payload(new_IOBufferBlock());
13461346
uint32_t udp_payload_len = std::min(window, this->_pmtu);
1347-
udp_payload->alloc(iobuffer_size_to_index(udp_payload_len));
1347+
udp_payload->alloc(iobuffer_size_to_index(udp_payload_len, max_quic_iobuffer_index()));
13481348

13491349
uint32_t written = 0;
13501350
for (int i = static_cast<int>(this->_minimum_encryption_level); i <= static_cast<int>(QUICEncryptionLevel::ONE_RTT); ++i) {
@@ -1499,7 +1499,7 @@ QUICNetVConnection::_packetize_frames(QUICEncryptionLevel level, uint64_t max_pa
14991499
size_t len = 0;
15001500
Ptr<IOBufferBlock> first_block = make_ptr<IOBufferBlock>(new_IOBufferBlock());
15011501
Ptr<IOBufferBlock> last_block = first_block;
1502-
first_block->alloc(iobuffer_size_to_index(0));
1502+
first_block->alloc(iobuffer_size_to_index(0, BUFFER_SIZE_INDEX_32K));
15031503
first_block->fill(0);
15041504

15051505
uint32_t seq_num = this->_seq_num++;

iocore/net/QUICPacketHandler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ QUICPacketHandler::_send_packet(const QUICPacket &packet, UDPConnection *udp_con
7676
{
7777
size_t udp_len;
7878
Ptr<IOBufferBlock> udp_payload(new_IOBufferBlock());
79-
udp_payload->alloc(iobuffer_size_to_index(pmtu));
79+
udp_payload->alloc(iobuffer_size_to_index(pmtu, BUFFER_SIZE_INDEX_32K));
8080
packet.store(reinterpret_cast<uint8_t *>(udp_payload->end()), &udp_len);
8181
udp_payload->fill(udp_len);
8282

mgmt/RecordsConfig.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,14 @@ static const RecordElement RecordsConfig[] =
720720
//##############################################################################
721721
{RECT_CONFIG, "proxy.config.io.max_buffer_size", RECD_INT, "32768", RECU_NULL, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
722722
,
723+
{RECT_CONFIG, "proxy.config.hostdb.io.max_buffer_index", RECD_INT, "8", RECU_NULL, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
724+
,
725+
{RECT_CONFIG, "proxy.config.payload.io.max_buffer_index", RECD_INT, "8", RECU_NULL, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
726+
,
727+
{RECT_CONFIG, "proxy.config.msg.io.max_buffer_index", RECD_INT, "8", RECU_NULL, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
728+
,
729+
{RECT_CONFIG, "proxy.config.log.io.max_buffer_index", RECD_INT, "8", RECU_NULL, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
730+
,
723731

724732
//##############################################################################
725733
//#

proxy/http/HttpConfig.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,8 @@ HttpConfig::startup()
12841284
HttpEstablishStaticConfigByte(c.enable_http_info, "proxy.config.http.enable_http_info");
12851285

12861286
HttpEstablishStaticConfigLongLong(c.max_post_size, "proxy.config.http.max_post_size");
1287+
HttpEstablishStaticConfigLongLong(c.max_payload_iobuf_index, "proxy.config.payload.io.max_buffer_index");
1288+
HttpEstablishStaticConfigLongLong(c.max_msg_iobuf_index, "proxy.config.msg.io.max_buffer_index");
12871289

12881290
//##############################################################################
12891291
//#
@@ -1527,6 +1529,8 @@ HttpConfig::reconfigure()
15271529

15281530
params->oride.cache_when_to_revalidate = m_master.oride.cache_when_to_revalidate;
15291531
params->max_post_size = m_master.max_post_size;
1532+
params->max_payload_iobuf_index = m_master.max_payload_iobuf_index;
1533+
params->max_msg_iobuf_index = m_master.max_msg_iobuf_index;
15301534

15311535
params->oride.cache_required_headers = m_master.oride.cache_required_headers;
15321536
params->oride.cache_range_lookup = INT_TO_BOOL(m_master.oride.cache_range_lookup);

proxy/http/HttpConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,9 @@ struct HttpConfigParams : public ConfigInfo {
747747
MgmtInt post_copy_size = 2048;
748748
MgmtInt max_post_size = 0;
749749

750+
MgmtInt max_payload_iobuf_index = BUFFER_SIZE_INDEX_32K;
751+
MgmtInt max_msg_iobuf_index = BUFFER_SIZE_INDEX_32K;
752+
750753
char *redirect_actions_string = nullptr;
751754
IpMap *redirect_actions_map = nullptr;
752755
RedirectEnabled::Action redirect_actions_self_action = RedirectEnabled::Action::INVALID;

proxy/http/HttpSM.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ HttpSM::state_read_client_request_header(int event, void *data)
843843
// When receive an "Expect: 100-continue" request from client, ATS sends a "100 Continue" response to client
844844
// immediately, before receive the real response from original server.
845845
if ((len == HTTP_LEN_100_CONTINUE) && (strncasecmp(expect, HTTP_VALUE_100_CONTINUE, HTTP_LEN_100_CONTINUE) == 0)) {
846-
int64_t alloc_index = buffer_size_to_index(len_100_continue_response);
846+
int64_t alloc_index = buffer_size_to_index(len_100_continue_response, t_state.http_config_param->max_payload_iobuf_index);
847847
if (ua_entry->write_buffer) {
848848
free_MIOBuffer(ua_entry->write_buffer);
849849
ua_entry->write_buffer = nullptr;
@@ -898,7 +898,7 @@ HttpSM::wait_for_full_body()
898898
alloc_index = DEFAULT_REQUEST_BUFFER_SIZE_INDEX;
899899
}
900900
} else {
901-
alloc_index = buffer_size_to_index(t_state.hdr_info.request_content_length);
901+
alloc_index = buffer_size_to_index(t_state.hdr_info.request_content_length, t_state.http_config_param->max_payload_iobuf_index);
902902
}
903903
MIOBuffer *post_buffer = new_MIOBuffer(alloc_index);
904904
IOBufferReader *buf_start = post_buffer->alloc_reader();
@@ -5676,7 +5676,7 @@ HttpSM::setup_transform_to_server_transfer()
56765676
ink_assert(post_transform_info.entry->vc == post_transform_info.vc);
56775677

56785678
int64_t nbytes = t_state.hdr_info.transform_request_cl;
5679-
int64_t alloc_index = buffer_size_to_index(nbytes);
5679+
int64_t alloc_index = buffer_size_to_index(nbytes, t_state.http_config_param->max_payload_iobuf_index);
56805680
MIOBuffer *post_buffer = new_MIOBuffer(alloc_index);
56815681
IOBufferReader *buf_start = post_buffer->alloc_reader();
56825682

@@ -5756,7 +5756,8 @@ HttpSM::do_setup_post_tunnel(HttpVC_t to_vc_type)
57565756
alloc_index = DEFAULT_REQUEST_BUFFER_SIZE_INDEX;
57575757
}
57585758
} else {
5759-
alloc_index = buffer_size_to_index(t_state.hdr_info.request_content_length);
5759+
alloc_index =
5760+
buffer_size_to_index(t_state.hdr_info.request_content_length, t_state.http_config_param->max_payload_iobuf_index);
57605761
}
57615762
MIOBuffer *post_buffer = new_MIOBuffer(alloc_index);
57625763
IOBufferReader *buf_start = post_buffer->alloc_reader();
@@ -6177,7 +6178,8 @@ HttpSM::setup_cache_read_transfer()
61776178
ink_assert(cache_sm.cache_read_vc != nullptr);
61786179

61796180
doc_size = t_state.cache_info.object_read->object_size_get();
6180-
alloc_index = buffer_size_to_index(doc_size + index_to_buffer_size(HTTP_HEADER_BUFFER_SIZE_INDEX));
6181+
alloc_index = buffer_size_to_index(doc_size + index_to_buffer_size(HTTP_HEADER_BUFFER_SIZE_INDEX),
6182+
t_state.http_config_param->max_payload_iobuf_index);
61816183

61826184
#ifndef USE_NEW_EMPTY_MIOBUFFER
61836185
MIOBuffer *buf = new_MIOBuffer(alloc_index);
@@ -6230,7 +6232,7 @@ HttpSM::setup_cache_transfer_to_transform()
62306232
cache_response_hdr_bytes = t_state.hdr_info.cache_response.length_get();
62316233

62326234
doc_size = t_state.cache_info.object_read->object_size_get();
6233-
alloc_index = buffer_size_to_index(doc_size);
6235+
alloc_index = buffer_size_to_index(doc_size, t_state.http_config_param->max_payload_iobuf_index);
62346236
MIOBuffer *buf = new_MIOBuffer(alloc_index);
62356237
IOBufferReader *buf_start = buf->alloc_reader();
62366238

@@ -6375,7 +6377,7 @@ HttpSM::setup_internal_transfer(HttpSMHandler handler_arg)
63756377
int64_t buf_size =
63766378
index_to_buffer_size(HTTP_HEADER_BUFFER_SIZE_INDEX) + (is_msg_buf_present ? t_state.internal_msg_buffer_size : 0);
63776379

6378-
MIOBuffer *buf = new_MIOBuffer(buffer_size_to_index(buf_size));
6380+
MIOBuffer *buf = new_MIOBuffer(buffer_size_to_index(buf_size, t_state.http_config_param->max_payload_iobuf_index));
63796381
IOBufferReader *buf_start = buf->alloc_reader();
63806382

63816383
// First write the client response header into the buffer
@@ -6443,7 +6445,7 @@ HttpSM::find_http_resp_buffer_size(int64_t content_length)
64436445
}
64446446
} else {
64456447
int64_t buf_size = index_to_buffer_size(HTTP_HEADER_BUFFER_SIZE_INDEX) + content_length;
6446-
alloc_index = buffer_size_to_index(buf_size);
6448+
alloc_index = buffer_size_to_index(buf_size, t_state.http_config_param->max_payload_iobuf_index);
64476449
}
64486450

64496451
return alloc_index;

proxy/http/HttpTransact.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5560,8 +5560,9 @@ HttpTransact::handle_trace_and_options_requests(State *s, HTTPHdr *incoming_hdr)
55605560
s->free_internal_msg_buffer();
55615561
s->internal_msg_buffer_size = req_length * 2;
55625562

5563-
if (s->internal_msg_buffer_size <= max_iobuffer_size) {
5564-
s->internal_msg_buffer_fast_allocator_size = buffer_size_to_index(s->internal_msg_buffer_size);
5563+
if (s->internal_msg_buffer_size <= BUFFER_SIZE_FOR_INDEX(s->http_config_param->max_msg_iobuf_index)) {
5564+
s->internal_msg_buffer_fast_allocator_size =
5565+
buffer_size_to_index(s->internal_msg_buffer_size, s->http_config_param->max_msg_iobuf_index);
55655566
s->internal_msg_buffer = static_cast<char *>(ioBufAllocator[s->internal_msg_buffer_fast_allocator_size].alloc_void());
55665567
} else {
55675568
s->internal_msg_buffer_fast_allocator_size = -1;

proxy/logging/LogBuffer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ LogBuffer::LogBuffer(LogObject *owner, size_t size, size_t buf_align, size_t wri
111111
//
112112
int64_t alloc_size = size + buf_align;
113113

114-
if (alloc_size <= max_iobuffer_size) {
115-
m_buffer_fast_allocator_size = buffer_size_to_index(alloc_size);
114+
if (alloc_size <= BUFFER_SIZE_FOR_INDEX(Log::config->logbuffer_max_iobuf_index)) {
115+
m_buffer_fast_allocator_size = buffer_size_to_index(alloc_size, Log::config->logbuffer_max_iobuf_index);
116116
m_unaligned_buffer = static_cast<char *>(ioBufAllocator[m_buffer_fast_allocator_size].alloc_void());
117117
} else {
118118
m_buffer_fast_allocator_size = -1;

0 commit comments

Comments
 (0)