Message ID | 20230726142029.2867663-2-liujian56@huawei.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | fix rmem incorrect accounting in bpf_tcp_ingress() | expand |
On Wed, Jul 26, 2023 at 4:15 PM Liu Jian <liujian56@huawei.com> wrote: > > Compared with sk_wmem_schedule(), sk_rmem_schedule() not only performs > rmem accounting, but also checks skb_pfmemalloc. The __sk_rmem_schedule() > helper function is introduced here to perform only rmem accounting related > activities. > Why not care about pfmemalloc ? Why is it safe ? You need to give more details, or simply reuse the existing helper. > Signed-off-by: Liu Jian <liujian56@huawei.com> > --- > include/net/sock.h | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/include/net/sock.h b/include/net/sock.h > index 2eb916d1ff64..58bf26c5c041 100644 > --- a/include/net/sock.h > +++ b/include/net/sock.h > @@ -1617,16 +1617,20 @@ static inline bool sk_wmem_schedule(struct sock *sk, int size) > return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_SEND); > } > > -static inline bool > -sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size) > +static inline bool __sk_rmem_schedule(struct sock *sk, int size) > { > int delta; > > if (!sk_has_account(sk)) > return true; > delta = size - sk->sk_forward_alloc; > - return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV) || > - skb_pfmemalloc(skb); > + return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV); > +} > + > +static inline bool > +sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size) > +{ > + return __sk_rmem_schedule(sk, size) || skb_pfmemalloc(skb); > } > > static inline int sk_unused_reserved_mem(const struct sock *sk) > -- > 2.34.1 >
Eric Dumazet wrote: > On Wed, Jul 26, 2023 at 4:15 PM Liu Jian <liujian56@huawei.com> wrote: > > > > Compared with sk_wmem_schedule(), sk_rmem_schedule() not only performs > > rmem accounting, but also checks skb_pfmemalloc. The __sk_rmem_schedule() > > helper function is introduced here to perform only rmem accounting related > > activities. > > > > Why not care about pfmemalloc ? Why is it safe ? > > You need to give more details, or simply reuse the existing helper. I would just use the existing helper. Seems it should be fine. > > > Signed-off-by: Liu Jian <liujian56@huawei.com> > > --- > > include/net/sock.h | 12 ++++++++---- > > 1 file changed, 8 insertions(+), 4 deletions(-) > > > > diff --git a/include/net/sock.h b/include/net/sock.h > > index 2eb916d1ff64..58bf26c5c041 100644 > > --- a/include/net/sock.h > > +++ b/include/net/sock.h > > @@ -1617,16 +1617,20 @@ static inline bool sk_wmem_schedule(struct sock *sk, int size) > > return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_SEND); > > } > > > > -static inline bool > > -sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size) > > +static inline bool __sk_rmem_schedule(struct sock *sk, int size) > > { > > int delta; > > > > if (!sk_has_account(sk)) > > return true; > > delta = size - sk->sk_forward_alloc; > > - return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV) || > > - skb_pfmemalloc(skb); > > + return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV); > > +} > > + > > +static inline bool > > +sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size) > > +{ > > + return __sk_rmem_schedule(sk, size) || skb_pfmemalloc(skb); > > } > > > > static inline int sk_unused_reserved_mem(const struct sock *sk) > > -- > > 2.34.1 > >
On 2023/7/28 3:16, John Fastabend wrote: > Eric Dumazet wrote: >> On Wed, Jul 26, 2023 at 4:15 PM Liu Jian <liujian56@huawei.com> wrote: >>> >>> Compared with sk_wmem_schedule(), sk_rmem_schedule() not only performs >>> rmem accounting, but also checks skb_pfmemalloc. The __sk_rmem_schedule() >>> helper function is introduced here to perform only rmem accounting related >>> activities. >>> >> >> Why not care about pfmemalloc ? Why is it safe ? >> >> You need to give more details, or simply reuse the existing helper. I didn't think so much. I extracted this helper just to do rmem accounting in bpf_tcp_ingress(), because I didn't see the pfmemalloc flag set when alloc sk_msg in sk_msg_alloc(). And thanks for your review. > > I would just use the existing helper. Seems it should be fine. ok, let's just leave it as it is. Thanks John. > >> >>> Signed-off-by: Liu Jian <liujian56@huawei.com> >>> --- >>> include/net/sock.h | 12 ++++++++---- >>> 1 file changed, 8 insertions(+), 4 deletions(-) >>> >>> diff --git a/include/net/sock.h b/include/net/sock.h >>> index 2eb916d1ff64..58bf26c5c041 100644 >>> --- a/include/net/sock.h >>> +++ b/include/net/sock.h >>> @@ -1617,16 +1617,20 @@ static inline bool sk_wmem_schedule(struct sock *sk, int size) >>> return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_SEND); >>> } >>> >>> -static inline bool >>> -sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size) >>> +static inline bool __sk_rmem_schedule(struct sock *sk, int size) >>> { >>> int delta; >>> >>> if (!sk_has_account(sk)) >>> return true; >>> delta = size - sk->sk_forward_alloc; >>> - return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV) || >>> - skb_pfmemalloc(skb); >>> + return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV); >>> +} >>> + >>> +static inline bool >>> +sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size) >>> +{ >>> + return __sk_rmem_schedule(sk, size) || skb_pfmemalloc(skb); >>> } >>> >>> static inline int sk_unused_reserved_mem(const struct sock *sk) >>> -- >>> 2.34.1 >>> > >
diff --git a/include/net/sock.h b/include/net/sock.h index 2eb916d1ff64..58bf26c5c041 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1617,16 +1617,20 @@ static inline bool sk_wmem_schedule(struct sock *sk, int size) return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_SEND); } -static inline bool -sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size) +static inline bool __sk_rmem_schedule(struct sock *sk, int size) { int delta; if (!sk_has_account(sk)) return true; delta = size - sk->sk_forward_alloc; - return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV) || - skb_pfmemalloc(skb); + return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV); +} + +static inline bool +sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size) +{ + return __sk_rmem_schedule(sk, size) || skb_pfmemalloc(skb); } static inline int sk_unused_reserved_mem(const struct sock *sk)
Compared with sk_wmem_schedule(), sk_rmem_schedule() not only performs rmem accounting, but also checks skb_pfmemalloc. The __sk_rmem_schedule() helper function is introduced here to perform only rmem accounting related activities. Signed-off-by: Liu Jian <liujian56@huawei.com> --- include/net/sock.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)