tomasz kapela, @tomaszkapela linuxcon europe, berlin 2016...the fancy typed pointer...

61
Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016

Upload: others

Post on 01-Apr-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

Tomasz Kapela, @tomaszkapela

LinuxCon Europe, Berlin 2016

Page 2: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

Hype

Page 3: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

3

The NVM programming model

Page 4: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

The solution

Page 5: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

5

NVMLOpen source set of libraries available at www.github.com/pmem/nvml

Library Description

libpmem The basic library, flush to persistence

libvmem Volatile Memory Allocator

libvmmalloc Transparent use of libvmem

libpmemblk Persistent memory carved into blocks

libpmemlog Log file (append-mostly)

libpmemobj Transactional Object Store

Page 6: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

6

libpmemobj

Application

libpmem

Load/Store

memory-mapped pmem

libpmemobj

transactionsatomic

operations

allocatorlists

locks

API API API

Page 7: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

Pointers by libpmemobj

Page 8: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

8

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Page 9: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

9

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Page 10: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

10

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Page 11: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

11

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Page 12: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

12

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Type declarations necessary

Page 13: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

13

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Page 14: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

14

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Type declarations necessary

A lot of macros to make this feasible

Page 15: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

15

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Page 16: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

16

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Type declarations necessary

A lot of macros to make this feasible

A lot of macros to handle the TOID

Page 17: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

17

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Page 18: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

18

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Type declarations necessary

A lot of macros to make this feasible

A lot of macros to handle the TOID

– Why?

Page 19: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

19

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Page 20: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

20

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Type declarations necessary

A lot of macros to make this feasible

A lot of macros to handle the TOID

– Why?

Is it usable?

Page 21: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

21

The fancy typed pointer – TOID

Type safety introduced to a fancy based pointer.

Type declarations necessary

A lot of macros to make this feasible

A lot of macros to handle the TOID

– Why?

Is it usable?

Page 22: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

Addressing the pain points

Page 23: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

23

The fancy typed pointer – persistent_ptr

Encapsulate type info into a smart pointer.

No explicit type declaration

Page 24: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

24

The fancy typed pointer – persistent_ptr

Encapsulate type info into a smart pointer.

No explicit type declaration

– typeid(T).hash_code()

Page 25: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

25

The fancy typed pointer – persistent_ptr

Encapsulate type info into a smart pointer.

No explicit type declaration

– typeid(T).hash_code()

No more macros!

Page 26: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

26

The fancy typed pointer – persistent_ptr

Encapsulate type info into a smart pointer.

Page 27: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

27

The fancy typed pointer – persistent_ptr

Encapsulate type info into a smart pointer.

No explicit type declaration

– typeid(T).hash_code()

No more macros!

Mimics a well known construct

– std::shared_ptr

Now is it usable?

Page 28: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

28

The fancy typed pointer – persistent_ptr

Encapsulate type info into a smart pointer.

Page 29: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

29

The fancy typed pointer – persistent_ptr

Encapsulate type info into a smart pointer.

Page 30: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

30

The fancy typed pointer – persistent_ptr

Known issues

No polymorphic types allowed in persistent memory

– Vtables rebuild issue

typeid(T).hash_code()

– Returns an unspecified value, except that within a single execution of the program, it shall return the same value for any two type_info objects which compare equal.

Page 31: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

Transactions by libpmemobj

Page 32: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

32

Transactions

Consistency critical roll-back transactions.

ACID like properties

Page 33: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

33

Transactions

Consistency critical roll-back transactions.

ACID like properties

„C” exceptions

Page 34: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

34

Transactions

Consistency critical roll-back transactions.

ACID like properties

„C” exceptions

Page 35: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

35

Transactions

Consistency critical roll-back transactions.

ACID like properties

„C” exceptions

Page 36: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

36

Transactions

Consistency critical roll-back transactions.

ACID like properties

„C” exceptions

Macros to make this usable

Page 37: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

37

