Swap file for a novice

Hallo, everyone, from Wales UK
I'm recently back in Zorin after a 4 year spell with Trisquel. I have 17.2 installed on a Lenovo ThinkPad T400, which I think has a nominal 4Gb RAM. I'm very happy to be back in Zorin, and generally everything runs very well. Certainly in terms of the internet it seems quite fast to me.
But none of the applications I principally use - Betterbird, Opera, , LibreOffice, Zim, XnView - like being left running - they have to be allowed time to 're-awaken'.
So I'm wondering if a swap-file arrangement might help with that ?
I've found the Tutorial Create or Resize Swap file/Partition, but have not yet got pass the first command line.
So, advice, please: in the first place, would a swapfile ease my issue ? And if it would, would it be better to go for an empty USB stick, or for space on the hard-drive (I don't keep much actually on the machine, other than the systems) ?
[And if the answers to those questions encourage me to try, I suspect I'll need some hand-holding on the actual process !]
Thank you for reading....
Sincerely
Ian Graham

1 Like

A swap-file would solve your issue... If you don't already have swap enabled, that is.

if you have an SSD on your computer, I'd recommend using that. If you have an hard drive, I'd recommend using the USB drive, because normally HDDs have really slow multi-access reads and writes.

I'll help you if you do need it.
Have a great evening.

1 Like

Zorin OS creates a swapfile out of the box. If you have followed the installation using the default settings, you should already have that created. You can verify this simply by launching the System Monitor, under the Resources tab:

There you can see how much Swap space you have allocated, and how much is currently in use. This machine has 4 GB of RAM and it gave me 4 GB of swap, so I'd assume you should have something very similar.

If you see that you're using a lot of swap space, it might be a good idea to increase it. Although, you should consider buying a memory stick, if you can. It'll extend the life of the drive and make the experience smoother.

Thank you both for your responses. Very helpful.
Ian G.

I have checked and yes, I do have an installed swap-file. I have a hard drive, so it would probably be better to use a stick. I have formated a stick and mounted it so I can see it is /dev/sdc1. So I have tried to modify the command line from the tutorial, but the system doesn't like it. I will try to attach a screen dump.
Do I need to disable the existing swap file ?
And as a wild side-step - is there an app that will automate the processes I need ?

Thank you again, in anticipation .
Ian G.

just some extra input .
i have a OLD laptop with 4G ram , my swap file is set to 2G but it never uses swap basically cause i set swappiness value to 0 . Mind you i have a SSD , which in my opinion ,if you upgrade to SSD would solve waiting for "re-awakening".
i always close a program when i'm done ,and when i open again ,it opens in a second or 2 .(i'm on Lite so system resources is less also)
a swap file only helps when your system is running out of ram , is that the case ?
also keep in mind swap is slower than ram , and keeping swap on a hard drive is more reliable and faster than a swap on USB. and USB drives wear out faster with frequent writes .

ok after all said and done , if you want to set your swappinnes value , and keep it set after reboots , use these 2 commands

sudo bash -c "echo 'vm.swappiness = 0' >> /etc/sysctl.conf"
sudo sysctl -p

note mine is set to 0 , but you can change the value to whatever suits you , the higher the value the more frequent system would write to swap .
if you not running out of normal ram , i'd suggest to set value to 10.
but if you really want your lappy to fly .... get a SSD
:smiley:

not to clear what you mean here , are you saying you want to leave those programs open all the time , in an effort for them to open more quickly when you need them ?
or are you closing them and they take too long to open ?

no need to , you already have a swap file , no need to disable it and create a new one .
i get that you want to create a swap file on USB now , but i would discourage that .

This is why I prefer manual partitioning.

  1. Create "/' root file system of 80 Gb, formatted to Ext4.

  2. Create Extended Partition and create 8 Gb swap area at end of extended partition.

  3. Everything left marked as '/home' and format to Ext4.

Using Gparted at point of install choosing, 'Other/Manual install.

The fallocate commands needs a filename, but you are providing a block device that corresponds to the external drive that you have connected. If you run ls -l /dev/sdc*, the results come back looking something like this (in my example, it's /dev/sda but it's the same thing):

brw-rw---- 1 root disk 8, 0 Dec  2 10:10 /dev/sda
brw-rw---- 1 root disk 8, 1 Dec  2 10:10 /dev/sda1
^

Pay attention to the first character; it describes the type of file that it is. A b meaning block device, which broadly speaking means a drive. You would need to provide the path to an actual file.

For reference, you can take a look at the default file created as swap, usually located at /swapfile:

-rw------- 1 root root 3376414720 Oct  8 21:53 /swapfile

A single - means this is a regular file. Notice that it was very strict read/write permissions as this will potentially contain sensitive information, including passwords and things like that.

So, you would first create the file at the new drive or partition:

sudo fallocate -l 2G /dev/sdc1/swapfile
sudo chmod 600 /dev/sdc1/swapfile
sudo mkswap /dev/sdc1/swapfile

Then, disable swap and remove the current swapfile:

sudo swapoff /swapfile
sudo rm /swapfile

And, finally, enable swap again but pointing to the newly created file for that purpose.

sudo swapon /dev/sdc1/swapfile

Do note, however, that upon rebooting the system will try to mount the previous swapfile. You need to update that now, as well:

sudoedit /etc/fstab

This will bring up a terminal-based text editor, but you can also use the regular text editor, just remember that you need to edit this file with elevated privileges.

You should see an entry at the bottom that looks something like this:

/swapfile none  swap  sw 0  0

You need to change it to point to the new swapfile in the other drive:

/dev/sdc1/swapfile none  swap  sw 0  0

With all that said, I do not recommend you follow through with this setup.

I mean, I don't really know your exact use case but if you can spare 2 or even 4 GB off of your SSD, that would be much simpler to manage in the long run, and it'll be much faster and efficient.

On the other hand, since you are already making use of another drive, you shouldn't use USB flash drives which are notoriously unreliable. Use a proper drive if you can, and while you're at it use a whole partition to make things simpler.

And even before your commit to one strategy or another, I think it's worth looking into this a bit further to determine whether swap really is going to help. Try using one program at the time to see how the response times vary; after a few days you should have a better sense of whether you're pushing the system's resources a bit too far.

In Trisquel (on this same machine) I used a slightly different core set of applications, but with Icedove (the email client), LibreOffice (albeit a 7 version) and Xnview I just left them open once used, and didn't have the wake-up issue. I'm much happier generally in Zorin, but as well as the 'sleeping/waking' thing, I would say almost everything takes quite a long time to open.

I am very grateful for your generous patience in giving such a full reply, which I think I understand.
And I note you wider advice. Together with several other answers in the second half of today, I think I need to summon a degree of patience in current use, and think seriously about upgrading to better-resourced machine.

1 Like

Thank you very much indeed "diolch yn fawr" to all who have replied, and most recently to 14nd, swarfendorf437 (who helped me in my first coming with Zorin 5 or 6 years or so ago) and zenzen.
(I'm being prompted to 'consider replying to several posts at once', but my two previous replies were to specific points, and this one is intended more as a sign-off.)
I think it is fairly clear that my present set-up is probably the best I can get on this particular machine, and I'm grateful to all who have given thoughtful guidance to that effect. As noted in one of those 'specific' replies, I think I need to consider my options in acquiring a machine with (probably) a SSD not a hard-drive and certainly more RAM.
I think this whole thread reflects great credit on the spirit of the forum. Thank you again.
Sincerely
Ian Graham

From what I read about Trisquel, it uses the LXDE desktop environment which is much more lightweight in terms of resource usage. While Gnome has improved a lot, you'd still have to adjust your behavior to run fewer programs at the time. I'd say that is simply the case here.

I have an old Chromebook that I still use from time to time, with 4GB as well, and while it can handle most of my usual workload I have to be careful not to run too many things at once.

Another alternative to get a bit more of juice out of the system is to use ZRAM, which is just compressed memory to basically make the most out of your limited RAM. It comes at the cost of increased CPU usage and potentially shorter battery life, however, but not so much that it would be too noticeable, so it's worth a try I think.

Or alternatively try Q4OS 32-bit Plasma. Because it is 32-bit it should fly on your 64-bit notebook:

Just to acknowledge with thanks your further thoughts. Will respond more fully later.
IG

I'm sorry not to have rounded this off sooner. Initially I was watching my machine, which seemed (maybe?) to be bedding in. And then Storm Darragh intervened. We were without power, phone or internet for 60+ hours.

So: re the most recent suggestions: I have looked at them.
The ZRam is I think a bit above my paygrade, and certainly I'm not inclined to rock the boat of my present installation; but I'm sure it may be of interest to others.
Q40S I am aware of. I did quite an intensive best-option restoration of two Packard Bells dot-s machines a couple of years ago, and that was certainly one option. But in the end I went then with Linux Mint, purely on 'look and feel', which is such a personal thing, and yet critical to any OS choice,once one has slipped the bounds of Microsoft. And is the reason I am happy now to be back in Zorin - it simply seems more intuitive to my particular mind than other options I've tried.

The last thing to note is that, trying to be as objective as I can be, I do think the 'waiting for a software to respond' annoyance has abated somewhat. Do pathways in an OS become grooved with repetition, or is that too anthropomorphic?

Any way, thanks again to everyone who has responded to my original post. Much appreciated.

Computers are deterministic by design, so unfortunately the answer to this is "no"; if the input doesn't change, neither does the output.

Like everything else, computers degrade over time. Hard drives are the most affected by this since they have moving parts. You can try a few optimizations here and there to reduce read/write activity on the drive, but an upgrade to a SSD is the single most effective thing you can probably do to increase performance on any computer, especially relatively old ones.

You might want to open the computer and give it a good clean from the inside as well: use isopropyl alcohol to clean all the connectors, apply a fresh patch of thermal paste on the CPU, and clear any dust using a can of compressed air, applying it gently all around, including the fans. Heat and dust are the silent killers of computers.

That is the beauty of open source, there are plenty of ponds to fish in. I think you might want to try other distributions that are lighter on resource consumption. These typically are the ones without fancy visual effects and such. Zorin OS Lite might just be good enough, and close enough to something you're already used to.

Hope everyone is okay after the storm, and good luck!