Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code optimizations to reduce disk writes on SONiC switches #20640

Merged
merged 11 commits into from
Dec 5, 2024
Merged
2 changes: 1 addition & 1 deletion dockers/docker-orchagent/docker-init.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mkdir -p /etc/swss/config.d/
mkdir -p /etc/supervisor/
mkdir -p /etc/supervisor/conf.d/

mkdir -p /dev/shm/supervisor/
assrinivasan marked this conversation as resolved.
Show resolved Hide resolved

CFGGEN_PARAMS=" \
-d \
Expand Down
1 change: 1 addition & 0 deletions files/build_templates/docker_image_ctl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ start() {
{%- endif %}
-e RUNTIME_OWNER=local \
--uts=host \{# W/A: this should be set per-docker, for those dockers which really need host's UTS namespace #}
--tmpfs /var/log/supervisor:rw \
{%- if install_debug_image == "y" %}
-v /src:/src:ro -v /debug:/debug:rw \
{%- endif %}
Expand Down
5 changes: 5 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/sonic-nettools_*.deb || \
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
sudo setcap 'cap_net_raw=+ep' $FILESYSTEM_ROOT/usr/bin/wol

# This is needed for moving monit logs, state and logrotate status to tmpfs
sudo bash -c "echo \"d /dev/shm/monit/ 0755 root root\" > $FILESYSTEM_ROOT/etc/tmpfiles.d/tmpfs-monit.conf"
sudo bash -c "echo \"d /dev/shm/logrotate/ 0755 root root\" > $FILESYSTEM_ROOT/etc/tmpfiles.d/tmpfs-logrotate.conf"


# Install a patched version of ifupdown2 (and its dependencies via 'apt-get -y install -f')
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/ifupdown2_*.deb || \
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
Expand Down
6 changes: 5 additions & 1 deletion files/image_config/logrotate/logrotateOverride.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[Unit]
Requires=logrotate-config.service
Requires=logrotate-config.service

[Service]
assrinivasan marked this conversation as resolved.
Show resolved Hide resolved
ExecStart=
ExecStart=/usr/sbin/logrotate --state /dev/shm/logrotate/status /etc/logrotate.conf
6 changes: 3 additions & 3 deletions files/image_config/monit/monitrc
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
## default the file is placed in $HOME/.monit.id.
#
# set idfile /var/.monit.id
set idfile /var/lib/monit/id
set idfile /dev/shm/monit/id
#
## Set the location of the Monit state file which saves monitoring states
## on each cycle. By default the file is placed in $HOME/.monit.state. If
## the state file is stored on a persistent filesystem, Monit will recover
## the monitoring state across reboots. If it is on temporary filesystem, the
## state will be lost on reboot which may be convenient in some situations.
#
set statefile /var/lib/monit/state
set statefile /dev/shm/monit/state
#
#

Expand Down Expand Up @@ -91,7 +91,7 @@
## available in the back end filesystem).
#
set eventqueue
basedir /var/lib/monit/events # set the base directory where events will be stored
basedir /dev/shm/monit/events # set the base directory where events will be stored
slots 100 # optionally limit the queue size
#
#
Expand Down
3 changes: 3 additions & 0 deletions files/initramfs-tools/union-mount.j2
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ mkdir -p ${rootmnt}/boot
mkdir -p ${rootmnt}/host/$image_dir/boot
mount --bind ${rootmnt}/host/$image_dir/boot ${rootmnt}/boot

## Mount the /tmp directory as tmpfs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@assrinivasan How much memory are we loosing on platform with small RAM? Arista 7050-QX?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are currently allocating 25% of total RAM towards /tmp directory on all platforms.

mount -t tmpfs -o rw,nosuid,nodev,size=25% tmpfs ${rootmnt}/tmp

## Mount loop device or tmpfs for /var/log
if $logs_inram; then
# NOTE: some platforms, when reaching initramfs stage, have a small
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def load_peers():
Load peers from FRR.
:return: set of peers, which are already installed in FRR
"""
command = ["vtysh", "-c", "show bgp vrfs json"]
command = ["vtysh", "-H", "/dev/null", "-c", "show bgp vrfs json"]
ret_code, out, err = run_command(command)
if ret_code == 0:
js_vrf = json.loads(out)
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-bgpcfgd/bgpmon/bgpmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def update_new_peer_states(self, peer_dict):

# Get a new snapshot of BGP neighbors and store them in the "new" location
def get_all_neigh_states(self):
cmd = ["vtysh", "-c", 'show bgp summary json']
cmd = ["vtysh", "-H", "/dev/null", "-c", 'show bgp summary json']
retry_attempt = 0

while retry_attempt < self.MAX_RETRY_ATTEMPTS:
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-bgpcfgd/tests/test_bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def constructor(constants_path, bgp_router_id="", peer_type="general", with_lo0_
}

return_value_map = {
"['vtysh', '-c', 'show bgp vrfs json']": (0, "{\"vrfs\": {\"default\": {}}}", ""),
"['vtysh', '-H', '/dev/null', '-c', 'show bgp vrfs json']": (0, "{\"vrfs\": {\"default\": {}}}", ""),
"['vtysh', '-c', 'show bgp vrf default neighbors json']": (0, "{\"10.10.10.1\": {}, \"20.20.20.1\": {}, \"fc00:10::1\": {}}", "")
}

Expand Down
Loading