@@ -2091,24 +2091,18 @@ int sk_wait_data(struct sock *sk, long *timeo, const struct sk_buff *skb)
20912091EXPORT_SYMBOL (sk_wait_data );
20922092
20932093/**
2094- * __sk_mem_schedule - increase sk_forward_alloc and memory_allocated
2094+ * __sk_mem_raise_allocated - increase memory_allocated
20952095 * @sk: socket
20962096 * @size: memory size to allocate
2097+ * @amt: pages to allocate
20972098 * @kind: allocation type
20982099 *
2099- * If kind is SK_MEM_SEND, it means wmem allocation. Otherwise it means
2100- * rmem allocation. This function assumes that protocols which have
2101- * memory_pressure use sk_wmem_queued as write buffer accounting.
2100+ * Similar to __sk_mem_schedule(), but does not update sk_forward_alloc
21022101 */
2103- int __sk_mem_schedule (struct sock * sk , int size , int kind )
2102+ int __sk_mem_raise_allocated (struct sock * sk , int size , int amt , int kind )
21042103{
21052104 struct proto * prot = sk -> sk_prot ;
2106- int amt = sk_mem_pages (size );
2107- long allocated ;
2108-
2109- sk -> sk_forward_alloc += amt * SK_MEM_QUANTUM ;
2110-
2111- allocated = sk_memory_allocated_add (sk , amt );
2105+ long allocated = sk_memory_allocated_add (sk , amt );
21122106
21132107 if (mem_cgroup_sockets_enabled && sk -> sk_memcg &&
21142108 !mem_cgroup_charge_skmem (sk -> sk_memcg , amt ))
@@ -2169,28 +2163,47 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind)
21692163
21702164 trace_sock_exceed_buf_limit (sk , prot , allocated );
21712165
2172- /* Alas. Undo changes. */
2173- sk -> sk_forward_alloc -= amt * SK_MEM_QUANTUM ;
2174-
21752166 sk_memory_allocated_sub (sk , amt );
21762167
21772168 if (mem_cgroup_sockets_enabled && sk -> sk_memcg )
21782169 mem_cgroup_uncharge_skmem (sk -> sk_memcg , amt );
21792170
21802171 return 0 ;
21812172}
2173+ EXPORT_SYMBOL (__sk_mem_raise_allocated );
2174+
2175+ /**
2176+ * __sk_mem_schedule - increase sk_forward_alloc and memory_allocated
2177+ * @sk: socket
2178+ * @size: memory size to allocate
2179+ * @kind: allocation type
2180+ *
2181+ * If kind is SK_MEM_SEND, it means wmem allocation. Otherwise it means
2182+ * rmem allocation. This function assumes that protocols which have
2183+ * memory_pressure use sk_wmem_queued as write buffer accounting.
2184+ */
2185+ int __sk_mem_schedule (struct sock * sk , int size , int kind )
2186+ {
2187+ int ret , amt = sk_mem_pages (size );
2188+
2189+ sk -> sk_forward_alloc += amt << SK_MEM_QUANTUM_SHIFT ;
2190+ ret = __sk_mem_raise_allocated (sk , size , amt , kind );
2191+ if (!ret )
2192+ sk -> sk_forward_alloc -= amt << SK_MEM_QUANTUM_SHIFT ;
2193+ return ret ;
2194+ }
21822195EXPORT_SYMBOL (__sk_mem_schedule );
21832196
21842197/**
2185- * __sk_mem_reclaim - reclaim memory_allocated
2198+ * __sk_mem_reduce_allocated - reclaim memory_allocated
21862199 * @sk: socket
2187- * @amount: number of bytes (rounded down to a SK_MEM_QUANTUM multiple)
2200+ * @amount: number of quanta
2201+ *
2202+ * Similar to __sk_mem_reclaim(), but does not update sk_forward_alloc
21882203 */
2189- void __sk_mem_reclaim (struct sock * sk , int amount )
2204+ void __sk_mem_reduce_allocated (struct sock * sk , int amount )
21902205{
2191- amount >>= SK_MEM_QUANTUM_SHIFT ;
21922206 sk_memory_allocated_sub (sk , amount );
2193- sk -> sk_forward_alloc -= amount << SK_MEM_QUANTUM_SHIFT ;
21942207
21952208 if (mem_cgroup_sockets_enabled && sk -> sk_memcg )
21962209 mem_cgroup_uncharge_skmem (sk -> sk_memcg , amount );
@@ -2199,6 +2212,19 @@ void __sk_mem_reclaim(struct sock *sk, int amount)
21992212 (sk_memory_allocated (sk ) < sk_prot_mem_limits (sk , 0 )))
22002213 sk_leave_memory_pressure (sk );
22012214}
2215+ EXPORT_SYMBOL (__sk_mem_reduce_allocated );
2216+
2217+ /**
2218+ * __sk_mem_reclaim - reclaim sk_forward_alloc and memory_allocated
2219+ * @sk: socket
2220+ * @amount: number of bytes (rounded down to a SK_MEM_QUANTUM multiple)
2221+ */
2222+ void __sk_mem_reclaim (struct sock * sk , int amount )
2223+ {
2224+ amount >>= SK_MEM_QUANTUM_SHIFT ;
2225+ sk -> sk_forward_alloc -= amount << SK_MEM_QUANTUM_SHIFT ;
2226+ __sk_mem_reduce_allocated (sk , amount );
2227+ }
22022228EXPORT_SYMBOL (__sk_mem_reclaim );
22032229
22042230int sk_set_peek_off (struct sock * sk , int val )
0 commit comments