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

Adding mount size #48

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Conversation

lkunjumon
Copy link

No description provided.

@lkunjumon
Copy link
Author

Below command will give the avialbale size of block

root@localhost:/home/admin# df /tmp/tmp.C4jZJkN3bo | tail -1 | tr -s ' ' | cut -d' ' -f4
7901600

root@localhost:/home/admin# df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 1533572 0 1533572 0% /dev
tmpfs 310496 58112 252384 19% /run
root-overlay 12147768 3606048 7901600 32% /
/dev/sda2 12147768 3606048 7901600 32% /host

@@ -31,7 +31,8 @@ export cur_wd
archive_path=$(realpath "$0")
tmp_dir=$(mktemp -d)
if [ "$(id -u)" = "0" ] ; then
mount -t tmpfs tmpfs-installer $tmp_dir || exit 1
mount_size=$(df $tmp_dir | tail -1 | tr -s ' ' | cut -d' ' -f4)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this logic for? Are you trying to take available space from tmpfs??

Copy link
Author

@lkunjumon lkunjumon Apr 7, 2021

Choose a reason for hiding this comment

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

@antony-rheneus
yes
mktemp -d
/tmp/tmp.yWbDbATGf2
root@localhost:/home/admin# df /tmp/tmp.yWbDbATGf2
Filesystem 1K-blocks Used Available Use% Mounted on
root-overlay 12147768 3606788 7900860 32% /
root@localhost:/home/admin#

Copy link
Author

Choose a reason for hiding this comment

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

@antony-rheneus Updated mount size depends on image size.

