Commit 21214d55 authored by Jakub Kicinski's avatar Jakub Kicinski

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.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 9dfc685e b8e0def3
...@@ -1210,6 +1210,8 @@ struct proto { ...@@ -1210,6 +1210,8 @@ struct proto {
unsigned int inuse_idx; unsigned int inuse_idx;
#endif #endif
int (*forward_alloc_get)(const struct sock *sk);
bool (*stream_memory_free)(const struct sock *sk, int wake); bool (*stream_memory_free)(const struct sock *sk, int wake);
bool (*stream_memory_read)(const struct sock *sk); bool (*stream_memory_read)(const struct sock *sk);
/* Memory pressure */ /* Memory pressure */
...@@ -1217,6 +1219,7 @@ struct proto { ...@@ -1217,6 +1219,7 @@ struct proto {
void (*leave_memory_pressure)(struct sock *sk); void (*leave_memory_pressure)(struct sock *sk);
atomic_long_t *memory_allocated; /* Current allocated memory. */ atomic_long_t *memory_allocated; /* Current allocated memory. */
struct percpu_counter *sockets_allocated; /* Current number of sockets. */ struct percpu_counter *sockets_allocated; /* Current number of sockets. */
/* /*
* Pressure flag: try to collapse. * Pressure flag: try to collapse.
* Technical note: it is used by multiple contexts non atomically. * 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) ...@@ -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)); 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) 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)) 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) ...@@ -1573,6 +1584,11 @@ static inline void sk_mem_charge(struct sock *sk, int size)
sk->sk_forward_alloc -= 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) static inline void sk_mem_uncharge(struct sock *sk, int size)
{ {
int reclaimable; int reclaimable;
...@@ -1589,8 +1605,8 @@ static inline void sk_mem_uncharge(struct sock *sk, int size) ...@@ -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 * If we reach 2 MBytes, reclaim 1 MBytes right now, there is
* no need to hold that much forward allocation anyway. * no need to hold that much forward allocation anyway.
*/ */
if (unlikely(reclaimable >= 1 << 21)) if (unlikely(reclaimable >= SK_RECLAIM_THRESHOLD))
__sk_mem_reclaim(sk, 1 << 20); __sk_mem_reclaim(sk, SK_RECLAIM_CHUNK);
} }
static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb) static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb)
......
...@@ -150,7 +150,7 @@ void inet_sock_destruct(struct sock *sk) ...@@ -150,7 +150,7 @@ void inet_sock_destruct(struct sock *sk)
WARN_ON(atomic_read(&sk->sk_rmem_alloc)); WARN_ON(atomic_read(&sk->sk_rmem_alloc));
WARN_ON(refcount_read(&sk->sk_wmem_alloc)); WARN_ON(refcount_read(&sk->sk_wmem_alloc));
WARN_ON(sk->sk_wmem_queued); WARN_ON(sk->sk_wmem_queued);
WARN_ON(sk->sk_forward_alloc); WARN_ON(sk_forward_alloc_get(sk));
kfree(rcu_dereference_protected(inet->inet_opt, 1)); kfree(rcu_dereference_protected(inet->inet_opt, 1));
dst_release(rcu_dereference_protected(sk->sk_dst_cache, 1)); dst_release(rcu_dereference_protected(sk->sk_dst_cache, 1));
......
...@@ -271,7 +271,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk, ...@@ -271,7 +271,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
struct inet_diag_meminfo minfo = { struct inet_diag_meminfo minfo = {
.idiag_rmem = sk_rmem_alloc_get(sk), .idiag_rmem = sk_rmem_alloc_get(sk),
.idiag_wmem = READ_ONCE(sk->sk_wmem_queued), .idiag_wmem = READ_ONCE(sk->sk_wmem_queued),
.idiag_fmem = sk->sk_forward_alloc, .idiag_fmem = sk_forward_alloc_get(sk),
.idiag_tmem = sk_wmem_alloc_get(sk), .idiag_tmem = sk_wmem_alloc_get(sk),
}; };
......
This diff is collapsed.
...@@ -227,7 +227,7 @@ struct mptcp_sock { ...@@ -227,7 +227,7 @@ struct mptcp_sock {
u64 ack_seq; u64 ack_seq;
u64 rcv_wnd_sent; u64 rcv_wnd_sent;
u64 rcv_data_fin_seq; u64 rcv_data_fin_seq;
int wmem_reserved; int rmem_fwd_alloc;
struct sock *last_snd; struct sock *last_snd;
int snd_burst; int snd_burst;
int old_wspace; int old_wspace;
...@@ -272,19 +272,6 @@ struct mptcp_sock { ...@@ -272,19 +272,6 @@ struct mptcp_sock {
char ca_name[TCP_CA_NAME_MAX]; char ca_name[TCP_CA_NAME_MAX];
}; };
#define mptcp_lock_sock(___sk, cb) do { \
struct sock *__sk = (___sk); /* silence macro reuse warning */ \
might_sleep(); \
spin_lock_bh(&__sk->sk_lock.slock); \
if (__sk->sk_lock.owned) \
__lock_sock(__sk); \
cb; \
__sk->sk_lock.owned = 1; \
spin_unlock(&__sk->sk_lock.slock); \
mutex_acquire(&__sk->sk_lock.dep_map, 0, 0, _RET_IP_); \
local_bh_enable(); \
} while (0)
#define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock) #define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock)
#define mptcp_data_unlock(sk) spin_unlock_bh(&(sk)->sk_lock.slock) #define mptcp_data_unlock(sk) spin_unlock_bh(&(sk)->sk_lock.slock)
......
...@@ -457,7 +457,7 @@ META_COLLECTOR(int_sk_fwd_alloc) ...@@ -457,7 +457,7 @@ META_COLLECTOR(int_sk_fwd_alloc)
*err = -1; *err = -1;
return; return;
} }
dst->value = sk->sk_forward_alloc; dst->value = sk_forward_alloc_get(sk);
} }
META_COLLECTOR(int_sk_sndbuf) META_COLLECTOR(int_sk_sndbuf)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment