Scheduling and switching of Linux process management

Source: Internet
Author: User

Process scheduling and switching directly affect the execution efficiency of the process subsystem. Linux rejects the process switching method provided by the i386 hardware. Manually save the process context. On the scheduling strategy, Recent versions have changed a lot. In particular, the 2.6.23 version is far from the previously released 2.6.0. In scheduling. We use 2.6.9 as a benchmark for analysis.

One: Process switching

The process switching process is implemented in Context_switch (). From its code:

 static inline void Context_switch (struct rq *rq, struct task_struct *prev, struct task_struct *next) {Stru
   CT mm_struct *mm, *OLDMM;
   Prepare_task_switch (RQ, Prev, next);
   MM = next->mm;
   OLDMM = prev->active_mm; * * For Paravirt, this is coupled with a exit in switch_to to * combine the page table reload and the switch Backe
   nd into * one hypercall.
   * * Arch_enter_lazy_cpu_mode ();
     Task->mm is empty. is a kernel thread if (unlikely (!mm)) {//kernel thread shares the last running process of mm NEXT->ACTIVE_MM = OLDMM;
     Add Reference Count Atomic_inc (&oldmm->mm_count);
   Enter_lazy_tlb (OLDMM, next);
   else//If it is a user process, switch the running space switch_mm (OLDMM, MM, next);
     If the previous run process is kernel thread if (unlikely (!prev->mm)) {//Assignment active_mm is empty.
     prev->active_mm = NULL;
   Update the PREV_MM member of the run queue rq->prev_mm = OLDMM; } * * * Since the Runqueue lock'll be released by the next * task (which is a invalid locking op but in the-CAs E * of the scheduLer It's a obvious special-case), so we * do a early LOCKDEP release: * * #ifndef __ARCH_WANT_UNLOCKED_CTXSW
Spin_release (&rq->lock.dep_map, 1, _THIS_IP_); #endif/* We just switch the register state and the stack.
   *///switch Process Execution Environment switch_to (prev, Next, prev);
   Barrier ();  * * THIS_RQ must is evaluated again because Prev may have moved * CPUs since it called schedule (), thus the ' RQ '
   Its stack * frame would be invalid.
*///process switch after processing work finish_task_switch (THIS_RQ (), prev); }

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.