GithubHelp home page GithubHelp logo

bear-metal / memfd Goto Github PK

View Code? Open in Web Editor NEW
6.0 5.0 0.0 15 KB

A Ruby wrapper around the memfd_create(2) system call which creates an anonymous memory-backed file

License: Other

Ruby 54.78% C 45.22%

memfd's Introduction

Memfd

Status

Travis Build Status

Description

Memfd is a wrapper around the memfd_create system call which creates an anonymous memory-backed file and returns a file descriptor reference to it. It provides a simple alternative to manually mounting a tmpfs filesystem and creating and opening a file in that filesystem. The file is a regular file on a kernel-internal filesystem and thus supports most operations such as ftruncate(2), read(2), dup(2), mmap(2) etc.

Imagine that malloc(3) returns a file descriptor instead of a pointer. The system call also introduced a new feature called "file sealing". With file sealing you can specify to the kernel that the file backed by anonymous memory has certain restrictions such as: no writes occur to the file, and the file size does not shrink or grow. For IPC based servers the F_SEAL_SHRINK seal is of interest and the server can be sure clients won't shrink it's buffers and can read files without side effects of unexpected shrinking.

Use cases

  • Shared memory buffers don't require a mount point or having to create files on the filesystem soley to use as shared memory.
  • An alternative to creating files in /tmp if there's never an intention to actually link the file in the filesystem.
  • Zero-copy transfer of large objects through IPC: one process creates a shared memory object and just passes the file descriptor to a remote process.
  • Preventing specific operations on a file through the file sealing API.
  • Better server stability and less risk of unexpected SIGBUS due to unexpected client buffer alterations.

Installation

Linux ONLY!

gem install memfd

Synopsis

TODO

#! /usr/bin/env ruby

require 'memfd'

Requirements

  • Ruby 2.1.0 or higher, including any development packages necessary to compile native extensions.

  • A Linux Kernel version > 3.17

Development

  bundle install
  bundle exec rake

License

MIT. See the LICENSE.txt file.

memfd's People

Contributors

methodmissing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.