Announcement

Collapse
No announcement yet.

Do I need a swap partition [and can i add one, if I do]?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Do I need a swap partition [and can i add one, if I do]?

    Good morning,

    I'm running 14.04, 64 bit, all up to date. I've noticed some slight performance problems recently - a lot of disk activity in bursts, mainly. Looking at the system activity, Chrome seems to be hogging memory. This is probably my fault, as I prefer to run with several Chrome windows open (on different desktops) each with multiple tabs. I'm wondering if the activity is all the Chrome being written to disk, in which case would a swap partition help?

    (I don't have a swap partition. I didn't think I'd need it - 4GB of RAM after all. However, I find I only have 3GB of RAM....)

    If a swap partition is the answer, what is the simplest way to add it? I've read several posts about (A) creating a swap file via CL, or (B) creating a new partition then modifying FSTAB and whatever. Either of these would take me out of my comfort zone.

    Could I use Clonezilla? Backup /home and /root, create a new (swap) partition, then restore /home and /root?

    Thanks

    #2
    It depends on how heavy your multitasking is. Try KinfoCenter to monitor your memory usage. If application data reaches high percentages and disk cache/buffers are low (without free memory), then maybe you might need some changes.

    If your multitasking is not heavy, 4GB of ram could be enough. I have 2*2GB dimms and hardly ever multitask, so I have big fat margins. Running the os on a ssd with /root, /home, no swap. Don't worry about the 3GB of ram indicated, the others are reserved by the onboard/embedded graphics if you don’t have a separate vga card. Mine says total physical memory 3,37GB (using graphics via APU).

    If you do need swap, you can set it on a different hdd if you don’t have space. But maybe you wont need it at all with 4GB ram...
    Last edited by zahtar; Jun 20, 2014, 05:48 PM.

    Comment


      #3
      if you need to create a swap partition you can do so at anytime. In order to activate it use the 'swapon' command.

      Depending on how much ram you have and how memory intensive your programs are you may not need swap. If you want to ever use suspend to disk as a shutdown alternative then you will need swap. I usually just set aside 2GB for swap when setting up a machine because disk space is pretty cheep and one swap partition can be shared by several distros.
      Mark Your Solved Issues [SOLVED]
      (top of thread: thread tools)

      Comment


        #4
        Comfort zone or not, you're going to have do a little work to get a swap partition in use. You could make and use a swap file instead. But until we know more about your setup the answers can't be specific. Based on your post, we don' really even know yet if a swap partition or file would be the answer,

        If you have some unallocated space on your hard drive, a swap partition will be rather simple. If you do not have unallocated space on your hard drive, you'll have to make some by shrinking one of your existing partitions. If you want to try a swap file instead, here's how that's done:


        Create the file:
        Code:
        dd if=/dev/zero of=/myswap bs=1M count=4096
        Make it swap:
        Code:
        mkswap /myswap
        Activate it:
        Code:
        swapon /myswap
        See if it worked:
        Code:
        free -m
        In order to always start the swapfile at bootup, edit /etc/fstab and add
        Code:
        /myswap           swap          swap    defaults    0 0
        This makes a 4GB swp file in your / partition. If you want it smaller or larger, adjust the 4096 to how many MBs you want. If you have more room in /home use /home/myswap instead of /myswap.


        A swap partition is preferred because it avoids the overhead of the file system when all you need is an addressable pool. But nothing prevents you from using a swap file instead of a swap partition, or in addition to a swap partition. Also, rarely a swap file may become corrupted by a system error. Swap files are somewhat slower than a swap partition and can't be moved (only deleted and recreated), but you don't have to muck about with your partitions to use one.

        Please Read Me

        Comment


          #5
          Thanks for the responses, guys.

          I think I'd be better off going for a swap partition, rather than a file. More work, yes, but a better solution. But I don't now if I need one.

          I never suspend, so i don't need one for that. With "average" applications and windows open, KInfoCentre tells me I've 3GB of physical memory, and I'm using about 95% of it - 75% is application date, 20% is system cache. Is this good or bad (or normal)? Would a swap partition improve things?

          Thanks

          Comment


            #6
            Two recommendations:

            1) YES, use a swap partition, for several reasons
            2) To significantly improve the performance of chromium, set the cache to run in a tmpfs (i.e. in memory), by symlinking ~/jollyjack/.cache/chromium to /run/user/1000 (or your user number if it is not 1000).

            Comment


              #7
              Originally posted by jollyjack View Post
              Thanks for the responses, guys.

              I think I'd be better off going for a swap partition, rather than a file. More work, yes, but a better solution. But I don't now if I need one.

              I never suspend, so i don't need one for that. With "average" applications and windows open, KInfoCentre tells me I've 3GB of physical memory, and I'm using about 95% of it - 75% is application date, 20% is system cache. Is this good or bad (or normal)? Would a swap partition improve things?

              Thanks
              I would say yes you need swap if you're using 95% of available RAM. However, "system cache" is actually available RAM for programs, your system is just holding data in it until needed by something.

              It's worthy to note that using swap is not exactly a performance booster. Hard drive access is several magnitudes of order slower than RAM access. I would advise, along with the change dibl suggests, you look into ways to reduce the memory usage of Chrome. I would also shut down all unneeded processes and "features" of Kubuntu and end any programs you're using before you open Chrome so that you're using less RAM overall. I realize this isn't a great answer, but our hardware will always be the limitation and you have to adjust to what's available.

              Here's what I would do:
              Reboot to a "fresh" desktop (don't launch anything and make sure "restore session" is unchecked).
              Open a terminal and check memory usage via free -m
              Open System Settings and look at the services that are running automatically at startup.
              Turn off all that you don't need: I am sure there are at least 4-5 things running by default that are unnecessary.
              Uninstall any programs that run in the background that you don't need - like apparmor.
              Uninstall any chrome extensions you can live without, more than 3 or 4 will eat a ton of memory.
              Finally, if you are going to stick with Chrome, get used to closing tabs you don't need right now.

              My gut tells me you should be able to have a decently running system with 3GB.

              Please Read Me

              Comment


                #8
                As far as the task of creating a swap partition:

                Shrink a current partition to allow for the size of swap you want (1-2GB is plenty if you don't hibernate).
                Make the swap partition.
                Edit /etc/fstab and add the swap line just like above except use the partition name (/dev/sda-whatever) instead of /myswap.
                Start swap with the swapon -a command.

                I could give more specific instructions if you supplied the output of sudo fdisk -l

                Please Read Me

                Comment


                  #9
                  Thanks oshunluvr and dibl

                  1. I have created the symlink, I think, If I understood it correctly. In /run/user/1000, there is now a soft/symbolic link that points to /jollyjack/.cache/chromium - is that right?

                  2. I ran free -m as suggested. It gave me

                  Total memory = 2872
                  used = 1050
                  Free = 1822
                  Shared = 54
                  Buffer = 66
                  Cache = 432

                  3. I've already done what I can to slim Kubuntu down, including stopping from autostarting all the services that I know I don't need. There are some i don't recognise, so I've left them alone. When I was in the "empty" desktop, I ran KRunner - the biggest users of memory were Plasma, KDE4, MySQLD and KWin. After those, each process was using 10K or less. Akonadi was taking a bit of memory - can I disable it? I don't use any of the Kubuntu products like KMail - I prefer Thunderbird.

                  4. Chrome Extensions. I only have 5/6 of them, mainly small and simple. Adblock is big, as is Shockwave plug-in, but I don't think I can do without them....

                  Given the above, would |i benefit from a swap partition?

                  Thanks for all the help.

                  Comment


                    #10
                    Honestly, that doesn't seem too bad. Maybe your best bet is to minimize multi-tasking when surfing. You probably should still do the swap partition anyway. It'll be a great learning experience if nothing else.

                    Please Read Me

                    Comment


                      #11
                      Originally posted by jollyjack View Post
                      Thanks oshunluvr and dibl

                      1. I have created the symlink, I think, If I understood it correctly. In /run/user/1000, there is now a soft/symbolic link that points to /jollyjack/.cache/chromium - is that right?
                      No, that's backwards. Under /home/jollyjack/.cache there should be a symlink named "chromium" that points to /run/user/1000. I assume you are using the packaged chromium from the *buntu repo, not the downloaded tarball for Linux.

                      You could also put the link under /home/jollyjack/.cache/chromium, or even /home/jollyjack/.cache/chromium/default -- those structures remain static through reboots.
                      Last edited by dibl; Jun 23, 2014, 11:17 AM.

                      Comment


                        #12
                        A 50:50 chance, and I had to get it wrong. The story of my life.

                        Cheers

                        Comment


                          #13
                          Originally posted by jollyjack View Post
                          A 50:50 chance, and I had to get it wrong. The story of my life.

                          Cheers
                          lol

                          Please Read Me

                          Comment


                            #14
                            Hi,

                            I'll have a go at creating the swap partition tonight. As you say, it's a useful learning process.

                            Thanks to you all for your help.

                            Cheers

                            Comment


                              #15
                              Well, with your help gentlemen, I think I've done it.

                              All four primary partitions were in use, so I'd to turn /dev/sda4 into an extended partition then create two new partitions - a small swap and another. Then edit /etc/fstab (that was exciting), then enter swapon /dev/sda5.

                              Output of free -m is

                              total used free shared buffers cached
                              Mem: 2872 2082 790 168 78 801
                              -/+ buffers/cache: 1202 1670
                              Swap: 2991 0 2991



                              Am I done?

                              Cheers

                              Comment

                              Working...
                              X