eunomia-bpf / bpftime

Userspace eBPF runtime for Observability, Network & General Extensions Framework
https://eunomia.dev/bpftime/
MIT License
788 stars 74 forks source link

eBPF Map size is larger than shared memory size, cause `boost::interprocess::bad_alloc` #308

Closed janetat closed 1 month ago

janetat commented 3 months ago

问题

  1. 共享内存是静态分配的,大小为20M。
  2. 共享内存里保存着bpftime用到的数据结构,包括eBPF Maps。
  3. 如果eBPF Maps数据不断增长,超过共享内存大小怎么办?

期望

共享内存可以动态增长吗?

Officeyutong commented 3 months ago

There is a PR to allow defining shared memory size at runtime, but it's not finished yet https://github.com/eunomia-bpf/bpftime/pull/285

janetat commented 3 months ago

https://github.com/eunomia-bpf/bpftime/pull/285 这是通过命令行的方式传递共享内存大小,也是静态、固定的。

期望是达到Max之后,还能自动地增加共享内存么?

Officeyutong commented 3 months ago

285 这是通过命令行的方式传递共享内存大小,也是静态、固定的。

期望是达到Max之后,还能自动地增加共享内存么?

It's not supported now. But since boost::interprocess provided such ability, we may add it later


   //!Tries to resize the managed shared memory object so that we have
   //!room for more objects.
   //!
   //!This function is not synchronized so no other thread or process should
   //!be reading or writing the file
   static bool grow(const char *shmname, size_type extra_bytes)
   {
      return base_t::template grow
         <basic_managed_shared_memory>(shmname, extra_bytes);
   }
yunwei37 commented 1 month ago

Now you can use flag like BPFTIME_SHM_MEMORY_MB to control the size of the shared memory. For example,

SPDLOG_LEVEL=Debug BPFTIME_SHM_MEMORY_MB=50 LD_PRELOAD=/home/yunwei37/bpftime/build/runtime/syscall-server/libbpftime-syscall-server.so ./example/malloc/malloc

It can set the shared memory size to 50MB. We may use grow in the future.