Log what is being written to swap

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Log what is being written to swap

Postby serene » Sun Apr 14, 2013 6:02 pm

For a laptop with 16 G memory, that never suspends or hibernates... I'm considering disabling the swap partition.

Could someone please recommend a short bash script to log details for what exactly (if any) activity is being writen to the swap partition ?

Thank you
Serene
User avatar
serene
LXF regular
 
Posts: 111
Joined: Sun Jun 19, 2005 12:43 pm

Postby purplepenguin » Mon Apr 15, 2013 4:32 pm

Code: Select all
sudo top | grep Swap


Will output the swap usage to the terminal. It updates every few secs or so.

I just tried
Code: Select all
sudo top | grep Swap >> swap.txt


The file swap.txt was created but nothing was written to it?

Hope this helps.

Edit**

I left the command running whilst I had my tea. When I came back there was data written to the file.

You could pop the command in a executable file and create a cron job to run it, or just start it when you want to monitor your swap usage.
So it looks like I'm back to LinuxMint again. Why you ask? Because my machine smell nicer.

I'm not too sure I'd want a Mint and Cinnamon muffin with my brew though. Guess I'm lucky they don't run my local bakery.
purplepenguin
LXF regular
 
Posts: 124
Joined: Wed Oct 05, 2011 2:19 pm
Location: Blissfully at the Command Line

Postby nelz » Mon Apr 15, 2013 10:39 pm

You don't need to run it with cron, it keeps running the way you have run it and will keep filling the file. By default, it updates every three seconds, which will soon be a lot of data. You can change this with -d.

BTW, top runs as a user, you don't need to use sudo.

You may be better off using a combination of swapon and watch

Code: Select all
watch /sbin/swapon -s
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8470
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby serene » Wed Apr 17, 2013 8:43 pm

Thank you both.

This is a little difficult to record due to the swap isn't being used for anything. Which stress test would you use to force the swap to be read and written to .


Thank you.
Serene
User avatar
serene
LXF regular
 
Posts: 111
Joined: Sun Jun 19, 2005 12:43 pm

Postby nelz » Wed Apr 17, 2013 8:46 pm

Loading a shedload of large digital photos into GIMP always does it for me :)
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8470
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby serene » Fri Apr 19, 2013 2:01 pm

Will follow up, thanks.

Cheers

Serene



[SOLVED]
User avatar
serene
LXF regular
 
Posts: 111
Joined: Sun Jun 19, 2005 12:43 pm


Return to Programming

Who is online

Users browsing this forum: Google [Bot] and 2 guests