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

代码缺陷! #37

Open
YangXin-Sheep opened this issue Oct 25, 2022 · 5 comments
Open

代码缺陷! #37

YangXin-Sheep opened this issue Oct 25, 2022 · 5 comments

Comments

@YangXin-Sheep
Copy link

YangXin-Sheep commented Oct 25, 2022

static inline struct shm_hash_entry *shm_get_hentry_ptr(struct shmcache_context *context,
const int64_t offset)
{
···
base = shmopt_get_value_segment(context, conv.segment.index & 0xFF);
···
}

static inline int64_t shm_get_hentry_offset(struct shm_hash_entry *entry)
{
···
conv.segment.index = entry->memory.index.segment | 0x4000;
···
}

为什么段segment index只用了8位,代表段数最多只能是255,设置段地址|0x4000也是看不懂什么操作!

@happyfish100
Copy link
Owner

union shm_hentry_offset {
int64_t offset;
struct {
int index :16;
int64_t offset :48;
} segment;
};

segment index是16位啊!

@happyfish100
Copy link
Owner

0x4000为占位符。

@YangXin-Sheep
Copy link
Author

YangXin-Sheep commented Oct 27, 2022

按entry->memory.index.segment | 0x4000作为占位符,我理解低14位都是可用的,但是conv.segment.index & 0xFF这里只使用了低8位啊,说明目前只有255字节是可以用的。所以我理解0xFF是不是写错了,应该是0xFFFF,当时在阅读代码的时候一直纳闷0xFF是16位?

@YangXin-Sheep
Copy link
Author

union shm_hentry_offset { int64_t offset; struct { int index :16; int64_t offset :48; } segment; };

segment index是16位啊!

段地址index 16位,offset 48位段内偏移这个是没有问题的。conv.segment.index & 0xFF这里只拿了低8位,也就是目前只支持了最大127个段,因为int有符号。

@YangXin-Sheep
Copy link
Author

这里实际上分配的时候才有striping的概念,但是寻址实际还是只有段的概念。

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