What is ternary content-addressable memory (TCAM)?

What is ternary content-addressable memory (TCAM)?

Ternary content-addressable memory (TCAM) is a special type of high-speed memory that searches its entire contents in one clock cycle. The term ternary refers to the ability of memory to store and query data using three different inputs: 0, 1 and X. TCAM is commonly used by network routers to store address lookup tables.

TCAM is a more flexible version of content-addressable memory (CAM).

What is content-addressable memory?

Content-addressable memory is a special type of computer memory that stores data, like RAM. In RAM, the central processing unit (CPU) can only access data by specifying the memory address and reading the data. CAM can also work in reverse; the CPU specifies what data it is trying to match — the key — and returns to memory the memory location corresponding to the search key. CAM can only find exact matches in binary strings.

TCAM, for its part, searches memory to match the key, just like CAM, and can also use a mask to show “don’t care” or wildcard bits. This results in three possible states: 0, 1 and X, a wildcard. Using mask pieces allows for greater search flexibility.

How is TCAM used?

TCAM can perform one search every clock cycle. This is much faster than traditional RAM searches, which require many clock cycles to query and check each memory location.

To illustrate the search power of TCAM compared to traditional RAM, imagine that you are looking for a specific sentence in a book. Searching traditional RAM can be like going through each page one by one to find the sentence. A CAM is a book with an index or concordance that you can check to see where in the book a word is used.

CAM and TCAM have some disadvantages. These memory cells require additional transistors to support the search feature. This makes it more expensive and less dense compared to traditional RAM. Each memory cell must be active in each cycle to perform the search, so it requires more power and produces more heat.

The benefits of transistors.
To support advanced search capabilities, TCAM requires more transistors than conventional memory, making it more expensive.

Because of the tradeoffs, CAM and TCAM are often used as an additional memory location for special applications to store a relatively small set of data that needs to be looked up quickly, frequently. The most popular use is for network routers to store rule lookup tables. Other uses are within the CPU’s translation lookaside buffer, in database systems or in artificial neural networks.

TCAM in networks

Large network routers can process tens of millions of packets per second. That means it has to do millions of small lookups to match the packet in the routing table. TCAM allows the router to perform a search and find a result in only one cycle.

For example, a rule can be set up to match all IP addresses in the subnet. This can be recorded as 00001010,XXXXXXXXX,XXXXXXXXX,XXXXXXXXX in TCAM. If the IP address is entered, it will be translated into the binary string 00001010,01100100,00010100,00000101, and it will match the rule.

Routing tables often contain rules for things like media access control addresses, IP addresses, network protocols or ports. All of this is directly encoded as binary data in a packet header, so TCAM can easily find them.

Because of its special use, the TCAM of a router is usually smaller than the total RAM. A small business router can have about 20 megabytes worth of TCAM storage. Larger internet routers used by backbone internet service providers may need to store the entire Border Gateway Protocol table in TCAM, which is easy almost a million entries. These routers typically use dedicated application-specific integrated circuits and may have separate TCAM storage for different uses. If a router is unable to store all routing entries in TCAM, it will revert to slow memory, resulting in high CPU usage and dropped packets.

The administrator usually does not directly control TCAM storage. When programming the router, the software takes the rules and translates them into TCAM. The administrator can define how the TCAM storage is divided. For example, IPv4 rules use less memory space than IPv6, so setting the router to prioritize IPv4 storage will allow for more saved rules.

TCAM can also be used to detect network intrusion. These tools can store known malicious fingerprints or hashes and easily compare observed traffic with malicious data stored in TCAM.

Diagram of an IPv6 header.
Routing table rules are directly encoded in a packet header, making them easy to find in ternary content-addressable memory.

TCAM in neural networks, machine learning and AI

The possible use of TCAM for neural networks, machine learning and artificial intelligence (AI) is currently an active area of ​​research. It is understood that the very similar nature of TCAM search compared to conventional memory may facilitate many of these processes. Since it is still being researched, there are currently no major hardware devices available on the market for this use.

Learn about common network protocols and their functions, common types of networks with their use cases and types of network devices. Explore the differences between AI vs. machine learning vs. deep learning and see memory management strategies to improve virtual machine performance.

Leave a comment