aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/stream.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/core/stream.c')
-rw-r--r--net/core/stream.c84
1 files changed, 1 insertions, 83 deletions
diff --git a/net/core/stream.c b/net/core/stream.c
index bf188ffdbdbe..4a0ad152c9c4 100644
--- a/net/core/stream.c
+++ b/net/core/stream.c
@@ -172,17 +172,6 @@ do_interrupted:
172 172
173EXPORT_SYMBOL(sk_stream_wait_memory); 173EXPORT_SYMBOL(sk_stream_wait_memory);
174 174
175void sk_stream_rfree(struct sk_buff *skb)
176{
177 struct sock *sk = skb->sk;
178
179 skb_truesize_check(skb);
180 atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
181 sk->sk_forward_alloc += skb->truesize;
182}
183
184EXPORT_SYMBOL(sk_stream_rfree);
185
186int sk_stream_error(struct sock *sk, int flags, int err) 175int sk_stream_error(struct sock *sk, int flags, int err)
187{ 176{
188 if (err == -EPIPE) 177 if (err == -EPIPE)
@@ -194,77 +183,6 @@ int sk_stream_error(struct sock *sk, int flags, int err)
194 183
195EXPORT_SYMBOL(sk_stream_error); 184EXPORT_SYMBOL(sk_stream_error);
196 185
197void __sk_stream_mem_reclaim(struct sock *sk)
198{
199 atomic_sub(sk->sk_forward_alloc >> SK_STREAM_MEM_QUANTUM_SHIFT,
200 sk->sk_prot->memory_allocated);
201 sk->sk_forward_alloc &= SK_STREAM_MEM_QUANTUM - 1;
202 if (*sk->sk_prot->memory_pressure &&
203 (atomic_read(sk->sk_prot->memory_allocated) <
204 sk->sk_prot->sysctl_mem[0]))
205 *sk->sk_prot->memory_pressure = 0;
206}
207
208EXPORT_SYMBOL(__sk_stream_mem_reclaim);
209
210int sk_stream_mem_schedule(struct sock *sk, int size, int kind)
211{
212 int amt = sk_stream_pages(size);
213 struct proto *prot = sk->sk_prot;
214
215 sk->sk_forward_alloc += amt * SK_STREAM_MEM_QUANTUM;
216 atomic_add(amt, prot->memory_allocated);
217
218 /* Under limit. */
219 if (atomic_read(prot->memory_allocated) < prot->sysctl_mem[0]) {
220 if (*prot->memory_pressure)
221 *prot->memory_pressure = 0;
222 return 1;
223 }
224
225 /* Over hard limit. */
226 if (atomic_read(prot->memory_allocated) > prot->sysctl_mem[2]) {
227 prot->enter_memory_pressure();
228 goto suppress_allocation;
229 }
230
231 /* Under pressure. */
232 if (atomic_read(prot->memory_allocated) > prot->sysctl_mem[1])
233 prot->enter_memory_pressure();
234
235 if (kind) {
236 if (atomic_read(&sk->sk_rmem_alloc) < prot->sysctl_rmem[0])
237 return 1;
238 } else if (sk->sk_wmem_queued < prot->sysctl_wmem[0])
239 return 1;
240
241 if (!*prot->memory_pressure ||
242 prot->sysctl_mem[2] > atomic_read(prot->sockets_allocated) *
243 sk_stream_pages(sk->sk_wmem_queued +
244 atomic_read(&sk->sk_rmem_alloc) +
245 sk->sk_forward_alloc))
246 return 1;
247
248suppress_allocation:
249
250 if (!kind) {
251 sk_stream_moderate_sndbuf(sk);
252
253 /* Fail only if socket is _under_ its sndbuf.
254 * In this case we cannot block, so that we have to fail.
255 */
256 if (sk->sk_wmem_queued + size >= sk->sk_sndbuf)
257 return 1;
258 }
259
260 /* Alas. Undo changes. */
261 sk->sk_forward_alloc -= amt * SK_STREAM_MEM_QUANTUM;
262 atomic_sub(amt, prot->memory_allocated);
263 return 0;
264}
265
266EXPORT_SYMBOL(sk_stream_mem_schedule);
267
268void sk_stream_kill_queues(struct sock *sk) 186void sk_stream_kill_queues(struct sock *sk)
269{ 187{
270 /* First the read buffer. */ 188 /* First the read buffer. */
@@ -277,7 +195,7 @@ void sk_stream_kill_queues(struct sock *sk)
277 BUG_TRAP(skb_queue_empty(&sk->sk_write_queue)); 195 BUG_TRAP(skb_queue_empty(&sk->sk_write_queue));
278 196
279 /* Account for returned memory. */ 197 /* Account for returned memory. */
280 sk_stream_mem_reclaim(sk); 198 sk_mem_reclaim(sk);
281 199
282 BUG_TRAP(!sk->sk_wmem_queued); 200 BUG_TRAP(!sk->sk_wmem_queued);
283 BUG_TRAP(!sk->sk_forward_alloc); 201 BUG_TRAP(!sk->sk_forward_alloc);