tc: use ll_init_map() only when needed
Subsystems (2)
PATCH 1/1 tc: use ll_init_map() only when needed
Some setups can have thousands of devices.
ll_init_map() is rather expensive for them.
Only call ll_init_map() in the following cases:
1) tc runs in batch mode.
2) tc runs in monitor mode.
3) tc dumps qdiscs/classes/filters for all netdev.
This greatly reduces RTNL pressure on common operations.
--- tc/f_route.c | 1 - tc/m_mirred.c | 2 -- tc/tc.c | 1 + tc/tc_class.c | 6 ++---- tc/tc_filter.c | 32 ++++++++++++++++---------------- tc/tc_qdisc.c | 5 ++--- 6 files changed, 21 insertions(+), 26 deletions(-)
tc/f_route.c +0 -1
@@ -76,7 +76,6 @@ static int route_parse_opt(const struct filter_util *qu, char *handle, int argc,__u32 id;NEXT_ARG (); -ll_init_map (&rth);if ((id =ll_name_to_index (*argv)) <=0 ) {fprintf (stderr,"Illegal \"fromif\"\n" );return -1 ;
tc/m_mirred.c +0 -2
@@ -213,8 +213,6 @@ parse_direction(const struct action_util *a, int *argc_p, char ***argv_p,if (d[0 ]) {int idx; -ll_init_map (&rth); - idx =ll_name_to_index (d);if (!idx)return nodev (d);
tc/tc.c +1 -0
@@ -243,6 +243,7 @@ static int batch(const char *name)return -1 ; } +ll_init_map (&rth); ret =do_batch (name, force, tc_batch_cmd,NULL );rtnl_close (&rth);
tc/tc_class.c +2 -4
@@ -136,11 +136,11 @@ static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv) }if (d[0 ]) { -ll_init_map (&rth); - req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d); + }else { +ll_init_map (&rth); }if (rtnl_talk (&rth, &req.n,NULL ) <0 )
@@ -437,8 +437,6 @@ static int tc_class_list(int argc, char **argv) argc--; argv++; } -ll_init_map (&rth); -if (d[0 ]) { t.tcm_ifindex =ll_name_to_index (d);if (!t.tcm_ifindex)
tc/tc_filter.c +16 -16
@@ -188,16 +188,17 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)addattr_l (&req.n,sizeof (req),TCA_KIND , k,strlen (k)+1 );if (d[0 ]) { -ll_init_map (&rth); - req.t.tcm_ifindex =ll_name_to_index (d);if (req.t.tcm_ifindex ==0 ) {fprintf (stderr,"Cannot find device \"%s\"\n" , d);return 1 ; } - }else if (block_index) { - req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; - req.t.tcm_block_index = block_index; + }else { +ll_init_map (&rth); +if (block_index) { + req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; + req.t.tcm_block_index = block_index; + } }if (q) {
@@ -539,8 +540,6 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv) }if (d[0 ]) { -ll_init_map (&rth); - req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d);
@@ -704,21 +703,22 @@ static int tc_filter_list(int cmd, int argc, char **argv) req.t.tcm_info =TC_H_MAKE (prio<<16 , protocol); -ll_init_map (&rth); -if (d[0 ]) { req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d); filter_ifindex = req.t.tcm_ifindex; - }else if (block_index) { -if (!tc_qdisc_block_exists (block_index)) { -fprintf (stderr,"Cannot find block \"%u\"\n" , block_index); -return 1 ; + }else { +ll_init_map (&rth); +if (block_index) { +if (!tc_qdisc_block_exists (block_index)) { +fprintf (stderr,"Cannot find block \"%u\"\n" , block_index); +return 1 ; + } + req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; + req.t.tcm_block_index = block_index; + filter_block_index = block_index; } - req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; - req.t.tcm_block_index = block_index; - filter_block_index = block_index; }if (filter_chain_index_set)
tc/tc_qdisc.c +2 -3
@@ -193,8 +193,6 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)if (d[0 ]) {int idx; -ll_init_map (&rth); - idx =ll_name_to_index (d);if (!idx)return -nodev (d);
@@ -411,13 +409,14 @@ static int tc_qdisc_list(int argc, char **argv) argc--; argv++; } -ll_init_map (&rth);if (d[0 ]) { req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d); filter_ifindex = req.t.tcm_ifindex; + }else { +ll_init_map (&rth); }if (dump_invisible) {
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Jamal: waiting for your review ...
Quoted 183 lines · Eric Dumazet
Some setups can have thousands of devices.
ll_init_map()is rather expensive for them.Only call
ll_init_map()in the following cases:1) tc runs in batch mode.
2) tc runs in monitor mode.
3) tc dumps qdiscs/classes/filters for all netdev.This greatly reduces RTNL pressure on common operations.
Signed-off-by Eric Dumazet <[email protected]>--- tc/f_route.c | 1 - tc/m_mirred.c | 2 -- tc/tc.c | 1 + tc/tc_class.c | 6 ++---- tc/tc_filter.c | 32 ++++++++++++++++---------------- tc/tc_qdisc.c | 5 ++--- 6 files changed, 21 insertions(+), 26 deletions(-)tc/f_route.c +0
-1@@ -76,7 +76,6 @@ static int route_parse_opt(const struct filter_util *qu, char *handle, int argc,__u32 id;NEXT_ARG (); -ll_init_map (&rth);if ((id =ll_name_to_index (*argv)) <=0 ) {fprintf (stderr,"Illegal \"fromif\"\n" );return -1 ;tc/m_mirred.c +0
-2@@ -213,8 +213,6 @@ parse_direction(const struct action_util *a, int *argc_p, char ***argv_p,if (d[0 ]) {int idx; -ll_init_map (&rth); - idx =ll_name_to_index (d);if (!idx)return nodev (d);tc/tc.c +1
-0@@ -243,6 +243,7 @@ static int batch(const char *name)return -1 ; } +ll_init_map (&rth); ret =do_batch (name, force, tc_batch_cmd,NULL );rtnl_close (&rth);tc/tc_class.c +2
-4@@ -136,11 +136,11 @@ static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv) }if (d[0 ]) { -ll_init_map (&rth); - req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d); + }else { +ll_init_map (&rth); }if (rtnl_talk (&rth, &req.n,NULL ) <0 )@@ -437,8 +437,6 @@ static int tc_class_list(int argc, char **argv) argc--; argv++; } -ll_init_map (&rth); -if (d[0 ]) { t.tcm_ifindex =ll_name_to_index (d);if (!t.tcm_ifindex)tc/tc_filter.c +16
-16@@ -188,16 +188,17 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)addattr_l (&req.n,sizeof (req),TCA_KIND , k,strlen (k)+1 );if (d[0 ]) { -ll_init_map (&rth); - req.t.tcm_ifindex =ll_name_to_index (d);if (req.t.tcm_ifindex ==0 ) {fprintf (stderr,"Cannot find device \"%s\"\n" , d);return 1 ; } - }else if (block_index) { - req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; - req.t.tcm_block_index = block_index; + }else { +ll_init_map (&rth); +if (block_index) { + req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; + req.t.tcm_block_index = block_index; + } }if (q) {@@ -539,8 +540,6 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv) }if (d[0 ]) { -ll_init_map (&rth); - req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d);@@ -704,21 +703,22 @@ static int tc_filter_list(int cmd, int argc, char **argv) req.t.tcm_info =TC_H_MAKE (prio<<16 , protocol); -ll_init_map (&rth); -if (d[0 ]) { req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d); filter_ifindex = req.t.tcm_ifindex; - }else if (block_index) { -if (!tc_qdisc_block_exists (block_index)) { -fprintf (stderr,"Cannot find block \"%u\"\n" , block_index); -return 1 ; + }else { +ll_init_map (&rth); +if (block_index) { +if (!tc_qdisc_block_exists (block_index)) { +fprintf (stderr,"Cannot find block \"%u\"\n" , block_index); +return 1 ; + } + req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; + req.t.tcm_block_index = block_index; + filter_block_index = block_index; } - req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; - req.t.tcm_block_index = block_index; - filter_block_index = block_index; }if (filter_chain_index_set)tc/tc_qdisc.c +2
-3@@ -193,8 +193,6 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)if (d[0 ]) {int idx; -ll_init_map (&rth); - idx =ll_name_to_index (d);if (!idx)return -nodev (d);@@ -411,13 +409,14 @@ static int tc_qdisc_list(int argc, char **argv) argc--; argv++; } -ll_init_map (&rth);if (d[0 ]) { req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d); filter_ifindex = req.t.tcm_ifindex; + }else { +ll_init_map (&rth); }if (dump_invisible) {
Quoted 3 lines · David Ahern
Jamal: waiting for your review ...
Looks good - running tdc on it to make sure nothing breaks...
cheers,
jamal
Quoted 185 lines · Eric Dumazet
Quoted 183 lines
Some setups can have thousands of devices.
ll_init_map()is rather expensive for them.Only call
ll_init_map()in the following cases:1) tc runs in batch mode.
2) tc runs in monitor mode.
3) tc dumps qdiscs/classes/filters for all netdev.This greatly reduces RTNL pressure on common operations.
Signed-off-by Eric Dumazet <[email protected]>--- tc/f_route.c | 1 - tc/m_mirred.c | 2 -- tc/tc.c | 1 + tc/tc_class.c | 6 ++---- tc/tc_filter.c | 32 ++++++++++++++++---------------- tc/tc_qdisc.c | 5 ++--- 6 files changed, 21 insertions(+), 26 deletions(-)tc/f_route.c +0
-1@@ -76,7 +76,6 @@ static int route_parse_opt(const struct filter_util *qu, char *handle, int argc,__u32 id;NEXT_ARG (); -ll_init_map (&rth);if ((id =ll_name_to_index (*argv)) <=0 ) {fprintf (stderr,"Illegal \"fromif\"\n" );return -1 ;tc/m_mirred.c +0
-2@@ -213,8 +213,6 @@ parse_direction(const struct action_util *a, int *argc_p, char ***argv_p,if (d[0 ]) {int idx; -ll_init_map (&rth); - idx =ll_name_to_index (d);if (!idx)return nodev (d);tc/tc.c +1
-0@@ -243,6 +243,7 @@ static int batch(const char *name)return -1 ; } +ll_init_map (&rth); ret =do_batch (name, force, tc_batch_cmd,NULL );rtnl_close (&rth);tc/tc_class.c +2
-4@@ -136,11 +136,11 @@ static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv) }if (d[0 ]) { -ll_init_map (&rth); - req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d); + }else { +ll_init_map (&rth); }if (rtnl_talk (&rth, &req.n,NULL ) <0 )@@ -437,8 +437,6 @@ static int tc_class_list(int argc, char **argv) argc--; argv++; } -ll_init_map (&rth); -if (d[0 ]) { t.tcm_ifindex =ll_name_to_index (d);if (!t.tcm_ifindex)tc/tc_filter.c +16
-16@@ -188,16 +188,17 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)addattr_l (&req.n,sizeof (req),TCA_KIND , k,strlen (k)+1 );if (d[0 ]) { -ll_init_map (&rth); - req.t.tcm_ifindex =ll_name_to_index (d);if (req.t.tcm_ifindex ==0 ) {fprintf (stderr,"Cannot find device \"%s\"\n" , d);return 1 ; } - }else if (block_index) { - req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; - req.t.tcm_block_index = block_index; + }else { +ll_init_map (&rth); +if (block_index) { + req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; + req.t.tcm_block_index = block_index; + } }if (q) {@@ -539,8 +540,6 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv) }if (d[0 ]) { -ll_init_map (&rth); - req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d);@@ -704,21 +703,22 @@ static int tc_filter_list(int cmd, int argc, char **argv) req.t.tcm_info =TC_H_MAKE (prio<<16 , protocol); -ll_init_map (&rth); -if (d[0 ]) { req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d); filter_ifindex = req.t.tcm_ifindex; - }else if (block_index) { -if (!tc_qdisc_block_exists (block_index)) { -fprintf (stderr,"Cannot find block \"%u\"\n" , block_index); -return 1 ; + }else { +ll_init_map (&rth); +if (block_index) { +if (!tc_qdisc_block_exists (block_index)) { +fprintf (stderr,"Cannot find block \"%u\"\n" , block_index); +return 1 ; + } + req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; + req.t.tcm_block_index = block_index; + filter_block_index = block_index; } - req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; - req.t.tcm_block_index = block_index; - filter_block_index = block_index; }if (filter_chain_index_set)tc/tc_qdisc.c +2
-3@@ -193,8 +193,6 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)if (d[0 ]) {int idx; -ll_init_map (&rth); - idx =ll_name_to_index (d);if (!idx)return -nodev (d);@@ -411,13 +409,14 @@ static int tc_qdisc_list(int argc, char **argv) argc--; argv++; } -ll_init_map (&rth);if (d[0 ]) { req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d); filter_ifindex = req.t.tcm_ifindex; + }else { +ll_init_map (&rth); }if (dump_invisible) {
Jamal Hadi Salim
Acked-byQuoted 17 lines · David Ahern
Jamal: waiting for your review ...
Quoted 13 lines · Eric Dumazet
Some setups can have thousands of devices.
ll_init_map()is rather expensive for them.Only call
ll_init_map()in the following cases:1) tc runs in batch mode.
2) tc runs in monitor mode.
3) tc dumps qdiscs/classes/filters for all netdev.This greatly reduces RTNL pressure on common operations.
Signed-off-by Eric Dumazet <[email protected]>
cheers,
jamal
Quoted 171 lines
Quoted 170 lines
--- tc/f_route.c | 1 - tc/m_mirred.c | 2 -- tc/tc.c | 1 + tc/tc_class.c | 6 ++---- tc/tc_filter.c | 32 ++++++++++++++++---------------- tc/tc_qdisc.c | 5 ++--- 6 files changed, 21 insertions(+), 26 deletions(-)tc/f_route.c +0
-1@@ -76,7 +76,6 @@ static int route_parse_opt(const struct filter_util *qu, char *handle, int argc,__u32 id;NEXT_ARG (); -ll_init_map (&rth);if ((id =ll_name_to_index (*argv)) <=0 ) {fprintf (stderr,"Illegal \"fromif\"\n" );return -1 ;tc/m_mirred.c +0
-2@@ -213,8 +213,6 @@ parse_direction(const struct action_util *a, int *argc_p, char ***argv_p,if (d[0 ]) {int idx; -ll_init_map (&rth); - idx =ll_name_to_index (d);if (!idx)return nodev (d);tc/tc.c +1
-0@@ -243,6 +243,7 @@ static int batch(const char *name)return -1 ; } +ll_init_map (&rth); ret =do_batch (name, force, tc_batch_cmd,NULL );rtnl_close (&rth);tc/tc_class.c +2
-4@@ -136,11 +136,11 @@ static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv) }if (d[0 ]) { -ll_init_map (&rth); - req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d); + }else { +ll_init_map (&rth); }if (rtnl_talk (&rth, &req.n,NULL ) <0 )@@ -437,8 +437,6 @@ static int tc_class_list(int argc, char **argv) argc--; argv++; } -ll_init_map (&rth); -if (d[0 ]) { t.tcm_ifindex =ll_name_to_index (d);if (!t.tcm_ifindex)tc/tc_filter.c +16
-16@@ -188,16 +188,17 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)addattr_l (&req.n,sizeof (req),TCA_KIND , k,strlen (k)+1 );if (d[0 ]) { -ll_init_map (&rth); - req.t.tcm_ifindex =ll_name_to_index (d);if (req.t.tcm_ifindex ==0 ) {fprintf (stderr,"Cannot find device \"%s\"\n" , d);return 1 ; } - }else if (block_index) { - req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; - req.t.tcm_block_index = block_index; + }else { +ll_init_map (&rth); +if (block_index) { + req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; + req.t.tcm_block_index = block_index; + } }if (q) {@@ -539,8 +540,6 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv) }if (d[0 ]) { -ll_init_map (&rth); - req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d);@@ -704,21 +703,22 @@ static int tc_filter_list(int cmd, int argc, char **argv) req.t.tcm_info =TC_H_MAKE (prio<<16 , protocol); -ll_init_map (&rth); -if (d[0 ]) { req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d); filter_ifindex = req.t.tcm_ifindex; - }else if (block_index) { -if (!tc_qdisc_block_exists (block_index)) { -fprintf (stderr,"Cannot find block \"%u\"\n" , block_index); -return 1 ; + }else { +ll_init_map (&rth); +if (block_index) { +if (!tc_qdisc_block_exists (block_index)) { +fprintf (stderr,"Cannot find block \"%u\"\n" , block_index); +return 1 ; + } + req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; + req.t.tcm_block_index = block_index; + filter_block_index = block_index; } - req.t.tcm_ifindex =TCM_IFINDEX_MAGIC_BLOCK ; - req.t.tcm_block_index = block_index; - filter_block_index = block_index; }if (filter_chain_index_set)tc/tc_qdisc.c +2
-3@@ -193,8 +193,6 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)if (d[0 ]) {int idx; -ll_init_map (&rth); - idx =ll_name_to_index (d);if (!idx)return -nodev (d);@@ -411,13 +409,14 @@ static int tc_qdisc_list(int argc, char **argv) argc--; argv++; } -ll_init_map (&rth);if (d[0 ]) { req.t.tcm_ifindex =ll_name_to_index (d);if (!req.t.tcm_ifindex)return -nodev (d); filter_ifindex = req.t.tcm_ifindex; + }else { +ll_init_map (&rth); }if (dump_invisible) {
Quoted 16 lines · Jamal Hadi Salim
Quoted 14 lines · David Ahern
Jamal: waiting for your review ...
Quoted 10 lines · Eric Dumazet
Some setups can have thousands of devices.
ll_init_map()is rather expensive for them.Only call
ll_init_map()in the following cases:1) tc runs in batch mode.
2) tc runs in monitor mode.
3) tc dumps qdiscs/classes/filters for all netdev.
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
This greatly reduces RTNL pressure on common operations.
Signed-off-by Eric Dumazet <[email protected]>Acked-by Jamal Hadi Salim <[email protected]>
Gentle reminder, this patch has not been merged.
I have other patches coming that depend on this one.
Thanks!
Quoted 21 lines · Eric Dumazet
Quoted 20 lines · Jamal Hadi Salim
Quoted 17 lines · David Ahern
Jamal: waiting for your review ...
Quoted 13 lines · Eric Dumazet
Some setups can have thousands of devices.
ll_init_map()is rather expensive for them.Only call
ll_init_map()in the following cases:1) tc runs in batch mode.
2) tc runs in monitor mode.
3) tc dumps qdiscs/classes/filters for all netdev.This greatly reduces RTNL pressure on common operations.
Signed-off-by Eric Dumazet <[email protected]>
Quoted 8 lines
Quoted 2 lines
Acked-by Jamal Hadi Salim <[email protected]>Gentle reminder, this patch has not been merged.
I have other patches coming that depend on this one.
Thanks!
fixed the long line length and applied. please cc Jamal on all tc patches; there is a MAINTAINERS file for iproute2 to indicate who needs to be added to patches.
Quoted 4 lines · David Ahern
fixed the long line length and applied. please cc Jamal on all tc patches; there is a
MAINTAINERSfile for iproute2 to indicate who needs to be added to patches.
LGTM, thanks!