Importance of Swap Partition
- What is the purpose of a swap partition?
- How do I know I have just enough swap partition? Not too much/little.
My Ubuntu PC is used for typical stuff:
- Web (email, facebook, etc.)
- Some movies
- gaming is rare
system-installation hard-drive filesystem swap disk
add a comment |
- What is the purpose of a swap partition?
- How do I know I have just enough swap partition? Not too much/little.
My Ubuntu PC is used for typical stuff:
- Web (email, facebook, etc.)
- Some movies
- gaming is rare
system-installation hard-drive filesystem swap disk
By what's been posted it seems I have WAY too much swap. 3GB RAM, 300GB HD, and a 8GB partition for swap.
– lamcro
Oct 24 '10 at 2:29
2
Extra swap that doesn't get used isn't going to hurt you, and reclaiming 1.7% of your drive to make it smaller is probably not worth the effort. Yes, it's far larger than you'll probably ever use, I wouldn't worry about it.
– msw
Oct 24 '10 at 15:02
1
You can also see it as a "future proof" swap partition, if you ever add extra memory to your system, you won't have to enlarge the swap... :)
– JanC
Oct 24 '10 at 15:29
add a comment |
- What is the purpose of a swap partition?
- How do I know I have just enough swap partition? Not too much/little.
My Ubuntu PC is used for typical stuff:
- Web (email, facebook, etc.)
- Some movies
- gaming is rare
system-installation hard-drive filesystem swap disk
- What is the purpose of a swap partition?
- How do I know I have just enough swap partition? Not too much/little.
My Ubuntu PC is used for typical stuff:
- Web (email, facebook, etc.)
- Some movies
- gaming is rare
system-installation hard-drive filesystem swap disk
system-installation hard-drive filesystem swap disk
edited Aug 3 '14 at 16:23
Tim
19.6k1484139
19.6k1484139
asked Oct 23 '10 at 18:35
lamcro
606921
606921
By what's been posted it seems I have WAY too much swap. 3GB RAM, 300GB HD, and a 8GB partition for swap.
– lamcro
Oct 24 '10 at 2:29
2
Extra swap that doesn't get used isn't going to hurt you, and reclaiming 1.7% of your drive to make it smaller is probably not worth the effort. Yes, it's far larger than you'll probably ever use, I wouldn't worry about it.
– msw
Oct 24 '10 at 15:02
1
You can also see it as a "future proof" swap partition, if you ever add extra memory to your system, you won't have to enlarge the swap... :)
– JanC
Oct 24 '10 at 15:29
add a comment |
By what's been posted it seems I have WAY too much swap. 3GB RAM, 300GB HD, and a 8GB partition for swap.
– lamcro
Oct 24 '10 at 2:29
2
Extra swap that doesn't get used isn't going to hurt you, and reclaiming 1.7% of your drive to make it smaller is probably not worth the effort. Yes, it's far larger than you'll probably ever use, I wouldn't worry about it.
– msw
Oct 24 '10 at 15:02
1
You can also see it as a "future proof" swap partition, if you ever add extra memory to your system, you won't have to enlarge the swap... :)
– JanC
Oct 24 '10 at 15:29
By what's been posted it seems I have WAY too much swap. 3GB RAM, 300GB HD, and a 8GB partition for swap.
– lamcro
Oct 24 '10 at 2:29
By what's been posted it seems I have WAY too much swap. 3GB RAM, 300GB HD, and a 8GB partition for swap.
– lamcro
Oct 24 '10 at 2:29
2
2
Extra swap that doesn't get used isn't going to hurt you, and reclaiming 1.7% of your drive to make it smaller is probably not worth the effort. Yes, it's far larger than you'll probably ever use, I wouldn't worry about it.
– msw
Oct 24 '10 at 15:02
Extra swap that doesn't get used isn't going to hurt you, and reclaiming 1.7% of your drive to make it smaller is probably not worth the effort. Yes, it's far larger than you'll probably ever use, I wouldn't worry about it.
– msw
Oct 24 '10 at 15:02
1
1
You can also see it as a "future proof" swap partition, if you ever add extra memory to your system, you won't have to enlarge the swap... :)
– JanC
Oct 24 '10 at 15:29
You can also see it as a "future proof" swap partition, if you ever add extra memory to your system, you won't have to enlarge the swap... :)
– JanC
Oct 24 '10 at 15:29
add a comment |
6 Answers
6
active
oldest
votes
The swap partition serves a couple of purposes.
It serves as 'backup' RAM. That is, should your computer run out of RAM, it will use the swap area as a temporary source of more memory. More specifically, it will 'swap' unused items from the RAM into the swap area in order to leave spare space for the applications that need it at that instant. This is not ideal as the data transfer rate to the hard drive is significantly lower than that to your normal RAM. In practice this means its much slower to retrieve information from the swap area.
It is used when the computer hibernates. Hibernation involves taking an image of the RAM in its current state (like an ISO represents an image), and saves it to the swap area. It then reloads this image when the computer restarts.
To be most useful, the swap area should be at least (RAM * 1.5) although more is recommended. For example, on my system with 3gb of RAM, I have a swap area of 7.2gb.
If you don't use something it is ideal to swap it to disk, and use the RAM for things that you do use (for example moving CUPS or other daemons you don't use very often to swap gives you more memory for caching disk data that actually gets used a lot).
– JanC
Oct 24 '10 at 15:35
-1; "(RAM * 1.5) although more is recommended" - on the desktop PC? You are repeating conventional wisdom that has been false for years.
– user280493
Aug 3 '14 at 16:32
@user280493 Worth noting that the answer was years old ... years ago when you commented.
– Crisfole
Feb 28 '18 at 4:18
add a comment |
This is very close to the same as this question about the “right” size for a swap partition. Much of the same information from my answer there applies - basically, if you want to hibernate you generally want your swap space to be at least as big as your RAM, and other than that a round number like 1 or 2 GB is easily sufficient. Because swap is so much slower than RAM, if you're filling up multiple gigabytes of swap your computer has almost certainly become unusably slow.
There's also no real need for a swap partition - swap files (available on the mainstream linux filesystems) give the same performance and make it trivially easy to add more swap space if you decide you haven't got enough.
add a comment |
here a very deep information about swap
some people say the double of your ram but personally i recommend this :
swap = 1.5 X Total Ram
Example :
if you have 2Gb of ram -> swap = 1.5 x 2 = 3
P.D : Ubuntu Desktop uses Swap to Hibernate (PC off, no power needed, program states saved). If Hibernation is important to you, have more swap space then ram + swap overflow.
add a comment |
The free
command can tell you how much swap you are using. For example on this machine:
$ free -m
total used free buffers cached
Mem: 1947 1863 84 312 758
-/+ buffers/cache: 792 1154
Swap: 4000 3 3997
shows me that I have 2GB (1947m) RAM and that the system has used most of it. However, 312m is used for I/O buffers and the remainder (758m) the system has decided to fill with disk cache.
The disk cache is interesting because it is using fast memory instead of slow disk for its contents. The contents could be gotten from disk, but they are kept around in case they are needed. This also means that there is 758m of memory that can be reclaimed in an instant if necessary because the system knows it can find that data on the disk instead.
That is why there is a second line showing that if there were no buffering and cache, I'd have half my RAM (1154m) available for use.
The third line shows that I have an overly large swap partition (it was there and wasn't doing anything) of which a whopping 3m have been used. This is stuff that the kernel really doesn't expect to have to use anytime soon so it was stuck out on the "back porch".
While free
gives you the snapshot now, vmstat
can give you a running picture:
$ vmstat 10
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 3588 86236 316524 769132 0 0 14 13 126 81 4 1 95 0
0 0 3588 83872 316532 770512 0 0 0 20 264 1229 3 1 96 0
There's a lot of information there, but of interest is that there is no swap-in (si) or swap-out (so) traffic. Which means I'm not using the swap at all over the last 10 seconds.
add a comment |
- Swap area is the part of Hard Disk space used to support limited
space RAM memory. RAM is limited in size so, some applications need
more RAM than the available RAM space, In that case this Swap Space
also called as Virtual Memory used to support RAM. - It is slower in speed compared to RAM's speed. When we run a large
application then the least recently used part of that application
in swapped to Swap Area on the Hard Drive, it is swapped back from
Swap Area when it is needed. This gives Operating System a feel of
just having more RAM than actually it is. - It is a dedicated partition on Hard Disk created while installing Operating System.
- It is good if create Swap Area of Double the size of RAM.
You can check used and available Swap Area using following command:
$ cat /proc/swaps
Filename Type Size Used Priority
/dev/sda10 partition 7812092 16 -1
add a comment |
I have a laptop with a slow hard drive, but relatively high RAM (8GB). On this setup, I find a swap drive to be counterproductive for the following reasons:
Getting applications back out of swap is slow, comparable to loading the application from scratch. I would rather have an environment that responds quickly, even if that means I sometimes have to close and reload applications, than an environment which sometimes stalls on me unexpectedly.
If I wanted the ability to hibernate, that would mean writing a lot of data to disk. That would be a constant drain on battery if it was done persistently (the default behaviour of swappiness 60), or if it was only done at hibernation time (by reducing swapiness), then it would take a long time to actually hibernate. I found suspending to be RAM instead of suspending to disk to be quite satisfactory. It could stay suspended for a couple of days, and it would unsuspend much more quickly than a full hibernation.
Because the hard drive is slow, I prefer to keep 1GB of RAM reserved for disk cache, effectively exchanging memory for speed. This keeps my machine snappy, but it does mean I can use only 7GB of my 8GB of RAM for applications. The software I use to achieve that is a fork of earlyoom which kills old browser tabs when 88% of the RAM has been used. I occasionally have to reload old browser tabs which have been killed off.
When would this advice not apply?
If you have a fast hard disk drive, or an SSD, and have fewer concerns about battery drain, then the disadvantages I outlined above will not apply. (Although early SSDs might have issues with wear, I believe any SSDs sold since 2018 should be fine.)
If your machine has very little RAM, or you like to use multiple memory-hungry applications at the same time, then you may need to use swap to get your work done, regardless of the disadvantages. This was the primary use-case for swap, before memory started to become cheaper.
If you really need hibernation (perhaps you want to suspend your laptop, and re-open it after a few days without charging) then you need a swap drive (recommended at least as large as your RAM).
Caveat:
- Some of the software that we leave running for a long time (especially the OS and desktop environment) will load code into memory which will never actually be used again. These pages could be moved to swap and will never need to be pulled out again, thus avoiding the disadvantages I mentioned earlier. For this reason, I sometimes create a small 512MB or 1GB swap file, and let the unused pages of memory get swapped out. This just leaves me with a little more RAM for applications. (Needed: A technique for measuring swap churn, to help tune the size of this swap file.)
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f9092%2fimportance-of-swap-partition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
The swap partition serves a couple of purposes.
It serves as 'backup' RAM. That is, should your computer run out of RAM, it will use the swap area as a temporary source of more memory. More specifically, it will 'swap' unused items from the RAM into the swap area in order to leave spare space for the applications that need it at that instant. This is not ideal as the data transfer rate to the hard drive is significantly lower than that to your normal RAM. In practice this means its much slower to retrieve information from the swap area.
It is used when the computer hibernates. Hibernation involves taking an image of the RAM in its current state (like an ISO represents an image), and saves it to the swap area. It then reloads this image when the computer restarts.
To be most useful, the swap area should be at least (RAM * 1.5) although more is recommended. For example, on my system with 3gb of RAM, I have a swap area of 7.2gb.
If you don't use something it is ideal to swap it to disk, and use the RAM for things that you do use (for example moving CUPS or other daemons you don't use very often to swap gives you more memory for caching disk data that actually gets used a lot).
– JanC
Oct 24 '10 at 15:35
-1; "(RAM * 1.5) although more is recommended" - on the desktop PC? You are repeating conventional wisdom that has been false for years.
– user280493
Aug 3 '14 at 16:32
@user280493 Worth noting that the answer was years old ... years ago when you commented.
– Crisfole
Feb 28 '18 at 4:18
add a comment |
The swap partition serves a couple of purposes.
It serves as 'backup' RAM. That is, should your computer run out of RAM, it will use the swap area as a temporary source of more memory. More specifically, it will 'swap' unused items from the RAM into the swap area in order to leave spare space for the applications that need it at that instant. This is not ideal as the data transfer rate to the hard drive is significantly lower than that to your normal RAM. In practice this means its much slower to retrieve information from the swap area.
It is used when the computer hibernates. Hibernation involves taking an image of the RAM in its current state (like an ISO represents an image), and saves it to the swap area. It then reloads this image when the computer restarts.
To be most useful, the swap area should be at least (RAM * 1.5) although more is recommended. For example, on my system with 3gb of RAM, I have a swap area of 7.2gb.
If you don't use something it is ideal to swap it to disk, and use the RAM for things that you do use (for example moving CUPS or other daemons you don't use very often to swap gives you more memory for caching disk data that actually gets used a lot).
– JanC
Oct 24 '10 at 15:35
-1; "(RAM * 1.5) although more is recommended" - on the desktop PC? You are repeating conventional wisdom that has been false for years.
– user280493
Aug 3 '14 at 16:32
@user280493 Worth noting that the answer was years old ... years ago when you commented.
– Crisfole
Feb 28 '18 at 4:18
add a comment |
The swap partition serves a couple of purposes.
It serves as 'backup' RAM. That is, should your computer run out of RAM, it will use the swap area as a temporary source of more memory. More specifically, it will 'swap' unused items from the RAM into the swap area in order to leave spare space for the applications that need it at that instant. This is not ideal as the data transfer rate to the hard drive is significantly lower than that to your normal RAM. In practice this means its much slower to retrieve information from the swap area.
It is used when the computer hibernates. Hibernation involves taking an image of the RAM in its current state (like an ISO represents an image), and saves it to the swap area. It then reloads this image when the computer restarts.
To be most useful, the swap area should be at least (RAM * 1.5) although more is recommended. For example, on my system with 3gb of RAM, I have a swap area of 7.2gb.
The swap partition serves a couple of purposes.
It serves as 'backup' RAM. That is, should your computer run out of RAM, it will use the swap area as a temporary source of more memory. More specifically, it will 'swap' unused items from the RAM into the swap area in order to leave spare space for the applications that need it at that instant. This is not ideal as the data transfer rate to the hard drive is significantly lower than that to your normal RAM. In practice this means its much slower to retrieve information from the swap area.
It is used when the computer hibernates. Hibernation involves taking an image of the RAM in its current state (like an ISO represents an image), and saves it to the swap area. It then reloads this image when the computer restarts.
To be most useful, the swap area should be at least (RAM * 1.5) although more is recommended. For example, on my system with 3gb of RAM, I have a swap area of 7.2gb.
edited Dec 22 '12 at 19:09
Eric Carvalho
41.3k17113144
41.3k17113144
answered Oct 23 '10 at 19:19
richzilla
7,919174361
7,919174361
If you don't use something it is ideal to swap it to disk, and use the RAM for things that you do use (for example moving CUPS or other daemons you don't use very often to swap gives you more memory for caching disk data that actually gets used a lot).
– JanC
Oct 24 '10 at 15:35
-1; "(RAM * 1.5) although more is recommended" - on the desktop PC? You are repeating conventional wisdom that has been false for years.
– user280493
Aug 3 '14 at 16:32
@user280493 Worth noting that the answer was years old ... years ago when you commented.
– Crisfole
Feb 28 '18 at 4:18
add a comment |
If you don't use something it is ideal to swap it to disk, and use the RAM for things that you do use (for example moving CUPS or other daemons you don't use very often to swap gives you more memory for caching disk data that actually gets used a lot).
– JanC
Oct 24 '10 at 15:35
-1; "(RAM * 1.5) although more is recommended" - on the desktop PC? You are repeating conventional wisdom that has been false for years.
– user280493
Aug 3 '14 at 16:32
@user280493 Worth noting that the answer was years old ... years ago when you commented.
– Crisfole
Feb 28 '18 at 4:18
If you don't use something it is ideal to swap it to disk, and use the RAM for things that you do use (for example moving CUPS or other daemons you don't use very often to swap gives you more memory for caching disk data that actually gets used a lot).
– JanC
Oct 24 '10 at 15:35
If you don't use something it is ideal to swap it to disk, and use the RAM for things that you do use (for example moving CUPS or other daemons you don't use very often to swap gives you more memory for caching disk data that actually gets used a lot).
– JanC
Oct 24 '10 at 15:35
-1; "(RAM * 1.5) although more is recommended" - on the desktop PC? You are repeating conventional wisdom that has been false for years.
– user280493
Aug 3 '14 at 16:32
-1; "(RAM * 1.5) although more is recommended" - on the desktop PC? You are repeating conventional wisdom that has been false for years.
– user280493
Aug 3 '14 at 16:32
@user280493 Worth noting that the answer was years old ... years ago when you commented.
– Crisfole
Feb 28 '18 at 4:18
@user280493 Worth noting that the answer was years old ... years ago when you commented.
– Crisfole
Feb 28 '18 at 4:18
add a comment |
This is very close to the same as this question about the “right” size for a swap partition. Much of the same information from my answer there applies - basically, if you want to hibernate you generally want your swap space to be at least as big as your RAM, and other than that a round number like 1 or 2 GB is easily sufficient. Because swap is so much slower than RAM, if you're filling up multiple gigabytes of swap your computer has almost certainly become unusably slow.
There's also no real need for a swap partition - swap files (available on the mainstream linux filesystems) give the same performance and make it trivially easy to add more swap space if you decide you haven't got enough.
add a comment |
This is very close to the same as this question about the “right” size for a swap partition. Much of the same information from my answer there applies - basically, if you want to hibernate you generally want your swap space to be at least as big as your RAM, and other than that a round number like 1 or 2 GB is easily sufficient. Because swap is so much slower than RAM, if you're filling up multiple gigabytes of swap your computer has almost certainly become unusably slow.
There's also no real need for a swap partition - swap files (available on the mainstream linux filesystems) give the same performance and make it trivially easy to add more swap space if you decide you haven't got enough.
add a comment |
This is very close to the same as this question about the “right” size for a swap partition. Much of the same information from my answer there applies - basically, if you want to hibernate you generally want your swap space to be at least as big as your RAM, and other than that a round number like 1 or 2 GB is easily sufficient. Because swap is so much slower than RAM, if you're filling up multiple gigabytes of swap your computer has almost certainly become unusably slow.
There's also no real need for a swap partition - swap files (available on the mainstream linux filesystems) give the same performance and make it trivially easy to add more swap space if you decide you haven't got enough.
This is very close to the same as this question about the “right” size for a swap partition. Much of the same information from my answer there applies - basically, if you want to hibernate you generally want your swap space to be at least as big as your RAM, and other than that a round number like 1 or 2 GB is easily sufficient. Because swap is so much slower than RAM, if you're filling up multiple gigabytes of swap your computer has almost certainly become unusably slow.
There's also no real need for a swap partition - swap files (available on the mainstream linux filesystems) give the same performance and make it trivially easy to add more swap space if you decide you haven't got enough.
edited Apr 13 '17 at 12:24
Community♦
1
1
answered Oct 24 '10 at 1:45
RAOF
10.8k12646
10.8k12646
add a comment |
add a comment |
here a very deep information about swap
some people say the double of your ram but personally i recommend this :
swap = 1.5 X Total Ram
Example :
if you have 2Gb of ram -> swap = 1.5 x 2 = 3
P.D : Ubuntu Desktop uses Swap to Hibernate (PC off, no power needed, program states saved). If Hibernation is important to you, have more swap space then ram + swap overflow.
add a comment |
here a very deep information about swap
some people say the double of your ram but personally i recommend this :
swap = 1.5 X Total Ram
Example :
if you have 2Gb of ram -> swap = 1.5 x 2 = 3
P.D : Ubuntu Desktop uses Swap to Hibernate (PC off, no power needed, program states saved). If Hibernation is important to you, have more swap space then ram + swap overflow.
add a comment |
here a very deep information about swap
some people say the double of your ram but personally i recommend this :
swap = 1.5 X Total Ram
Example :
if you have 2Gb of ram -> swap = 1.5 x 2 = 3
P.D : Ubuntu Desktop uses Swap to Hibernate (PC off, no power needed, program states saved). If Hibernation is important to you, have more swap space then ram + swap overflow.
here a very deep information about swap
some people say the double of your ram but personally i recommend this :
swap = 1.5 X Total Ram
Example :
if you have 2Gb of ram -> swap = 1.5 x 2 = 3
P.D : Ubuntu Desktop uses Swap to Hibernate (PC off, no power needed, program states saved). If Hibernation is important to you, have more swap space then ram + swap overflow.
edited Oct 23 '10 at 19:07
answered Oct 23 '10 at 18:48
hhlp
32.2k1477131
32.2k1477131
add a comment |
add a comment |
The free
command can tell you how much swap you are using. For example on this machine:
$ free -m
total used free buffers cached
Mem: 1947 1863 84 312 758
-/+ buffers/cache: 792 1154
Swap: 4000 3 3997
shows me that I have 2GB (1947m) RAM and that the system has used most of it. However, 312m is used for I/O buffers and the remainder (758m) the system has decided to fill with disk cache.
The disk cache is interesting because it is using fast memory instead of slow disk for its contents. The contents could be gotten from disk, but they are kept around in case they are needed. This also means that there is 758m of memory that can be reclaimed in an instant if necessary because the system knows it can find that data on the disk instead.
That is why there is a second line showing that if there were no buffering and cache, I'd have half my RAM (1154m) available for use.
The third line shows that I have an overly large swap partition (it was there and wasn't doing anything) of which a whopping 3m have been used. This is stuff that the kernel really doesn't expect to have to use anytime soon so it was stuck out on the "back porch".
While free
gives you the snapshot now, vmstat
can give you a running picture:
$ vmstat 10
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 3588 86236 316524 769132 0 0 14 13 126 81 4 1 95 0
0 0 3588 83872 316532 770512 0 0 0 20 264 1229 3 1 96 0
There's a lot of information there, but of interest is that there is no swap-in (si) or swap-out (so) traffic. Which means I'm not using the swap at all over the last 10 seconds.
add a comment |
The free
command can tell you how much swap you are using. For example on this machine:
$ free -m
total used free buffers cached
Mem: 1947 1863 84 312 758
-/+ buffers/cache: 792 1154
Swap: 4000 3 3997
shows me that I have 2GB (1947m) RAM and that the system has used most of it. However, 312m is used for I/O buffers and the remainder (758m) the system has decided to fill with disk cache.
The disk cache is interesting because it is using fast memory instead of slow disk for its contents. The contents could be gotten from disk, but they are kept around in case they are needed. This also means that there is 758m of memory that can be reclaimed in an instant if necessary because the system knows it can find that data on the disk instead.
That is why there is a second line showing that if there were no buffering and cache, I'd have half my RAM (1154m) available for use.
The third line shows that I have an overly large swap partition (it was there and wasn't doing anything) of which a whopping 3m have been used. This is stuff that the kernel really doesn't expect to have to use anytime soon so it was stuck out on the "back porch".
While free
gives you the snapshot now, vmstat
can give you a running picture:
$ vmstat 10
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 3588 86236 316524 769132 0 0 14 13 126 81 4 1 95 0
0 0 3588 83872 316532 770512 0 0 0 20 264 1229 3 1 96 0
There's a lot of information there, but of interest is that there is no swap-in (si) or swap-out (so) traffic. Which means I'm not using the swap at all over the last 10 seconds.
add a comment |
The free
command can tell you how much swap you are using. For example on this machine:
$ free -m
total used free buffers cached
Mem: 1947 1863 84 312 758
-/+ buffers/cache: 792 1154
Swap: 4000 3 3997
shows me that I have 2GB (1947m) RAM and that the system has used most of it. However, 312m is used for I/O buffers and the remainder (758m) the system has decided to fill with disk cache.
The disk cache is interesting because it is using fast memory instead of slow disk for its contents. The contents could be gotten from disk, but they are kept around in case they are needed. This also means that there is 758m of memory that can be reclaimed in an instant if necessary because the system knows it can find that data on the disk instead.
That is why there is a second line showing that if there were no buffering and cache, I'd have half my RAM (1154m) available for use.
The third line shows that I have an overly large swap partition (it was there and wasn't doing anything) of which a whopping 3m have been used. This is stuff that the kernel really doesn't expect to have to use anytime soon so it was stuck out on the "back porch".
While free
gives you the snapshot now, vmstat
can give you a running picture:
$ vmstat 10
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 3588 86236 316524 769132 0 0 14 13 126 81 4 1 95 0
0 0 3588 83872 316532 770512 0 0 0 20 264 1229 3 1 96 0
There's a lot of information there, but of interest is that there is no swap-in (si) or swap-out (so) traffic. Which means I'm not using the swap at all over the last 10 seconds.
The free
command can tell you how much swap you are using. For example on this machine:
$ free -m
total used free buffers cached
Mem: 1947 1863 84 312 758
-/+ buffers/cache: 792 1154
Swap: 4000 3 3997
shows me that I have 2GB (1947m) RAM and that the system has used most of it. However, 312m is used for I/O buffers and the remainder (758m) the system has decided to fill with disk cache.
The disk cache is interesting because it is using fast memory instead of slow disk for its contents. The contents could be gotten from disk, but they are kept around in case they are needed. This also means that there is 758m of memory that can be reclaimed in an instant if necessary because the system knows it can find that data on the disk instead.
That is why there is a second line showing that if there were no buffering and cache, I'd have half my RAM (1154m) available for use.
The third line shows that I have an overly large swap partition (it was there and wasn't doing anything) of which a whopping 3m have been used. This is stuff that the kernel really doesn't expect to have to use anytime soon so it was stuck out on the "back porch".
While free
gives you the snapshot now, vmstat
can give you a running picture:
$ vmstat 10
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 3588 86236 316524 769132 0 0 14 13 126 81 4 1 95 0
0 0 3588 83872 316532 770512 0 0 0 20 264 1229 3 1 96 0
There's a lot of information there, but of interest is that there is no swap-in (si) or swap-out (so) traffic. Which means I'm not using the swap at all over the last 10 seconds.
answered Oct 23 '10 at 19:16
msw
4,18611826
4,18611826
add a comment |
add a comment |
- Swap area is the part of Hard Disk space used to support limited
space RAM memory. RAM is limited in size so, some applications need
more RAM than the available RAM space, In that case this Swap Space
also called as Virtual Memory used to support RAM. - It is slower in speed compared to RAM's speed. When we run a large
application then the least recently used part of that application
in swapped to Swap Area on the Hard Drive, it is swapped back from
Swap Area when it is needed. This gives Operating System a feel of
just having more RAM than actually it is. - It is a dedicated partition on Hard Disk created while installing Operating System.
- It is good if create Swap Area of Double the size of RAM.
You can check used and available Swap Area using following command:
$ cat /proc/swaps
Filename Type Size Used Priority
/dev/sda10 partition 7812092 16 -1
add a comment |
- Swap area is the part of Hard Disk space used to support limited
space RAM memory. RAM is limited in size so, some applications need
more RAM than the available RAM space, In that case this Swap Space
also called as Virtual Memory used to support RAM. - It is slower in speed compared to RAM's speed. When we run a large
application then the least recently used part of that application
in swapped to Swap Area on the Hard Drive, it is swapped back from
Swap Area when it is needed. This gives Operating System a feel of
just having more RAM than actually it is. - It is a dedicated partition on Hard Disk created while installing Operating System.
- It is good if create Swap Area of Double the size of RAM.
You can check used and available Swap Area using following command:
$ cat /proc/swaps
Filename Type Size Used Priority
/dev/sda10 partition 7812092 16 -1
add a comment |
- Swap area is the part of Hard Disk space used to support limited
space RAM memory. RAM is limited in size so, some applications need
more RAM than the available RAM space, In that case this Swap Space
also called as Virtual Memory used to support RAM. - It is slower in speed compared to RAM's speed. When we run a large
application then the least recently used part of that application
in swapped to Swap Area on the Hard Drive, it is swapped back from
Swap Area when it is needed. This gives Operating System a feel of
just having more RAM than actually it is. - It is a dedicated partition on Hard Disk created while installing Operating System.
- It is good if create Swap Area of Double the size of RAM.
You can check used and available Swap Area using following command:
$ cat /proc/swaps
Filename Type Size Used Priority
/dev/sda10 partition 7812092 16 -1
- Swap area is the part of Hard Disk space used to support limited
space RAM memory. RAM is limited in size so, some applications need
more RAM than the available RAM space, In that case this Swap Space
also called as Virtual Memory used to support RAM. - It is slower in speed compared to RAM's speed. When we run a large
application then the least recently used part of that application
in swapped to Swap Area on the Hard Drive, it is swapped back from
Swap Area when it is needed. This gives Operating System a feel of
just having more RAM than actually it is. - It is a dedicated partition on Hard Disk created while installing Operating System.
- It is good if create Swap Area of Double the size of RAM.
You can check used and available Swap Area using following command:
$ cat /proc/swaps
Filename Type Size Used Priority
/dev/sda10 partition 7812092 16 -1
answered Nov 10 '17 at 14:19
Vijesh
12
12
add a comment |
add a comment |
I have a laptop with a slow hard drive, but relatively high RAM (8GB). On this setup, I find a swap drive to be counterproductive for the following reasons:
Getting applications back out of swap is slow, comparable to loading the application from scratch. I would rather have an environment that responds quickly, even if that means I sometimes have to close and reload applications, than an environment which sometimes stalls on me unexpectedly.
If I wanted the ability to hibernate, that would mean writing a lot of data to disk. That would be a constant drain on battery if it was done persistently (the default behaviour of swappiness 60), or if it was only done at hibernation time (by reducing swapiness), then it would take a long time to actually hibernate. I found suspending to be RAM instead of suspending to disk to be quite satisfactory. It could stay suspended for a couple of days, and it would unsuspend much more quickly than a full hibernation.
Because the hard drive is slow, I prefer to keep 1GB of RAM reserved for disk cache, effectively exchanging memory for speed. This keeps my machine snappy, but it does mean I can use only 7GB of my 8GB of RAM for applications. The software I use to achieve that is a fork of earlyoom which kills old browser tabs when 88% of the RAM has been used. I occasionally have to reload old browser tabs which have been killed off.
When would this advice not apply?
If you have a fast hard disk drive, or an SSD, and have fewer concerns about battery drain, then the disadvantages I outlined above will not apply. (Although early SSDs might have issues with wear, I believe any SSDs sold since 2018 should be fine.)
If your machine has very little RAM, or you like to use multiple memory-hungry applications at the same time, then you may need to use swap to get your work done, regardless of the disadvantages. This was the primary use-case for swap, before memory started to become cheaper.
If you really need hibernation (perhaps you want to suspend your laptop, and re-open it after a few days without charging) then you need a swap drive (recommended at least as large as your RAM).
Caveat:
- Some of the software that we leave running for a long time (especially the OS and desktop environment) will load code into memory which will never actually be used again. These pages could be moved to swap and will never need to be pulled out again, thus avoiding the disadvantages I mentioned earlier. For this reason, I sometimes create a small 512MB or 1GB swap file, and let the unused pages of memory get swapped out. This just leaves me with a little more RAM for applications. (Needed: A technique for measuring swap churn, to help tune the size of this swap file.)
add a comment |
I have a laptop with a slow hard drive, but relatively high RAM (8GB). On this setup, I find a swap drive to be counterproductive for the following reasons:
Getting applications back out of swap is slow, comparable to loading the application from scratch. I would rather have an environment that responds quickly, even if that means I sometimes have to close and reload applications, than an environment which sometimes stalls on me unexpectedly.
If I wanted the ability to hibernate, that would mean writing a lot of data to disk. That would be a constant drain on battery if it was done persistently (the default behaviour of swappiness 60), or if it was only done at hibernation time (by reducing swapiness), then it would take a long time to actually hibernate. I found suspending to be RAM instead of suspending to disk to be quite satisfactory. It could stay suspended for a couple of days, and it would unsuspend much more quickly than a full hibernation.
Because the hard drive is slow, I prefer to keep 1GB of RAM reserved for disk cache, effectively exchanging memory for speed. This keeps my machine snappy, but it does mean I can use only 7GB of my 8GB of RAM for applications. The software I use to achieve that is a fork of earlyoom which kills old browser tabs when 88% of the RAM has been used. I occasionally have to reload old browser tabs which have been killed off.
When would this advice not apply?
If you have a fast hard disk drive, or an SSD, and have fewer concerns about battery drain, then the disadvantages I outlined above will not apply. (Although early SSDs might have issues with wear, I believe any SSDs sold since 2018 should be fine.)
If your machine has very little RAM, or you like to use multiple memory-hungry applications at the same time, then you may need to use swap to get your work done, regardless of the disadvantages. This was the primary use-case for swap, before memory started to become cheaper.
If you really need hibernation (perhaps you want to suspend your laptop, and re-open it after a few days without charging) then you need a swap drive (recommended at least as large as your RAM).
Caveat:
- Some of the software that we leave running for a long time (especially the OS and desktop environment) will load code into memory which will never actually be used again. These pages could be moved to swap and will never need to be pulled out again, thus avoiding the disadvantages I mentioned earlier. For this reason, I sometimes create a small 512MB or 1GB swap file, and let the unused pages of memory get swapped out. This just leaves me with a little more RAM for applications. (Needed: A technique for measuring swap churn, to help tune the size of this swap file.)
add a comment |
I have a laptop with a slow hard drive, but relatively high RAM (8GB). On this setup, I find a swap drive to be counterproductive for the following reasons:
Getting applications back out of swap is slow, comparable to loading the application from scratch. I would rather have an environment that responds quickly, even if that means I sometimes have to close and reload applications, than an environment which sometimes stalls on me unexpectedly.
If I wanted the ability to hibernate, that would mean writing a lot of data to disk. That would be a constant drain on battery if it was done persistently (the default behaviour of swappiness 60), or if it was only done at hibernation time (by reducing swapiness), then it would take a long time to actually hibernate. I found suspending to be RAM instead of suspending to disk to be quite satisfactory. It could stay suspended for a couple of days, and it would unsuspend much more quickly than a full hibernation.
Because the hard drive is slow, I prefer to keep 1GB of RAM reserved for disk cache, effectively exchanging memory for speed. This keeps my machine snappy, but it does mean I can use only 7GB of my 8GB of RAM for applications. The software I use to achieve that is a fork of earlyoom which kills old browser tabs when 88% of the RAM has been used. I occasionally have to reload old browser tabs which have been killed off.
When would this advice not apply?
If you have a fast hard disk drive, or an SSD, and have fewer concerns about battery drain, then the disadvantages I outlined above will not apply. (Although early SSDs might have issues with wear, I believe any SSDs sold since 2018 should be fine.)
If your machine has very little RAM, or you like to use multiple memory-hungry applications at the same time, then you may need to use swap to get your work done, regardless of the disadvantages. This was the primary use-case for swap, before memory started to become cheaper.
If you really need hibernation (perhaps you want to suspend your laptop, and re-open it after a few days without charging) then you need a swap drive (recommended at least as large as your RAM).
Caveat:
- Some of the software that we leave running for a long time (especially the OS and desktop environment) will load code into memory which will never actually be used again. These pages could be moved to swap and will never need to be pulled out again, thus avoiding the disadvantages I mentioned earlier. For this reason, I sometimes create a small 512MB or 1GB swap file, and let the unused pages of memory get swapped out. This just leaves me with a little more RAM for applications. (Needed: A technique for measuring swap churn, to help tune the size of this swap file.)
I have a laptop with a slow hard drive, but relatively high RAM (8GB). On this setup, I find a swap drive to be counterproductive for the following reasons:
Getting applications back out of swap is slow, comparable to loading the application from scratch. I would rather have an environment that responds quickly, even if that means I sometimes have to close and reload applications, than an environment which sometimes stalls on me unexpectedly.
If I wanted the ability to hibernate, that would mean writing a lot of data to disk. That would be a constant drain on battery if it was done persistently (the default behaviour of swappiness 60), or if it was only done at hibernation time (by reducing swapiness), then it would take a long time to actually hibernate. I found suspending to be RAM instead of suspending to disk to be quite satisfactory. It could stay suspended for a couple of days, and it would unsuspend much more quickly than a full hibernation.
Because the hard drive is slow, I prefer to keep 1GB of RAM reserved for disk cache, effectively exchanging memory for speed. This keeps my machine snappy, but it does mean I can use only 7GB of my 8GB of RAM for applications. The software I use to achieve that is a fork of earlyoom which kills old browser tabs when 88% of the RAM has been used. I occasionally have to reload old browser tabs which have been killed off.
When would this advice not apply?
If you have a fast hard disk drive, or an SSD, and have fewer concerns about battery drain, then the disadvantages I outlined above will not apply. (Although early SSDs might have issues with wear, I believe any SSDs sold since 2018 should be fine.)
If your machine has very little RAM, or you like to use multiple memory-hungry applications at the same time, then you may need to use swap to get your work done, regardless of the disadvantages. This was the primary use-case for swap, before memory started to become cheaper.
If you really need hibernation (perhaps you want to suspend your laptop, and re-open it after a few days without charging) then you need a swap drive (recommended at least as large as your RAM).
Caveat:
- Some of the software that we leave running for a long time (especially the OS and desktop environment) will load code into memory which will never actually be used again. These pages could be moved to swap and will never need to be pulled out again, thus avoiding the disadvantages I mentioned earlier. For this reason, I sometimes create a small 512MB or 1GB swap file, and let the unused pages of memory get swapped out. This just leaves me with a little more RAM for applications. (Needed: A technique for measuring swap churn, to help tune the size of this swap file.)
edited Dec 30 '18 at 14:59
answered Nov 10 '17 at 13:32
joeytwiddle
8891020
8891020
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f9092%2fimportance-of-swap-partition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
By what's been posted it seems I have WAY too much swap. 3GB RAM, 300GB HD, and a 8GB partition for swap.
– lamcro
Oct 24 '10 at 2:29
2
Extra swap that doesn't get used isn't going to hurt you, and reclaiming 1.7% of your drive to make it smaller is probably not worth the effort. Yes, it's far larger than you'll probably ever use, I wouldn't worry about it.
– msw
Oct 24 '10 at 15:02
1
You can also see it as a "future proof" swap partition, if you ever add extra memory to your system, you won't have to enlarge the swap... :)
– JanC
Oct 24 '10 at 15:29