Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


OpenVZ VPS using SWAP when RAM is available
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

OpenVZ VPS using SWAP when RAM is available

RuchirablogRuchirablog Member
edited November 2013 in General

Hi Guys,
I have a 256MB OpenVZ SSD VPS from RN and I'm running a LAMP+64MB Memcached instance +Wordpress setup on it. Site gets about 2500+ visits and 5000+ page views a day and VPS handles it like breeze.

What I'm concerned about is that it uses SWAP when plenty of RAM is available for use.

root@XXXXX:~# free -m
             total       used       free     shared    buffers     cached
Mem:           256        181         74          0          0         96
-/+ buffers/cache:         84        171
Swap:          256         85        170
root@XXXXX:~# uname -a
Linux XXXXX 2.6.32-042stab078.28 #1 SMP Mon Jul 8 10:17:22 MSK 2013 i686 GNU/Linux
top - 04:25:30 up 42 days, 16:19,  1 user,  load average: 0.00, 0.00, 0.00
Tasks:  20 total,   1 running,  19 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:    262144 total,   172368 used,    89776 free,        0 buffers
KiB Swap:   262144 total,    87480 used,   174664 free,    91828 cached

However I didn't noticed any slow downs or anything like that. Support told me this is fine unless its taking a hit on performance! But I haven't seen this behavior on my BuyVM or Fliphost OpenVZ VPS's. I don't have much experience in OpenVZ because I was using XEN for past 3,4 years.

Do you guys have any clue about this? I'm thinking about moving the site to a KVM VPS just because this is bugging me :P

