Is there a way for the Linux Kernel to know the cache line size of theCPU it's on, besides #define X86_CACHE_LINE_SZ 32 or whatnot? I amlooking in /proc/cpuinfo trying to determine how to run cachingoptimizations and interested in this information and its implications.It may also be useful if I can get this information at run time inapplication code.

For the curious (those of you who don't care, stop reading; those whoare going to tell me I shouldn't care about these numbers, keep readinganyway), I am trying to avoid false sharing in a memory allocator,mainly by bitmapping cache lines on top of the 16 byte block bitmap perthread.

In many cases I avoid segment sharing altogether. Segments sufferingfrom lack of use are returned to the global scope for other threads; butso are segments in terminated threads. Threads needing more space tryto retrieve their own segments; when this is not possible, they retrievesegments from terminated threads. When both of these options fails,segments owned by active threads set in the global scope are adopted.

When segments are shared, there is the potential that the same cacheline may be allocated in different threads, possibly leading toconcurrent access to the same cache line on different CPUs in an SMPenvironment. To avoid this, each active thread with any allocations ina shared segment will keep a bitmap of its own used cache lines, andoverlay that bitmap onto the master cache line bitmap for the segment.

Cache lines in use but not by the current thread will not be used by thecurrent thread for allocations. Whenever a thread terminates, itremoves all cache lines it holds from use in the master cache linebitmap; false sharing cannot occur if there is no thread to share with,so overlapping cache lines with the dead thread is not an issue (and nottechnically possible).

Creative brains are a valuable, limited resource. They shouldn't be wasted on re-inventing the wheel when there are so many fascinating new problems waiting out there. -- Eric Steven Raymond

We will enslave their women, eat their children and rape their cattle! -- Bosc, Evil alien overlord from the fifth dimension-----BEGIN PGP SIGNATURE-----Version: GnuPG v1.4.3 (GNU/Linux)Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIVAwUBRQSvJAs1xW0HCTEFAQIAqg/+MPRPOIJyJAjofYY6vihj+2+THCKEXUL8wdWbxSixKSi12RWK3YJhlDI4TjeSfke4QU5CwC80msb4tKnMouS6oWqauWMLHOqGky1b4I57IAB94Jol2ydyUd87GhNShQWpwACnH5+e6bdm4qUCtY62mDRH3DcEC+VryAtNVClXQjOvHBkhDaraHZQVXXa4ucOPgLr4eyVutxOMDQQ2Rf8wOGHvSIFMkEK3qTledtIOrTfvMEpB75peT2+1cS08ku90j+as3+IyDIPviRBuF5goO6JcH3XJFBlEYqord1i44PZdsQHPK68W7x+Pglof3yGw1VEmB2/UTf3J+n2FMh+NxEdrxeq1pyKJMljokFb8u6czjN/g10xGj/JvJKhV/9k2xwcs0SRPR0CHavrKCpO4QdvOQOMalqZ9dzPKQHMiLJliTRsDAD9gVhplMODFEbGaiHDmjccuDtyFs8TtxgMc0wQArzJu9SSOYZOszWMXpR9HbE3P1KKctQuD4h2T2wdUnR2Rc49Upoo8TdtOAMJgabx9jlPlt5IZuZrUiBx+gC5ac2UhrI2shOJBUYc4h5OG3zFZ4b4UJ97kz2v50V8FCYzqENMDhfQQ8VHLd2LDDdhBGKKKUTWboYFV/NlJBiWpxzhOfEz8wg9llmYIMIY+iGdGRqBzkCkfxUyVeiEgSFE==+Y7F-----END PGP SIGNATURE------To unsubscribe from this list: send the line "unsubscribe linux-kernel" inthe body of a message to majordomo@vger.kernel.orgMore majordomo info at http://vger.kernel.org/majordomo-info.htmlPlease read the FAQ at http://www.tux.org/lkml/