Linux VPS Server process kswapd0 and events/0 consume a lot of CPU problems _linux

Source: Internet
Author: User
Tags memory usage cpu usage vps vps server

This afternoon, the site two times the machine, the dispatch to Aliyun, found that the reason is the server's CPU 100%.

After restarting the server, use the top command to see which processes are consuming so much CPU usage. Stare at a good more than 10 minutes, the main CPU-consuming process has two, one is MySQL, the other is Apache. As you can see from the figure below, MySQL takes up a lot of CPU usage. Apache single Process Although not much, but there are a number of Apache processes at the same time, but also consumes a lot of CPU use.

Of course, these are not enough to get the server's CPU straight up and down, and then find two big guys:

As MySQL's CPU consumption drops, there are two strange processes: Kswapd0 and events/0.

1. kswapd0

Linux uses KSWAPD for virtual memory management such, pages that have been the recently accessed are kept in memory and Le SS Active pages are paged out to disk.

(What is a page?) ... Linux uses manages memory in units called pages.

So,the KSWAPD process regularly decreases the ages of unreferenced pages...and at the end they are paged out (moved out) to D Isk

The role of the KSWAPD0 process: It is virtual memory management, is responsible for page change, the operating system every time will wake up KSWAPD to see if the memory is tight, if not nervous, then sleep, in the KSWAPD, there are 2 thresholds, pages_hige and Pages_low, When the number of free memory pages is lower than Pages_low, the KSWAPD process scans the memory and releases 32 free pages at a time until the number of the page is Pages_high.

Look at memory usage and find that the memory is really not working, and sometimes you've used swap.

2. events/0

Another process events/0 is a worker thread, primarily used to perform delay work. Let's start with a brief introduction.

We all know that the bottom half of the interrupt mechanism is three kinds: soft interrupt, Tasklet and work queue. Soft interrupts are rarely used, and only the network is used in the kernel, and the delay is minimal.

Tasklet is an application of soft interrupts, and all thread-registered Tasklet are executed sequentially. So Tasklet's execution environment is a soft interrupt context, so you can't block or sleep. In general, the Tasklet delay is also small enough to meet most of the requirements.

If you can sleep in the bottom half, you have to use a work queue. The work queue is actually called by a specialized thread that gives the kernel a function of the bottom half to be done. This way the work queue is running in the thread environment, not afraid of sleep. Of course, sleep affects the execution of other bottom halves registered to the same thread, but does not cause large problems. Each CPU has a thread (Events/n,n is numbered) responsible for executing the work queue, the first CPU thread is events/0, if it is dual-core, there will be a EVENTS/1 thread. The program uses a work queue, so each execution will have an extra events/0 (worker thread on the first CPU).

Kernel soft interrupt Auxiliary processing thread ksoftirqd/n (n is CPU number), they are responsible for starting soft interrupts triggered by soft interrupts. They will trigger the soft interrupts to be invoked when the system is idle, not immediately. This allows user space to not be hungry, and the soft interrupts that are triggered can be implemented as quickly as possible. ("Linux kernel design and implementation" 85 pages)

The reason for downtime is obvious, physical mem is insufficient, causing frequent swap. In fact, this is also a common VPS use of a problem, usually by the Apache occupy too much memory caused. KSWAPD0 is the system's virtual memory management program, if the physical memory is not enough, the system will wake up the kswapd0 process, by the KSWAPD0 allocated disk swap space for caching, thus occupying a large amount of CPU resources. Restart Apache, freeing up memory, and the problem disappears. But this is not a long-term solution, the best way is to spend some money to upgrade the memory. I also know that with the constant increase in the number of visits, certainly to upgrade the memory, but did not think the problem came so soon ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.