Transactions

Consistency critical roll-back transactions.

ACID like properties

„C” exceptions

Macros to make this usable

Page 38: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

38

Transactions

Consistency critical roll-back transactions.

ACID like properties

„C” exceptions

Macros to make this usable

Page 39: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

39

Transactions

Consistency critical roll-back transactions.

ACID like properties

„C” exceptions

Macros to make this usable

A bit error prone

– Even with the macros

Page 40: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

40

Transactions

Consistency critical roll-back transactions.

Page 41: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

41

Transactions

Consistency critical roll-back transactions.

ACID like properties

„C” exceptions

Macros to make this usable

A bit error prone

– Even with the macros

Snapshotting

Page 42: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

42

Transactions

Consistency critical roll-back transactions.

Page 43: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

Addressing the pain points

Page 44: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

44

Transactions

Making life easier with RAII and lambdas.

Manual and automatic transaction

Page 45: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

45

Transactions

Making life easier with RAII and lambdas.

Manual and automatic transaction

Page 46: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

46

Transactions

Making life easier with RAII and lambdas.

Manual and automatic transaction

– The problem with std::uncaught_exception

Page 47: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

47

Transactions

Making life easier with RAII and lambdas.

Manual and automatic transaction

– The problem with std::uncaught_exception

– CppCon2015/Declarative Control Flow - Andrei Alexandrescu

Page 48: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

48

Transactions

Making life easier with RAII and lambdas.

Manual and automatic transaction

– The problem with std::uncaught_exception

– Still can’t throw an exception though

Page 49: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

49

Transactions

Making life easier with RAII and lambdas.

Manual and automatic transaction

– The problem with std::uncaught_exception

– Still can’t throw an exception though

The lambda version

Page 50: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

50

Transactions

Making life easier with RAII and lambdas.

Manual and automatic transaction

– The problem with std::uncaught_exception

– Still can’t throw an exception though

The lambda version

Page 51: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

51

Transactions

Making life easier with RAII and lambdas.

Manual and automatic transaction

– The problem with std::uncaught_exception

– Still can’t throw an exception though

The lambda version

Page 52: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

52

Transactions

Making life easier with RAII and lambdas.

Manual and automatic transaction

– The problem with std::uncaught_exception

– Still can’t throw an exception though

The lambda version

– Self contained

– Somewhat ugly looking

Page 53: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

Using the containers

Page 54: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

54

Persistent memory containers

A proof of concept under way.

Targeting libc++ and libstdc++

Page 55: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

55

Persistent memory containers

A proof of concept under way.

Targeting libc++ and libstdc++

Page 56: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

56

Persistent memory containers

A proof of concept under way.

Targeting libc++ and libstdc++

– Libc++ is mostly working

– Libstdc++ needs a bit more work

Page 57: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

57

Persistent memory containers

A proof of concept under way.

Targeting libc++ and libstdc++

– Libc++ is mostly working

– Libstdc++ needs a bit more work

Page 58: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

58

Persistent memory containers

A proof of concept under way.

Targeting libc++ and libstdc++

– Libc++ is mostly working

– Libstdc++ needs a bit more work

Main pros

– It’s for free! (well, almost)

– Familiar interface

– Well tested implementation of containers

Page 59: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

59

Persistent memory containers

What are the known issues

Internally held data is not „aware” of persistence

T* used instead of allocator_traits::pointer

Layout versioning

Current implementation works only on x86_64

Page 60: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild
Page 61: Tomasz Kapela, @tomaszkapela LinuxCon Europe, Berlin 2016...The fancy typed pointer –persistent_ptr Known issues No polymorphic types allowed in persistent memory –Vtables rebuild

61

Handy links

The allocator branch:

https://github.com/tomaszkapela/nvml/tree/cpp-allocator

Libpmemobj++ documentation:

http://pmem.io/nvml/cpp_obj/

Pmem Google Groups page:

https://groups.google.com/forum/#!forum/pmem