platform: use new platform caching

System Internals / NetworkManager - Thomas Haller [redhat.com] - 17 June 2015 04:41 UTC

Switch platform caching implementation. Instead of caching libnl objects, cache our own types.

Don't remove yet the now obsolete functions.

Advantage:

- Performance- as we now cache our native NMPlatformObject instances, we no longer have to convert libnl objects every time we access the platform cache.- for most cases, access is now O(1) because we can lookup the object in a hash table. Note that ip4_address_get_all() still has to create a copy of the result (O(n)), but as the caller is about to use those elements, he cannot do better then O(n) anyway.

- We cache our own native types and have full control over them. We cannot extend the libnl objects, which has many short-commings:- _rtnl_addr_hack_lifetimes_rel_to_abs() to convert the timestamps to absolute values (and back).- hack_empty_master_iff_lower_up() would modify the internal flag, but it looses the original value. That means, we can only hack the state before putting a link into the cache, but we cannot revert that change, when a slave in the cache changes state. That was previously solved by always refetching the master when a slave changed. Now we can re-evaluate the connected state (DELAYED_ACTION_TYPE_MASTER_CONNECTED).- we implement functions like equality, to-string as most suitable for us. Before we needed hacks like nm_nl_object_diff(), nm_nl_cache_search(), route_search_cache().- we can extend our objects with exactly those properties we care, and possibly additional properties that are not representable in the libnl objects.- we no longer cache RTM_F_CLONED routes and they get rejected early on as we receive them.- In the future, maybe it'd be interesting the make platform objects immutable (and ref-counted) and expose them directly.

- Previous implementation did not order the refresh of objects but called check_cache_items(). Now, those actions are delayed and combined in an attempt to reduce the overall number of reloads. Realize how expensive a check_cache_items() for addresses and routes was: it would iterate all addresses/routes and call refresh_object(). The latter obtains a full dump of *all* objects again, and ignores all but the needle. Note that we probably still schedule some delayed actions that are not needed. Later we can optimize that further (related bug bgo #747985).

While some of these points could also have been implemented with caching of libnl objects, that would have become hard to maintain.

https://bugzilla.gnome.org/show_bug.cgi?id=747981

470bcef platform: use new platform caching
src/platform/nm-fake-platform.c | 58 ++-
src/platform/nm-linux-platform.c | 809 +++++++++++++++----------------------
src/platform/tests/test-address.c | 4 +-
src/platform/tests/test-link.c | 38 +-
src/platform/tests/test-route.c | 8 +-
src/tests/test-route-manager.c | 8 +-
6 files changed, 410 insertions(+), 515 deletions(-)

Upstream: cgit.freedesktop.org


  • Share