Boost >= 1.87 throws bad_alloc when allocating memory for a 64-byte aligned data structure using managed_shared_memory, even though there is sufficient free memory

オープン
#1,041 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp

調査の方向性

提供された managed_shared_memory の例を MyClass<32768> で再現し、include/boost/interprocess/mem_algo/detail/mem_algo_common.hpp の allocate_aligned を調査して、言及されている Boost バージョン間での動作を比較します。real_size が get_free_memory に対してどのように計算されるかを追跡します。回帰が説明され、アラインされた割り当ての動作が適切な回帰テストでカバーされれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Hi there, I haven't tested this with Boost 1.86, jumped straight from 1.85 to 1.87. The code snippet below works well in Boost 1.85, but when using 1.87 or 1.88, I noticed it fails and throw bad_alloc. Some changes related to memory_algorithm seem to break it. While debugging, I found that the real_size calculated in allocate_aligned is larger than the currently available free memory. I'm also wondering if I'm using it incorrectly. Please advise — thanks!

#include <iostream>
#include "boost/interprocess/interprocess_fwd.hpp"
#include "boost/interprocess/managed_shared_memory.hpp"
#include "boost/interprocess/shared_memory_object.hpp"

template <size_t N)>
class MyClass {
 public:
  static_assert((N & (N - 1)) == 0, "size must be power of 2");

private:
  alignas(64) std::array<uint8_t, N> data_;
};

namespace bip = boost::interprocess;



int main() {
  constexpr auto kName = "TestShm";
  bip::shared_memory_object::remove(kName);
  try {
    auto shm = bip::managed_shared_memory(bip::open_or_create, kName,
                                          65536);
    auto free_mem = shm.get_free_memory();
    std::cout << "Free mem: " << free_mem << std::endl;
    using Data = MyClass<32768>;
    [[maybe_unused]] auto data = shm.find_or_construct<Data>("Data")();
  }
  catch (const std::exception& e) {
    std::cout << "Fail, " << e.what() << std::endl;
    bip::shared_memory_object::remove(kName);
    return 1;
  }

  bip::shared_memory_object::remove(kName);
  return 0;
}

主要言語
HTML
スター
8.6k
フォーク
2k
平均マージ
9時間 35分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

boostorg/boost のほかの issue

boostorg/boost の issue をすべて見る

似ている issue

Operating Systems の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。