Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache line padding of Pool is incorrect #3

Open
ilnarb opened this issue Mar 28, 2011 · 10 comments
Open

Cache line padding of Pool is incorrect #3

ilnarb opened this issue Mar 28, 2011 · 10 comments

Comments

@ilnarb
Copy link

ilnarb commented Mar 28, 2011

usual cache line size is 64 byte.
it seems sizeof (Pool) == 32
you need to write
char cache_line_padding[CACHE_LINE_SIZE - sizeof(freed) - sizeof(raw) - sizeof(elem_size)];

@ivan-tkatchev
Copy link
Contributor

Why is that?
Why do you think that it's important that sizeof(Pool) be equal to the cache line size?

@ilnarb
Copy link
Author

ilnarb commented Mar 29, 2011

parts of two distinct Pool should not be placed into one cache line in order to prevent cache line contention. Current size of Pool == 32 bytes. In this case parts of two Pool always will be placed in a single cache line.
It's important that padding will align the next Pool object into different cache line. In case first Pool aligned to cache line and sizeof(Pool)== cache line size sizeof padding equal to CACHE_LINE_SIZE - sizeof(freed) - sizeof(raw) - sizeof(elem_size) will be enought. In other case, more padding is need.

@ilnarb
Copy link
Author

ilnarb commented Mar 29, 2011

to tell the truth, it will be better to aligning vs. apdding
attribute ((aligned(CACHE_LINE_SIZE)))

@ivan-tkatchev
Copy link
Contributor

Yes, of course. However, a Pool corresponds to a pool of free blocks, where each block in the pool is of a fixed, predetermined size. (There are thus 1023 such Pools, one for each possible block size, up to a block size of 8k.) Contention should be a problem only if one thread only allocates memory blocks of one fixed size, with another thread also allocating only blocks of another fixed size; this should be unrealistic in practice. (All threads should, theoretically, be allocating blocks of all sizes, uniformly.)

@ilnarb
Copy link
Author

ilnarb commented Mar 29, 2011

in that case, how about eliminating the line (size_t cache_line_padding;) at all?
it doesn't pad, just confuses.

@ivan-tkatchev
Copy link
Contributor

That's there to make Pool fit entirely into one cache line. I'm not really sure that brings any real benefit, but 32 is a nice and clean number, anyways. :)

1 similar comment
@ivan-tkatchev
Copy link
Contributor

That's there to make Pool fit entirely into one cache line. I'm not really sure that brings any real benefit, but 32 is a nice and clean number, anyways. :)

@ilnarb
Copy link
Author

ilnarb commented Mar 29, 2011

could i contact u tru icq? my num 8112260

@ivan-tkatchev
Copy link
Contributor

I don't have an ICQ number, but you can contact me via jabber/gtalk at [email protected].

@ilnarb
Copy link
Author

ilnarb commented Mar 30, 2011

/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants