include/net/proto_memory.h
Source file repositories/reference/linux-study-clean/include/net/proto_memory.h
File Facts
- System
- Linux kernel
- Corpus path
include/net/proto_memory.h- Extension
.h- Size
- 1968 bytes
- Lines
- 87
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
net/sock.hnet/hotdata.h
Detected Declarations
function sk_has_memory_pressurefunction proto_memory_pressurefunction sk_under_global_memory_pressurefunction sk_under_memory_pressurefunction proto_memory_allocatedfunction sk_memory_allocatedfunction proto_memory_pcpu_drainfunction sk_memory_allocated_addfunction sk_memory_allocated_sub
Annotated Snippet
#ifndef _PROTO_MEMORY_H
#define _PROTO_MEMORY_H
#include <net/sock.h>
#include <net/hotdata.h>
/* 1 MB per cpu, in page units */
#define SK_MEMORY_PCPU_RESERVE (1 << (20 - PAGE_SHIFT))
static inline bool sk_has_memory_pressure(const struct sock *sk)
{
return sk->sk_prot->memory_pressure != NULL;
}
static inline bool
proto_memory_pressure(const struct proto *prot)
{
if (!prot->memory_pressure)
return false;
return !!READ_ONCE(*prot->memory_pressure);
}
static inline bool sk_under_global_memory_pressure(const struct sock *sk)
{
return proto_memory_pressure(sk->sk_prot);
}
static inline bool sk_under_memory_pressure(const struct sock *sk)
{
if (!sk->sk_prot->memory_pressure)
return false;
if (mem_cgroup_sk_enabled(sk) &&
mem_cgroup_sk_under_memory_pressure(sk))
return true;
if (sk->sk_bypass_prot_mem)
return false;
return !!READ_ONCE(*sk->sk_prot->memory_pressure);
}
static inline long
proto_memory_allocated(const struct proto *prot)
{
return max(0L, atomic_long_read(prot->memory_allocated));
}
static inline long
sk_memory_allocated(const struct sock *sk)
{
return proto_memory_allocated(sk->sk_prot);
}
static inline void proto_memory_pcpu_drain(struct proto *proto)
{
int val = this_cpu_xchg(*proto->per_cpu_fw_alloc, 0);
if (val)
atomic_long_add(val, proto->memory_allocated);
}
static inline void
sk_memory_allocated_add(const struct sock *sk, int val)
{
struct proto *proto = sk->sk_prot;
val = this_cpu_add_return(*proto->per_cpu_fw_alloc, val);
if (unlikely(val >= READ_ONCE(net_hotdata.sysctl_mem_pcpu_rsv)))
proto_memory_pcpu_drain(proto);
}
static inline void
sk_memory_allocated_sub(const struct sock *sk, int val)
{
struct proto *proto = sk->sk_prot;
val = this_cpu_sub_return(*proto->per_cpu_fw_alloc, val);
if (unlikely(val <= -READ_ONCE(net_hotdata.sysctl_mem_pcpu_rsv)))
proto_memory_pcpu_drain(proto);
}
#endif /* _PROTO_MEMORY_H */
Annotation
- Immediate include surface: `net/sock.h`, `net/hotdata.h`.
- Detected declarations: `function sk_has_memory_pressure`, `function proto_memory_pressure`, `function sk_under_global_memory_pressure`, `function sk_under_memory_pressure`, `function proto_memory_allocated`, `function sk_memory_allocated`, `function proto_memory_pcpu_drain`, `function sk_memory_allocated_add`, `function sk_memory_allocated_sub`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.