Skip to content

Commit 069dae5

Browse files
alfrebAndreasAakesson
authored andcommitted
tcp: minor changes to window scaling
1 parent 565afc7 commit 069dae5

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

api/net/tcp/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace net {
3232
// default size of TCP window - how much data can be "in flight" (unacknowledged)
3333
static constexpr uint16_t default_window_size {0xffff};
3434
// window scaling + window size
35-
static constexpr uint8_t default_window_scaling {5};
35+
static constexpr uint8_t default_window_scaling {7};
3636
static constexpr uint32_t default_ws_window_size {8192 << default_window_scaling};
3737
// use of timestamps option
3838
static constexpr bool default_timestamps {true};

src/net/tcp/connection.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ Packet_view_ptr Connection::create_outgoing_packet()
323323
packet->set_source(local_);
324324
// Set Destination (remote)
325325
packet->set_destination(remote_);
326+
uint32_t shifted = std::min<uint32_t>((cb.RCV.WND >> cb.RCV.wind_shift), default_window_size);
327+
Ensures(shifted <= 0xffff);
326328

327-
const auto recv_wnd = recv_wnd_getter();
328-
//printf("recv_wnd %u\n", recv_wnd);
329-
packet->set_win(cb.RCV.WND >> cb.RCV.wind_shift);
329+
packet->set_win(shifted);
330330

331331
if(cb.SND.TS_OK)
332332
packet->add_tcp_option_aligned<Option::opt_ts_align>(host_.get_ts_value(), cb.get_ts_recent());
@@ -691,8 +691,9 @@ void Connection::recv_data(const Packet_view& in)
691691
// since it could be that we already preallocated that memory in our vector.
692692
// i also think we shouldn't reach this point due to State::check_seq checking
693693
// if we're inside the window. if packet is out of order tho we can change the RCV wnd (i think).
694-
if(recv_wnd_getter() == 0)
694+
if(recv_wnd_getter() == 0) {
695695
drop(in, Drop_reason::RCV_WND_ZERO);
696+
}
696697

697698

698699
// Keep track if a packet is being sent during the async read callback

src/net/tcp/tcp.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <net/tcp/packet4_view.hpp>
3131
#include <net/tcp/packet6_view.hpp>
3232
#include <kernel/os.hpp>
33+
#include <util/bitops.hpp>
34+
#include <util/units.hpp>
3335

3436
using namespace std;
3537
using namespace net;
@@ -375,11 +377,19 @@ void TCP::reset_pmtu(Socket dest, IP4::PMTU pmtu) {
375377

376378
uint32_t TCP::global_recv_wnd()
377379
{
378-
// 80% of free mem
379-
// normalize to 0 to avoid negative value (???)
380-
ssize_t avail = std::max<ssize_t>((static_cast<ssize_t>(OS::heap_avail()) * 80 / 100) / 2, 0);
381-
//printf("heap: %zi avail: %zu\n", (ssize_t)OS::heap_avail(), avail);
382-
return std::min<size_t>(avail, (1 << 30)); // max can only be 1GB
380+
using namespace util;
381+
382+
auto max_use = OS::heap_max() / 4; // TODO: make proportion into variable
383+
auto in_use = OS::heap_usage();
384+
385+
if (in_use >= max_use) {
386+
printf("global_recv_wnd: Receive window empty. Heap use: %zu \n", in_use);
387+
return 0;
388+
}
389+
390+
ssize_t buf_avail = max_use - in_use;
391+
392+
return std::min<size_t>(buf_avail, 4_MiB);
383393
}
384394

385395
void TCP::transmit(tcp::Packet_view_ptr packet)
@@ -615,6 +625,3 @@ TCP::Listeners::const_iterator TCP::cfind_listener(const Socket& socket) const
615625

616626
return it;
617627
}
618-
619-
620-

0 commit comments

Comments
 (0)