0 Replies Latest reply on Aug 23, 2009 11:58 AM by 807567

    Cache conscious - How is data read from memory into cache line?


      this question is a bit of an odd ball I'm afraid, but I simply don't know where to take it. I professionally develop server software on Solaris so I hope you guys can help me out. What I need to know to be cache conscious when implementing a hash table is how an OS generally, and Soalris/Linux especially, reads data from RAM into a cache line.

      Let's assume I have:
      * a CPU with a cache line size of 64 bytes
      * the page size of my OS set to 8 kb
      * my OS is a 32-bit system
      * my own memory allocator serving me one full page at a time

      How do I need to layout my data elements on a page to ensure they are placed cache consciously?


      A page is allocated. It is empty apart from a page header of 40 bytes.

      I want to insert a Data element1 of 50 bytes into the page.


      Do I need to align the page placement with my cache line size? Meaning I have to write my element with an offset of 64 bytes from the page start, leaving 14 bytes un-used?
      Page -------------------
      I Page header 40bytes I 16 bytes un-used I Data element1 50 bytes

      That would mean wasting a lot of space, especially since Data element2 would also have to take cache line size into account leaving another 14 un-used.

      Please, say it isn't so...

      Say I have a function blork with the following variables declared in C:

      void blork(void)
      struct foo {
      int var1;
      int var2;

      int var3;
      int var4

      Will the cache line look like this:
      var1, var2, var3, var4....

      var3, var4....

      Thanks in advance

      comp.os.linux.development.apps, comp.programming, comp.software-eng, comp.unix.programmer