Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Square Root of RAM for swap space formula

  1. #1
    Join Date
    Jan 2016
    Beans
    0

    Square Root of RAM for swap space formula

    I'm starting vague plans on how my next Linux installation could/should be, which includes working out what size of RUNTIME memory swap partition I should have, which may be encrypted. (To allow suspend to disk, I'm thinking of having a separate unencrypted swap partition).

    To this end, https://help.ubuntu.com/community/SwapFaq looks very useful. However, I have one main question regarding it (to stay on topic).

    The FAQ mentions having round(sqrt(RAM)) for the minimum swap space. How was this formula derived? How did it come into being?

    Just curious to find out the different methods for working out swap partition space.

  2. #2
    Join Date
    Jun 2010
    Location
    London, England
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Square Root of RAM for swap space formula

    Hibernation (suspend-to-disk) The hibernation feature (suspend-to-disk) writes out the contents of RAM to the swap partition before turning off the machine. Therefore, your swap partition should be at least as big as your RAM size. The hibernation implementation currently used in Ubuntu, swsusp, needs a swap or suspend partition. It cannot use a swap file on an active file system.
    No formula. Just sense & experience. With Hibernation we need a swap partition large enough to hold the maximum amount of data that could possibly be held in RAM.

    Depending on the user's work practices, machines with several GB of RAM may rarely use swap. If hibernation was never going to be attempted then a swap partition less than the amount of RAM would be acceptable.

    Opinions about the size of swap have altered since the days when machines came with less than 1 GB RAM. In those days swap was very likely necessary and 2 x RAM was often suggested. Times changes and views change.
    For less then 1GB of physical memory (RAM), it's highly recommended that the swap space should, as a base minimum, be equal to the amount of RAM. Also, it's recommended that the swap space is maximum twice the amount of RAM depending upon the amount of hard disk space available for the system because of diminishing returns.


    For more modern systems (>1GB), your swap space should be at a minimum minimum be equal to your physical memory (RAM) size "if you use hibernation", otherwise you need a minimum of round(sqrt(RAM)) and a maximum of twice the amount of RAM. The only downside to having more swap space than you will actually use, is the disk space you will be reserving for it.


    The "diminishing returns" means that if you need more swap space than twice your RAM size, you'd better add more RAM as Hard Disk Drive (HDD) access is about 10³ slower then RAM access, so something that would take 1 second, suddenly takes more then 15 minutes! And still more then a minute on a fast Solid State Drive (SSD)...
    round(sqrt(RAM))?

    No idea what that means. Bad spelling? Bad grammar? But if you like being baffled by science ...

    https://www.reddit.com/comments/2v8dty

    Regards.
    It is a machine. It is more stupid than we are. It will not stop us from doing stupid things.
    Ubuntu user #33,200. Linux user #530,530


  3. #3
    Join Date
    Sep 2011
    Beans
    615

    Re: Square Root of RAM for swap space formula

    It seems pretty clear what it MEANS and of course it is a formula or at least implies one. But why someone chose to express themselves so bizarrely instead of using English I can't imagine. I think it would be a legitimate expression in some languages but my bash can't make anything of it. C, maybe.

    And as to the logic of recommending the square root of the amount of RAM as the minimum amount of swap, that is even harder to fathom. Doing so and offering no explanation is . . . twisted.

    If there really is sense to this, I'd love to see an explanation. Could this be someone's idea of a clever prank?

  4. #4
    Join Date
    May 2010
    Location
    uk
    Beans
    9,299
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Square Root of RAM for swap space formula

    round(sqrt(RAM))?

    No idea what that means. Bad spelling? Bad grammar?
    It means take the square root of the amount of ram you have installed and then round it (i suspect round up in this case) to the nearest whole number.

    6B ram
    sqrt(6) = ~2.45
    round up = 3G swap.

    Really though, swap space required depends on you usage.

    You can create swap files on the fly and to this end the package swapspace may be useful for some. There was/is debate on the Ubuntu mailing list as to whether if it should be added by default in 16.04.

    There's also the zram-config package; compressed swap in memory.

    I hibernate this laptop so my amount of swap is the amount of RAM i have +1 G => 5G swap partition.

    Drive's are cheap and so file or partition swap space size doesn't bother me.

    But if you like being baffled by science ...

    https://www.reddit.com/comments/2v8dty
    Thanks for posting this.
    Last edited by matt_symes; January 28th, 2016 at 07:20 PM.
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

    Thinking about becoming an Ubuntu Member?

  5. #5
    Join Date
    Sep 2011
    Beans
    615

    Re: Square Root of RAM for swap space formula

    Right. The meaning is obvious. But none of this addresses OP's question, which I think is a darned good one:
    Quote Originally Posted by varenorn View Post
    How was this formula derived? How did it come into being?
    Unless it's somebody's idea of a joke, there must be some logic behind it, and like OP, I'd really like to know what it is, especially since it is so at variance with everything I've read on the subject, and seemingly totally contrary to common sense.

  6. #6
    Join Date
    May 2010
    Location
    uk
    Beans
    9,299
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Square Root of RAM for swap space formula

    Quote Originally Posted by Dreamer Fithp Apprentice View Post
    Right. The meaning is obvious.
    Do you really think that round(sqrt(RAM)) is obvious to everybody who frequents this forum, everybody that might stumble across this forum or that page from a web search or everybody on the planet ?

    The point being that because it obvious to you, that does not mean it's obvious to others.

    But none of this addresses OP's question, which I think is a darned good one:

    Unless it's somebody's idea of a joke, there must be some logic behind it, and like OP, I'd really like to know what it is, especially since it is so at variance with everything I've read on the subject, and seemingly totally contrary to common sense.
    The post has been answered.

    Really though, swap space required depends on you usage.
    On a high end desktop, where hibernation is not required and swapping is never expected to happen then the swap space required is expected to be zero.

    On a system where it is expected to hibernate then the swap size has to be at least the size of RAM plus some headroom to account for the worst hibernation case.

    Anywhere in between it's a heuristic, a rule of thumb and really does depend on how the system is expected to be used.

    That formula gives an arbitrary lower limit. One that is not set in stone, but a sensible value for a given amount of total system memory.

    Why was that specific formula suggested by the author of that section of the documentation page ? I've no idea. It gives a sensible lower limit but is not to be preferred over any other formula that also gives a sensible lower limit and it's designed for users that may be less experienced in running Linux. The rest of us have a pretty good idea what our swap usage is going to be and that, my friend, comes with experience.
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

    Thinking about becoming an Ubuntu Member?

  7. #7
    Join Date
    Sep 2007
    Location
    In here watching you!
    Beans
    Hidden!

    Re: Square Root of RAM for swap space formula

    =round(sqrt(RAM)) is an equation used in spreadsheets; such as, LibreOffice Calc. Substitute the amount of ram in GB units for "RAM". I have no idea where they came up with that equation though.

    @matt_symes, re #4 above, the round function in spreadsheets don't round up to 3 as in you example. It would round down to 2 which is the closest integer. There are roundup and rounddown spreadsheet functions to force it to round up or down.
    Last edited by Old_Grey_Wolf; January 29th, 2016 at 12:12 AM.
    Use whatever OS or desktop works for you. Dual boot or use VMs if you want. Backup your computer regularly, and definitely before upgrading, partitioning, or installing an OS.

    No support requests by PM please.

  8. #8
    Join Date
    May 2010
    Location
    uk
    Beans
    9,299
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Square Root of RAM for swap space formula

    Quote Originally Posted by Old_Grey_Wolf View Post
    =round(sqrt(RAM)) is an equation used in spreadsheets; such as, LibreOffice Calc. Substitute the amount of ram in GB units for "RAM". I have no idea where they came up with that equation though.
    Interesting. I didn't know that.

    @matt_symes, re #4 above, the round function in spreadsheets don't round up to 3 as in you example. It would round down to 2 which is the closest integer. There are roundup and rounddown spreadsheet functions to force it to round up or down.
    That's the same as most round functions. I mentioned rounding up only because it's erring on the side of caution when it comes to swap, but rounding down is just as valid as it's a heuristic.

    I'm glad you posted this

    Maybe you have solved the origin of that equation and if you have, 'hat tip'.
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

    Thinking about becoming an Ubuntu Member?

  9. #9
    Join Date
    Sep 2008
    Beans
    Hidden!

    Re: Square Root of RAM for swap space formula

    The formula I've had success with is 2XRAM up to a 4G swap. I have an 8G machine with a 4G swap and have never had a problem. The odds of the average user loading up their RAM above 4G is slim at best. Too large a swap file and performance begins to degrade as the system attempts to manage it, so I've read anyway.

  10. #10
    Join Date
    Sep 2011
    Beans
    615

    Re: Square Root of RAM for swap space formula

    @ matt_symes:

    I meant no disrespect to Grahammechanical and intended no offense to him. He is a level headed chap and I doubt if he took any.

    Quote Originally Posted by matt_symes View Post
    Do you really think that round(sqrt(RAM)) is obvious to everybody who frequents this forum
    No, but it seems clear that it was obvious to OP. He implicitly assumed the meaning was obvious. He did NOT ask what it meant. It seems clear that he knew what it meant. He even made that clear in the title of the thread. This is not a wiki. There are an immense number of threads on here that are not immediately clear to any random passerby. Finagle knows, there are plenty that are not clear to me. In responding to a query in a FORUM, I generally assume the main point is to try to respond to the individual poster which means to address what they are asking rather than re-explaining the question, when the question is clear enough that anyone able to answer it will understand it.

    If his question is clear to me, it is certainly clear enough to anybody who has a ghost of a chance of answering it, which, I reiterate, none of us have done.

    Quote Originally Posted by matt_symes View Post
    The post has been answered.
    You are apparently offended by my statement
    Quote Originally Posted by Dreamer Fithp Apprentice View Post
    But none of this addresses OP's question, which I think is a darned good one
    I regret if you're offended but I do not apologize for a simple statement that is clearly true. The POST has been RESPONDED to, but the QUESTION has NOT been ANSWERED. I re-read it again, very carefully. The ONLY questions were:
    Quote Originally Posted by varenorn View Post
    How was this formula derived? How did it come into being?
    These are the same question, posed twice with different wording to make it as clear as possible. OP is a commendably clear writer. He even prefaces the question with this declarative sentence:
    Quote Originally Posted by varenorn View Post
    However, I have one main question regarding it (to stay on topic).
    He could not possibly have been clearer. Those are the only sentences with question marks and he explicitly labels them as his "one main question".

    Well, there is much in your post of interest & OP posted in a chat sub-forum, so if he gets discursive commentary, that is to be expected. And I need to learn to watch the right column in the "unanswered posts" list and avoid responding to the ones in "chat" sub-fora. But even so, I won't be taken to task for a simple true statement without responding. Well, at least once. I won't be baited into a flame war.

    I stand by what I wrote. OP's question is very precise, explicit, and clear. And still unanswered. He isn't asking for advice on partitioning. There is a great deal of material here answering questions he did NOT ask, which is fine, since this is a chat sub-forum. But none of that invalidates the statement that the actual question has not been answered. It STILL hasn't been answered. I don't know the answer. I'd like to. Not because I'm looking for advice on partitioning any more than OP was, but for the same reason OP explicitly stated he was asking. I'm "just curious" about the basis of a very precise "official" statement that has no . . ., ahem, OBVIOUS explanation.
    Last edited by howefield; January 31st, 2016 at 01:38 AM. Reason: removed gratuitous insult.

Page 1 of 3 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •