Revert "Add limit and shrink policy for recycler (#15320)"

This reverts commit c2e8814dce.
This commit is contained in:
behzad nouri
2021-04-07 11:15:38 -04:00
parent 6907a2366e
commit e405747409
24 changed files with 129 additions and 491 deletions

View File

@@ -28,21 +28,19 @@ impl Packets {
Packets { packets }
}
pub fn new_with_recycler(recycler: PacketsRecycler, size: usize) -> Option<Self> {
let maybe_packets = recycler.allocate();
maybe_packets.map(|mut packets| {
packets.reserve_and_pin(size);
Packets { packets }
})
pub fn new_with_recycler(recycler: PacketsRecycler, size: usize, name: &'static str) -> Self {
let mut packets = recycler.allocate(name);
packets.reserve_and_pin(size);
Packets { packets }
}
pub fn new_with_recycler_data(
recycler: &PacketsRecycler,
name: &'static str,
mut packets: Vec<Packet>,
) -> Option<Self> {
Self::new_with_recycler(recycler.clone(), packets.len()).map(|mut vec| {
vec.packets.append(&mut packets);
vec
})
) -> Self {
let mut vec = Self::new_with_recycler(recycler.clone(), packets.len(), name);
vec.packets.append(&mut packets);
vec
}
pub fn set_addr(&mut self, addr: &SocketAddr) {
@@ -78,7 +76,11 @@ pub fn to_packets_with_destination<T: Serialize>(
recycler: PacketsRecycler,
dests_and_data: &[(SocketAddr, T)],
) -> Packets {
let mut out = Packets::new_with_recycler(recycler, dests_and_data.len()).unwrap();
let mut out = Packets::new_with_recycler(
recycler,
dests_and_data.len(),
"to_packets_with_destination",
);
out.packets.resize(dests_and_data.len(), Packet::default());
for (dest_and_data, o) in dests_and_data.iter().zip(out.packets.iter_mut()) {
if !dest_and_data.0.ip().is_unspecified() && dest_and_data.0.port() != 0 {
@@ -136,9 +138,9 @@ mod tests {
#[test]
fn test_to_packets_pinning() {
let recycler = PacketsRecycler::new_without_limit("");
let recycler = PacketsRecycler::default();
for i in 0..2 {
let _first_packets = Packets::new_with_recycler(recycler.clone(), i + 1);
let _first_packets = Packets::new_with_recycler(recycler.clone(), i + 1, "first one");
}
}
}