What it is
Hydra is an operating system kernel built at Carnegie-Mellon University in the 1970s for C.mmp, a multiprocessor. The paper “Policy/Mechanism Separation in Hydra” by R. Levin, E. Cohen, W. Corwin, F. Pollack and W. Wulf (1975) describes how Hydra applies one design principle: the kernel provides mechanisms, the protected operations that act on resources, and user-level programs choose policies, the rules that decide how resources are used. The paper examines scheduling, paging and protection, and shows which pieces of policy still had to stay in the kernel.
Basis of this account
This account rests on the paper as published in the proceedings of the Fifth ACM Symposium on Operating Systems Principles (SOSP), Austin, Texas, November 1975, pages 132 to 140; ACM is the Association for Computing Machinery. It was read in a copy posted for a course at the University of Wisconsin (https://swift.sites.cs.wisc.edu/classes/cs736-fa06/papers/hydra-policy-mechanism.pdf). The abstract, Sections 1, 2 and 4 and the Summary were read in full; Section 3, on paging, was read in part. The other Hydra papers that this one relies on for its notions of object and capability were not read. Nothing was run.
What the paper claims
The authors make these claims.
Why separate. Policies built into existing kernels, claimed to behave well on average, often fail in the special cases that matter to a particular user. Policies written as ordinary user programs are easier to adapt and tune, and the authors want several policies for the same resource to exist at once.
Why not completely. Any user program may contain bugs or be malicious, so a policy program must not damage other programs or monopolize a resource. And some decisions, such as which process runs next, are needed too often to call a user program each time, because switching between protection domains, the separate sets of access rights in which programs run, is costly on C.mmp. The authors call their answer a compromise and name it the principle of policy/mechanism separation.
Two meanings of mechanism. A kernel mechanism is either a protected version of a hardware operation, such as a kernel operation that alone may set device control registers and checks each request first, or a parameterized policy: a fixed policy in the kernel whose behavior user programs steer through parameters.
Main result. In the abstract’s words, “the policy decisions which remain embedded in the kernel exist for the sole purpose of arbitrating conflicting requests for physical resources, and then only to the extent of guaranteeing fairness.”
Limits they admit. The kernel cannot support every conceivable policy. The type and number of parameters that the kernel offers decide which policies can be built. Excluding some policies is “itself a lower-level (i.e. kernel) policy of a sort”. Whether a piece of software counts as policy or as mechanism is relative: what one level implements as its policy, the level above uses as a mechanism, and even the kernel’s lowest mechanisms are policies for the use of the hardware. The Summary adds that not all policies are possible and that their set of mechanisms “is not the best possible”.
How it works
Scheduling shows the method most clearly.
KMPS (Kernel Multiprocessing System) is the part of the kernel that runs processes on the processors.
A policy module (PM) is a scheduler that runs as a user-level program. In the paper’s operational definition, a PM is any set of programs that hold capabilities, unforgeable references that carry access rights, for a group of processes and for one policy object, a mailbox through which the kernel sends the PM messages. Several PMs run at once, each for its own processes; the paper’s examples are one PM for interactive users, one for batch jobs and one being debugged.
The parameters that a PM sets for each of its processes are a priority; a processor mask, the processors allowed to run the process (only some C.mmp processors had floating-point hardware); a time quantum, given as a time slice of at most 0.5 seconds and a number of slices; and the largest number of pages, the fixed-size blocks in which memory is managed, that the process may hold in memory at once.
One scheduling cycle runs as follows; the operation names are the paper’s.
The PM sets the parameters of a process (
SETPCB) and starts it (START). Control of the process passes to KMPS, and the paging mechanism brings the pages the process is using into memory.KMPS runs the process in competition with all other started processes, guided only by the parameters. It uses priority scheduling: a process runs before a process of the same PM with a lower priority.
The process stops when its quantum ends, when it blocks on a semaphore §9.6 (a counter on which processes wait for one another), when it exceeds its page limit, when its PM stops it (
STOP), or when it terminates. KMPS places a message in the PM’s policy object.The PM receives the message (
RCVPOLICY), decides, possibly changes the parameters, and starts the process again or leaves it stopped.
The kernel keeps only the mechanism of blocking and unblocking. When a semaphore releases a stopped process, KMPS only reports it; the process runs again only when its PM starts it.
Policy remains in the kernel where PMs compete. KMPS must give each PM an agreed share of the processors: the paper describes a rate guarantee, a fixed percentage of the processor cycles over an interval, given separately for each class of processors, with cycles that a PM leaves unused shared out fairly among the other PMs. The authors state that this guarantee algorithm §14.1 had been simulated but not implemented. Paging follows the same pattern. Each PM is guaranteed a number of page frames, the places in physical memory that hold pages; the guarantees add up to all available frames, and the kernel itself chooses which page to replace, a mechanism that the authors say includes “quite a bit of policy”.
Protection is the cleanest case. Hydra’s capability mechanism is passive: a program that does not care about protection need not use it. One interaction is forced, though. Every process must be scheduled by some PM, which it may not trust. A PM cannot read the data or capabilities of the processes it schedules, and the kernel guarantees the outcome of negotiations between a process and its PM. A process that its PM restarts early, before its semaphore was released, or with a smaller processor mask or page limit than it asked for, gets an error from the operation that was interrupted, instead of continuing as if it had what it asked for. A kernel operation, RUNTIME, lets a process ask not to be stopped for a given time, for instance inside a critical section §9.4, a stretch of code that other processes must not enter at the same time. If the remaining quantum or the page limit does not cover the request, the process is stopped and its PM decides whether to raise them; restarted without a raise, the operation fails. The PM thus keeps control.
Worked example
This example is invented: the kinds of parameter are the paper’s, the numbers are not. A multiprocessor has 10 processors in one class. Three PMs share it with rate guarantees of 50%, 30% and 20% of the cycles in each 10-second interval. A processor-second is one processor busy for one second, so an interval holds processor-seconds. PM A is therefore guaranteed processor-seconds, PM B and PM C .
PM B, an interactive scheduler, starts an editor process with priority 7 and a quantum of 4 slices of 0.25 seconds. The editor may therefore run for second of processor time before KMPS stops it and writes a message into B’s policy object. B reads the message, sees that the editor used its whole quantum, and restarts it with a lower priority. That decision is policy, and it was made entirely at user level.
In one interval PM C uses only 5 of its 20 processor-seconds. The unused processor-seconds go to A and B, shared fairly as the paper’s goals require. Then PM A gets a bug that restarts its processes forever with the largest quantum allowed. KMPS still holds A to its guaranteed share whenever B and C claim theirs, so the bug cannot cause starvation §9.18 of B’s editor, that is, leave it waiting indefinitely for a processor. That limit is the policy that stays in the kernel: no PM can choose the policy of taking the whole machine.
What this account does not establish
The paper describes a design and reports no measurements of cost or flexibility. The scheduling guarantee, the main piece of policy left in the kernel, was not implemented when the paper was written.
The claim that the kernel keeps policy only to arbitrate fairly is the authors’ reading of their own kernel. Their text also shows a page-replacement mechanism that “includes quite a bit of policy”, and a footnote admits a few facilities kept in the kernel only for efficiency. Whether these count as mechanism is exactly the relativity that the authors point out.
Separation moves the choice of policy, not the need for enforcement. A user-level PM still depends on the kernel to enforce its parameters and to protect the other PMs from it.
Hydra was shaped by its hardware. The PDP-11 (Programmed Data Processor 11) processors of C.mmp produce 16-bit addresses, so a program could address at most bytes, 64 KiB, at a time, and the address-translation hardware could not support demand paging in the usual sense, in which a page is loaded only when a program first touches it. Some mechanisms exist because of that hardware, and the paper notes that other hardware would let some facilities leave the kernel.
This account did not read the companion Hydra papers, so it does not describe Hydra’s object and capability system beyond what this paper states.
Questions answered
Can policy and mechanism be separated absolutely?
Policy and mechanism cannot be separated absolutely: some policy always stays inside the protected mechanism, and the authors of Hydra, a kernel built around the separation of policy and mechanism §1.19, say so themselves (Levin, Cohen, Corwin, Pollack and Wulf, 1975). Three reasons follow from their paper.
Shared resources need an arbiter. When several user-level policies compete for processors or memory, the kernel must decide between them, and that decision is policy. Hydra keeps it to guaranteeing each policy a fair share, but cannot remove it.
The interface limits the policies. User-level policy acts only through the operations and parameters that the kernel offers, so the kernel designer’s choice fixes which policies can be built. Refusing the rest, for example a policy that takes the whole machine, is itself a kernel policy.
Speed forces policy into the kernel. A decision needed many times a second, such as which process runs next, cannot call a user program each time, so the kernel holds a parameterized policy that user programs only tune.
Calling software policy or mechanism is also relative: what one level implements as policy, the level above uses as mechanism.
The achievable goal is a stated separation, not an absolute one. Name the interface, list the decisions that user-level code can change through it, and list the constraints that the trusted mechanism still enforces whatever the policy says, such as protecting other programs and keeping shares fair. Moving policy code out of the kernel changes who may choose a policy and what each decision costs; it does not remove the need for those constraints.
Related entries: Policy versus mechanism (§1.19), Capability security (§1.40), Starvation (§9.18), Microkernel, monolithic kernel, and service isolation (§19.5.4), Flask: separating security policy from enforcement mechanisms (§21.12). Further reading: [216].