Skip to content
This repository was archived by the owner on Aug 29, 2020. It is now read-only.

[memory] Handle hosts without swap.#41

Open
rillian wants to merge 2 commits intocjbassi:masterfrom
rillian:noswap
Open

[memory] Handle hosts without swap.#41
rillian wants to merge 2 commits intocjbassi:masterfrom
rillian:noswap

Conversation

@rillian
Copy link
Copy Markdown

@rillian rillian commented Feb 19, 2020

Accept Error returns from psutil::memory::swap_memory() and record
an empty swap statistic. Fixes an unwrap() panic on machines without
any swap enabled.

Accept Error returns from psutil::memory::swap_memory() and record
an empty swap statistic. Fixes an uwrap() panic on machines without
any swap enabled.
Result of running `cargo fmt`.
@cjbassi
Copy link
Copy Markdown
Owner

cjbassi commented Feb 19, 2020

This sounds like it's actually a bug with rust-psutil. Could you post the error message you get?

@rillian
Copy link
Copy Markdown
Author

rillian commented Feb 19, 2020

The CI failure is a clippy warning about unrelated code.

 width >= 10 + 1;

in disk.rs. Happy to fix, but not related to this pr.

@rillian
Copy link
Copy Markdown
Author

rillian commented Feb 19, 2020

Error message:

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 2.76s
     Running `target/debug/ytop`
Backtrace (most recent call first):
  File "rust:src/libcore/result.rs", line 956, in core::result::Result<T,E>::unwrap
  File "src/widgets/mem.rs", line 71, in <ytop::widgets::mem::MemWidget as ytop::update::UpdatableWidget>::update
    let swap = memory::swap_memory().unwrap();
  File "src/update.rs", line 30, in ytop::update::update_widgets
    widget.update();
  File "src/main.rs", line 163, in ytop::main
    update_widgets(&mut app.widgets, update_seconds);

The application panicked (crashed).
  called `Result::unwrap()` on an `Err` value: MissingData { path: "/proc/vmstat", contents: "nr_free_pages 66025\nnr_zone_inactive_anon 2428\nnr_zone_active_anon 3579\nnr_zone_inactive_file 26779\nnr_zone_active_file 22325\nnr_zone_unevictable 0\nnr_zone_write_pending 0\nnr_mlock 0\nnr_page_table_pages 160\nnr_kernel_stack 776\nnr_bounce 0\nnr_free_cma 0\nnr_inactive_anon 2428\nnr_active_anon 3579\nnr_inactive_file 26779\nnr_active_file 22325\nnr_unevictable 0\nnr_slab_reclaimable 1732\nnr_slab_unreclaimable 2406\nnr_isolated_anon 0\nnr_isolated_file 0\nworkingset_nodes 2790\nworkingset_refault 286876043\nworkingset_activate 19681950\nworkingset_restore 3158968\nworkingset_nodereclaim 0\nnr_anon_pages 3511\nnr_mapped 4383\nnr_file_pages 51605\nnr_dirty 0\nnr_writeback 0\nnr_writeback_temp 0\nnr_shmem 2496\nnr_shmem_hugepages 0\nnr_shmem_pmdmapped 0\nnr_anon_transparent_hugepages 0\nnr_unstable 0\nnr_vmscan_write 5544\nnr_vmscan_immediate_reclaim 17649\nnr_dirtied 2173938\nnr_written 2120384\nnr_kernel_misc_reclaimable 0\nnr_dirty_threshold 20306\nnr_dirty_background_threshold 10141\n" }
in src/libcore/result.rs, line 1188
thread: main

@rillian
Copy link
Copy Markdown
Author

rillian commented Feb 19, 2020

possibly something is odd with the kernel; as you can see, the swap-related lines aren't present in /proc/vmstat.

@cjbassi
Copy link
Copy Markdown
Owner

cjbassi commented Feb 19, 2020

Hmm, yeah I'll have to dig into it tomorrow. Could you also post the output of uname - a?

@rillian
Copy link
Copy Markdown
Author

rillian commented Feb 19, 2020

Linux nimbus 5.1.4+ #21 SMP Mon May 27 11:12:00 AEST 2019 mips GNU/Linux
Source config

It looks like the vmstat fields psutil wants are conditional on CONFIG_VM_EVENT_COUNTERS which is not enabled in this kernel build, probably to keep things trim; it's a lightweight NAS.

The relevant meminfo fields are present (and zero) on the device, as the ytop client already seems to expect. If you want to handle this in psutil instead, making those fields Options, would be a reasonable approach. It seems simpler to me to just handle the MissingData result, since the stat is available unconditionally on macOS.

@cjbassi
Copy link
Copy Markdown
Owner

cjbassi commented Feb 19, 2020

Very interesting, thanks for the links. I think the best way to go about this is to make the missing fields optional in rust psutil.

@rillian
Copy link
Copy Markdown
Author

rillian commented Feb 20, 2020

Ok, let me know if you want anything tested.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants