Sunday, 31 January 2016

Logitech Media Server memory mangement under Linux

I've had a Squeezebox up and running for many years.  Its served me very well in that time,  and although admittedly a bit "techie" for all tastes it runs well and  has been reliable over the years. 

Around a year ago the NAS I was holding the data on and running the server software from (ancient Netgear ReadyNAS NV+ running sparc) died a sudden death.  Despite many attempts I could neither revive the NAS nor even get the data back from it.

I did have some backups and other sources for getting the data back,  and after a few weeks I had amassed most of it again,  thank goodness.  All those hours of burning CDs,  filling in MP3 tags and finding appropriate album images had not been wasted. 

I have an old Dell machine running in a small area I laughingly refer to as an "office area" and I thought: since its almost always running: why not use this as a media server instead.  So I went ahead and installed the linux version of the Logitech software on there and then added a 2nd hard drive and copied over my music and photos. 

After a good deal of fiddling around the setup seemed to work well: except for one thing.  A huge memory leak!  Within a week of a reboot the machine (Dell Vostro 200 with 4GB of RAM) had pretty much run out of memory.

A few days ago I came across a YouTube posting by Joe Collins which was talking about memory management under Linux.

He mentioned this command:

sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"

I ran this on the machine and lo and behold: back came some free memory.

The next job was to schedule this to run regularly: otherwise the freed up memory would slowly disappear again. 

So I created a cron job to facilitate this.

Since the command was preceded by "sudo" I needed to edit the root contab file in order for it to run so the command was:

sudo crontab -e

This command takes you into the appropriate file to edit (after choosing your editor, in this case I chose NANO).

 At this point you need to enter some syntax into the file which firstly tells cron how often you want the command to run and secondly gives it the command to run. 

In my case the command was:

*/120 * * * * sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"

The first bit (*/120 * * * *) tells cron to run the job every 120 minutes,  and the 2nd is our command.

No more reboots to reclaim memory for me! 


0 comments:

Post a comment