Merge branch 'vendor/OPENSSL'
[dragonfly.git] / share / doc / smm / 18.net / c.t
1 .\" Copyright (c) 1983, 1986, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)c.t 8.1 (Berkeley) 6/8/93
29 .\"
30 .nr H2 1
31 .\".ds RH "Buffering and congestion control
32 .br
33 .ne 2i
34 .NH
35 \s+2Buffering and congestion control\s0
36 .PP
37 One of the major factors in the performance of a protocol is
38 the buffering policy used.  Lack of a proper buffering policy
39 can force packets to be dropped, cause falsified windowing
40 information to be emitted by protocols, fragment host memory,
41 degrade the overall host performance, etc.  Due to problems
42 such as these, most systems allocate a fixed pool of memory
43 to the networking system and impose
44 a policy optimized for ``normal'' network operation.  
45 .PP
46 The networking system developed for UNIX is little different in this
47 respect.  At boot time a fixed amount of memory is allocated by
48 the networking system.  At later times more system memory
49 may be requested as the need arises, but at no time is
50 memory ever returned to the system.  It is possible to
51 garbage collect memory from the network, but difficult.  In
52 order to perform this garbage collection properly, some
53 portion of the network will have to be ``turned off'' as
54 data structures are updated.  The interval over which this
55 occurs must kept small compared to the average inter-packet
56 arrival time, or too much traffic may
57 be lost, impacting other hosts on the network, as well as
58 increasing load on the interconnecting mediums.  In our
59 environment we have not experienced a need for such compaction,
60 and thus have left the problem unresolved.
61 .PP
62 The mbuf structure was introduced in chapter 5.  In this
63 section a brief description will be given of the allocation
64 mechanisms, and policies used by the protocols in performing
65 connection level buffering.
66 .NH 2
67 Memory management
68 .PP
69 The basic memory allocation routines manage a private page map,
70 the size of which determines the maximum amount of memory
71 that may be allocated by the network.
72 A small amount of memory is allocated at boot time
73 to initialize the mbuf and mbuf page cluster free lists.
74 When the free lists are exhausted, more memory is requested
75 from the system memory allocator if space remains in the map.
76 If memory cannot be allocated,
77 callers may block awaiting free memory,
78 or the failure may be reflected to the caller immediately.
79 The allocator will not block awaiting free map entries, however,
80 as exhaustion of the page map usually indicates that buffers have been lost
81 due to a ``leak.''
82 The private page table is used by the network buffer management
83 routines in remapping pages to
84 be logically contiguous as the need arises.  In addition, an
85 array of reference counts parallels the page table and is used
86 when multiple references to a page are present.
87 .PP
88 Mbufs are 128 byte structures, 8 fitting in a 1Kbyte
89 page of memory.  When data is placed in mbufs,
90 it is copied or remapped into logically contiguous pages of
91 memory from the network page pool if possible.
92 Data smaller than half of the size
93 of a page is copied into one or more 112 byte mbuf data areas. 
94 .NH 2
95 Protocol buffering policies
96 .PP
97 Protocols reserve fixed amounts of
98 buffering for send and receive queues at socket creation time.  These
99 amounts define the high and low water marks used by the socket routines
100 in deciding when to block and unblock a process.  The reservation
101 of space does not currently
102 result in any action by the memory management
103 routines.
104 .PP
105 Protocols which provide connection level flow control do this
106 based on the amount of space in the associated socket queues.  That
107 is, send windows are calculated based on the amount of free space
108 in the socket's receive queue, while receive windows are adjusted
109 based on the amount of data awaiting transmission in the send queue.
110 Care has been taken to avoid the ``silly window syndrome'' described
111 in [Clark82] at both the sending and receiving ends.
112 .NH 2
113 Queue limiting
114 .PP
115 Incoming packets from the network are always received unless
116 memory allocation fails.  However, each Level 1 protocol
117 input queue
118 has an upper bound on the queue's length, and any packets
119 exceeding that bound are discarded.  It is possible for a host to be
120 overwhelmed by excessive network traffic (for instance a host
121 acting as a gateway from a high bandwidth network to a low bandwidth
122 network).  As a ``defensive'' mechanism the queue limits may be
123 adjusted to throttle network traffic load on a host.
124 Consider a host willing to devote some percentage of
125 its machine to handling network traffic. 
126 If the cost of handling an
127 incoming packet can be calculated so that an acceptable
128 ``packet handling rate''
129 can be determined, then input queue lengths may be dynamically
130 adjusted based on a host's network load and the number of packets
131 awaiting processing.  Obviously, discarding packets is
132 not a satisfactory solution to a problem such as this
133 (simply dropping packets is likely to increase the load on a network);
134 the queue lengths were incorporated mainly as a safeguard mechanism.
135 .NH 2
136 Packet forwarding
137 .PP
138 When packets can not be forwarded because of memory limitations,
139 the system attempts to generate a ``source quench'' message.  In addition,
140 any other problems encountered during packet forwarding are also
141 reflected back to the sender in the form of ICMP packets.  This
142 helps hosts avoid unneeded retransmissions.
143 .PP
144 Broadcast packets are never forwarded due to possible dire
145 consequences.  In an early stage of network development, broadcast
146 packets were forwarded and a ``routing loop'' resulted in network
147 saturation and every host on the network crashing.