Skip to contentSkip to conversation

net: core: Use the bitmap API to allocate bitmaps

PATCH Superseded Andy Shevchenko 4 participants 11 messages Sep 11, 2023 – Sep 13, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#1 lore raw

PATCH 2/2 net: core: Sort headers alphabetically

In reply to Andy Shevchenko

It's rather a gigantic list of heards that is very hard to follow. Sorting helps to see what's already included and what's not. It improves a maintainability in a long term.

---
 net/core/dev.c | 135 +++++++++++++++++++++++++------------------------
 1 file changed, 69 insertions(+), 66 deletions(-)
net/core/dev.c +69 -66
index 85df22f05c38..d795a6c5a591 100644
@@ -68,91 +68,94 @@
  *				        - netif_rx() feedback
  */
 
-#include <linux/uaccess.h>
+#include <linux/audit.h>
 #include <linux/bitmap.h>
+#include <linux/bpf.h>
+#include <linux/bpf_trace.h>
 #include <linux/capability.h>
 #include <linux/cpu.h>
-#include <linux/types.h>
-#include <linux/kernel.h>
-#include <linux/hash.h>
-#include <linux/slab.h>
-#include <linux/sched.h>
-#include <linux/sched/mm.h>
-#include <linux/mutex.h>
-#include <linux/rwsem.h>
-#include <linux/string.h>
-#include <linux/mm.h>
-#include <linux/socket.h>
-#include <linux/sockios.h>
+#include <linux/cpu_rmap.h>
+#include <linux/crash_dump.h>
+#include <linux/ctype.h>
+#include <linux/delay.h>
+#include <linux/dmaengine.h>
+#include <linux/err.h>
 #include <linux/errno.h>
-#include <linux/interrupt.h>
-#include <linux/if_ether.h>
-#include <linux/netdevice.h>
+#include <linux/errqueue.h>
 #include <linux/etherdevice.h>
 #include <linux/ethtool.h>
-#include <linux/skbuff.h>
+#include <linux/hash.h>
+#include <linux/hashtable.h>
+#include <linux/highmem.h>
+#include <linux/hrtimer.h>
+#include <linux/if_arp.h>
+#include <linux/if_ether.h>
+#include <linux/if_macvlan.h>
+#include <linux/if_vlan.h>
+#include <linux/indirect_call_wrapper.h>
+#include <linux/inetdevice.h>
+#include <linux/in.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/jhash.h>
+#include <linux/kernel.h>
 #include <linux/kthread.h>
-#include <linux/bpf.h>
-#include <linux/bpf_trace.h>
-#include <net/net_namespace.h>
-#include <net/sock.h>
-#include <net/busy_poll.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/netdevice.h>
+#include <linux/netfilter_netdev.h>
+#include <linux/net_namespace.h>
+#include <linux/netpoll.h>
+#include <linux/once_lite.h>
+#include <linux/pm_runtime.h>
+#include <linux/prandom.h>
+#include <linux/random.h>
+#include <linux/rcupdate.h>
 #include <linux/rtnetlink.h>
+#include <linux/rwsem.h>
+#include <linux/sched.h>
+#include <linux/sched/mm.h>
+#include <linux/sctp.h>
+#include <linux/skbuff.h>
+#include <linux/slab.h>
+#include <linux/socket.h>
+#include <linux/sockios.h>
 #include <linux/stat.h>
+#include <linux/static_key.h>
+#include <linux/string.h>
+#include <linux/types.h>
+#include <linux/uaccess.h>
+#include <linux/vmalloc.h>
+
+#include <asm/current.h>
+
+#include <net/busy_poll.h>
+#include <net/checksum.h>
+#include <net/devlink.h>
 #include <net/dsa.h>
 #include <net/dst.h>
 #include <net/dst_metadata.h>
 #include <net/gro.h>
-#include <net/pkt_sched.h>
-#include <net/pkt_cls.h>
-#include <net/checksum.h>
-#include <net/xfrm.h>
-#include <net/tcx.h>
-#include <linux/highmem.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/netpoll.h>
-#include <linux/rcupdate.h>
-#include <linux/delay.h>
-#include <net/iw_handler.h>
-#include <asm/current.h>
-#include <linux/audit.h>
-#include <linux/dmaengine.h>
-#include <linux/err.h>
-#include <linux/ctype.h>
-#include <linux/if_arp.h>
-#include <linux/if_vlan.h>
-#include <linux/ip.h>
 #include <net/ip.h>
