Commit 94b9bb5480e73cec4552b19fc3f809742b4ebf67
Committed by
David S. Miller
1 parent
baf5d743d1
Exists in
master
and in
7 other branches
[XFRM] Optimize SA dumping
Same comments as in "[XFRM] Optimize policy dumping" The numbers are (20K SAs):
Showing 1 changed file with 11 additions and 13 deletions Side-by-side Diff
net/xfrm/xfrm_state.c
... | ... | @@ -1099,7 +1099,7 @@ |
1099 | 1099 | void *data) |
1100 | 1100 | { |
1101 | 1101 | int i; |
1102 | - struct xfrm_state *x; | |
1102 | + struct xfrm_state *x, *last = NULL; | |
1103 | 1103 | struct hlist_node *entry; |
1104 | 1104 | int count = 0; |
1105 | 1105 | int err = 0; |
1106 | 1106 | |
... | ... | @@ -1107,24 +1107,22 @@ |
1107 | 1107 | spin_lock_bh(&xfrm_state_lock); |
1108 | 1108 | for (i = 0; i <= xfrm_state_hmask; i++) { |
1109 | 1109 | hlist_for_each_entry(x, entry, xfrm_state_bydst+i, bydst) { |
1110 | - if (xfrm_id_proto_match(x->id.proto, proto)) | |
1111 | - count++; | |
1110 | + if (!xfrm_id_proto_match(x->id.proto, proto)) | |
1111 | + continue; | |
1112 | + if (last) { | |
1113 | + err = func(last, count, data); | |
1114 | + if (err) | |
1115 | + goto out; | |
1116 | + } | |
1117 | + last = x; | |
1118 | + count++; | |
1112 | 1119 | } |
1113 | 1120 | } |
1114 | 1121 | if (count == 0) { |
1115 | 1122 | err = -ENOENT; |
1116 | 1123 | goto out; |
1117 | 1124 | } |
1118 | - | |
1119 | - for (i = 0; i <= xfrm_state_hmask; i++) { | |
1120 | - hlist_for_each_entry(x, entry, xfrm_state_bydst+i, bydst) { | |
1121 | - if (!xfrm_id_proto_match(x->id.proto, proto)) | |
1122 | - continue; | |
1123 | - err = func(x, --count, data); | |
1124 | - if (err) | |
1125 | - goto out; | |
1126 | - } | |
1127 | - } | |
1125 | + err = func(last, 0, data); | |
1128 | 1126 | out: |
1129 | 1127 | spin_unlock_bh(&xfrm_state_lock); |
1130 | 1128 | return err; |