From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 7 03:34:37 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 863FB16A4CE for ; Mon, 7 Mar 2005 03:34:37 +0000 (GMT) Received: from smtp.ucla.edu (smtp.ucla.edu [169.232.46.136]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3560B43D1D for ; Mon, 7 Mar 2005 03:34:37 +0000 (GMT) (envelope-from ashcs@ucla.edu) Received: from mail.ucla.edu (mail.ucla.edu [169.232.46.135]) by smtp.ucla.edu (8.13.2/8.13.2) with ESMTP id j273Yau6003708 for ; Sun, 6 Mar 2005 19:34:36 -0800 Received: from ash (s226-171.resnet.ucla.edu [164.67.226.171]) (authenticated bits=0) by mail.ucla.edu (8.13.3/8.13.3) with ESMTP id j273Ya71026187 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT) for ; Sun, 6 Mar 2005 19:34:36 -0800 Message-ID: <000801c522c6$ad04a940$abe243a4@ash> From: "Ashwin Chandra" To: Date: Sun, 6 Mar 2005 19:35:14 -0800 MIME-Version: 1.0 X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Probable-Spam: no X-Spam-Hits: 0.152 X-Scanned-By: smtp.ucla.edu on 169.232.46.136 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.1 Subject: taking a process and all associated threads off the run queue X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Mar 2005 03:34:37 -0000 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: =20 FOREACH_THREAD_IN_PROC(p, td) { if(p->p_km_switch =3D=3D 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 =3D=3D 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