July 12th, 2017

Why is the maximum number of TLS slots 1088? What a strange number.

Commenter Max noted that the maximum number of TLS slots is 1088 and wondered why such a strange number. “I mean, it does not look like a perfect number in terms of 2-based numeric system.”

It looks a little better in base 2. The value is 10001000000 which breaks down as 1024 + 64.

When TLS was first introduced, the number of available TLS slots was 64, and those slots were pre-allocated as part of the thread control block. Over time, 64 slots turn out not to be enough, so the kernel team modified the code to allocate a page of data per thread once the 65th request for a TLS slot was made. A page of data is 4KB, which has enough room for 1024 32-bit values. That’s why the total is 1088. It’s the original 64 slots, plus an addition 1024 slots.

Note that the statement that “the maximum number of slots is 1088” is a statement of current implementation, not a contractual obligation. The contractual obligation is that there will always be at least TLS_MINIMUM_AVAILABLE slots available. Any more than that is just gravy.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.