| 1 | # Memory Widget |
| 2 | |
| 3 | The memory widget provides a visual representation of RAM and swap usage over time. |
| 4 | |
| 5 | <figure> |
| 6 | <img src="../../../assets/screenshots/memory.webp" alt="A picture of an expanded memory widget."/> |
| 7 | </figure> |
| 8 | |
| 9 | ## Features |
| 10 | |
| 11 | The legend displays the current usage in terms of percentage and actual usage in binary units (KiB, MiB, GiB, etc.). |
| 12 | If the total RAM or swap available is 0, then it is automatically hidden from the legend and graph. |
| 13 | |
| 14 | One can also adjust the displayed time range through either the keyboard or mouse, with a range of 30s to 600s. |
| 15 | |
| 16 | This widget can also be configured to display Nvidia and AMD GPU memory usage (`--disable_gpu` on Linux/Windows to disable) or cache memory usage (`--enable_cache_memory`). |
| 17 | |
| 18 | ## Key bindings |
| 19 | |
| 20 | Note that key bindings are generally case-sensitive. |
| 21 | |
| 22 | | Binding | Action | |
| 23 | | --------- | --------------------------------------- | |
| 24 | | ++plus++ | Zoom in on chart (decrease time range) | |
| 25 | | ++minus++ | Zoom out on chart (increase time range) | |
| 26 | | ++equal++ | Reset zoom | |
| 27 | |
| 28 | ## Mouse bindings |
| 29 | |
| 30 | | Binding | Action | |
| 31 | | ------------ | -------------------------------------------------------------- | |
| 32 | | ++"Scroll"++ | Scrolling up or down zooms in or out of the graph respectively | |
| 33 | |
| 34 | ## How are memory values determined? |
| 35 | |
| 36 | ### Linux |
| 37 | |
| 38 | Memory usage is calculated using the following formula based on values from `/proc/meminfo` (based on [htop's implementation](https://github.com/htop-dev/htop/blob/976c6123f41492aaf613b9d172eef1842fb7b0a3/linux/LinuxProcessList.c#L1584)): |
| 39 | |
| 40 | ``` |
| 41 | MemTotal - MemFree - Buffers - (Cached + SReclaimable - Shmem) |
| 42 | ``` |
| 43 | |
| 44 | You can find more info on `/proc/meminfo` and its fields [here](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/s2-proc-meminfo). |
| 45 | |
| 46 | ### Windows |
| 47 | |
| 48 | In Windows, we calculate swap by querying `Get-Counter "\Paging File(*)\% Usage"`. This |
| 49 | is also what some libraries like [psutil](https://github.com/giampaolo/psutil/blob/master/psutil/arch/windows/mem.c) use. However, note there are also a few other valid methods of |
| 50 | representing "swap" in Windows (e.g. using `GetPerformanceInfo`), which all slightly don't |
| 51 | match. |