Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions init-zram_broadband.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
####################################################################################
# If not stated otherwise in this file or this component's Licenses.txt file the
# following copyright and licenses apply:
#
# Copyright 2018 RDK Management
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##################################################################################
. /etc/include.properties
. /etc/device.properties

ZRAM_LOGFILE="${LOG_PATH}/zram.log"
Comment thread
manedurphy marked this conversation as resolved.

echo_t() {
echo "$(date +"%y%m%d-%T.%6N") $1" >>$ZRAM_LOGFILE
}

# Wait for the DM system to come up
dmIsUp=1
while [ "x$dmIsUp" != "x0" ]; do
dmcli eRT getv Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MEMSWAP.Enable | grep value
dmIsUp=$?
sleep 10
done

Comment thread
manedurphy marked this conversation as resolved.
# Check if MEMSWAP is enabled by RFC, exit if not enabled
MEMSWAP_RFC_ENABLE=$(dmcli eRT retv Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MEMSWAP.Enable)
Comment thread
manedurphy marked this conversation as resolved.
if [ "x$MEMSWAP_RFC_ENABLE" != "xtrue" ]; then
echo_t "MEMSWAP is disabled"
exit 1
fi

# Load ZRAM module with one block device for SWAP
if modinfo zram | grep -q ' zram_num_devices:' 2>/dev/null; then
MODPROBE_ARGS="zram_num_devices=1"
elif modinfo zram | grep -q ' num_devices:' 2>/dev/null; then
Comment thread
manedurphy marked this conversation as resolved.
MODPROBE_ARGS="num_devices=1"
else
exit 1
fi
modprobe zram "$MODPROBE_ARGS"
Comment thread
manedurphy marked this conversation as resolved.

# Wait for the module to load
sleep 3

# Configure the disk size
MEMSWAP_DISK_SIZE=$(dmcli eRT retv Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MEMSWAP.DiskSize)
if [ -z "$MEMSWAP_DISK_SIZE" ]; then
echo_t "MEMSWAP disk size not retrieved from RFC, setting to default of 300MB"
Comment thread
manedurphy marked this conversation as resolved.
MEMSWAP_DISK_SIZE=300
fi
echo "${MEMSWAP_DISK_SIZE}M" >/sys/block/zram0/disksize
echo_t "MEMSWAP disk size set to ${MEMSWAP_DISK_SIZE}M"

# Configure the system swappiness
MEMSWAP_TUNABLES_SWAPPINESS=$(dmcli eRT retv Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MEMSWAP.Tunables.Swappiness)
Comment thread
manedurphy marked this conversation as resolved.
if [ -z "$MEMSWAP_TUNABLES_SWAPPINESS" ]; then
echo_t "MEMSWAP swappiness not retrieved from RFC, keeping system default"
else
sysctl -w vm.swappiness="$MEMSWAP_TUNABLES_SWAPPINESS"
echo_t "System swappiness set to ${MEMSWAP_TUNABLES_SWAPPINESS}"
Comment thread
manedurphy marked this conversation as resolved.
fi

# Configure the system watermark scale factor
MEMSWAP_TUNABLES_WATERMARK_SCALE_FACTOR=$(dmcli eRT retv Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MEMSWAP.Tunables.WatermarkScaleFactor)
if [ -z "$MEMSWAP_TUNABLES_WATERMARK_SCALE_FACTOR" ]; then
echo_t "MEMSWAP watermark scale factor not retrieved from RFC, keeping system default"
else
sysctl -w vm.watermark_scale_factor="$MEMSWAP_TUNABLES_WATERMARK_SCALE_FACTOR"
echo_t "System watermark scale factor set to ${MEMSWAP_TUNABLES_WATERMARK_SCALE_FACTOR}"
Comment thread
manedurphy marked this conversation as resolved.
fi

# Configure the system page cluster for SWAP
MEMSWAP_TUNABLES_PAGE_CLUSTER=$(dmcli eRT retv Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MEMSWAP.Tunables.PageCluster)
if [ -z "$MEMSWAP_TUNABLES_PAGE_CLUSTER" ]; then
echo_t "MEMSWAP page cluster not retrieved from RFC, keeping system default"
else
sysctl -w vm.page-cluster="$MEMSWAP_TUNABLES_PAGE_CLUSTER"
echo_t "System page cluster for SWAP set to ${MEMSWAP_TUNABLES_PAGE_CLUSTER}"
Comment thread
manedurphy marked this conversation as resolved.
fi

# Enable the ZRAM SWAP device
mkswap /dev/zram0
swapon -p 5 /dev/zram0
Loading