In-kernel cache based on eBPF.

Overview

BMC

BMC (BPF Memory Cache) is an in-kernel cache for memcached. It enables runtime, crash-safe extension of the Linux kernel to process specific memcached requests before the execution of the standard network stack. BMC does not require modification of neither the Linux kernel nor the memcached application. Running memcached with BMC improves throughput by up to 18x compared to the vanilla memcached application.

Requirements

Linux kernel v5.3 or higher is required to run BMC.

Other software dependencies are required to build BMC and Memcached-SR (see Building BMC and Building Memcached-SR).

Build instructions

Building BMC

BMC must be compiled with libbpf and other header files obtained from kernel sources. The project does not include the kernel sources, but the kernel-src-download.sh and kernel-src-prepare.sh scripts automate the download of the kernel sources and prepare them for the compilation of BMC.

These scripts require the following software to be installed:

gpg curl tar xz make gcc flex bison libssl-dev libelf-dev

The project uses llvm and clang version 9 to build BMC, but more recent versions might work as well:

llvm-9 clang-9

Note that libelf-dev is also required to build libbpf and BMC.

With the previous software installed, BMC can be built with the following:

$ ./kernel-src-download.sh
$ ./kernel-src-prepare.sh
$ cd bmc && make

After BMC has been successfully built, kernel sources can be removed by running the kernel-src-remove.sh script from the project root.

Building Memcached-SR

Memcached-SR is based on memcached v1.5.19. Building it requires the following software:

clang-9 (or gcc-9) automake libevent-dev

Either clang-9 or gcc-9 is required in order to compile memcached without linking issues. Depending on your distribution, you might also need to use the -Wno-deprecated-declarations compilation flag.

Memcached-SR can be built with the following:

$ cd memcached-sr 
$ ./autogen.sh
$ CC=clang-9 CFLAGS='-DREUSEPORT_OPT=1 -Wno-deprecated-declarations' ./configure && make

The memcached binary will be located in the memcached-sr directory.

License

Files under the bmc directory are licensed under the GNU Lesser General Public License version 2.1 license.

Files under the memcached-sr directory are licensed under the BSD-3-Clause BSD license.

