patch-2.2.17 linux/net/core/sock.c

Next file: linux/net/ipv4/af_inet.c
Previous file: linux/net/core/dev.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.2.16/net/core/sock.c linux/net/core/sock.c
@@ -132,6 +132,8 @@
 
 #define min(a,b)	((a)<(b)?(a):(b))
 
+struct linux_mib net_statistics;
+
 /* Run time adjustable parameters. */
 __u32 sysctl_wmem_max = SK_WMEM_MAX;
 __u32 sysctl_rmem_max = SK_RMEM_MAX;
@@ -566,6 +568,35 @@
 			skb->sk = sk;
 			return skb;
 		}
+#ifdef CONFIG_INET
+		net_statistics.SockMallocOOM++; 
+#endif
+	}
+	return NULL;
+}
+
+/*
+ * Allocate memory from the sockets send buffer, telling caller about real OOM. 
+ * err is only set for oom, not for socket buffer overflow.
+ */ 
+struct sk_buff *sock_wmalloc_err(struct sock *sk, unsigned long size, int force, int priority, int *err)
+{
+	*err = 0; 
+	/* Note: overcommitment possible */ 
+	if (force || atomic_read(&sk->wmem_alloc) < sk->sndbuf) {
+		struct sk_buff * skb;
+		*err = -ENOMEM; 
+		skb = alloc_skb(size, priority);
+		if (skb) {
+			*err = 0;
+			atomic_add(skb->truesize, &sk->wmem_alloc);
+			skb->destructor = sock_wfree;
+			skb->sk = sk;
+			return skb;
+		}
+#ifdef CONFIG_INET
+		net_statistics.SockMallocOOM++; 
+#endif
 	}
 	return NULL;
 }
@@ -583,6 +614,9 @@
 			skb->sk = sk;
 			return skb;
 		}
+#ifdef CONFIG_INET
+		net_statistics.SockMallocOOM++;
+#endif 
 	}
 	return NULL;
 }
@@ -602,6 +636,9 @@
 		if (mem)
 			return mem;
 		atomic_sub(size, &sk->omem_alloc);
+#ifdef CONFIG_INET
+		net_statistics.SockMallocOOM++; 
+#endif
 	}
 	return NULL;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)