Skip to contentSkip to conversation

batman-adv: use kmem_cache for translation table

PATCH Applied Sven Eckelmann 3 participants 6 messages Jun 25, 2016 – Jul 8, 2016 Batman advanced

lore
Share & tools
lore

Sven Eckelmann

author maintainer
#0 lore raw

PATCH 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
index f61479b..ef07e5b 100644
@@ -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
index 7c7e2c0..02b0f85 100644
@@ -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
author maintainer
#1 lore raw
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 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.

Quoted 5 lines

[1] https://open-mesh.org/projects/batman-adv/wiki/Kmalloc-kmem-cache-tests

---

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

#2 lore raw
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 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.

Quoted 5 lines

[1] https://open-mesh.org/projects/batman-adv/wiki/Kmalloc-kmem-cache-tests

---

Here is the changelog (since the RFC):

Quoted 8 lines

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

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)

author maintainer
#3 lore raw

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_cache and tt_req_cache sizes for specific setups?

No, I don't have any numbers.

Kind regards,
Sven

#4 lore raw
Quoted 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_cache and tt_req_cache sizes 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 0
batadv_tt_req_cache 1 63 64 63 1 : tunables 120 60 8 : slabdata 1 1 0
batadv_tt_change_cache 0 0 32 124 1 : tunables 120 60 8 : slabdata 0 0 0
batadv_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:

#5 lore raw
In reply to Sven Eckelmann
Quoted 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 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

Quoted 8 lines
---
 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