diff options
Diffstat (limited to 'include/net/sock.h')
-rw-r--r-- | include/net/sock.h | 73 |
1 files changed, 23 insertions, 50 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index 7db3db112baa..2210fec65669 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -54,8 +54,8 @@ | |||
54 | #include <linux/security.h> | 54 | #include <linux/security.h> |
55 | #include <linux/slab.h> | 55 | #include <linux/slab.h> |
56 | #include <linux/uaccess.h> | 56 | #include <linux/uaccess.h> |
57 | #include <linux/page_counter.h> | ||
57 | #include <linux/memcontrol.h> | 58 | #include <linux/memcontrol.h> |
58 | #include <linux/res_counter.h> | ||
59 | #include <linux/static_key.h> | 59 | #include <linux/static_key.h> |
60 | #include <linux/aio.h> | 60 | #include <linux/aio.h> |
61 | #include <linux/sched.h> | 61 | #include <linux/sched.h> |
@@ -273,6 +273,7 @@ struct cg_proto; | |||
273 | * @sk_rcvtimeo: %SO_RCVTIMEO setting | 273 | * @sk_rcvtimeo: %SO_RCVTIMEO setting |
274 | * @sk_sndtimeo: %SO_SNDTIMEO setting | 274 | * @sk_sndtimeo: %SO_SNDTIMEO setting |
275 | * @sk_rxhash: flow hash received from netif layer | 275 | * @sk_rxhash: flow hash received from netif layer |
276 | * @sk_incoming_cpu: record cpu processing incoming packets | ||
276 | * @sk_txhash: computed flow hash for use on transmit | 277 | * @sk_txhash: computed flow hash for use on transmit |
277 | * @sk_filter: socket filtering instructions | 278 | * @sk_filter: socket filtering instructions |
278 | * @sk_protinfo: private area, net family specific, when not using slab | 279 | * @sk_protinfo: private area, net family specific, when not using slab |
@@ -350,6 +351,12 @@ struct sock { | |||
350 | #ifdef CONFIG_RPS | 351 | #ifdef CONFIG_RPS |
351 | __u32 sk_rxhash; | 352 | __u32 sk_rxhash; |
352 | #endif | 353 | #endif |
354 | u16 sk_incoming_cpu; | ||
355 | /* 16bit hole | ||
356 | * Warned : sk_incoming_cpu can be set from softirq, | ||
357 | * Do not use this hole without fully understanding possible issues. | ||
358 | */ | ||
359 | |||
353 | __u32 sk_txhash; | 360 | __u32 sk_txhash; |
354 | #ifdef CONFIG_NET_RX_BUSY_POLL | 361 | #ifdef CONFIG_NET_RX_BUSY_POLL |
355 | unsigned int sk_napi_id; | 362 | unsigned int sk_napi_id; |
@@ -833,6 +840,11 @@ static inline int sk_backlog_rcv(struct sock *sk, struct sk_buff *skb) | |||
833 | return sk->sk_backlog_rcv(sk, skb); | 840 | return sk->sk_backlog_rcv(sk, skb); |
834 | } | 841 | } |
835 | 842 | ||
843 | static inline void sk_incoming_cpu_update(struct sock *sk) | ||
844 | { | ||
845 | sk->sk_incoming_cpu = raw_smp_processor_id(); | ||
846 | } | ||
847 | |||
836 | static inline void sock_rps_record_flow_hash(__u32 hash) | 848 | static inline void sock_rps_record_flow_hash(__u32 hash) |
837 | { | 849 | { |
838 | #ifdef CONFIG_RPS | 850 | #ifdef CONFIG_RPS |
@@ -897,6 +909,7 @@ static inline void sock_rps_reset_rxhash(struct sock *sk) | |||
897 | if (!__rc) { \ | 909 | if (!__rc) { \ |
898 | *(__timeo) = schedule_timeout(*(__timeo)); \ | 910 | *(__timeo) = schedule_timeout(*(__timeo)); \ |
899 | } \ | 911 | } \ |
912 | sched_annotate_sleep(); \ | ||
900 | lock_sock(__sk); \ | 913 | lock_sock(__sk); \ |
901 | __rc = __condition; \ | 914 | __rc = __condition; \ |
902 | __rc; \ | 915 | __rc; \ |
@@ -1061,7 +1074,7 @@ enum cg_proto_flags { | |||
1061 | }; | 1074 | }; |
1062 | 1075 | ||
1063 | struct cg_proto { | 1076 | struct cg_proto { |
1064 | struct res_counter memory_allocated; /* Current allocated memory. */ | 1077 | struct page_counter memory_allocated; /* Current allocated memory. */ |
1065 | struct percpu_counter sockets_allocated; /* Current number of sockets. */ | 1078 | struct percpu_counter sockets_allocated; /* Current number of sockets. */ |
1066 | int memory_pressure; | 1079 | int memory_pressure; |
1067 | long sysctl_mem[3]; | 1080 | long sysctl_mem[3]; |
@@ -1213,34 +1226,26 @@ static inline void memcg_memory_allocated_add(struct cg_proto *prot, | |||
1213 | unsigned long amt, | 1226 | unsigned long amt, |
1214 | int *parent_status) | 1227 | int *parent_status) |
1215 | { | 1228 | { |
1216 | struct res_counter *fail; | 1229 | page_counter_charge(&prot->memory_allocated, amt); |
1217 | int ret; | ||
1218 | 1230 | ||
1219 | ret = res_counter_charge_nofail(&prot->memory_allocated, | 1231 | if (page_counter_read(&prot->memory_allocated) > |
1220 | amt << PAGE_SHIFT, &fail); | 1232 | prot->memory_allocated.limit) |
1221 | if (ret < 0) | ||
1222 | *parent_status = OVER_LIMIT; | 1233 | *parent_status = OVER_LIMIT; |
1223 | } | 1234 | } |
1224 | 1235 | ||
1225 | static inline void memcg_memory_allocated_sub(struct cg_proto *prot, | 1236 | static inline void memcg_memory_allocated_sub(struct cg_proto *prot, |
1226 | unsigned long amt) | 1237 | unsigned long amt) |
1227 | { | 1238 | { |
1228 | res_counter_uncharge(&prot->memory_allocated, amt << PAGE_SHIFT); | 1239 | page_counter_uncharge(&prot->memory_allocated, amt); |
1229 | } | ||
1230 | |||
1231 | static inline u64 memcg_memory_allocated_read(struct cg_proto *prot) | ||
1232 | { | ||
1233 | u64 ret; | ||
1234 | ret = res_counter_read_u64(&prot->memory_allocated, RES_USAGE); | ||
1235 | return ret >> PAGE_SHIFT; | ||
1236 | } | 1240 | } |
1237 | 1241 | ||
1238 | static inline long | 1242 | static inline long |
1239 | sk_memory_allocated(const struct sock *sk) | 1243 | sk_memory_allocated(const struct sock *sk) |
1240 | { | 1244 | { |
1241 | struct proto *prot = sk->sk_prot; | 1245 | struct proto *prot = sk->sk_prot; |
1246 | |||
1242 | if (mem_cgroup_sockets_enabled && sk->sk_cgrp) | 1247 | if (mem_cgroup_sockets_enabled && sk->sk_cgrp) |
1243 | return memcg_memory_allocated_read(sk->sk_cgrp); | 1248 | return page_counter_read(&sk->sk_cgrp->memory_allocated); |
1244 | 1249 | ||
1245 | return atomic_long_read(prot->memory_allocated); | 1250 | return atomic_long_read(prot->memory_allocated); |
1246 | } | 1251 | } |
@@ -1254,7 +1259,7 @@ sk_memory_allocated_add(struct sock *sk, int amt, int *parent_status) | |||
1254 | memcg_memory_allocated_add(sk->sk_cgrp, amt, parent_status); | 1259 | memcg_memory_allocated_add(sk->sk_cgrp, amt, parent_status); |
1255 | /* update the root cgroup regardless */ | 1260 | /* update the root cgroup regardless */ |
1256 | atomic_long_add_return(amt, prot->memory_allocated); | 1261 | atomic_long_add_return(amt, prot->memory_allocated); |
1257 | return memcg_memory_allocated_read(sk->sk_cgrp); | 1262 | return page_counter_read(&sk->sk_cgrp->memory_allocated); |
1258 | } | 1263 | } |
1259 | 1264 | ||
1260 | return atomic_long_add_return(amt, prot->memory_allocated); | 1265 | return atomic_long_add_return(amt, prot->memory_allocated); |
@@ -1588,6 +1593,7 @@ struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len, | |||
1588 | int *errcode, int max_page_order); | 1593 | int *errcode, int max_page_order); |
1589 | void *sock_kmalloc(struct sock *sk, int size, gfp_t priority); | 1594 | void *sock_kmalloc(struct sock *sk, int size, gfp_t priority); |
1590 | void sock_kfree_s(struct sock *sk, void *mem, int size); | 1595 | void sock_kfree_s(struct sock *sk, void *mem, int size); |
1596 | void sock_kzfree_s(struct sock *sk, void *mem, int size); | ||
1591 | void sk_send_sigurg(struct sock *sk); | 1597 | void sk_send_sigurg(struct sock *sk); |
1592 | 1598 | ||
1593 | /* | 1599 | /* |
@@ -1872,29 +1878,6 @@ static inline int skb_copy_to_page_nocache(struct sock *sk, char __user *from, | |||
1872 | return 0; | 1878 | return 0; |
1873 | } | 1879 | } |
1874 | 1880 | ||
1875 | static inline int skb_copy_to_page(struct sock *sk, char __user *from, | ||
1876 | struct sk_buff *skb, struct page *page, | ||
1877 | int off, int copy) | ||
1878 | { | ||
1879 | if (skb->ip_summed == CHECKSUM_NONE) { | ||
1880 | int err = 0; | ||
1881 | __wsum csum = csum_and_copy_from_user(from, | ||
1882 | page_address(page) + off, | ||
1883 | copy, 0, &err); | ||
1884 | if (err) | ||
1885 | return err; | ||
1886 | skb->csum = csum_block_add(skb->csum, csum, skb->len); | ||
1887 | } else if (copy_from_user(page_address(page) + off, from, copy)) | ||
1888 | return -EFAULT; | ||
1889 | |||
1890 | skb->len += copy; | ||
1891 | skb->data_len += copy; | ||
1892 | skb->truesize += copy; | ||
1893 | sk->sk_wmem_queued += copy; | ||
1894 | sk_mem_charge(sk, copy); | ||
1895 | return 0; | ||
1896 | } | ||
1897 | |||
1898 | /** | 1881 | /** |
1899 | * sk_wmem_alloc_get - returns write allocations | 1882 | * sk_wmem_alloc_get - returns write allocations |
1900 | * @sk: socket | 1883 | * @sk: socket |
@@ -2276,16 +2259,6 @@ bool sk_ns_capable(const struct sock *sk, | |||
2276 | bool sk_capable(const struct sock *sk, int cap); | 2259 | bool sk_capable(const struct sock *sk, int cap); |
2277 | bool sk_net_capable(const struct sock *sk, int cap); | 2260 | bool sk_net_capable(const struct sock *sk, int cap); |
2278 | 2261 | ||
2279 | /* | ||
2280 | * Enable debug/info messages | ||
2281 | */ | ||
2282 | extern int net_msg_warn; | ||
2283 | #define NETDEBUG(fmt, args...) \ | ||
2284 | do { if (net_msg_warn) printk(fmt,##args); } while (0) | ||
2285 | |||
2286 | #define LIMIT_NETDEBUG(fmt, args...) \ | ||
2287 | do { if (net_msg_warn && net_ratelimit()) printk(fmt,##args); } while(0) | ||
2288 | |||
2289 | extern __u32 sysctl_wmem_max; | 2262 | extern __u32 sysctl_wmem_max; |
2290 | extern __u32 sysctl_rmem_max; | 2263 | extern __u32 sysctl_rmem_max; |
2291 | 2264 | ||