@@ -2323,10 +2323,14 @@ EXPORT_SYMBOL(sock_cmsg_send);
static void sk_enter_memory_pressure(struct sock *sk)
{
- if (!sk->sk_prot->enter_memory_pressure)
- return;
+ if (sk->sk_prot->enter_memory_pressure) {
+ sk->sk_prot->enter_memory_pressure(sk);
+ } else {
+ unsigned long *memory_pressure = sk->sk_prot->memory_pressure;
- sk->sk_prot->enter_memory_pressure(sk);
+ if (memory_pressure && !READ_ONCE(*memory_pressure))
+ WRITE_ONCE(*memory_pressure, 1);
+ }
}
static void sk_leave_memory_pressure(struct sock *sk)
Currently sk_leave_memory_pressure() offers a generic implementation for protocol lacking the leave_memory_pressure() helper, but supporting the memory pressure model. sk_enter_memory_pressure() lacks such bits. As a result we get code duplication and additional, avoidable indirect calls. This change provides a generic implementation for entering memory pressure, similar to the existing sk_leave_memory_pressure(). Note: no existing protocol is affected, until the existing enter_memory_pressure helper is removed from the relevant 'proto' struct. Signed-off-by: Paolo Abeni <pabeni@redhat.com> --- net/core/sock.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)