batman-adv: use kmem_cache for translation table
Sven Eckelmann
maintainerPATCH v2 1/1 batman-adv: use kmem_cache for translation table
The translation table (global, local) is usually the part of batman-adv which has the most dynamical allocated objects. Most of them (tt_local_entry, tt_global_entry, tt_orig_list_entry, tt_change_node, tt_req_node, tt_roam_node) are equally sized. So it makes sense to have them allocated from a kmem_cache for each type.
This approach allowed a small wireless router (TP-Link TL-841NDv8; SLUB allocator) to store 34% more translation table entries compared to the current implementation.
[1] https://open-mesh.org/projects/batman-adv/wiki/Kmalloc-kmem-cache-tests
--- net/batman-adv/main.c | 16 +++- net/batman-adv/translation-table.c | 169 +++++++++++++++++++++++++++++++++---- net/batman-adv/translation-table.h | 3 + 3 files changed, 169 insertions(+), 19 deletions(-)
net/batman-adv/main.c +14 -2
@@ -82,6 +82,12 @@ static void batadv_recv_handler_init(void);static int __init batadv_init (void ) { +int ret; + + ret =batadv_tt_cache_init (); +if (ret <0 ) +return ret; +INIT_LIST_HEAD (&batadv_hardif_list);batadv_algo_init ();
@@ -93,9 +99,8 @@ static int __init batadv_init(void)batadv_tp_meter_init (); batadv_event_workqueue =create_singlethread_workqueue ("bat_events" ); -if (!batadv_event_workqueue) -return -ENOMEM ; + goto err_create_wq;batadv_socket_init ();batadv_debugfs_init ();
@@ -108,6 +113,11 @@ static int __init batadv_init(void) BATADV_SOURCE_VERSION, BATADV_COMPAT_VERSION);return 0 ; + +err_create_wq: +batadv_tt_cache_destroy (); + +return -ENOMEM ; } static void __exit batadv_exit(void)
@@ -123,6 +133,8 @@ static void __exit batadv_exit(void) batadv_event_workqueue =NULL ;rcu_barrier (); + +batadv_tt_cache_destroy (); }int batadv_mesh_init (struct net_device *soft_iface)
net/batman-adv/translation-table.c +152 -17
304 lines not on this page · raw message
net/batman-adv/translation-table.h +3 -0
@@ -59,4 +59,7 @@ bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,bool batadv_tt_global_is_isolated (struct batadv_priv *bat_priv,const u8 *addr,unsigned short vid); +int batadv_tt_cache_init (void ); +void batadv_tt_cache_destroy (void ); +#endif /* _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ */
Signature · 1 line
2.8.1
Sven Eckelmann
maintainerQuoted 10 lines · On Saturday 25 June 2016 16:44:06 Sven Eckelmann wrote:
The translation table (global, local) is usually the part of batman-adv which has the most dynamical allocated objects. Most of them (
tt_local_entry,tt_global_entry,tt_orig_list_entry,tt_change_node,tt_req_node,tt_roam_node) are equally sized. So it makes sense to have them allocated from akmem_cachefor each type.This approach allowed a small wireless router (TP-Link TL-841NDv8; SLUB allocator) to store 34% more translation table entries compared to the current implementation.
Quoted 5 lines
[1] https://open-mesh.org/projects/batman-adv/wiki/Kmalloc-kmem-cache-tests
Reported-by Linus Lüssing <[email protected]>Signed-off-by Sven Eckelmann <[email protected]>---
Here is the changelog (since the RFC):
v2:
- use kmem_cache_zalloc instead of kmem_cache_alloc + memset as suggested by Linus
- add cache batadv_tt_change_cache, batadv_tt_req_cache, batadv_tt_roam_cache
- Added Reported-by
- rewrote commit message
- summarize+link the results from Linus' tests
Kind regards,
Sven
Quoted 19 lines · Sven Eckelmann
Quoted 10 lines · On Saturday 25 June 2016 16:44:06 Sven Eckelmann wrote:
The translation table (global, local) is usually the part of batman-adv which has the most dynamical allocated objects. Most of them (
tt_local_entry,tt_global_entry,tt_orig_list_entry,tt_change_node,tt_req_node,tt_roam_node) are equally sized. So it makes sense to have them allocated from akmem_cachefor each type.This approach allowed a small wireless router (TP-Link TL-841NDv8; SLUB allocator) to store 34% more translation table entries compared to the current implementation.
Quoted 5 lines
[1] https://open-mesh.org/projects/batman-adv/wiki/Kmalloc-kmem-cache-tests
Reported-by Linus Lüssing <[email protected]>Signed-off-by Sven Eckelmann <[email protected]>---
Here is the changelog (since the RFC):
Quoted 8 lines
v2:
- usekmem_cache_zallocinstead ofkmem_cache_alloc+ memset as suggested by Linus
- add cachebatadv_tt_change_cache,batadv_tt_req_cache,batadv_tt_roam_cache
- Added Reported-by
- rewrote commit message
- summarize+link the results from Linus' tests
Looks good. Do you have any typical numbers regarding tt_change_cache and tt_req_cache sizes for specific setups?
Just wondering whether it is worth it to have extra caches for these two. (if you don't have any numbers, I might have a look at /proc/slabinfo with your patch for some Freifunk network(s) later today)
Sven Eckelmann
maintainerOn Monday 27 June 2016 06:02:18 Linus Lüssing wrote:
[...]
Quoted 2 lines
Looks good. Do you have any typical numbers regarding
tt_change_cacheandtt_req_cachesizes for specific setups?
No, I don't have any numbers.
Kind regards,
Sven
Linus Lüssing
Acked-byQuoted 6 lines · Sven Eckelmann
On Monday 27 June 2016 06:02:18 Linus Lüssing wrote:
[...]Quoted 2 lines
Looks good. Do you have any typical numbers regarding
tt_change_cacheandtt_req_cachesizes for specific setups?No, I don't have any numbers.
Freifunk Rhein-Neckar at about 4pm (~700 nodes, ~1800 clients, batman-adv compat15):
-----batadv_tt_roam_cache 0 0 64 63 1 : tunables 120 60 8 : slabdata 0 0 0batadv_tt_req_cache 1 63 64 63 1 : tunables 120 60 8 : slabdata 1 1 0batadv_tt_change_cache 0 0 32 124 1 : tunables 120 60 8 : slabdata 0 0 0batadv_tt_orig_cache 3210 3213 64 63 1 : tunables 120 60 8 : slabdata 51 51 0
batadv_tg_cache 3162 3162 128 31 1 : tunables 120 60 8 : slabdata 102 102 0 batadv_tl_cache 2 31 128 31 1 : tunables 120 60 8 : slabdata 1 1 0
-----
-> snapshot taken from an x86 machine connected to a Gluon ar71xx node.
So the roam, req, change and tl cache are mostly empty here. On the other hand, they could probably gain a significant size once a larger LAN gets bridged to bat0, I guess. Also looks like various file systems have about half a dozen caches each with most of them being quite empty most of the time.
So, I guess it's ok to have the roam/req/change/tl caches.
Not sure whether I should (since TT is Antonio's part) but the patch looks correct, the previous version with the same concept tested and looks very similar to what I had incidentally been coding at the same time as Sven :), so:
Marek Lindner
AppliedQuoted 12 lines · On Saturday, June 25, 2016 16:44:06 Sven Eckelmann wrote:
The translation table (global, local) is usually the part of batman-adv which has the most dynamical allocated objects. Most of them (
tt_local_entry,tt_global_entry,tt_orig_list_entry,tt_change_node,tt_req_node,tt_roam_node) are equally sized. So it makes sense to have them allocated from akmem_cachefor each type.This approach allowed a small wireless router (TP-Link TL-841NDv8; SLUB allocator) to store 34% more translation table entries compared to the current implementation.
[1] https://open-mesh.org/projects/batman-adv/wiki/Kmalloc-kmem-cache-tests
Quoted 8 lines
Reported-by Linus Lüssing <[email protected]>Signed-off-by Sven Eckelmann <[email protected]>--- net/batman-adv/main.c | 16 +++- net/batman-adv/translation-table.c | 169 +++++++++++++++++++++++++++++++++---- net/batman-adv/translation-table.h | 3 + 3 files changed, 169 insertions(+), 19 deletions(-)
Applied in revision eb079fb.
Thanks,
Marek