Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
The FDP team is no longer accepting new bugs in Bugzilla. Please report your issues under FDP project in Jira. Thanks.

Bug 1967882

Summary: [ovn-controller] lflow-cache doesn't automatically release memory when scaled down
Product: Red Hat Enterprise Linux Fast Datapath Reporter: Dumitru Ceara <dceara>
Component: OVNAssignee: Dumitru Ceara <dceara>
Status: CLOSED ERRATA QA Contact: Jianlin Shi <jishi>
Severity: medium Docs Contact:
Priority: medium    
Version: FDP 20.HCC: aconstan, anusaxen, astoycos, ctrautma, dceara, jiji, jishi, kfida, msheth, trozet
Target Milestone: ---Keywords: Performance
Target Release: FDP 21.I   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: perfscale-ovn
Fixed In Version: ovn21.09-21.09.0-9.el8fdp Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1958349 Environment:
Last Closed: 2021-12-09 15:37:27 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1958349    

Description Dumitru Ceara 2021-06-04 09:55:15 UTC
+++ This bug was initially created as a clone of Bug #1958349 +++

Description of problem:
The perfscale team ran cluster-density with 2000 projects at 100 node scale. The observation was that the ovn-controller memory grew to 10GB and stayed at 10GB even after the cleanup

Version-Release number of selected component (if applicable):
Cluster version is 4.8.0-0.nightly-2021-04-30-201824
sh-4.4# ovs-vswitchd --version
ovs-vswitchd (Open vSwitch) 2.15.0


How reproducible:
Always

Steps to Reproduce:
1. Run kube-burner cluster-density with 2k projects at 100 node scale

Actual results:
ovn-controller memory not freed/released to OS

Expected results:
memory should be released/freed

Additional info:
Must-gathers requested (VPN required) http://dell-r510-01.perf.lab.eng.rdu2.redhat.com/msheth/may-7-must-gathers-ovn-controller-mem/

--- Additional comment from Dumitru Ceara on 2021-05-11 08:58:58 UTC ---

This might be related to malloc fastbins not being consolidated and not
honoring M_TRIM_THRESHOLD (default 128KB) [0] [1].

One option would be to disable fast bins for ovn-controller although
that needs to be scale tested properly as it might affect performance.
This can be done at runtime without changing the OVN code by setting the 
GLIBC_TUNABLES before ovn-controller is started, e.g.:

GLIBC_TUNABLES=glibc.malloc.mxfast=0
export GLIBC_TUNABLES

[0] https://bugzilla.redhat.com/show_bug.cgi?id=921676
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=14827
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=14827#c7

Comment 1 Dumitru Ceara 2021-06-04 10:03:27 UTC
Fix posted upstream for review: http://patchwork.ozlabs.org/project/ovn/list/?series=247198&state=*

Comment 2 Dumitru Ceara 2021-06-15 13:08:02 UTC
v2 posted for review: http://patchwork.ozlabs.org/project/ovn/list/?series=248901&state=*

Comment 3 Dumitru Ceara 2021-06-18 20:02:16 UTC
v3 posted for review: http://patchwork.ozlabs.org/project/ovn/list/?series=249720&state=*

Comment 7 Jianlin Shi 2021-10-25 03:36:17 UTC
Tested with following script:

systemctl start openvswitch                           
systemctl start ovn-northd                                      
ovn-nbctl set-connection ptcp:6641
ovn-sbctl set-connection ptcp:6642                         
ovs-vsctl set open . external_ids:system-id=hv1 external_ids:ovn-remote=tcp:20.0.40.25:6642 external_ids:ovn-encap-type=geneve external_ids:ovn-encap-ip=20.0.40.25 external_ids:ovn-trim-wmark-perc-lflow-c
ache=80 external_ids:ovn-trim-limit-lflow-cache=1000 external_ids:ovn-enable-lflow-cache=true
systemctl restart ovn-controller                     
                                                  
ovn-nbctl set NB_GLOBAL . options:northd_probe_interval=180000  
ovn-nbctl set connection . inactivity_probe=180000               
ovs-vsctl set open . external_ids:ovn-openflow-probe-interval=180
ovs-vsctl set open . external_ids:ovn-remote-probe-interval=180000
ovn-sbctl set connection . inactivity_probe=180000                  
                                                                                                 
ovn-nbctl ls-add public                                                 
ovn-nbctl lsp-add public ln_p1           
ovn-nbctl lsp-set-addresses ln_p1 unknown     
ovn-nbctl lsp-set-type ln_p1 localnet              
ovn-nbctl lsp-set-options ln_p1 network_name=nattest
                                                                              
controller_pid=$(cat /var/run/ovn/ovn-controller.pid )
grep RSS /proc/$controller_pid/status > test_stat
                                                                  
i=1                      
for m in `seq 0 9`;do                                      
  for n in `seq 1 99`;do                             
    ovn-nbctl lr-add r${i}          
    ovn-nbctl lrp-add r${i} r${i}_public 00:de:ad:ff:$m:$n 172.16.$m.$n/16
    ovn-nbctl lrp-add r${i} r${i}_s${i} 00:de:ad:fe:$m:$n 173.$m.$n.1/24
    ovn-nbctl lr-nat-add r${i} dnat_and_snat 172.16.${m}.$((n+100)) 173.$m.$n.2
    ovn-nbctl lrp-set-gateway-chassis r${i}_public hv1
                                                                
                # s1      
    ovn-nbctl ls-add s${i}                                 
                                                  
                # s1 - r1               
    ovn-nbctl lsp-add s${i} s${i}_r${i}              
    ovn-nbctl lsp-set-type s${i}_r${i} router     
    ovn-nbctl lsp-set-addresses s${i}_r${i} router              
    ovn-nbctl lsp-set-options s${i}_r${i} router-port=r${i}_s${i}
                # s1 - vm1                                      
    ovn-nbctl lsp-add s$i vm$i                             
    ovn-nbctl lsp-set-addresses vm$i "00:de:ad:01:$m:$n 173.$m.$n.2"
    ovs-vsctl add-port br-int vm$i -- set interface vm$i type=internal external_ids:iface-id=vm$i
    ovn-nbctl lrp-add r$i r${i}_public 40:44:00:00:$m:$n 172.16.$m.$n/16
    ovn-nbctl lsp-add public public_r${i}
    ovn-nbctl lsp-set-type public_r${i} router
    ovn-nbctl lsp-set-addresses public_r${i} router
    
    ovn-nbctl lsp-set-options public_r${i} router-port=r${i}_public
    let i++
    if [ $i -gt 300 ];then
       break;
    fi 
  done
  if [ $i -gt 300 ];then
    break;
  fi
