Slash OpenVZ Memory Usage by Shrinking Thread Stack

Tuesday, March 23, 2010

I recently bought a small virtual server (OpenVZ, 128mb memory, 256mb burstable) for web hosting. I knew that it would be a challenge to work with limited memory, especially since OpenVZ doesn’t swap like Xen. For starters, I went with a 32-bit minimal Debian setup, because 64-bit pointers use twice as much memory as 32-bit pointers. Apache was also out of the picture, but Lighttpd easily filled the role. MySQL was also heavily tweaked to limit resource usage. All in all, I had a happy little system that used 60mb-100mb of memory.

This morning, I discovered that there is more memory to be saved… in the form of the thread stack. See, each thread that is spawned is given a chunk of memory to use as stack. On my laptop, the default stack size is 8mb. On my VPS, it’s 10mb. Now, I believe a well-designed program should come nowhere near using 8mb of stack, let alone 10mb. So I used the nifty ulimit bash command to set the default stack size to 256kb instead. To make the setting global, I added the following line to the top of my /etc/init.d/rc file, so the limit is set early during the boot process:

ulimit -s 256

After a reboot, I found that not only did memory usage drop down to 30mb-60mb, the system remained fully functional. 256kb of stack should be plenty for most threads, but certain apps could make do with even less. For example, Debian Lenny runs rsyslogd by default, which is a pretty beefy process that could make do with just 128kb of stack.

While 256kb should be a safe option for most systems, I was able to go down to 128kb without losing functionality, but also without reclaiming much memory; thus, I went back up to 256kb. Would the system refuse to boot if the stack size were set too low? I’ll leave this experiment to the more adventurous souls out there…

In case you successfully perform this tweak, don’t just let the extra memory sit there; after all, free memory is wasted memory. In my case, I was able to run a couple more PHP FastCGI processes to improve concurrency.

5 Comments

  1. MK says:

    Thanks much dude, I just ran into this “allocated” measurement issue in OpenVZ and assumed I could use not ulimit, but thanks to you I will give it a try :)

  2. BawlAmili says:

    Дисконт от 5% до 40% для TopSwissWatch на наручные мужские реплики часов: 3672209 http://cl0ckst0ck.ru/promocode/c10_3672209.jpg

  3. inazolfeflano says:

    Продаю акки Outlook.com Plus

    Продаю автореганные аккаунты Outlook.com Plus в одни руки

    По всем вопросам пишите сразу в аську ICQ 231538

    купить аккаунты вконтакте онлайн , сервис продаж аккаунтов вконтакте , blogspot купить аккаунты , продажа аккаунтов вконтакте , продажа аккаунтов wordpress , аккаунты одноклассников , mamba распрадажа , онлайн магазин аккаунтов соц сетей , купить аккаунты mail.ru , продажа аккаунтов gmail , куплю аккаунты вконтакте , фейсбук продажа аккаунтов , продаю loveplanet аккаунт , купить аккаунт яндекс , продам аккаунты одноклассники , продажа акков вк , купить аккаунты вконтакте , магазин онлайн покупки аккаунто , редиректы pochta.ru , купить аккаунты вконтакте , авторег в майле , gjregrf frrfeynjd d facebook , купить аккаунты вконтакте , продам аккаунты мамба з , купить аккаунты вк онлайн , аккаунты вконтакте , купить аккаунты вконтакте , акаунты на мамбе , twitter продажа аккаунтов , онлайн магазин аккаунтов вконтакте , купить аккаунты вконтакте 2012 , куплю аккаунты вконтакте , продажа аккаунтов mail.ru , реальный аккаунт в мамбе получить бесплатно , продажа аккаунтов gmail , магазин аккаунтов вконтакте , купить аккаунты вконтакте , продам аккаунты мамба з , gjregrf frrfeynjd d facebook , аккаунт вконтакте купить 200 друзей , продам аккаунты одноклассники , купить аккаунты вконтакте онлайн , продажа аккаунтов mail.ru , магазин аккаунтов facebook , купить жж аккаунт , купить аккаунты вконтакте , купить аккаунты qip.ru , купить аккаунты в контакте , магазин аккаунтов , купить аккаунты aol.com , аккаунты от mamba , купить facebook pva , покупка аккаунтов в контакте , купить аккаунты для вконтакте , продажа аккаунтов одноклассники , аккаунты gmail купить

  4. DuhDaubyUnula says:

    The Lexington VA Medical Center consists of six centers located in Kentucky, West Virginia and Tennessee which are a part of the VA MidSouth Healthcare Network. Outpatient clinics are situated in the communities of Morehead, Somerset, Hazard and Berea Kentucky to meet the needs of those veterans living outside the Lexington area. Other outpatient clinics within the MidSouth Network are located in Virginia, Arkansas, Indiana, and Mississippi.

    Student visa are normally granted for an initial period of one year but they can also take into consideration the length of the course you intend to study on. You really need to ensure your visa covers the whole of your study period as it is quite common for student visas to expire during your stay which can cause lots of problems. However the UK has a good visa service that ensures any renewal happens in the fastest possible time so it has minimum effect on the student. Regardless of this fact it really is important to find out in advance how long the course is and tell the immigration officials so your visa can last the entire time.

    Another disadvantage of health insurance is that it will not cover any conditions you have suffered in the last 5 years (pre-existing conditions) in the first two years of the policy. However, with a moratorium policy the condition may be covered if you go two years advice, treatment and symptom free for that condition. There are also ‘fixed’ moratorium policies, which promise to cover agreed pre-existing conditions after two years on the policy, regardless of whether they reoccur in that time. If you compare health insurance quotes online make sure you understand which type of underwriting will suit you.

    Nonetheless, there is much to learn from the single-payer method of health care. This article will explore the British health care system – another single-payer plan – and its relative successes, failures, and efforts at policy reform.

    good information

    To be honest, everyone, I’m as sick of the healthcare debate as anyone, so I wasn’t planning to write this series. However, instead of focusing on trying to find healthcare reform that would actually work, the debate for the most part has been centered on the myths of universal healthcare. President Obama was so concerned about “disinformation” that he appointed a Disinformation Czar, even though most of the disinformation has been spread by the White House. In an attempt to combat that disinformation, here is part two of my series on the myths of universal healthcare.

    There will always be some unqualified people who try to get by, but a recruitment agency is much better able to weed these people out than most employers are. That ensures that there is a better chance of getting good people the first time, instead of having to go through interviews and more interviews. Recruitment agencies are especially good for healthcare workers because they often administer specific tests that showcase whether these people have the right skills for the healthcare business where they will be working. If they cannot do what they say they can do, they will be weeded out and not interviewed by the company.

    As the occupational field of healthcare continues to evolve throughout Kentucky, the number of employment opportunities expand as well. Healthcare Information Technology (IT) is a field that is gaining attention for its innovative means to produce new technology and infrastructure. As patient and health databases continue to grow larger, the roles to manage the IT will expand and grow as well.

Leave a Reply

Pingbacks & Trackbacks

  1. Shrinking thread | Mygeneticherit - Pingback on 2012/03/03