Skip to content

[sonic_installer] Add swap setup support#1787

Merged
lolyu merged 7 commits intosonic-net:masterfrom
lolyu:sonic_installer_swap
Sep 3, 2021
Merged

[sonic_installer] Add swap setup support#1787
lolyu merged 7 commits intosonic-net:masterfrom
lolyu:sonic_installer_swap

Conversation

@lolyu
Copy link
Contributor

@lolyu lolyu commented Aug 28, 2021

What I did

  • Let's add swap memory setup support for sonic_installer command so it could run on devices with limited memory resources.

How I did it

  • Add the following new options to sonic_installer:
    1. --skip-setup-swap: if present, will skip setup swap memory.
    2. --swap-mem-size: this will change the swap memory size(the default swap size is 1024 MiB)
    3. --total-mem-threshold: if the system total memory is less than the value passed to --total-mem-threshold(default 2048 MiB), sonic_installer will setup swap memory.
    4. --available-mem-threshold: if the system available memory is less than the value passed to --available-mem-threshold(default 1200 MiB), sonic_installer will setup swap memory.
  • Add class MutuallyExclusiveOption to check the mutually-exclusive relationship between options.
  • Add class SWAPAllocator to support swap memory setup/remove functionalities.
  • Also, when sonic_installer tries to setup swap, if the system disk free space is less than 4096 MiB, sonic_installer will not setup swap memory.

How to verify it

Run sonic_installer over devices with limited memory

  • sonic_installer install --help output:
# sonic_installer install --help
Warning: 'sonic_installer' command is deprecated and will be removed in the future
Please use 'sonic-installer' instead
Usage: sonic_installer install [OPTIONS] URL

  Install image from local binary or URL

Options:
  -y, --yes
  -f, --force                     Force installation of an image of a type
                                  which differs from that of the current
                                  running image
  --skip_migration                Do not migrate current configuration to the
                                  newly installed image
  --skip-package-migration        Do not migrate current packages to the newly
                                  installed image
  --skip-setup-swap               Skip setup temporary SWAP memory used for
                                  installation
  --swap-mem-size INTEGER         SWAP memory space size  [default: (1024
                                  MiB)] NOTE: this argument is mutually
                                  exclusive with arguments: skip_setup_swap
  --total-mem-threshold INTEGER   If system total memory is lower than
                                  threshold, setup SWAP memory  [default:
                                  (2048 MiB)] NOTE: this argument is mutually
                                  exclusive with arguments: skip_setup_swap
  --available-mem-threshold INTEGER
                                  If system available memory is lower than
                                  threhold, setup SWAP memory  [default: (1200
                                  MiB)] NOTE: this argument is mutually
                                  exclusive with arguments: skip_setup_swap
  --help                          Show this message and exit.

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

lolyu added 2 commits August 28, 2021 06:57
Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
@lolyu lolyu requested a review from yxieca August 28, 2021 07:12
@lolyu lolyu changed the title Sonic installer swap [sonic_installer] Add swap setup support Aug 28, 2021
@lolyu lolyu self-assigned this Aug 28, 2021
@lgtm-com
Copy link

lgtm-com bot commented Aug 28, 2021

This pull request introduces 1 alert when merging d3cb7bf into 83309c6 - view on LGTM.com

new alerts:

  • 1 for Unused import

lolyu added 2 commits August 28, 2021 13:16
Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
lolyu added 2 commits August 31, 2021 05:52
Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
@lolyu
Copy link
Contributor Author

lolyu commented Aug 31, 2021

  • unit tests result
tests/swap_allocator_test.py::TestSWAPAllocator::test_read_from_meminfo PASSED                                                                                                                 [  7%]
tests/swap_allocator_test.py::TestSWAPAllocator::test_setup_swapmem PASSED                                                                                                                     [ 15%]
tests/swap_allocator_test.py::TestSWAPAllocator::test_remove_swapmem PASSED                                                                                                                    [ 23%]
tests/swap_allocator_test.py::TestSWAPAllocator::test_swap_allocator_initialization_default_args PASSED                                                                                        [ 30%]
tests/swap_allocator_test.py::TestSWAPAllocator::test_swap_allocator_initialization_custom_args PASSED                                                                                         [ 38%]
tests/swap_allocator_test.py::TestSWAPAllocator::test_swap_allocator_context_enter_allocate_true_insufficient_total_memory PASSED                                                              [ 46%]
tests/swap_allocator_test.py::TestSWAPAllocator::test_swap_allocator_context_enter_allocate_true_insufficient_available_memory PASSED                                                          [ 53%]
tests/swap_allocator_test.py::TestSWAPAllocator::test_swap_allocator_context_enter_allocate_true_insufficient_disk_space PASSED                                                                [ 61%]
tests/swap_allocator_test.py::TestSWAPAllocator::test_swap_allocator_context_enter_allocate_true_swapfile_present PASSED                                                                       [ 69%]
tests/swap_allocator_test.py::TestSWAPAllocator::test_swap_allocator_context_enter_setup_error PASSED                                                                                          [ 76%]
tests/swap_allocator_test.py::TestSWAPAllocator::test_swap_allocator_context_enter_allocate_false PASSED                                                                                       [ 84%]
tests/swap_allocator_test.py::TestSWAPAllocator::test_swap_allocator_context_exit_is_allocated_true PASSED                                                                                     [ 92%]
tests/swap_allocator_test.py::TestSWAPAllocator::test_swap_allocator_context_exit_is_allocated_false PASSED                                                                                    [100%]

Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
@lolyu lolyu force-pushed the sonic_installer_swap branch from 14f82f9 to 92586e3 Compare August 31, 2021 07:05
@lolyu
Copy link
Contributor Author

lolyu commented Sep 1, 2021

@yxieca, could you please take a review for my updates? Thanks!

@lolyu
Copy link
Contributor Author

lolyu commented Sep 3, 2021

Looks like this PR could not be cherry-picked to 202012, will create a separate PR for 202012 branch.

@lolyu lolyu merged commit 171eb4f into sonic-net:master Sep 3, 2021
@lolyu lolyu deleted the sonic_installer_swap branch September 3, 2021 06:35
@qiluo-msft
Copy link
Contributor

This commit could not be cleanly cherry-pick to 202012. Please submit another PR.

lolyu added a commit that referenced this pull request Sep 13, 2021
@judyjoseph
Copy link
Contributor

This commit could not be cleanly cherry-pick to 202106. Please submit another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants