You are not logged in.

#1 2012-06-16 14:20:46

ismaelvc
Member
From: México, D.F.
Registered: 2012-02-26
Posts: 136

Why is this? emptyswap (from wiki): invalid argument.

Hello I just recently started reading 'The linux command line' to finally start learning shell scripting and such:

http://sourceforge.net/projects/linuxco … f/download

And today I found:

http://www.google.com.mx/url?q=https:// … tv-dnp--Ig

I use an old computer with 256mb of ram and 512mb of swap, so this hit my interest, but also I want to understand how it works. I get how the script works, and it does its job fine, even when the next error shows up:

ismaelvc@archlinux /usr/bin $ LANGUAGE=en sudo emptyswap
BEFORE EMPTY CACHES
             total       used       free     shared    buffers     cached
Mem:           246        131        115          0          3         55
-/+ buffers/cache:         72        174
Swap:          509         94        415
/usr/bin/emptyswap: line 5: echo: write error: Invalid argument

Output of free before moving swap:
             total       used       free     shared    buffers     cached
Mem:           246        105        140          0          0         32
-/+ buffers/cache:         72        173
Swap:          509         94        415

Output of free after:
             total       used       free     shared    buffers     cached
Mem:           246        170         76          0          0         39
-/+ buffers/cache:        129        116
Swap:          509          0        509

I have commented out that line, and it still works, but I dont understand why does this happens, I use this after finnishing using chrome as it takes a lot of ram and swap, and after a time another programs also get data swaped, so I use it to get a little speed back.

Here is the script:

#!/bin/sh
echo -e "BEFORE EMPTY CACHES"
free -m
echo 3 > /proc/sys/vm/drop_caches
echo 0 > /proc/sys/vm/drop_caches
msg="Cannot write swap back to RAM...\nNot enough memory - bye..."
mem=`free|grep Mem:|awk '{print $4}'`
swap=`free|grep Swap:|awk '{print $3}'`
test $mem -lt $swap && echo -e $msg && exit 1
echo -e "\nOutput of free before moving swap:" &&
free -m &&
swapoff -a && swapon -a &&
echo -e "\nOutput of free after:" &&
free -m &&
exit 0

Thanks is advance!


Laptop: LG LM70 Express                                                  Kernel: 3.14.2-1-ARCH   
CPU: Intel Pentium M processor @1.86GHz                  Hard Drive: 80G
Video: Mobility Radeon X600                                            X Driver: xf86-video-ati
Memory Size: 1.5G + zramswap: 384M + swap: 3G

Offline

#2 2012-06-16 20:24:26

ismaelvc
Member
From: México, D.F.
Registered: 2012-02-26
Posts: 136

Re: Why is this? emptyswap (from wiki): invalid argument.

drop_caches is a file that only has 0 in it

so it changes that 0 to a 3 and then revert it back to 0, why is this invalid? What is the use of this?


Laptop: LG LM70 Express                                                  Kernel: 3.14.2-1-ARCH   
CPU: Intel Pentium M processor @1.86GHz                  Hard Drive: 80G
Video: Mobility Radeon X600                                            X Driver: xf86-video-ati
Memory Size: 1.5G + zramswap: 384M + swap: 3G

Offline

#3 2012-06-16 20:53:52

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 13,737
Website

Re: Why is this? emptyswap (from wiki): invalid argument.

https://www.kernel.org/doc/Documentation/sysctl/vm.txt

Accepted values are "1", "2", and "3". Presumably it resets to 0 after the kernel completes the operation, so manually resetting the value is no longer necessary.

Note: this is speculation on my part.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#4 2012-06-16 21:18:56

ismaelvc
Member
From: México, D.F.
Registered: 2012-02-26
Posts: 136

Re: Why is this? emptyswap (from wiki): invalid argument.

Ok now I get it I'll confirm this, thanks!

EDIT: you are right shall I inform about this in the wiki?

Last edited by ismaelvc (2012-06-21 05:39:58)


Laptop: LG LM70 Express                                                  Kernel: 3.14.2-1-ARCH   
CPU: Intel Pentium M processor @1.86GHz                  Hard Drive: 80G
Video: Mobility Radeon X600                                            X Driver: xf86-video-ati
Memory Size: 1.5G + zramswap: 384M + swap: 3G

Offline

Board footer

Powered by FluxBB