Some confusion on Cyber RT's ShareMemory communication mechanism
Hi, folks
I've learned Cyber RT recently, got some information about its message transport mechanisms. Shared memory, as one of them, is used often. But I have some questions concerning to it, detailed as below:
- In file */cyber/transport/shm/shm_conf.h, some code snippet as follows:
// Extra size, Bitstatic const uint64_t EXTRA_SIZE;// State size, Bitstatic const uint64_t STATE_SIZE;// Block size, Bitstatic const uint64_t BLOCK_SIZE;// Message info size, Bitstatic const uint64_t MESSAGE_INFO_SIZE;
The "Bit" in the comment is meaning the minimum information bit or byte? If it means bit, I think the code snippet below (from shm_conf.cc) should be corrected.
uint64_t ShmConf::GetBlockBufSize(const uint64_t& ceiling_msg_size) { return ceiling_msg_size + MESSAGE_INFO_SIZE; }
void ShmConf::Update(const uint64_t& real_msg_size) { ceiling_msg_size_ = GetCeilingMessageSize(real_msg_size); block_buf_size_ = GetBlockBufSize(ceiling_msg_size_); block_num_ = GetBlockNum(ceiling_msg_size_); managed_shm_size_ = EXTRA_SIZE + STATE_SIZE + (BLOCK_SIZE + block_buf_size_) * block_num_; }
Statement return ceiling_msg_size + MESSAGE_INFO_SIZE; should be change to return ceiling_msg_size + MESSAGE_INFO_SIZE << 3;
Member variable managed_shm_size_ should be assigned to EXTRA_SIZE << 3 + STATE_SIZE << 3 + (BLOCK_SIZE << 3 + block_buf_size) * block_num_;_
- Under most circumstances, I think the Segment object created should not be remapped, since the parties need to use it can not know the changes unless by others notifications, but now Cyber RT seems couldn't let other parties to be notified when co-mmaped Segment's block size is changed.
In my case, I changed SysV share memory API shmget series to POSIX version shm_open series, and the default message size is MESSAGE_SIZE_16K, evidence: ShmConf::ShmConf() { Update(MESSAGE_SIZE_16K); }, compiled and run apollo, it coredumped often. I changed this argument to MESSAGE_SIZE_128K, the phenomenon also exists, but less frequency. I changed to MESSAGE_SIZE_1M or MESSAGE_SIZE_8M, the phenomenon disappeared, and the apollo run normally as before. During debug the core file, I find the code crashed many times from the remap operation, so I suspect it may be the cause.
Any ideas or insights, thanks in advance!
System information
- OS Platform and Distribution (e.g., Linux Ubuntu 14.04):Linux Ubuntu 16.04
- Apollo installed from (source or binary):source
- Apollo version (1.0, 1.5, 2.0, 2.5, 3.0):3.5
Sorry for typo, all "<< 3" should be ">> 3".
Hi, folks
I've learned Cyber RT recently, got some information about its message transport mechanisms. Shared memory, as one of them, is used often. But I have some questions concerning to it, detailed as below:
- In file */cyber/transport/shm/shm_conf.h, some code snippet as follows:
// Extra size, Bitstatic const uint64_t EXTRA_SIZE;// State size, Bitstatic const uint64_t STATE_SIZE;// Block size, Bitstatic const uint64_t BLOCK_SIZE;// Message info size, Bitstatic const uint64_t MESSAGE_INFO_SIZE;The "Bit" in the comment is meaning the minimum information bit or byte? If it means bit, I think the code snippet below (from shm_conf.cc) should be corrected.
uint64_t ShmConf::GetBlockBufSize(const uint64_t& ceiling_msg_size) { return ceiling_msg_size + MESSAGE_INFO_SIZE; }
void ShmConf::Update(const uint64_t& real_msg_size) { ceiling_msg_size_ = GetCeilingMessageSize(real_msg_size); block_buf_size_ = GetBlockBufSize(ceiling_msg_size_); block_num_ = GetBlockNum(ceiling_msg_size_); managed_shm_size_ = EXTRA_SIZE + STATE_SIZE + (BLOCK_SIZE + block_buf_size_) * block_num_; }
Statement
return ceiling_msg_size + MESSAGE_INFO_SIZE;should be change toreturn ceiling_msg_size + MESSAGE_INFO_SIZE << 3;Member variable managed_shm_size_ should be assigned to EXTRA_SIZE << 3 + STATE_SIZE << 3 + (BLOCK_SIZE << 3 + block_buf_size) * block_num_;_
- Under most circumstances, I think the Segment object created should not be remapped, since the parties need to use it can not know the changes unless by others notifications, but now Cyber RT seems couldn't let other parties to be notified when co-mmaped Segment's block size is changed.
In my case, I changed SysV share memory API shmget series to POSIX version shm_open series, and the default message size is MESSAGE_SIZE_16K, evidence:
ShmConf::ShmConf() { Update(MESSAGE_SIZE_16K); }, compiled and run apollo, it coredumped often. I changed this argument to MESSAGE_SIZE_128K, the phenomenon also exists, but less frequency. I changed to MESSAGE_SIZE_1M or MESSAGE_SIZE_8M, the phenomenon disappeared, and the apollo run normally as before. During debug the core file, I find the code crashed many times from the remap operation, so I suspect it may be the cause.Any ideas or insights, thanks in advance!
System information
- OS Platform and Distribution (e.g., Linux Ubuntu 14.04):Linux Ubuntu 16.04
- Apollo installed from (source or binary):source
- Apollo version (1.0, 1.5, 2.0, 2.5, 3.0):3.5
Hi Tony,
Thank you very much to point out the wrong comment in shm_conf.h! We will correct it as soon as possible. For question 2, maybe you need check the process of Recreation after replacing the SysV with POSIX. Thanks again for your contribution to the Apollo!
@gruminions Thank you very much for quick reply!
Closed for now.
Please reopen if you have further questions!