~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/net/proto_memory.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-or-later */
  2 #ifndef _PROTO_MEMORY_H
  3 #define _PROTO_MEMORY_H
  4 
  5 #include <net/sock.h>
  6 #include <net/hotdata.h>
  7 
  8 /* 1 MB per cpu, in page units */
  9 #define SK_MEMORY_PCPU_RESERVE (1 << (20 - PAGE_SHIFT))
 10 
 11 static inline bool sk_has_memory_pressure(const struct sock *sk)
 12 {
 13         return sk->sk_prot->memory_pressure != NULL;
 14 }
 15 
 16 static inline bool
 17 proto_memory_pressure(const struct proto *prot)
 18 {
 19         if (!prot->memory_pressure)
 20                 return false;
 21         return !!READ_ONCE(*prot->memory_pressure);
 22 }
 23 
 24 static inline bool sk_under_global_memory_pressure(const struct sock *sk)
 25 {
 26         return proto_memory_pressure(sk->sk_prot);
 27 }
 28 
 29 static inline bool sk_under_memory_pressure(const struct sock *sk)
 30 {
 31         if (!sk->sk_prot->memory_pressure)
 32                 return false;
 33 
 34         if (mem_cgroup_sockets_enabled && sk->sk_memcg &&
 35             mem_cgroup_under_socket_pressure(sk->sk_memcg))
 36                 return true;
 37 
 38         return !!READ_ONCE(*sk->sk_prot->memory_pressure);
 39 }
 40 
 41 static inline long
 42 proto_memory_allocated(const struct proto *prot)
 43 {
 44         return max(0L, atomic_long_read(prot->memory_allocated));
 45 }
 46 
 47 static inline long
 48 sk_memory_allocated(const struct sock *sk)
 49 {
 50         return proto_memory_allocated(sk->sk_prot);
 51 }
 52 
 53 static inline void proto_memory_pcpu_drain(struct proto *proto)
 54 {
 55         int val = this_cpu_xchg(*proto->per_cpu_fw_alloc, 0);
 56 
 57         if (val)
 58                 atomic_long_add(val, proto->memory_allocated);
 59 }
 60 
 61 static inline void
 62 sk_memory_allocated_add(const struct sock *sk, int val)
 63 {
 64         struct proto *proto = sk->sk_prot;
 65 
 66         val = this_cpu_add_return(*proto->per_cpu_fw_alloc, val);
 67 
 68         if (unlikely(val >= READ_ONCE(net_hotdata.sysctl_mem_pcpu_rsv)))
 69                 proto_memory_pcpu_drain(proto);
 70 }
 71 
 72 static inline void
 73 sk_memory_allocated_sub(const struct sock *sk, int val)
 74 {
 75         struct proto *proto = sk->sk_prot;
 76 
 77         val = this_cpu_sub_return(*proto->per_cpu_fw_alloc, val);
 78 
 79         if (unlikely(val <= -READ_ONCE(net_hotdata.sysctl_mem_pcpu_rsv)))
 80                 proto_memory_pcpu_drain(proto);
 81 }
 82 
 83 #endif /* _PROTO_MEMORY_H */
 84 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php