Section 21.13

Hydra: policy flexibility above protected mechanisms

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.

How it works

Scheduling shows the method most clearly.

One scheduling cycle runs as follows; the operation names are the paper’s.

  1. 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.

  2. 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.

  3. 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.

  4. 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 10×10=10010 \times 10 = 100 processor-seconds. PM A is therefore guaranteed 0.5×100=500.5 \times 100 = 50 processor-seconds, PM B 0.3×100=300.3 \times 100 = 30 and PM C 0.2×100=200.2 \times 100 = 20.

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 4×0.25=14 \times 0.25 = 1 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 20−5=1520 - 5 = 15 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 216=65,5362^{16} = 65{,}536 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.

  1. 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.

  2. 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.

  3. 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].