@@ -2091,24 +2091,18 @@ int sk_wait_data(struct sock *sk, long *timeo, const struct sk_buff *skb)
2091
2091
EXPORT_SYMBOL (sk_wait_data );
2092
2092
2093
2093
/**
2094
- * __sk_mem_schedule - increase sk_forward_alloc and memory_allocated
2094
+ * __sk_mem_raise_allocated - increase memory_allocated
2095
2095
* @sk: socket
2096
2096
* @size: memory size to allocate
2097
+ * @amt: pages to allocate
2097
2098
* @kind: allocation type
2098
2099
*
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
2102
2101
*/
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 )
2104
2103
{
2105
2104
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 );
2112
2106
2113
2107
if (mem_cgroup_sockets_enabled && sk -> sk_memcg &&
2114
2108
!mem_cgroup_charge_skmem (sk -> sk_memcg , amt ))
@@ -2169,28 +2163,47 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind)
2169
2163
2170
2164
trace_sock_exceed_buf_limit (sk , prot , allocated );
2171
2165
2172
- /* Alas. Undo changes. */
2173
- sk -> sk_forward_alloc -= amt * SK_MEM_QUANTUM ;
2174
-
2175
2166
sk_memory_allocated_sub (sk , amt );
2176
2167
2177
2168
if (mem_cgroup_sockets_enabled && sk -> sk_memcg )
2178
2169
mem_cgroup_uncharge_skmem (sk -> sk_memcg , amt );
2179
2170
2180
2171
return 0 ;
2181
2172
}
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
+ }
2182
2195
EXPORT_SYMBOL (__sk_mem_schedule );
2183
2196
2184
2197
/**
2185
- * __sk_mem_reclaim - reclaim memory_allocated
2198
+ * __sk_mem_reduce_allocated - reclaim memory_allocated
2186
2199
* @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
2188
2203
*/
2189
- void __sk_mem_reclaim (struct sock * sk , int amount )
2204
+ void __sk_mem_reduce_allocated (struct sock * sk , int amount )
2190
2205
{
2191
- amount >>= SK_MEM_QUANTUM_SHIFT ;
2192
2206
sk_memory_allocated_sub (sk , amount );
2193
- sk -> sk_forward_alloc -= amount << SK_MEM_QUANTUM_SHIFT ;
2194
2207
2195
2208
if (mem_cgroup_sockets_enabled && sk -> sk_memcg )
2196
2209
mem_cgroup_uncharge_skmem (sk -> sk_memcg , amount );
@@ -2199,6 +2212,19 @@ void __sk_mem_reclaim(struct sock *sk, int amount)
2199
2212
(sk_memory_allocated (sk ) < sk_prot_mem_limits (sk , 0 )))
2200
2213
sk_leave_memory_pressure (sk );
2201
2214
}
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
+ }
2202
2228
EXPORT_SYMBOL (__sk_mem_reclaim );
2203
2229
2204
2230
int sk_set_peek_off (struct sock * sk , int val )
0 commit comments