+#include <net/iw_handler.h>
 #include <net/mpls.h>
-#include <linux/ipv6.h>
-#include <linux/in.h>
-#include <linux/jhash.h>
-#include <linux/random.h>
+#include <net/netdev_rx_queue.h>
+#include <net/net_namespace.h>
+#include <net/pkt_cls.h>
+#include <net/pkt_sched.h>
+#include <net/sock.h>
+#include <net/tcx.h>
+#include <net/udp_tunnel.h>
+#include <net/xfrm.h>
+
 #include <trace/events/napi.h>
 #include <trace/events/net.h>
-#include <trace/events/skb.h>
 #include <trace/events/qdisc.h>
+#include <trace/events/skb.h>
 #include <trace/events/xdp.h>
-#include <linux/inetdevice.h>
-#include <linux/cpu_rmap.h>
-#include <linux/static_key.h>
-#include <linux/hashtable.h>
-#include <linux/vmalloc.h>
-#include <linux/if_macvlan.h>
-#include <linux/errqueue.h>
-#include <linux/hrtimer.h>
-#include <linux/netfilter_netdev.h>
-#include <linux/crash_dump.h>
-#include <linux/sctp.h>
-#include <net/udp_tunnel.h>
-#include <linux/net_namespace.h>
-#include <linux/indirect_call_wrapper.h>
-#include <net/devlink.h>
-#include <linux/pm_runtime.h>
-#include <linux/prandom.h>
-#include <linux/once_lite.h>
-#include <net/netdev_rx_queue.h>
 
 #include "dev.h"
 #include "net-sysfs.h"
Signature · 1 line
2.40.0.1.gaa8946217a0b
#0 lore raw

PATCH 1/2 net: core: Use the bitmap API to allocate bitmaps

Use bitmap_zalloc() and bitmap_free() instead of hand-writing them. It is less verbose and it improves the type checking and semantic.

While at it, add missing header inclusion (should be bitops.h, but with the above change it becomes bitmap.h).

---
 net/core/dev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/core/dev.c +3 -3
index ccff2b6ef958..85df22f05c38 100644
@@ -69,7 +69,7 @@
  */
 
 #include <linux/uaccess.h>
-#include <linux/bitops.h>
+#include <linux/bitmap.h>
 #include <linux/capability.h>
 #include <linux/cpu.h>
 #include <linux/types.h>
@@ -1080,7 +1080,7 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
 			return -EINVAL;
 
 		/* Use one page as a bit array of possible slots */
-		inuse = (unsigned long *) get_zeroed_page(GFP_ATOMIC);
+		inuse = bitmap_zalloc(max_netdevices, GFP_ATOMIC);
 		if (!inuse)
 			return -ENOMEM;
 
@@ -1109,7 +1109,7 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
 		}
 
 		i = find_first_zero_bit(inuse, max_netdevices);
-		free_page((unsigned long) inuse);
+		bitmap_free(inuse);
 	}
 
 	snprintf(buf, IFNAMSIZ, name, i);
Signature · 1 line
2.40.0.1.gaa8946217a0b
reviewer
#2 lore raw

Re: [PATCH net-next v1 2/2] net: core: Sort headers alphabetically

In reply to Andy Shevchenko
Quoted 5 lines · Andy Shevchenko

It's rather a gigantic list of heards that is very hard to follow. Sorting helps to see what's already included and what's not. It improves a maintainability in a long term.

Hi Andy,

At the risk of bike shedding, the sort function of Vim, when operating with the C locale, gives a slightly different order, as experssed by this incremental diff.

I have no objections to your oder, but I'm slightly curious as to how it came about.

net/core/dev.c +3 -3
index d795a6c5a591..770138babf7e 100644
@@ -92,9 +92,9 @@
 #include <linux/if_ether.h>
 #include <linux/if_macvlan.h>
 #include <linux/if_vlan.h>
+#include <linux/in.h>
 #include <linux/indirect_call_wrapper.h>
 #include <linux/inetdevice.h>
-#include <linux/in.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/ip.h>
@@ -105,9 +105,9 @@
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/net_namespace.h>
 #include <linux/netdevice.h>
 #include <linux/netfilter_netdev.h>
