From owner-freebsd-arch Sat Jan 5 20:40:12 2002 Delivered-To: freebsd-arch@freebsd.org Received: from rwcrmhc51.attbi.com (rwcrmhc51.attbi.com [204.127.198.38]) by hub.freebsd.org (Postfix) with ESMTP id 9738237B419 for ; Sat, 5 Jan 2002 20:40:08 -0800 (PST) Received: from InterJet.elischer.org ([12.232.206.8]) by rwcrmhc51.attbi.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20020106044008.KTH288.rwcrmhc51.attbi.com@InterJet.elischer.org>; Sun, 6 Jan 2002 04:40:08 +0000 Received: from localhost (localhost.elischer.org [127.0.0.1]) by InterJet.elischer.org (8.9.1a/8.9.1) with ESMTP id UAA35866; Sat, 5 Jan 2002 20:30:21 -0800 (PST) Date: Sat, 5 Jan 2002 20:30:20 -0800 (PST) From: Julian Elischer To: Terry Lambert Cc: Alfred Perlstein , arch@freebsd.org Subject: Re: freeing thread structures. In-Reply-To: <3C376690.6B14328@mindspring.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG You are "partially" confused. On Sat, 5 Jan 2002, Terry Lambert wrote: > Julian Elischer wrote: > > Yes but there must be a good synchronous way of doing this.. > > An async method will always lead to a lag in teh number of threads > > actually available, as it will.... hmmmm > > > > I was going to say that the availability of threads will be > > limited because there will e actually free threads that have not yet been > > properly freed, by which I mean that they have not had their ucred's > > crfree()'d yet etc. However it just occurs to me that > > maybe if we ran short of threads, we are probably in a situation to > > free them and make them available to ourselves.. > > Uh, if the problem is creds, under what circumstances in POSIX > is it permissable to have multiple threads in a process with > different credentials? we don't do this.. see later. > > In other words, aren't you asking the wrong question here? I > think the question is not "how can I free creds in thread_exit?", > it's "why am I storing creds per thread in the first place?". see later > > > The ready-to-free thread structureas don't have anything except for > > the ucred in them that really requires freeing before they are put into > > the thread cache. so it's not a lot of waste to let them gather up a > > bit... (They'd just be in the cache anyhow, unless it was full > > in which case the stackpages would be dissociated and freed) > > Yes, exactly. And referencing the cred via the thread doesn't > make sense anyway (IMO)... Remember that threads are short lived in the kernel. They exist only as long as a user thread 'dips' into the kernel, and are reaped when the control passes back into userland. This is because a single userland may spawn a virtually unlimmitted number of syscalls as they are now asynchronous. Now, if they all use the same credential, (which is shared between processes that have not moved to change them, (with a lazily evaluated copy-on-write semantic)) then if one syscall changes the cred at exactly the instant that another uses it, the second thread can reference an inconsitant cred, leaving room in the future for some sort of hack. I the scheme we have now, each thread, as it is assigned to a process, takes a reference to the processes ucred as it starts. That ucred will never change. when it is reaped teh reference is dropped again. If in the mean while another thread has applied to change the processes creds, then it will allocate a NEW ucred with a reference of 1, unreference the old one and substitute in the new one. All threads continue to work with the ucred that was in effect when they started their dip into the kernel. When they complete they return control to teh userland scheduler and do a thread_exit() which will decrement the ucred reference. If the process changed ucreds in the mean while it is concievable that the reference count may go to 0 and it be freed. The rule is that ucred is read-only. and thus requires no lock to access it from any thread that has it. it is the credential that was in effect when the syscall was started. There is NO syscall to change the ucred of a running thread. so Albert's idea is not a goer at this time :-) > > -- Terry > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-arch" in the body of the message > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message