Major Cache Operations
The protocol-independent (DST) part of the cache is a set of dst_entry data structures. Most of the activities in this chapter happen
through a dst_entry structure. The IPv4 and IPv6 data
structures rtable and rt6_info both include a dst_entry data
structure.
The dst_entry structure offers a set of virtual
functions in a field named dst_ops, which allows
higher-layer protocols to run protocol-specific functions that manipulate the entries. The
DST code is located in net/core/dst.c and include/net/dst.h.
All the routines that manipulate dst_entry
structures start with a dst_ prefix. Note that even
though they operate on dst_entry structures, they
actually affect the outer rtable structures, too.
DST is initialized with dst_init, invoked at boot
time by net_dev_init (see Chapter 5).
Cache Locking
Read-only operations, such as lookups , use a different locking mechanism from read-write operations such as insertion and deletion, but they naturally have to cooperate. Here is how they are handled:
- Read-only operations
These use the routines presented in the section "Cache Lookup" and are protected by a read-copy-update (RCU) read lock, as in the following snapshot:
rcu_read_lock( ); ...
perform lookup... rcu_read_unlock( );This code actually does no locking, because read operations can proceed simultaneously without interfering with each other.
- Read-write operations
The insertion of an entry (see the section "Adding Elements to the Cache") and the deletion of an entry ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access