Recently, I have been reluctantly reading Linux Kernel Code. however, I had a poor programming Foundation, and the Linux code was really amazing. I had to take a line of work and record myself on the blog for future reference.
In Linux, most Enum instances do not have enumeration names. Generally, after a string of types, an NR is used to indicate the number, at first, this made me very troubled by the obsessive-compulsive disorder that I had to understand in every detail. Later, I finally found that the actual functions of these names are just a definition similar to Macro, which is used to Index a certain type of set, the final NR variable is only a value used to record the number of types in this set, but this function can be implemented only because of the features of Enum. Here is an example in struct page:
Enum {MM_FILEPAGES, MM_ANONPAGES, MM_SWAPENTS, NR_MM_COUNTERS };
This Enum indicates that all pages may belong to one of the first three types, and their indexes are 0, 1, and 2, respectively. The last NR_MM_COUNTERS value here is 3 (values of Enumeration type in Enum increase one by one from 0), indicating that there are three page types in total. This value can be used later as some cyclic values.