-#include <linux/net_namespace.h>
 #include <linux/netpoll.h>
 #include <linux/once_lite.h>
 #include <linux/pm_runtime.h>
@@ -142,8 +142,8 @@
 #include <net/ip.h>
 #include <net/iw_handler.h>
 #include <net/mpls.h>
-#include <net/netdev_rx_queue.h>
 #include <net/net_namespace.h>
+#include <net/netdev_rx_queue.h>
 #include <net/pkt_cls.h>
 #include <net/pkt_sched.h>
 #include <net/sock.h>
reviewer Reviewed-by on v1 1/2
#10 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

Use bitmap_zalloc() and bitmap_free() instead of hand-writing them. It is less verbose and it improves the type checking and semantic.

While at it, add missing header inclusion (should be bitops.h, but with the above change it becomes bitmap.h).

#3 lore raw

Re: [PATCH net-next v1 2/2] net: core: Sort headers alphabetically

In reply to Simon Horman
Quoted 7 lines · Simon Horman
Quoted 5 lines · Andy Shevchenko

It's rather a gigantic list of heards that is very hard to follow. Sorting helps to see what's already included and what's not. It improves a maintainability in a long term.

Quoted 8 lines

Hi Andy,

At the risk of bike shedding, the sort function of Vim, when operating with the C locale, gives a slightly different order, as experssed by this incremental diff.

I have no objections to your oder, but I'm slightly curious as to how it came about.

!sort which is external command.

$ locale -k LC_COLLATE
collate-nrules=4
collate-rulesets=""
collate-symb-hash-sizemb=1303
collate-codeset="UTF-8"
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw

Re: [PATCH net-next v1 2/2] net: core: Sort headers alphabetically

Quoted 17 lines · Andy Shevchenko
Quoted 7 lines · Simon Horman
Quoted 5 lines · Andy Shevchenko

It's rather a gigantic list of heards that is very hard to follow. Sorting helps to see what's already included and what's not. It improves a maintainability in a long term.

Quoted 8 lines

Hi Andy,

At the risk of bike shedding, the sort function of Vim, when operating with the C locale, gives a slightly different order, as experssed by this incremental diff.

I have no objections to your oder, but I'm slightly curious as to how it came about.

Quoted 7 lines

!sort which is external command.

$ locale -k LC_COLLATE
collate-nrules=4
collate-rulesets=""
collate-symb-hash-sizemb=1303
collate-codeset="UTF-8"

I'm unsure this change is worthy. It will make any later fix touching the header list more difficult to backport, and I don't see a great direct advantage.

Please repost the first patch standalone.

Thanks,

Paolo

#5 lore raw

Re: [PATCH net-next v1 2/2] net: core: Sort headers alphabetically

Quoted 26 lines · Paolo Abeni
Quoted 17 lines · Andy Shevchenko
Quoted 7 lines · Simon Horman
Quoted 5 lines · Andy Shevchenko

It's rather a gigantic list of heards that is very hard to follow. Sorting helps to see what's already included and what's not. It improves a maintainability in a long term.

Quoted 8 lines

Hi Andy,

At the risk of bike shedding, the sort function of Vim, when operating with the C locale, gives a slightly different order, as experssed by this incremental diff.

I have no objections to your oder, but I'm slightly curious as to how it came about.

Quoted 7 lines

!sort which is external command.

$ locale -k LC_COLLATE
collate-nrules=4
collate-rulesets=""
collate-symb-hash-sizemb=1303
collate-codeset="UTF-8"
Quoted 3 lines

I'm unsure this change is worthy. It will make any later fix touching the header list more difficult to backport, and I don't see a great direct advantage.

As Rasmus put it here
https://lore.kernel.org/lkml/[email protected]/
In short term you can argue that it's not beneficial, but in long term it's given less conflicts.

Quoted 1 line

Please repost the first patch standalone.

Why to repost, what did I miss? It's available via lore, just run

b4 am -slt -P _ [email protected]

to get it :-)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH net-next v1 2/2] net: core: Sort headers alphabetically

Quoted 28 lines · Andy Shevchenko
Quoted 26 lines · Paolo Abeni
Quoted 24 lines · Andy Shevchenko
Quoted 7 lines · Simon Horman
Quoted 5 lines · Andy Shevchenko

It's rather a gigantic list of heards that is very hard to follow. Sorting helps to see what's already included and what's not. It improves a maintainability in a long term.

