Simple tests are as attached. On Sun, Mar 31, 2019 at 4:53 PM Xin Long <lucien.xin@xxxxxxxxx> wrote: > > sctp memory accounting is added in this patchset by using > these kernel APIs on send side: > > - sk_mem_charge() > - sk_mem_uncharge() > - sk_wmem_schedule() > - sk_under_memory_pressure() > - sk_mem_reclaim() > > and these on receive side: > > - sk_mem_charge() > - sk_mem_uncharge() > - sk_rmem_schedule() > - sk_under_memory_pressure() > - sk_mem_reclaim() > > With sctp memory accounting, we can limit the memory allocation by > either sysctl: > > # sysctl -w net.sctp.sctp_mem="10 20 50" > > or cgroup: > > # echo $((8<<14)) > \ > /sys/fs/cgroup/memory/sctp_mem/memory.kmem.tcp.limit_in_bytes > > When the socket is under memory pressure, the send side will block > and wait, while the receive side will renege or drop. > > Xin Long (2): > sctp: implement memory accounting on tx path > sctp: implement memory accounting on rx path > > include/net/sctp/sctp.h | 2 +- > net/sctp/sm_statefuns.c | 6 ++++-- > net/sctp/socket.c | 10 ++++++++-- > net/sctp/ulpevent.c | 19 ++++++++----------- > net/sctp/ulpqueue.c | 3 ++- > 5 files changed, 23 insertions(+), 17 deletions(-) > > -- > 2.1.0 >
#!/bin/sh # TOPO: local (10.73.131.158) <--> peer (10.73.131.202) [hosts not netns] peer_run() { ssh root@10.73.131.202 "$@" # echo " - peer run: $@" # echo " - print any key to continue after it's done" # read } modprobe sctp echo "sctp sysctl memory control rmem:" echo "--------------------------------" echo "10 20 50 rmem limit ->" pkill sctp_test 2> /dev/null sysctl -w net.sctp.sctp_mem="10 20 50" sctp_test -H 10.73.131.158 -P 1234 -l > /dev/null 2>&1 & sleep 3 peer_run "time sctp_test -H 10.73.131.202 -P 8000 -h 10.73.131.158 -p 1234 -s -c 5 > /dev/null 2>&1" echo "" echo "20 50 100 rmem limit ->" pkill sctp_test 2> /dev/null sysctl -w net.sctp.sctp_mem="20 50 100" sctp_test -H 10.73.131.158 -P 1234 -l > /dev/null 2>&1 & sleep 3 peer_run "time sctp_test -H 10.73.131.202 -P 8000 -h 10.73.131.158 -p 1234 -s -c 5 > /dev/null 2>&1" echo "" echo "sctp sysctl memory control wmem:" echo "--------------------------------" peer_run "sctp_test -H 10.73.131.202 -P 8000 -l > /dev/null 2>&1 &" tc qdisc add dev eth0 root netem delay 50ms echo "10 20 50 wmem limit ->" sysctl -w net.sctp.sctp_mem="5 10 20" time sctp_test -h 10.73.131.202 -p 8000 -H 10.73.131.158 -P 1234 -s -c 5 > /dev/null 2>&1 echo "" echo "10 50 100 wmem limit ->" sysctl -w net.sctp.sctp_mem="10 50 100 ->" time sctp_test -h 10.73.131.202 -p 8000 -H 10.73.131.158 -P 1234 -s -c 5 > /dev/null 2>&1 echo "" tc qdisc delete dev eth0 root peer_run "pkill sctp_test 2>/dev/null"
#!/bin/sh # TOPO: 127.0.0.1 lo modprobe sctp pkill sctp_test 2> /dev/null sctp_test -H 127.0.0.1 -P 1234 -l > /dev/null 2>&1 & sleep 3 mkdir /sys/fs/cgroup/memory/sctp_mem > /dev/null 2>&1; echo "sctp_wmem testing:" echo "------------------" echo "$((8<<14)) bytes for wmem limit ->" echo $((8<<14)) >/sys/fs/cgroup/memory/sctp_mem/memory.kmem.tcp.limit_in_bytes { echo $BASHPID > /sys/fs/cgroup/memory/sctp_mem/cgroup.procs time sctp_test -H 127.0.0.1 -P 8000 -h 127.0.0.1 -p 1234 -s -c 5 > /dev/null 2>&1 echo "" } & wait $! echo "$((8<<16)) bytes for wmem limit ->" echo $((8<<16)) >/sys/fs/cgroup/memory/sctp_mem/memory.kmem.tcp.limit_in_bytes { echo $BASHPID > /sys/fs/cgroup/memory/sctp_mem/cgroup.procs time sctp_test -H 127.0.0.1 -P 8000 -h 127.0.0.1 -p 1234 -s -c 5 > /dev/null 2>&1 echo "" } & wait $! echo "sctp_rmem testing:" echo "------------------" echo "$((8<<13)) bytes for rmem limit ->" pkill sctp_test 2> /dev/null echo $((8<<13)) >/sys/fs/cgroup/memory/sctp_mem/memory.kmem.tcp.limit_in_bytes { echo $BASHPID > /sys/fs/cgroup/memory/sctp_mem/cgroup.procs sctp_test -H 127.0.0.1 -P 1234 -l > /dev/null 2>&1 } & sleep 3 time sctp_test -H 127.0.0.1 -P 8000 -h 127.0.0.1 -p 1234 -s -c 5 > /dev/null 2>&1 echo "" echo "$((8<<14)) bytes for rmem limit ->" pkill sctp_test 2> /dev/null echo $((8<<14)) >/sys/fs/cgroup/memory/sctp_mem/memory.kmem.tcp.limit_in_bytes { echo $BASHPID > /sys/fs/cgroup/memory/sctp_mem/cgroup.procs sctp_test -H 127.0.0.1 -P 1234 -l > /dev/null 2>&1 } & sleep 3 time sctp_test -H 127.0.0.1 -P 8000 -h 127.0.0.1 -p 1234 -s -c 5 > /dev/null 2>&1 echo "" echo "sctp_wmem_and_rmem testing:" echo "---------------------------" echo "$((8<<14)) bytes for wmem AND rmem limit ->" pkill sctp_test 2> /dev/null echo $((8<<14)) >/sys/fs/cgroup/memory/sctp_mem/memory.kmem.tcp.limit_in_bytes { echo $BASHPID > /sys/fs/cgroup/memory/sctp_mem/cgroup.procs sctp_test -H 127.0.0.1 -P 1234 -l > /dev/null 2>&1 & sleep 3 time sctp_test -H 127.0.0.1 -P 8000 -h 127.0.0.1 -p 1234 -s -c 5 > /dev/null 2>&1 echo "" } & wait