Commit fb7328f
bpf: Introduce SK_BPF_MEMCG_FLAGS and SK_BPF_MEMCG_SOCK_ISOLATED.
We will decouple sockets from the global protocol memory accounting
if sockets have SK_BPF_MEMCG_SOCK_ISOLATED.
This can be flagged (and cleared) at the BPF_CGROUP_INET_SOCK_CREATE
hook by bpf_setsockopt() and is inherited to child sockets.
u32 flags = SK_BPF_MEMCG_SOCK_ISOLATED;
bpf_setsockopt(ctx, SOL_SOCKET, SK_BPF_MEMCG_FLAGS,
&flags, sizeof(flags));
SK_BPF_MEMCG_FLAGS is only supported at BPF_CGROUP_INET_SOCK_CREATE
and not supported on other hooks for some reasons:
1. UDP charges memory under sk->sk_receive_queue.lock instead
of lock_sock()
2. For TCP child sockets, memory accounting is adjusted only in
__inet_accept() which sk->sk_memcg allocation is deferred to
3. Modifying the flag after skb is charged to sk requires such
adjustment during bpf_setsockopt() and complicates the logic
unnecessarily
We can support other hooks later if a real use case justifies that.
Given sk->sk_memcg can be accessed in the fast path, it would
be preferable to place the flag field in the same cache line as
sk->sk_memcg.
However, struct sock does not have such a 1-byte hole.
Let's store the flag in the lowest bit of sk->sk_memcg and add
a helper to check the bit.
In the next patch, if mem_cgroup_sk_isolated() returns true,
the socket will not be charged to sk->sk_prot->memory_allocated.
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>1 parent 79910e9 commit fb7328f
6 files changed
+101
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2596 | 2596 | | |
2597 | 2597 | | |
2598 | 2598 | | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
2599 | 2602 | | |
2600 | 2603 | | |
2601 | 2604 | | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
2602 | 2611 | | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
| 2631 | + | |
| 2632 | + | |
| 2633 | + | |
2603 | 2634 | | |
2604 | 2635 | | |
2605 | 2636 | | |
2606 | 2637 | | |
2607 | 2638 | | |
2608 | 2639 | | |
2609 | 2640 | | |
| 2641 | + | |
| 2642 | + | |
| 2643 | + | |
| 2644 | + | |
| 2645 | + | |
2610 | 2646 | | |
2611 | 2647 | | |
2612 | 2648 | | |
| |||
2629 | 2665 | | |
2630 | 2666 | | |
2631 | 2667 | | |
| 2668 | + | |
| 2669 | + | |
| 2670 | + | |
| 2671 | + | |
| 2672 | + | |
| 2673 | + | |
| 2674 | + | |
| 2675 | + | |
| 2676 | + | |
2632 | 2677 | | |
2633 | 2678 | | |
2634 | 2679 | | |
2635 | 2680 | | |
2636 | 2681 | | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
| 2685 | + | |
| 2686 | + | |
2637 | 2687 | | |
2638 | 2688 | | |
2639 | 2689 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7182 | 7182 | | |
7183 | 7183 | | |
7184 | 7184 | | |
| 7185 | + | |
7185 | 7186 | | |
7186 | 7187 | | |
7187 | 7188 | | |
| |||
7204 | 7205 | | |
7205 | 7206 | | |
7206 | 7207 | | |
| 7208 | + | |
| 7209 | + | |
| 7210 | + | |
| 7211 | + | |
| 7212 | + | |
7207 | 7213 | | |
7208 | 7214 | | |
7209 | 7215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5723 | 5723 | | |
5724 | 5724 | | |
5725 | 5725 | | |
| 5726 | + | |
| 5727 | + | |
| 5728 | + | |
| 5729 | + | |
| 5730 | + | |
| 5731 | + | |
| 5732 | + | |
| 5733 | + | |
| 5734 | + | |
| 5735 | + | |
| 5736 | + | |
| 5737 | + | |
| 5738 | + | |
| 5739 | + | |
| 5740 | + | |
| 5741 | + | |
| 5742 | + | |
| 5743 | + | |
| 5744 | + | |
| 5745 | + | |
| 5746 | + | |
| 5747 | + | |
| 5748 | + | |
| 5749 | + | |
| 5750 | + | |
| 5751 | + | |
5726 | 5752 | | |
5727 | 5753 | | |
5728 | 5754 | | |
| 5755 | + | |
| 5756 | + | |
| 5757 | + | |
| 5758 | + | |
5729 | 5759 | | |
5730 | 5760 | | |
5731 | 5761 | | |
| |||
5743 | 5773 | | |
5744 | 5774 | | |
5745 | 5775 | | |
| 5776 | + | |
| 5777 | + | |
| 5778 | + | |
| 5779 | + | |
5746 | 5780 | | |
5747 | 5781 | | |
5748 | 5782 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2515 | 2515 | | |
2516 | 2516 | | |
2517 | 2517 | | |
| 2518 | + | |
2518 | 2519 | | |
2519 | 2520 | | |
2520 | 2521 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
758 | 758 | | |
759 | 759 | | |
760 | 760 | | |
| 761 | + | |
761 | 762 | | |
| 763 | + | |
762 | 764 | | |
763 | 765 | | |
764 | 766 | | |
765 | 767 | | |
766 | 768 | | |
| 769 | + | |
| 770 | + | |
767 | 771 | | |
768 | 772 | | |
769 | 773 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7182 | 7182 | | |
7183 | 7183 | | |
7184 | 7184 | | |
| 7185 | + | |
7185 | 7186 | | |
7186 | 7187 | | |
7187 | 7188 | | |
| |||
7204 | 7205 | | |
7205 | 7206 | | |
7206 | 7207 | | |
| 7208 | + | |
| 7209 | + | |
| 7210 | + | |
| 7211 | + | |
| 7212 | + | |
7207 | 7213 | | |
7208 | 7214 | | |
7209 | 7215 | | |
| |||
0 commit comments