done
#add host vm1
ip netns add vm1
ovs-vsctl add-port br-int vm1 -- set interface vm1 type=internal
ip link set vm1 netns vm1 
ip netns exec vm1 ip link set vm1 address 00:de:ad:01:00:01
ip netns exec vm1 ip addr add 173.0.1.2/24 dev vm1
ip netns exec vm1 ip link set vm1 up
ovs-vsctl set Interface vm1 external_ids:iface-id=vm1

ip netns add vm2
ovs-vsctl add-port br-int vm2 -- set interface vm2 type=internal
ip link set vm2 netns vm2 
ip netns exec vm2 ip link set vm2 address 00:de:ad:01:00:02
ip netns exec vm2 ip addr add 173.0.2.2/24 dev vm2
ip netns exec vm2 ip link set vm2 up
ovs-vsctl set Interface vm2 external_ids:iface-id=vm2

#set provide network
ovs-vsctl add-br nat_test
ip link set nat_test up
ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=nattest:nat_test

ip netns add vm0
ovs-vsctl add-port nat_test vm0 -- set interface vm0 type=internal
ip link set vm0 netns vm0
ip netns exec vm0 ip link set vm0 address 00:00:00:00:00:01
ip netns exec vm0 ip addr add 172.16.0.100/16 dev vm0
ip netns exec vm0 ip link set vm0 up
ovs-vsctl set Interface vm0 external_ids:iface-id=vm0
ip netns exec vm1 ip route add default via 173.0.1.1
ip netns exec vm2 ip route add default via 173.0.2.1

ovn-nbctl --wait=hv sync
sleep 30
ip netns exec vm1 ping 172.16.0.102 -c 1
ip netns exec vm1 ping 172.16.0.100 -c 1

echo "after add all ls" >> test_stat
grep RSS /proc/$controller_pid/status >> test_stat
ovn-appctl -t ovn-controller lflow-cache/show-stats >> test_stat

sleep 30
systemctl stop ovn-northd
sleep 60
systemctl start ovn-northd
ovn-nbctl ls-add ls_test
ovn-nbctl --wait=sb sync

i=100
for m in `seq 0 9`;do
  for n in `seq 1 99`;do
    ovn-nbctl lr-del r${i}
    ovs-vsctl del-port vm$i
    ovn-nbctl ls-del s${i}
    let i++
    if [ $i -gt 300 ];then
       break;
    fi 
  done
  if [ $i -gt 300 ];then
    break;
  fi
done

ovn-nbctl --wait=hv sync
sleep 30
ip netns exec vm1 ping 172.16.0.102 -c 1
ip netns exec vm1 ping 172.16.0.100 -c 1

echo "after del ls" >> test_stat
grep RSS /proc/$controller_pid/status >> test_stat
ovn-appctl -t ovn-controller lflow-cache/show-stats >> test_stat

result on ovn-2021-21.06.0-29:

[root@dell-per740-12 bz1967882]# rpm -qa | grep ovn-2021                                              
ovn-2021-21.06.0-29.el8fdp.x86_64
ovn-2021-central-21.06.0-29.el8fdp.x86_64                                                             
ovn-2021-host-21.06.0-29.el8fdp.x86_64

VmRSS:      6684 kB
after add all ls
VmRSS:   1516216 kB                                                                                   
Enabled: true
cache-conj-id   : 0
cache-expr      : 3300
cache-matches   : 224456
Mem usage (KB)  : 836128
after del ls
VmRSS:   1951032 kB

<=== RSS doesn't decrease automatically

Enabled: true
cache-conj-id   : 0
cache-expr      : 1089                                                                                
cache-matches   : 34712
Mem usage (KB)  : 140368

result on ovn-2021-21.09.0-12:

[root@dell-per740-12 bz1967882]# rpm -qa | grep ovn-2021                                              
ovn-2021-central-21.09.0-12.el8fdp.x86_64                                                             
ovn-2021-host-21.09.0-12.el8fdp.x86_64                                                                
ovn-2021-21.09.0-12.el8fdp.x86_64

VmRSS:      4724 kB                                                                                   
after add all ls
VmRSS:    972492 kB
Enabled: true
high-watermark  : 201103
total           : 201103
cache-conj-id   : 0
cache-expr      : 195607                                                                              
cache-matches   : 5496
trim count      : 0
Mem usage (KB)  : 247754
after del ls
VmRSS:    791956 kB

<=== RSS decreased automatically, which means mem is trimmed automatically

Enabled: true
high-watermark  : 33737
total           : 27037
cache-conj-id   : 0
cache-expr      : 25159
cache-matches   : 1878
trim count      : 8
Mem usage (KB)  : 45089

Comment 10 errata-xmlrpc 2021-12-09 15:37:27 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (ovn bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:5059