When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20...

27
When eBPF Meets FUSE Improving the performance of user file systems Ashish Bijlani, PhD Student, Georgia Tech @ashishbijlani 1

Transcript of When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20...

Page 1: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

When eBPF Meets FUSE Improving the performance of user file systems

Ashish Bijlani, PhD Student, Georgia Tech

@ashishbijlani 1

Page 2: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

In-Kernel vs User File Systems

“People who think that userspace filesystems are realistic for anything but toys are just misguided.”

- Linus Torvalds

“A lot of people once thought Linux and the machines it ran on were toys… Apparently I’m misguided.”

- Jeff Darcy

2

Page 3: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

In-Kernel vs User File Systems

• Examples – Ext4, OverlayFS, etc.

• Pros – Native performance

• Cons – Poor security/reliability – Not easy to develop/

debug/maintain

• Examples – EncFS, Gluster, etc.

• Pros – Improved security/

reliability – Easy to develop/debug/

maintain • Cons

– Poor performance!– Poor performance!

3

Page 4: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

File Systems in User Space (FUSE)

• State-of-the-art framework – All file system handlers

implemented in user space

• Over 100+ FUSE file systems – Stackable: Android SDCardFS,

EncFS, etc. – Network: GlusterFS, Ceph,

Amazon S3FS, etc. 4

struct fuse_lowlevel_ops ops { .lookup = handle_lookup, .access = NULL, .getattr = handle_getattr, .setattr = handle_setattr, .open = handle_open, .read = handle_read, .readdir = handle_readdir, .write = handle_write, // more handlers … .getxattr = handle_getxattr, .rename = handle_rename, .symlink = handle_symlink, .flush = NULL,

}

Page 5: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

FUSE Architecture

VFS

Application

Lower FS (e.g., EXT4)

FUSE Daemon

FUSE Driver

UserKernel

1

QUEUE

L I B F U S E

5

2

3

4

5

6

4’

Over the network

Stackable

Page 6: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

FUSE Performance• “tar xf linux-4.17.tar.xz”

– Intel i5-3350 quad core, Ubuntu 16.04.4 LTS – Linux 4.11.0, LibFUSE commit # 386b1b

Tim

e (s

ec)

0

4

8

11

15

HDD SSD

Native FUSE

6

Overhead HDD: 78.8% SSD: 81.1%

More noticeable on faster media!

Page 7: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

FUSE Performance• “cd linux-4.17; make tinyconfig; make -j4”

– Intel i5-3350 quad core, SSD, Ubuntu 16.04.4 LTS – Linux 4.11.0, LibFUSE commit # 386b1b

Tim

e (s

ec)

0

10

20

30

40

Native FUSE

17.54% overhead

7

Page 8: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

FUSE Architecture

VFS

Application

Lower FS (e.g., EXT4)

FUSE Daemon

FUSE Driver

UserKernel

1

QUEUE

L I B F U S E

open(“/mnt/foo/bar”)

8

lookup(“foo”)2

3

4

5

6

C O N T E X T S W I T C H

lookup() getattr() setattr() open() read() readdir() write() … rename() symlink() close() getxattr() setxattr()

Page 9: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

Requests received by FUSE daemon• “cd linux-4.17; make tinyconfig; make -j4”

# Re

ques

ts

0K

100K

200K

300K

400K

LookupG

etattrRenam

eSetattrCreateO

penReleaseG

etxattrM

kdirU

nlinkO

pendirReaddirReleasedirRead

Write

9

Page 10: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

FUSE Optimizations• Big 128K writes

– “-o max_write=131072” • Zero data copying for data I/O

– “-o splice_read, splice_write, splice_move” • Leveraging VFS caches

– Page cache for data I/O • “-o writeback_cache”

– Dentry and Inode caches for lookup() and getattr() • “entry_timeout”, “attr_timeout”

10

Page 11: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

FUSE Performance• “cd linux-4.17; make tinyconfig; make -j4”

• Intel i5-3350 quad core, Ubuntu 16.04.4 LTS • Linux 4.11.0, LibFUSE commit # 386b1b

Tim

e (s

ec)

0

10

20

30

40

Native Regular Optimized 11

Opts do not help much!

Opts Enabled -o max_write=128K -o splice_read -o splice_write -o splice_move entry_timeout > 0 attr_timeout > 0

Page 12: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

• “cd linux-4.17; make tinyconfig; make -j4”

# Re

ques

ts

0K

100K

200K

300K

400K

LookupG

etattrRenam

eSetattrCreateO

penReleaseG

etxattrM

kdirU

nlinkO

pendirReaddirReleasedirRead

Write

Regular Optimized

12

Requests received by FUSE daemon

4x fewer lookup()s

Page 13: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

• “cd linux-4.17; make tinyconfig; make -j4”

# Re

ques

ts

0K

100K

200K

300K

400K

LookupG

etattrRenam

eSetattrCreateO

penReleaseG

etxattrM

kdirU

nlinkO

pendirReaddirReleasedirRead

Write

Regular Optimized

13

Requests received by FUSE daemon

1 23

4

atime changes during read() invalidate cached attributes

Page 14: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

• “cd linux-4.17; make tinyconfig; make -j4”

# Re

