diff options
| author | Jakub Kicinski <kuba@kernel.org> | 2021-10-27 18:20:31 -0700 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2021-10-27 18:20:32 -0700 |
| commit | 21214d555ff2fd066d2c72cf1c8c7913ca8d71dd (patch) | |
| tree | afe574b7565b9ac5a3faa35cc08271702db6dc5c /include | |
| parent | 9dfc685e0262d4c5e44e13302f89841fa75173ca (diff) | |
| parent | b8e0def397d7753206b1290e32f73b299a59984c (diff) | |
| download | cachepc-linux-21214d555ff2fd066d2c72cf1c8c7913ca8d71dd.tar.gz cachepc-linux-21214d555ff2fd066d2c72cf1c8c7913ca8d71dd.zip | |
Merge branch 'mptcp-rework-fwd-memory-allocation-and-one-cleanup'
Mat Martineau says:
====================
mptcp: Rework fwd memory allocation and one cleanup
These patches from the MPTCP tree rework forward memory allocation for
MPTCP (with some supporting changes in the net core), and also clean up
an unused function parameter.
Patch 1 updates TCP code but does not change any behavior, and creates
some macros for reclaim thresholds that will be reused in the MPTCP
code.
Patch 2 adds sk_forward_alloc_get() to the networking core to support
MPTCP's forward allocation with the diag interface.
Patch 3 reworks forward memory for MPTCP.
Patch 4 removes an unused arg and has no functional changes.
====================
Link: https://lore.kernel.org/r/20211026232916.179450-1-mathew.j.martineau@linux.intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/net/sock.h | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index ff4e62aa62e5..4f0280ad6c23 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1210,6 +1210,8 @@ struct proto { unsigned int inuse_idx; #endif + int (*forward_alloc_get)(const struct sock *sk); + bool (*stream_memory_free)(const struct sock *sk, int wake); bool (*stream_memory_read)(const struct sock *sk); /* Memory pressure */ @@ -1217,6 +1219,7 @@ struct proto { void (*leave_memory_pressure)(struct sock *sk); atomic_long_t *memory_allocated; /* Current allocated memory. */ struct percpu_counter *sockets_allocated; /* Current number of sockets. */ + /* * Pressure flag: try to collapse. * Technical note: it is used by multiple contexts non atomically. @@ -1294,6 +1297,14 @@ static inline void sk_refcnt_debug_release(const struct sock *sk) INDIRECT_CALLABLE_DECLARE(bool tcp_stream_memory_free(const struct sock *sk, int wake)); +static inline int sk_forward_alloc_get(const struct sock *sk) +{ + if (!sk->sk_prot->forward_alloc_get) + return sk->sk_forward_alloc; + + return sk->sk_prot->forward_alloc_get(sk); +} + static inline bool __sk_stream_memory_free(const struct sock *sk, int wake) { if (READ_ONCE(sk->sk_wmem_queued) >= READ_ONCE(sk->sk_sndbuf)) @@ -1573,6 +1584,11 @@ static inline void sk_mem_charge(struct sock *sk, int size) sk->sk_forward_alloc -= size; } +/* the following macros control memory reclaiming in sk_mem_uncharge() + */ +#define SK_RECLAIM_THRESHOLD (1 << 21) +#define SK_RECLAIM_CHUNK (1 << 20) + static inline void sk_mem_uncharge(struct sock *sk, int size) { int reclaimable; @@ -1589,8 +1605,8 @@ static inline void sk_mem_uncharge(struct sock *sk, int size) * If we reach 2 MBytes, reclaim 1 MBytes right now, there is * no need to hold that much forward allocation anyway. */ - if (unlikely(reclaimable >= 1 << 21)) - __sk_mem_reclaim(sk, 1 << 20); + if (unlikely(reclaimable >= SK_RECLAIM_THRESHOLD)) + __sk_mem_reclaim(sk, SK_RECLAIM_CHUNK); } static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb) |
