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

wslact: improve memory-reclaim command #271

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions docs/wslact.1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Currently, we have two features available:
.nf
\fBts, time-sync\fR \- Time Sync
\fBam, auto-mount\fR \- Auto Mounting
\fBmr, mem-reclaim\fR \- Memory Reclaimation
\fBmr, memory-reclaim\fR \- Memory Reclamation
.fi
.in
.SH COMMANDS
Expand Down Expand Up @@ -52,11 +52,11 @@ pass a list of options you want to pass to \fImount\fR command.
print a simple help.
.in
.fi
.SS "Memory Reclaimation"
Memory Reclaimation (\fImem-reclaim\fR) feature allows you to reclaim memory by dropping memory cache. Requires sudo.
.SS "Memory Reclamation"
Memory Reclamation (\fImemory-reclaim\fR) feature allows you to reclaim memory by dropping memory cache. Requires sudo.
.TP
SYNOPSIS
.B wslact auto-mount
.B wslact memory-reclaim
.RB [ \-h ]
.TP
OPTIONS
Expand Down
3 changes: 2 additions & 1 deletion src/wslact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function memory_reclaim {
error_echo "\`wslact memory-reclaim\` requires you to run as root. Aborted." 1
fi

sync
echo 1 > /proc/sys/vm/drop_caches
echo "${info} Memory Reclaimed."
}
Expand All @@ -101,7 +102,7 @@ while [ "$1" != "" ]; do
case "$1" in
ts|time-sync|tr|time-reset) time_reset "$@"; exit;;
am|auto-mount|sm|smart-mount) auto_mount "$@"; exit;;
mr|mem-reclaim) memory_reclaim "$@"; exit;;
mr|memory-reclaim|mem-reclaim) memory_reclaim "$@"; exit;;
-h|--help) help "$0" "$help_short"; exit;;
-v|--version) version; exit;;
*) error_echo "Invalid Input. Aborted." 22;;
Expand Down
26 changes: 25 additions & 1 deletion tests/wslact.bats
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,28 @@
run out/wslact am -h
[ "${lines[0]}" = "wslact - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ]
[ "${lines[1]}" = "Usage: wslact auto-mount [-mh]" ]
}
}

@test "wslact - Memory Reclamation - Help" {
run out/wslact memory-reclaim --help
[ "${lines[0]}" = "wslact - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ]
[ "${lines[1]}" = "Usage: wslact memory-reclaim [-h]" ]
}

@test "wslact - Memory Reclamation - Help - Alt." {
run out/wslact memory-reclaim -h
[ "${lines[0]}" = "wslact - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ]
[ "${lines[1]}" = "Usage: wslact memory-reclaim [-h]" ]
}

@test "wslact - Memory Reclamation - short form - Help" {
run out/wslact mr --help
[ "${lines[0]}" = "wslact - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ]
[ "${lines[1]}" = "Usage: wslact memory-reclaim [-h]" ]
}

@test "wslact - Memory Reclamation - short form - Help - Alt." {
run out/wslact mr -h
[ "${lines[0]}" = "wslact - Part of wslu, a collection of utilities for Linux Subsystem for Windows (WSL)" ]
[ "${lines[1]}" = "Usage: wslact memory-reclaim [-h]" ]
}