Comments
  • tx_filter does not work?

    tx_filter does not work?

    After I start bmc, I can see that rx_filter has received data, but tx_filter has never been called.I don't see tx_filter being attached to the egress hook of tc in the code. Do I need to attach it separately?How to attach it?

    opened by zouwen4321 2
  • error while building bmc

    error while building bmc

    Hi, I'm tring to build bmc, got the following error while building

    I'm running this build in in following environment:

    1. debian 11
    2. clang 11, llvm 11
    3. gcc 10.2.1
    4. downloaded the kernel source by running apt source linux, and the kernel version is 5.10.84
    gcc -g -O2 -Wall -I. -I../linux-5.10.84/tools/lib -I../linux-5.10.84/tools/include/uapi  -o bmc bmc_user.c ../linux-5.10.84/tools/lib/bpf/libbpf.a -L../linux-5.10.84/tools/lib/bpf -l:libbpf.a -lelf
    In file included from /usr/include/linux/kernel.h:5,
                     from ../linux-5.10.84/tools/include/uapi/linux/netlink.h:5,
                     from ../linux-5.10.84/tools/include/uapi/linux/if_link.h:6,
                     from bmc_user.c:20:
    /usr/include/linux/sysinfo.h:9:2: error: unknown type name ‘__kernel_long_t’
        9 |  __kernel_long_t uptime;  /* Seconds since boot */
          |  ^~~~~~~~~~~~~~~
    /usr/include/linux/sysinfo.h:10:2: error: unknown type name ‘__kernel_ulong_t’
       10 |  __kernel_ulong_t loads[3]; /* 1, 5, and 15 minute load averages */
          |  ^~~~~~~~~~~~~~~~
    /usr/include/linux/sysinfo.h:11:2: error: unknown type name ‘__kernel_ulong_t’
       11 |  __kernel_ulong_t totalram; /* Total usable main memory size */
          |  ^~~~~~~~~~~~~~~~
    /usr/include/linux/sysinfo.h:12:2: error: unknown type name ‘__kernel_ulong_t’
       12 |  __kernel_ulong_t freeram; /* Available memory size */
          |  ^~~~~~~~~~~~~~~~
    /usr/include/linux/sysinfo.h:13:2: error: unknown type name ‘__kernel_ulong_t’
       13 |  __kernel_ulong_t sharedram; /* Amount of shared memory */
          |  ^~~~~~~~~~~~~~~~
    /usr/include/linux/sysinfo.h:14:2: error: unknown type name ‘__kernel_ulong_t’
       14 |  __kernel_ulong_t bufferram; /* Memory used by buffers */
          |  ^~~~~~~~~~~~~~~~
    /usr/include/linux/sysinfo.h:15:2: error: unknown type name ‘__kernel_ulong_t’
       15 |  __kernel_ulong_t totalswap; /* Total swap space size */
          |  ^~~~~~~~~~~~~~~~
    /usr/include/linux/sysinfo.h:16:2: error: unknown type name ‘__kernel_ulong_t’
       16 |  __kernel_ulong_t freeswap; /* swap space still available */
          |  ^~~~~~~~~~~~~~~~
    /usr/include/linux/sysinfo.h:19:2: error: unknown type name ‘__kernel_ulong_t’
       19 |  __kernel_ulong_t totalhigh; /* Total high memory size */
          |  ^~~~~~~~~~~~~~~~
    /usr/include/linux/sysinfo.h:20:2: error: unknown type name ‘__kernel_ulong_t’
       20 |  __kernel_ulong_t freehigh; /* Available high memory size */
          |  ^~~~~~~~~~~~~~~~
    /usr/include/linux/sysinfo.h:22:22: error: ‘__kernel_ulong_t’ undeclared here (not in a function)
       22 |  char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)]; /* Padding: libc5 uses this.. */
          |                      ^~~~~~~~~~~~~~~~
    
    opened by smartding 1
  • autogen.sh error for memcached-sr

    autogen.sh error for memcached-sr

    ./autogen.sh

    fatal: No names found, cannot describe anything.
    aclocal...
    autoheader...
    automake...
    autoconf...
    configure.ac:8: warning: 'AM_CONFIG_HEADER': this macro is obsolete.
    configure.ac:8: You should use the 'AC_CONFIG_HEADERS' macro instead.
    ./lib/autoconf/general.m4:2434: AC_DIAGNOSE is expanded from...
    aclocal.m4:745: AM_CONFIG_HEADER is expanded from...
    configure.ac:8: the top level
    configure.ac:79: warning: AC_PROG_CC_C99 is obsolete; use AC_PROG_CC
    configure.ac:82: warning: ac_ext=c
    configure.ac:82: ac_cpp='$CPP $CPPFLAGS'
    configure.ac:82: ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
    configure.ac:82: ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
    configure.ac:82: ac_compiler_gnu=$ac_cv_c_compiler_gnu
    configure.ac:82: if test -n "$ac_tool_prefix"; then
    configure.ac:82:   # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
    configure.ac:82: set dummy ${ac_tool_prefix}gcc; ac_word=$2
    configure.ac:82: { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
    configure.ac:82: printf %s "checking for $ac_word... " >&6; }
    configure.ac:82: if test ${ac_cv_prog_CC+y}
    configure.ac:82: then :
    configure.ac:82:   printf %s "(cached) " >&6
    configure.ac:82: else $as_nop
    configure.ac:82:   if test -n "$CC"; then
    configure.ac:82:   ac_cv_prog_CC="$CC" # Let the user override the test.
    configure.ac:82: else
    configure.ac:82: as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
    configure.ac:82: for as_dir in $PATH
    configure.ac:82: do
    configure.ac:82:   IFS=$as_save_IFS
    configure.ac:82:   case $as_dir in #(((
    configure.ac:82:     '' is m4_require'd but not m4_defun'd
    lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
    lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
    ./lib/autoconf/general.m4:2249: AC_CACHE_VAL is expanded from...
    ./lib/autoconf/programs.m4:41: _AC_CHECK_PROG is expanded from...
    ./lib/autoconf/programs.m4:101: AC_CHECK_PROG is expanded from...
    ./lib/autoconf/programs.m4:221: AC_CHECK_TOOL is expanded from...
    ./lib/autoconf/c.m4:452: AC_PROG_CC is expanded from...
    configure.ac:82: the top level
    
    opened by ultperf 0
  • "make" works under bmc folder but ./bmc eth0 churns error below:

    "make" works under bmc folder but ./bmc eth0 churns error below:

    ; for (off = 4; off < BMC_MAX_PACKET_LENGTH && payload+off+1 <= data_end && payload[off] == ' '; off++) {} // move offset to the start of the first key
    46: (1f) r7 -= r8
    47: (b7) r1 = 54
    48: (bf) r2 = r7
    49: (07) r2 += -50
    ; for (off = 4; off < BMC_MAX_PACKET_LENGTH && payload+off+1 <= data_end && payload[off] == ' '; off++) {} // move offset to the start of the first key
    50: (1d) if r7 == r1 goto pc+23
     R0=map_value(id=0,off=0,ks=4,vs=12,imm=0) R1_w=inv54 R2_w=inv(id=0) R6=ctx(id=0,off=0,imm=0) R7_w=inv(id=3) R8=pkt(id=0,off=0,r=54,imm=0) R10=fp0 fp-8=mmmm????
    ; for (off = 4; off < BMC_MAX_PACKET_LENGTH && payload+off+1 <= data_end && payload[off] == ' '; off++) {} // move offset to the start of the first key
    51: (bf) r3 = r8
    52: (0f) r3 += r1
    last_idx 52 first_idx 41
    regs=2 stack=0 before 51: (bf) r3 = r8
    regs=2 stack=0 before 50: (1d) if r7 == r1 goto pc+23
    regs=2 stack=0 before 49: (07) r2 += -50
    regs=2 stack=0 before 48: (bf) r2 = r7
    regs=2 stack=0 before 47: (b7) r1 = 54
    53: (71) r3 = *(u8 *)(r3 +0)
    invalid access to packet, off=54 size=1, R3(id=0,off=54,r=54)
    R3 offset is outside of the packet
    processed 52 insns (limit 1000000) max_states_per_insn 0 total_states 4 peak_states 4 mark_read 2
    
    libbpf: -- END LOG --
    libbpf: failed to load program 'bmc_rx_filter'
    libbpf: failed to load object './bmc_kern.o'
    Error: bpf_object__load_xattr failed
    
    
    opened by ultperf 1
  • error in compilation using bmc-cache/memcached-sr# CC=clang CFLAGS='-DREUSEPORT_OPT=1 -Wno-deprecated-declarations' ./configure && make

    error in compilation using bmc-cache/memcached-sr# CC=clang CFLAGS='-DREUSEPORT_OPT=1 -Wno-deprecated-declarations' ./configure && make

    bmc-cache/memcached-sr# CC=clang CFLAGS='-DREUSEPORT_OPT=1 -Wno-deprecated-declarations' ./configure && make

    ./configure: line 5148: syntax error near unexpected token `newline'
    
    opened by ultperf 0
  • Question on Benchmarks

    Question on Benchmarks

    Hi! I see that BMC is using UDP get requests for benchmarks. I was wondering how you dealt with packet drops. Did the open-loop generator retransmit requests after some time?

    opened by yanniszark 0
Owner
Orange
Open Source by Orange
Orange
Pelikan is Twitter's unified cache backend

Pelikan Pelikan is Twitter's framework for developing cache services. It is: Fast: Pelikan provides high-throughput and low-latency caching solutions.

Twitter 1.8k Jan 2, 2023
NetHunter Kernel for the OnePlus 7 Series based on DragonHeart Kernel

Linux kernel ============ This file was moved to Documentation/admin-guide/README.rst Please notice that there are several guides for kernel develop

cyberknight777 9 Mar 13, 2022
ebpf syscall recording demo project

ebpf syscall recording demo project

Sascha Grunert 9 Jun 7, 2022
Loads a signed kernel driver which allows you to map any driver to kernel mode without any traces of the signed / mapped driver.

CosMapper Loads a signed kernel driver (signed with leaked cert) which allows you to map any driver to kernel mode without any traces of the signed /

null 157 Jan 2, 2023
A kernel module to provide /system/xbin/su to Android Kernel (especially to WSA)

WSA-Kernel-SU Intro This is a kernel module to provide /system/xbin/su to Android Kernel (especially to WSA). Only works on 4.17+ kernel. For older ke

LSPosed 166 Jan 3, 2023
a unix inspired, non posix compliant micro kernel (more of a monolithic kernel for now though) that i am working on in my spare time

toy-kernel a unix inspired, non posix compliant micro kernel (more of a monolithic kernel for now though) that i am working on in my spare time prereq

czapek 13 Nov 27, 2022
A kernel module that patches Linux kernel "on-the-fly" to skip TASK_RSS_EVENTS_THRESH check in check_sync_rss_stat

split-rss-counting-patch A kernel module that patches Linux kernel "on-the-fly" to skip TASK_RSS_EVENTS_THRESH check in check_sync_rss_stat. Why? Read

Bao-Hiep Le 3 Mar 6, 2022
Custom kernel for sweet based on Delta, builds hosted on @sweet_epsilon on Telegram (GH releases are outdated)

Linux kernel ============ This file was moved to Documentation/admin-guide/README.rst Please notice that there are several guides for kernel develop

Udit Karode 14 Mar 29, 2022
xeus-wren is a Jupyter kernel for wren based on the native implementation of the Jupyter protocol xeus.

xeus-wren is a Jupyter kernel for wren based on the native implementation of the Jupyter protocol xeus. Installation xeus-wren has not been packaged f

Thorsten Beier 4 Mar 9, 2022
Inoki's NB1 kernel source tree based on Nokia official tarball

Inoki's NB1 kernel source tree based on Nokia official tarball

Inoki 2 Aug 31, 2022
Nexus Xtreme CAF Kernel | Based On Predator Stormbreaker

Linux kernel release 4.x <http://kernel.org/> These are the release notes for Linux version 4. Read them carefully, as they tell you what this is al

Ayush 0 Oct 7, 2021
BookOS is a tiny OS based on xbook2 kernel, you can use it to study!

BookOS操作系统 BookOS操作系统是一个基于xbook2内核的操作系统,可运行在qemu,bochs,virtual box,vmware等虚拟机中。也可以在物理机上面运行(需要有系统支持的驱动才行) xbook2内核地址: https://github.com/hzcx998/xbook2

Jason Hu 62 Dec 17, 2022
A collection of user-space Linux kernel specific guided fuzzers based on LKL

kBdysch kBdysch is a collection of fast Linux kernel specific fuzzing harnesses supposed to be run in userspace in a guided fuzzing manner. It was des

Anatoly Trosinenko 63 Nov 25, 2022
Optimized Linux kernel for Arch / Arch-based distros

Linux kernel ============ There are several guides for kernel developers and users. These guides can be rendered in a number of formats, like HTML an

cyberknight777 11 Oct 5, 2022
Pixel 4/XL kernel.

Linux kernel ============ This file was moved to Documentation/admin-guide/README.rst Please notice that there are several guides for kernel develop

Sultan Alsawaf 80 Dec 11, 2022
PS4 kernel hooking library / payload.

PS4 KHook PS4 KHook is a minimalist kernel hooking payload. It targets 5.05 but it can be used with any firmware (or even non-PS4 systems) with modifi

Specter 48 Dec 27, 2022
A CAF rebased kernel for Mi 9 & RedMi K20 Pro MIUI 12.5

Linux kernel ============ This file was moved to Documentation/admin-guide/README.rst Please notice that there are several guides for kernel develop

Stephen Sin 76 Jan 8, 2023
Quick fix to iphone usb tethering with ios14 or higher for Linux kernel lower than 5.10.4

Quick fix to Linux Iphone USB tethering with IOS 14 or higher (Tested with ubuntu 18.04, kernel 5.4.0-65, if you fail in the build, please download yo

null 24 Sep 18, 2022
Kernel file/process/object tool

kt Kernel file/process/object tool killav bypass av dump lsass basic vs2019 + cpp + wdk usage(64-bit only) kdu -map sys.sys kt -F -d c:\windows\notepa

null 62 Nov 30, 2022