Commit 890e519
can: raw: use bitfields to store flags in struct raw_sock
The bound, loopback, recv_own_msgs, fd_frames, xl_frames and
join_filters fields of struct raw_sock just need to store one bit of
information.
Declare all those members as a bitfields of type unsigned int and
width one bit.
Add a temporary variable to raw_setsockopt() and raw_getsockopt() to
make the conversion between the stored bits and the socket interface.
This reduces the size of struct raw_sock by sixteen bytes.
Statistics before:
$ pahole --class_name=raw_sock net/can/raw.o
struct raw_sock {
struct sock sk __attribute__((__aligned__(8))); /* 0 776 */
/* XXX last struct has 1 bit hole */
/* --- cacheline 12 boundary (768 bytes) was 8 bytes ago --- */
int bound; /* 776 4 */
int ifindex; /* 780 4 */
struct net_device * dev; /* 784 8 */
netdevice_tracker dev_tracker; /* 792 0 */
struct list_head notifier; /* 792 16 */
int loopback; /* 808 4 */
int recv_own_msgs; /* 812 4 */
int fd_frames; /* 816 4 */
int xl_frames; /* 820 4 */
struct can_raw_vcid_options raw_vcid_opts; /* 824 4 */
canid_t tx_vcid_shifted; /* 828 4 */
/* --- cacheline 13 boundary (832 bytes) --- */
canid_t rx_vcid_shifted; /* 832 4 */
canid_t rx_vcid_mask_shifted; /* 836 4 */
int join_filters; /* 840 4 */
int count; /* 844 4 */
struct can_filter dfilter; /* 848 8 */
struct can_filter * filter; /* 856 8 */
can_err_mask_t err_mask; /* 864 4 */
/* XXX 4 bytes hole, try to pack */
struct uniqframe * uniq; /* 872 8 */
/* size: 880, cachelines: 14, members: 20 */
/* sum members: 876, holes: 1, sum holes: 4 */
/* member types with bit holes: 1, total: 1 */
/* forced alignments: 1 */
/* last cacheline: 48 bytes */
} __attribute__((__aligned__(8)));
...and after:
$ pahole --class_name=raw_sock net/can/raw.o
struct raw_sock {
struct sock sk __attribute__((__aligned__(8))); /* 0 776 */
/* XXX last struct has 1 bit hole */
/* --- cacheline 12 boundary (768 bytes) was 8 bytes ago --- */
int ifindex; /* 776 4 */
/* XXX 4 bytes hole, try to pack */
struct net_device * dev; /* 784 8 */
netdevice_tracker dev_tracker; /* 792 0 */
struct list_head notifier; /* 792 16 */
unsigned int bound:1; /* 808: 0 4 */
unsigned int loopback:1; /* 808: 1 4 */
unsigned int recv_own_msgs:1; /* 808: 2 4 */
unsigned int fd_frames:1; /* 808: 3 4 */
unsigned int xl_frames:1; /* 808: 4 4 */
unsigned int join_filters:1; /* 808: 5 4 */
/* XXX 2 bits hole, try to pack */
/* Bitfield combined with next fields */
struct can_raw_vcid_options raw_vcid_opts; /* 809 4 */
/* XXX 3 bytes hole, try to pack */
canid_t tx_vcid_shifted; /* 816 4 */
canid_t rx_vcid_shifted; /* 820 4 */
canid_t rx_vcid_mask_shifted; /* 824 4 */
int count; /* 828 4 */
/* --- cacheline 13 boundary (832 bytes) --- */
struct can_filter dfilter; /* 832 8 */
struct can_filter * filter; /* 840 8 */
can_err_mask_t err_mask; /* 848 4 */
/* XXX 4 bytes hole, try to pack */
struct uniqframe * uniq; /* 856 8 */
/* size: 864, cachelines: 14, members: 20 */
/* sum members: 852, holes: 3, sum holes: 11 */
/* sum bitfield members: 6 bits, bit holes: 1, sum bit holes: 2 bits */
/* member types with bit holes: 1, total: 1 */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20250917-can-raw-repack-v2-2-395e8b3a4437@kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>1 parent fc8418e commit 890e519
1 file changed
+35
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
86 | 85 | | |
87 | 86 | | |
88 | 87 | | |
89 | 88 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | | - | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| |||
560 | 560 | | |
561 | 561 | | |
562 | 562 | | |
563 | | - | |
564 | 563 | | |
| 564 | + | |
565 | 565 | | |
566 | 566 | | |
567 | 567 | | |
| |||
682 | 682 | | |
683 | 683 | | |
684 | 684 | | |
685 | | - | |
| 685 | + | |
686 | 686 | | |
687 | 687 | | |
688 | | - | |
| 688 | + | |
689 | 689 | | |
690 | 690 | | |
| 691 | + | |
691 | 692 | | |
692 | 693 | | |
693 | 694 | | |
694 | | - | |
| 695 | + | |
695 | 696 | | |
696 | 697 | | |
697 | | - | |
| 698 | + | |
698 | 699 | | |
699 | 700 | | |
| 701 | + | |
700 | 702 | | |
701 | 703 | | |
702 | 704 | | |
703 | | - | |
| 705 | + | |
704 | 706 | | |
705 | 707 | | |
706 | | - | |
| 708 | + | |
707 | 709 | | |
708 | 710 | | |
709 | 711 | | |
710 | | - | |
| 712 | + | |
711 | 713 | | |
712 | 714 | | |
713 | | - | |
| 715 | + | |
714 | 716 | | |
715 | 717 | | |
716 | 718 | | |
717 | | - | |
| 719 | + | |
718 | 720 | | |
719 | 721 | | |
720 | | - | |
| 722 | + | |
721 | 723 | | |
722 | 724 | | |
| 725 | + | |
| 726 | + | |
723 | 727 | | |
724 | 728 | | |
725 | 729 | | |
| |||
739 | 743 | | |
740 | 744 | | |
741 | 745 | | |
742 | | - | |
| 746 | + | |
743 | 747 | | |
744 | 748 | | |
745 | | - | |
| 749 | + | |
746 | 750 | | |
747 | 751 | | |
| 752 | + | |
748 | 753 | | |
749 | 754 | | |
750 | 755 | | |
| |||
758 | 763 | | |
759 | 764 | | |
760 | 765 | | |
| 766 | + | |
761 | 767 | | |
762 | 768 | | |
763 | 769 | | |
| |||
806 | 812 | | |
807 | 813 | | |
808 | 814 | | |
809 | | - | |
| 815 | + | |
| 816 | + | |
810 | 817 | | |
811 | 818 | | |
812 | 819 | | |
813 | 820 | | |
814 | 821 | | |
815 | | - | |
| 822 | + | |
| 823 | + | |
816 | 824 | | |
817 | 825 | | |
818 | 826 | | |
819 | 827 | | |
820 | 828 | | |
821 | | - | |
| 829 | + | |
| 830 | + | |
822 | 831 | | |
823 | 832 | | |
824 | 833 | | |
825 | 834 | | |
826 | 835 | | |
827 | | - | |
| 836 | + | |
| 837 | + | |
828 | 838 | | |
829 | 839 | | |
830 | 840 | | |
| |||
849 | 859 | | |
850 | 860 | | |
851 | 861 | | |
852 | | - | |
| 862 | + | |
| 863 | + | |
853 | 864 | | |
854 | 865 | | |
855 | 866 | | |
| |||
0 commit comments