ques

ts

0K

100K

200K

300K

400K

LookupG

etattrRenam

eSetattrCreateO

penReleaseG

etxattrM

kdirU

nlinkO

pendirReaddirReleasedirRead

Write

Regular Optimized

14

Requests received by FUSE daemon

1’2’

VFS issues getxattr() for each write() for

reading security labels

Page 15: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

eBPF

15

• Berkeley Packet Filter (BPF) – Pseudo machine architecture for packet filtering

• eBPF enhances BPF – Evolved as a generic kernel extension framework – Used by tracing, perf, and network subsystems

Page 16: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

eBPF Overview

16

• Extensions written in C • Compiled into BPF code • Code is verified and

loaded into kernel • Execution under virtual

machine runtime • Shared BPF maps with

user space

BPF C program

Clang/LLVM

user

kernel

bytecode

syscall()

Verifier

bpf virtual machine

Kernel functions

sandbox key-value data struct

BPF Map

Page 17: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

eBPF Simplified Example

17

struct bpf_map_def map = { .type = BPF_MAP_TYPE_ARRAY, .key_size = sizeof(u32), .value_size = sizeof(u64), .max_entries = 1, // single element };

// tracepoint/syscalls/sys_enter_open int count_open(struct syscall *args) { u32 key = 0; u64 *val = bpf_map_lookup_elem(map, &key); if (val) __sync_fetch_and_add(val, 1); }

Page 18: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

ExtFUSE: eBPF meets FUSE

18

• Extension framework for File systems in User space – Register “thin” extensions - handle requests in kernel

• Avoid user space context switch!

– Share data between FUSE daemon and extensions using BPF maps

• Cache metadata in the kernel

Page 19: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

FUSE Architecture

VFS

Application

Lower FS (e.g., EXT4)

FUSE Driver

UserKernel

1

QUEUE

19

2

3

4

5

6

BPF VM3’

FUSE DaemonL I B F U S E

BPF Handlers L I B E x t F U S E

BPF Map 4’

0’7

Cache Meta- data

Load BPF Code Deliver req to

extension

Serve from cache

Page 20: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

ExtFUSE Simplified Example

20

struct bpf_map_def map = { .type = BPF_MAP_TYPE_HASH, .key_size = sizeof(u64), // ino (param 0) .value_size = sizeof(struct fuse_attr_out), .max_entries = MAX_NUM_ATTRS, // 2 << 16 };

// getattr() kernel extension - cache attrs int getattr(struct extfuse_args *args) { u32 key = bpf_extfuse_read(args, PARAM0); u64 *val = bpf_map_lookup_elem(map, &key); if (val) bpf_extfuse_write(args, PARAM0, val); }

Page 21: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

ExtFUSE Simplified Example

21

// setattr() kernel extension - invalidate attrs int setattr(struct extfuse_args *args) { u32 key = bpf_extfuse_read(args, PARAM0); if (val) bpf_map_delete_elem(map, &key); }

• Invalidate cached attrs from kernel extensions. E.g.,

• Cache attrs from FUSE daemon – Insert into map on atime change

• Similarly, cache lookup()s and xattr()s

Page 22: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

ExtFUSE Performance• “cd linux-4.17; make tinyconfig; make -j4”

• Intel i5-3350 quad core, SSD, Ubuntu 16.04.4 LTS • Linux 4.11.0, LibFUSE commit # 386b1b

Tim

e (s

ec)

0

10

20

30

40

Native Regular Optimized ExtFUSE 22

Overhead Regular Latency: 17.54% ExtFUSE Latency: 5.71% ExtFUSE Memory: 50MB (worst case) Cached lookup, attr, xattr

Page 23: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

• “cd linux-4.17; make tinyconfig; make -j4”

# Re

ques

ts

0K

100K

200K

300K

400K

LookupG

etattrRenam

eSetattrCreateO

penReleaseG

etxattrM

kdirU

nlinkO

pendirReaddirReleasedirRead

Write

Regular Optimized ExtFUSE

23

Requests received by FUSE daemon

Very few getattr()s

Very few getxattr()s

Page 24: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

• BPF code to cache/invalidate meta-data in kernel – Applies potentially to all FUSE file systems – e.g., Gluster readdir ahead results could be cached

• BPF code to perform custom filtering or perm checks – e.g., Android SDCardFS uid checks in lookup(), open()

• BPF code to forward I/O requests to lower FS in kernel – e.g., install/remove target file descriptor in BPF map

24

ExtFUSE Applications

Page 25: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

• Work in progress at Georgia Tech – Applying to Gluster, Ceph, EncFS, Android

SDCardFS, etc. – Project page: https://extfuse.github.io

• References – FUSE performance study by FSL, Stony Brook – IOVisor eBPF Project – BPF Compiler Collection (BCC) Toolchain

25

ExtFUSE Status and References

Page 26: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

Thank You!

26

[email protected]

www.linkedin.com/in/ashishbijlani

Page 27: When eBPF Meets FUSE - Linux Foundation Events...• Linux 4.11.0, LibFUSE commit # 386b1b) 0 10 20 30 40 Native Regular Optimized ExtFUSE 22 Overhead Regular Latency: 17.54% ExtFUSE

27