Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 05 Mar 2019 12:08:39 -0800
From:      Kirk McKusick <mckusick@mckusick.com>
To:        Edward Napierala <trasz@freebsd.org>
Cc:        FreeBSD FS <freebsd-fs@freebsd.org>
Subject:   Re: 'td' vs sys/fs/nfsserver/
Message-ID:  <201903052008.x25K8d4Z011653@chez.mckusick.com>
In-Reply-To: <CAFLM3-ouStEoEmXUmgJzaR5RoR954a4-RdK%2BNe6dzzqzsr50-A@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Let me give a brief historical perspective on how we ended up with
td getting passed nearly everywhere. It arose in the early 1980's
as I was leading an effort to get rid of kernel global user area.

The state of a process was stored in its process entry and its user
structure. The state needed only when the process was running was
stored in the user structure. State needed when the process was not
running was stored in the process structure. Thus the user structure
could be swapped out when the process was idle. The idea was to keep
the process structure as small as possible. On each context switch,
the process' user structure was brought into memory if it had been
swapped out and then mapped to the global kernel "u" variable.

One of the fields in the user structure was u_error. So functions
returned an error by setting u.u_error. If the kernel needed to do
an internal I/O operation (say read the contents of a directory
block to find an entry), it would need to save u.u_error, do the
I/O, check u.u_error to find out if it succeeded, then restore
u.u_error.

Our goal was to get rid of the user structure. So we made a sweep
over the entire kernel to get rid of uses of u.u_* accesses. For
u.u_error we changed functions so that they always returned errors.

Many of the fields that now appear in the uio structure were in the
user area. So we gathered them together to define the uio structure
and passed a pointer to a uio structure to functions that needed
to use it.

Finding out the current process was done using u.u_procp.  We
eliminated this by passing the process pointer in as one of the
parameters to each system call. Once we moved to threads, the
pointer to the process was changed to be a pointer to the thread.

Most of these changes were correct and carry over nicely to today.
In retrospect, the passing of the thread was not the right approach.
It becomes a parameter to near every call and is often just a
passthrough. So, if I had a time machine and could go back, I
would have dropped the idea of passing the process pointer and
just stuck with usng then curproc(), now curthread().

So, this is a long-winded way of saying that purging the passing
of td seems like a reasonable idea though one has to ask if the
cost in code churn is worth the effort.

	Kirk McKusick



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201903052008.x25K8d4Z011653>