Comments

  • TheLinuxBugTheLinuxBug Member
    edited November 2013

    You need to modify the Swappiness of your swap. Follow that article and set swpiness to 10. Then only when the server really must use swap will it swap. In a lot of cases if you don't change this it will swap to keep some memory free for if one of your services need it (cut down on things that are cached that you haven't used for a while).

    Hope this helps.

    Cheers!

    Thanked by 1Ruchirablog
  • @TheLinuxBug said:
    You need to modify the [Swappiness]

    Yeah but this is an OpenVZ VPS. thanks for the suggestion though :)

  • MaouniqueMaounique Host Rep, Veteran

    It is normal, many apps need to use swap for internal accounting things even if there is enough memory, same on real machines, this is why some apps especially java were so unhappy on old kernel without swap (burst ovz).
    I think you should not worry, the access to swap is low.

    Thanked by 1Ruchirablog
  • @Maounique said:
    It is normal, many apps need to use swap for internal accounting things

    Yikes. I don't know even where to start.. Speechless

  • The 'internal accounting' bit might be awkward phrasing but it's close enough to describe it in a simplified form. Another take is that some applications will preallocate more memory than they actually need. Any pages in that address space they don't actively use will likely get swapped out according to the swappiness. So as long as the program isn't actively using those pages, then the OS pushing it out to make room for file caching is fine.

    Java was not happy on the old burst kernels because they couldn't distinguish where the burst memory cutoff was. This caused the JVM heap to span into unguaranteed memory making it extremely subject to OOM kills from the host node. You could tell it explicitly where that boundary was though. Since the JVM heap is continually used on a rolling basis, it isn't as impacted as most things by the swappiness so there's no need to mention it here.

  • nonubynonuby Member
    edited November 2013

    @tchen said:
    The 'internal accounting' bit might be awkward phrasing but it's close enough to describe it in a simplified form.

    No. Simply no. Just no. It's not 'close enough' it is retarded! You are about as close as black is white.

    If I facepalm this anymore ...

    Just read any book. Linux Kernel Development, No Starch Linux, Professional Linux Architecture.. Take your pick..

    Would really like to be polite, but it's not even close.. not even near. And the sad thing is this isn't qualified with a suitable disclaimer

    We're all learning until we die but ffs don't. just don't

  • @nonuby So.... instead of telling people to become experts in OS virtual memory design, I invite you to phrase it in your own words something that is both accurate and easy to understand.

  • nonubynonuby Member
    edited November 2013

    @tchen, Im suggesting to read the details before [b]you[/b] volunteer or defend information that is just wrong, these vetted authors explain stuff much better than I could can do. Suggesting apps opt in to to put "internal accounting" information into swap, wow, i honestly require baseline before a discussion incurs. I played with trying to fit your idea against madvise, but still.. sorry.. its so wrong.. bring it up a bit and let a discussion begin .

    Im not suggesting people become experts in virtual memory design (but its not hard to grasp in 2.4 or 2.6 based kernel), but why defend something you clearly dont understand?

  • MaouniqueMaounique Host Rep, Veteran

    Everyone knows a book explains it better, but you already put up half a page without giving any useful info, so, until you can explain it better in at least the space you wasted for nothing, shut up.
    Besides, who are you, for real ?

  • said: What I'm concerned about is that it uses SWAP when plenty of RAM is available for use.

    There's one or two reasons for this:

    1. You're using a lot more memory at times than you realize. Do you have a nightly backup job? Rsync, for example, can suck memory and cause other processes to hit swap. Or you're getting a spike in web traffic, and you've over-allocated related processes (httpd, php, mysql).

    2. The host node is quite "full" -- putting it politely :) Let's face it, all budget OVZ providers oversell RAM. Everything else being equal, you'll see a lot more vSwap usage on a full node than a near-empty one.

    Thanked by 1Ruchirablog
  • @nonuby said:
    tchen, Im suggesting to read the details before [b]you[/b] volunteer or defend information that is just wrong... i honestly require baseline before a discussion incurs. I played with trying to fit your idea against madvise, but still.. sorry.. its so wrong.. bring it up a bit and let a discussion begin .

    Im not suggesting people become experts in virtual memory design (but its not hard to grasp in 2.4 or 2.6 based kernel), but why defend something you clearly dont understand?

    Here's your baseline .... from Chapter 11, Swap Manager in Understanding the Linux Virtual Memory Manager by Mel Gorman (right at the top so you can't possibly miss it)

    There are two principle reasons that the existence of swap space is desirable. First, it expands the amount of memory a process may use. Virtual memory and swap space allows a large process to run even if the process is only partially resident. As “old” pages may be swapped out, the amount of memory addressed may easily exceed RAM as demand paging will ensure the pages are reloaded if necessary.

    The casual reader may think that with a sufficient amount of memory, swap is unnecessary but this brings us to the second reason. A significant number of the pages referenced by a process early in its life may only be used for initialisation and then never used again. It is better to swap out those pages and create more disk buffers than leave them resident and unused.

    You're placing too much emphasis on accounting and perhaps transcribing it too much towards user beancounter accounting, maybe? I dunno. No one here has any idea why you're so angry since you don't say.

    From a layman's perspective, malloc is a form of accounting. While the programs themselves don't directly control the VMM's decision to page in and out ram, a lot of them do preallocate large sections of address space for their own internal heap management. That will trigger this behavior we're talking about as most of it tends to be dormant.

    It's fine if you think @Maounique should have used different terms or perhaps left out some important details. But starting an argument without any substantive backing other than some lame appeal to authority is the wrong way to make people think you know stuff. And as I type this, I don't think you do.

    Thanked by 2Maounique Darwin
  • MaouniqueMaounique Host Rep, Veteran
    edited November 2013

    Thanks !

    Unfortunately, in a forum and as a non-native speaker is difficult to go in much detail, I try to explain as short and as clear for a non-professional as possible.
    Sometimes I sacrifice clarity for the sake of space.
    Many people argued that I write too much in my posts just because i wish to make things clear, but any added clarity as well as the original contribution is irrelevant if the people interested skip it because it is TL;DR.
    In this case my main point was for the OP. I wanted to explain that:
    1. Swap usage is normal even if there is enough memory for the program to fit;
    2. It is best to leave it this way, the kernel usually knows best what to move to swap (in this case vswap even).
    I agree it was not perfect, but if we try to give perfect explanations we must re-write the books, however OP understood the point and this was the purpose of my reply.

    What was yours @nonuby, how did you contribute to the conversation, other than wasting your and our time ? Are you trying to pay some debt against me ? Because I am pretty sure I know who you are.

  • I dont have much idea about the vswap but , i prefer that the vswap should not be more. I think that the lesser the vswap the more dedicated resources will be available to your vps. i might be wrong :) (openvz)

    Thanked by 1Ruchirablog
  • When hosting java webapps, I notice swap is used a little bit too when I have still much memory

    Thanked by 1Ruchirablog
  • tchentchen Member
    edited November 2013

    @jcaleb said:
    When hosting java webapps, I notice swap is used a little bit too when I have still much memory

    It's probably nothing to worry about unless you're getting swap io in vmstat. I said the JVM allocation is rolling which oversimplifies it. It's actually broken up into different partitions. There's a PermGen which stores class meta data and strings which tends to be cluttered esp if you have dynamic compilation or class loaders that don't clean up after themselves. Orphaned classes and strings can get shoved into swap without issue.

    Web apps also don't tend to hold on to objects for very long and so they live primarily in the young generation space. This too is split up into more fine grained partitions. Then there's the really old tenured generation (2/3 of the total heap). Because of this setup, you do have a lot of unused allocated memory in certain scenarios like web. More stateful programs will occupy a flatter distribution across the generations.

    So, swap does have an effect if your application suddenly decides to behave differently. Or the edge case where you have waaaaay too much memory allocated to the JVM and it takes too long to hit a minor GC. I don't think you're in either camp so it's ok.

    Thanked by 1jcaleb
Sign In or Register to comment.