Quoted 8 lines

Hi Andy,

At the risk of bike shedding, the sort function of Vim, when operating with the C locale, gives a slightly different order, as experssed by this incremental diff.

I have no objections to your oder, but I'm slightly curious as to how it came about.

!sort which is external command.

$ locale -k LC_COLLATE
collate-nrules=4
collate-rulesets=""
collate-symb-hash-sizemb=1303
collate-codeset="UTF-8"
Quoted 8 lines
Quoted 3 lines

I'm unsure this change is worthy. It will make any later fix touching the header list more difficult to backport, and I don't see a great direct advantage.

As Rasmus put it here
https://lore.kernel.org/lkml/[email protected]/
In short term you can argue that it's not beneficial, but in long term it's given less conflicts.

I agree with Paolo.

This is just code churn.
The includes will become unsorted eventually. Headers might get renamed, split, etc. Keeping things sorted is a headache.

#7 lore raw

Re: [PATCH net-next v1 2/2] net: core: Sort headers alphabetically

Quoted 6 lines · Alexei Starovoitov
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Paolo Abeni
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Simon Horman

On Mon, Sep 11, 2023 at 06:45:34PM +0300, Andy Shevchenko wrote:

...

Quoted 10 lines
Quoted 8 lines
Quoted 3 lines

I'm unsure this change is worthy. It will make any later fix touching the header list more difficult to backport, and I don't see a great direct advantage.

As Rasmus put it here
https://lore.kernel.org/lkml/[email protected]/
In short term you can argue that it's not beneficial, but in long term it's given less conflicts.

I agree with Paolo.

I see.

Quoted 4 lines

This is just code churn.
The includes will become unsorted eventually. Headers might get renamed, split, etc. Keeping things sorted is a headache.

Keeping the mess is simpler, I agree. :-(

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#8 lore raw

Re: [PATCH net-next v1 2/2] net: core: Sort headers alphabetically

In reply to Andy Shevchenko
Quoted 36 lines · Andy Shevchenko
Quoted 26 lines · Paolo Abeni
Quoted 17 lines · Andy Shevchenko
Quoted 7 lines · Simon Horman
Quoted 5 lines · Andy Shevchenko

It's rather a gigantic list of heards that is very hard to follow. Sorting helps to see what's already included and what's not. It improves a maintainability in a long term.

Quoted 8 lines

Hi Andy,

At the risk of bike shedding, the sort function of Vim, when operating with the C locale, gives a slightly different order, as experssed by this incremental diff.

I have no objections to your oder, but I'm slightly curious as to how it came about.

Quoted 7 lines

!sort which is external command.

$ locale -k LC_COLLATE
collate-nrules=4
collate-rulesets=""
collate-symb-hash-sizemb=1303
collate-codeset="UTF-8"
Quoted 3 lines

I'm unsure this change is worthy. It will make any later fix touching the header list more difficult to backport, and I don't see a great direct advantage.

As Rasmus put it here
https://lore.kernel.org/lkml/[email protected]/
In short term you can argue that it's not beneficial, but in long term it's given less conflicts.

Quoted 7 lines
Quoted 1 line

Please repost the first patch standalone.

Why to repost, what did I miss? It's available via lore, just run

b4 am -slt -P _ [email protected]

to get it :-)

It's fairly better if actions (changes) on patches are taken by the
submitter: it scales way better, and if the other path take places we can be easily flooded with small (but likely increasingly less smaller) requests that will soon prevent any other activity from being taken.

Please, repost the single patch, it would be easier to me.

Thanks!

Paolo

#9 lore raw

Re: [PATCH net-next v1 2/2] net: core: Sort headers alphabetically

Quoted 3 lines · Paolo Abeni
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Paolo Abeni

On Tue, 2023-09-12 at 19:35 +0300, Andy Shevchenko wrote:

...

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

Please repost the first patch standalone.

Why to repost, what did I miss? It's available via lore, just run

b4 am -slt -P _ [email protected]

Quoted 8 lines
Quoted 1 line

to get it :-)

It's fairly better if actions (changes) on patches are taken by the
submitter: it scales way better, and if the other path take places we can be easily flooded with small (but likely increasingly less smaller) requests that will soon prevent any other activity from being taken.

Please, repost the single patch, it would be easier to me.

Done.

Signature · 2 lines
With Best Regards,
Andy Shevchenko