rajkumar38 pushed a commit to rajkumar38/sonic-buildimage that referenced this pull request Apr 19, 2021
[dataset] Add dataset "system uptime" into non-db client. (Marvell-OpenNOS#52)
Adding new data set to query Sonic OS version. (Marvell-OpenNOS#50)
[gnmi_server] Disregard EOF status for STREAM subs (Marvell-OpenNOS#48)

Signed-off-by: Yong Zhao <[email protected]>
# Untar and launch install script in a tmpfs
cur_wd=$(pwd)
export cur_wd
archive_path=$(realpath "$0")
tmp_dir=$(mktemp -d)
if [ "$(id -u)" = "0" ] ; then
mount -t tmpfs tmpfs-installer $tmp_dir || exit 1
mount_size=$(df $tmp_dir | tail -1 | tr -s ' ' | cut -d' ' -f4)
if [ "$mount_size" -lt "$((image_size*3))" ]; then
mount_size=$((image_size*3))
Copy link
Contributor

Choose a reason for hiding this comment

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

mount size should be aligned in power of 2.
try to ceil the image_size*3 to next aligned multiple of page size.

mount_size=$(df $tmp_dir | tail -1 | tr -s ' ' | cut -d' ' -f4)
if [ "$mount_size" -lt "$((image_size*3))" ]; then
#align mount_size to next power of two
mount_size=$(echo $((image_size*3)) | awk '{ print 2^int(((log($1)/log(2))+ 1)) }')
Copy link
Contributor

Choose a reason for hiding this comment

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

Dont complicate with math logic.
Use dictionry/array, to select numbers 8,16,32,64,128

Copy link
Contributor

Choose a reason for hiding this comment

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

Can u change logic to
image_size=du target/sonic-marvell-armhf.bin | awk '{print $1}'
mount_size=$((((image_size*3)/1000/1000)+1))
mount -o remount,size="${mount_size}G" -t tmpfs tmpfs-installer $tmp_dir || exit 1

Copy link
Author

Choose a reason for hiding this comment

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

okay

@@ -25,13 +25,20 @@ fi

echo " OK."

image_size=$(du "$0" | awk '{print $1}')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check du returns aligned size like 8,16,32,... this would ease in getting mount size

Copy link
Author

Choose a reason for hiding this comment

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

@antony-rheneus du return without aligned .

if [ "$mount_size" -lt "$((image_size*3))" ]; then
#align mount_size to next power of two
mount_size=$(echo $((image_size*3)) | awk '{ print 2^int(((log($1)/log(2))+ 1)) }')
mount -o remount,size="${mount_size}K" -t tmpfs tmpfs-installer $tmp_dir || exit 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead K, use G, so that calculation wud be easier

Copy link
Author

@lkunjumon lkunjumon Apr 28, 2021

Choose a reason for hiding this comment

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

@antony-rheneus changing mount_size to Gb is enough right? after mounting size is aligned .below is the mout_size in K when 4G is mounted

tmpfs-installer 4194304 0 4194304 0% /tmp/tmp.vHn5rFZYE1

# Untar and launch install script in a tmpfs
cur_wd=$(pwd)
export cur_wd
archive_path=$(realpath "$0")
tmp_dir=$(mktemp -d)
if [ "$(id -u)" = "0" ] ; then
mount -t tmpfs tmpfs-installer $tmp_dir || exit 1
mount_size=$(df $tmp_dir | tail -1 | tr -s ' ' | cut -d' ' -f4)
if [ "$mount_size" -lt "$((image_size*3))" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Does mount size is in 'KB' and as well as image_size in 'KB'?

@lkunjumon
Copy link
Author

@antony-rheneus updated the command to get actual size of compressed image.

@lkunjumon
Copy link
Author

@radha-danda @antony-rheneus updated image_size check, can we add this check "$mount_size" -eq "$((image_size))" .

# Untar and launch install script in a tmpfs
cur_wd=$(pwd)
export cur_wd
archive_path=$(realpath "$0")
tmp_dir=$(mktemp -d)
if [ "$(id -u)" = "0" ] ; then
mount -t tmpfs tmpfs-installer $tmp_dir || exit 1
mount_size=$(df $tmp_dir | tail -1 | tr -s ' ' | cut -d' ' -f4)
if [ "$mount_size" -lt "$((image_size))" ] || [ "$mount_size" -eq "$((image_size))" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

use -le

Also
do extra padding like plus 100K free

@lkunjumon
Copy link
Author

@antony-rheneus Added padding to image size.

# Untar and launch install script in a tmpfs
cur_wd=$(pwd)
export cur_wd
archive_path=$(realpath "$0")
tmp_dir=$(mktemp -d)
if [ "$(id -u)" = "0" ] ; then
mount -t tmpfs tmpfs-installer $tmp_dir || exit 1
mount_size=$(df $tmp_dir | tail -1 | tr -s ' ' | cut -d' ' -f4)
if [ "$mount_size" -le "$((image_size + $padding))" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

declare padding before this line.
also add comment as extra space for tmp

@lkunjumon
Copy link
Author

@antony-rheneus Updated the comments.

@lkunjumon
Copy link
Author

@antony-rheneus can use tmp_dir insted of tmp?

# Untar and launch install script in a tmpfs
cur_wd=$(pwd)
export cur_wd
archive_path=$(realpath "$0")
tmp_dir=$(mktemp -d)
if [ "$(id -u)" = "0" ] ; then
mount -t tmpfs tmpfs-installer $tmp_dir || exit 1
mount_size=$(df $tmp_dir | tail -1 | tr -s ' ' | cut -d' ' -f4)
# Extra space for tmp
padding=102400
Copy link
Contributor

Choose a reason for hiding this comment

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

write the size value, also in the comment in KBs or MBs

Copy link
Contributor

Choose a reason for hiding this comment

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

not adding, only checking extra space after extraction

Copy link
Author

Choose a reason for hiding this comment

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

@antony-rheneus pls review the comments

Copy link
Author

Choose a reason for hiding this comment

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

@antony-rheneus Please review updated commit.

# Adding extra 100K free space for tmp_dir
padding=102400
if [ "$mount_size" -le "$((image_size + padding))" ]; then
mount_size=$((((image_size + padding)/1024/1024)+1))
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, you dont need to add at all, as already we add up 1G extra

@lkunjumon
Copy link
Author

@radha-danda pls review

@@ -24,6 +24,10 @@ if [ "$sha1" != "$payload_sha1" ] ; then
fi

echo " OK."
#Image size in KB
bytes=$((($(sed -e '1,/^exit_marker$/d' "$0" | tar --to-stdout -xf - | wc -c) + 1023 ) / 1024))
Copy link
Contributor

Choose a reason for hiding this comment

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

see QiLuo's change... no need to converto to KB

Copy link
Author

@lkunjumon lkunjumon Jun 15, 2021

Choose a reason for hiding this comment

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

@antony-rheneus

Below is his comments,
Here it is dividing one time only with 1024, and mouting size in MB
bytes = $(sed -e '1,/^exit_marker$/d' "$0" | tar --to-stdout -xf - | wc -c)
image_size=$((bytes + 1023) / 1024)
mount_size=$((image_size + 31) / 32) * 32
mount -o remount,size="${mount_size}M"

@@ -24,6 +24,10 @@ if [ "$sha1" != "$payload_sha1" ] ; then
fi

echo " OK."
#Image size in KB
bytes=$((($(sed -e '1,/^exit_marker$/d' "$0" | tar --to-stdout -xf - | wc -c) + 1023 ) / 1024))
Copy link
Contributor

Choose a reason for hiding this comment

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

change variable name bytes to "image_size_in_kb"

@@ -32,6 +36,13 @@ archive_path=$(realpath "$0")
tmp_dir=$(mktemp -d)
if [ "$(id -u)" = "0" ] ; then
mount -t tmpfs tmpfs-installer $tmp_dir || exit 1
mount_size=$(df $tmp_dir | tail -1 | tr -s ' ' | cut -d' ' -f4)
Copy link
Contributor

Choose a reason for hiding this comment

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

mount_size is in KB

mount_size=$(df $tmp_dir | tail -1 | tr -s ' ' | cut -d' ' -f4)
#checking extra 100KB space in tmp_dir, after image extraction
padding=102400
if [ "$mount_size" -le "$((image_size + padding))" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

comparing KB and MB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants