taking a process and all associated threads off the run queue

Ashwin Chandra ashcs at ucla.edu
Mon Mar 7 03:34:37 GMT 2005


Hi all,
I am trying to modify the scheduler to take off some processes (such as those generated by a forkbomb ... malicious) off the run queue. I have been looking into the scheduler and proc.h and see there is one way by putting threads on the 'suspension' queue. I am not sure if this is the same thing. But anyway, I modified sched_cpu in sched_4bsd.c to look something like this:
 

FOREACH_THREAD_IN_PROC(p, td)
                  {
                    if(p->p_km_switch == P_NON_RUN)
                      {
                        if( !TD_IS_SUSPENDED(td)  )
                          {
                            //thread_suspend_one(td);
                            printf("suspending thread associated with %s\n", td->td_ksegrp->kg_proc->p_comm);
                            TD_SET_SUSPENDED(td);
                          }
                      }
                    else if(p->p_km_switch == P_RUN)
                      {
                        if(TD_IS_SUSPENDED(td))
                          {
                            //thread_unsuspend_one(td);
                            printf("clearing suspending thread associated with %s\n", td->td_ksegrp->kg_proc->p_comm);
                            TD_CLR_SUSPENDED(td);
                          }
                      }


                  }



the p_km_switch turns on when a process exceeds a certain threshold of memory usage and context switching. If the threads associated with this process are suspended, and the system becomes less loady, then they are unsuspended (The P_RUN flag is set externally). So I tried this out, and it seems to sort of work although when I print out the p->p_suspcount, it says its 0, so I am not sure if this is even working right.


Im sure you guys know the scheduler much better than I do. What would be the best way to modify the scheduler so that given a certain NON_RUN flag I can pretty much take a process of the run queue and then later put it back on when the system is less loaded?


Thanks a lot,
Ash


More information about the freebsd-hackers mailing list