### Building and Installing Experimental PMDK Packages (sh) Source: https://github.com/pmem/pmdk/blob/master/INSTALL.md This command enables the building and installation of experimental PMDK components, which are not included in standard packages by default. Users can specify 'install', 'rpm', or 'dpkg' to perform the respective action. ```sh make EXPERIMENTAL=y [install,rpm,dpkg] ``` -------------------------------- ### Example PMEMOBJ_CONF_FILE Content - Configuration File Source: https://github.com/pmem/pmdk/blob/master/doc/pmem_ctl/pmem_ctl.5.md This snippet provides an example of a configuration file that can be pointed to by the `PMEMOBJ_CONF_FILE` environment variable. It shows how to use comments (`#`) and whitespace for readability while configuring `prefault.at_open` and `prefault.at_create` settings. ```Text ######################### # My pmemobj configuration ######################### # # Global settings: prefault. # modify the behavior of pre-faulting at_open = 1; # prefault when the pool is opened prefault. at_create = 0; # but don't prefault when it's created # Per-pool settings: # ... ``` -------------------------------- ### CTL Configuration String Format - Full Sequence Example Source: https://github.com/pmem/pmdk/blob/master/doc/pmem_ctl/pmem_ctl.5.md This snippet provides a comprehensive example of a full `ctl` configuration sequence. It combines multiple entry point assignments with their respective arguments, illustrating the complete structure for the `PMEMOBJ_CONF` environment variable. ```Text (first_entry_point)=(arguments, ...);...;(last_entry_point)=(arguments, ...); ``` -------------------------------- ### daxio Utility Usage Examples - Shell Source: https://github.com/pmem/pmdk/blob/master/doc/daxio/daxio.1.md This section provides practical examples demonstrating various operations performed by the `daxio` utility on Device DAX devices, including zeroing, dumping data, and copying with specific offsets. ```Shell # daxio --zero /dev/dax1.0 ``` ```Shell # daxio --input=/dev/dax1.0 --output=/home/myfile --len=2M --seek=4096 ``` ```Shell # cat /dev/zero | daxio --output=/dev/dax1.0 ``` ```Shell # daxio --input=/dev/zero --output=/dev/dax1.0 --skip=4096 ``` -------------------------------- ### Running Initial Setup Playbook (Generic) Source: https://github.com/pmem/pmdk/blob/master/utils/ansible/README.md Executes the initial setup Ansible playbook, which can be either `opensuse-setup.yml` or `rockylinux-setup.yml`, to provision the system and create a new user named `pmdkuser`. This step is typically performed as root. ```Shell export SETUP_SCRIPT= # opensuse-setup.yml or rockylinux-setup.yml sudo ansible-playbook $SETUP_SCRIPT --extra-vars "new_user=pmdkuser" ``` -------------------------------- ### Installing PMDK Libraries (sh) Source: https://github.com/pmem/pmdk/blob/master/INSTALL.md This command installs the compiled PMDK libraries to the system-wide locations. It requires superuser privileges ('sudo') to write to system directories. ```sh sudo make install ``` -------------------------------- ### Running PMDK Unit Tests (sh) Source: https://github.com/pmem/pmdk/blob/master/INSTALL.md This command builds and executes the unit tests for the PMDK libraries. It requires the 'ndctl' package to be installed and may depend on a prepared 'src/test/testconfig.sh' file for specific test configurations. ```sh make check ``` -------------------------------- ### OpenSUSE: Running Initial Setup Playbook (Root) Source: https://github.com/pmem/pmdk/blob/master/utils/ansible/README.md Executes the `opensuse-setup.yml` playbook as root to provision the system and create a new user `pmdkuser` with a specified password. A manual reboot might be required, after which the playbook is re-run to complete the setup. ```Shell # as root: ansible-playbook opensuse-setup.yml --extra-vars "new_user=pmdkuser new_user_pass=pmdkpass" # reboot shall be performed only if the playbook requests to do it. reboot # ... cd pmdk/utils/ansible ansible-playbook opensuse-setup.yml --extra-vars "new_user=pmdkuser new_user_pass=pmdkpass" ``` -------------------------------- ### Building and Installing PMDK from Source (Shell) Source: https://github.com/pmem/pmdk/blob/master/README.md This snippet provides shell commands to clone the PMDK repository from GitHub, navigate into the directory, and build the project using `make`. It outlines the basic steps for compiling PMDK from its source code, requiring prior installation of dependencies as mentioned in INSTALL.md. ```sh # get the source code git clone https://github.com/pmem/pmdk cd pmdk # build make -j ``` -------------------------------- ### Rocky Linux: Initial System Preparation (Root) Source: https://github.com/pmem/pmdk/blob/master/utils/ansible/README.md Prepares a Rocky Linux system by installing `git-core` and `ansible-core`, installing the `ansible.posix` collection, cloning the PMDK repository, and navigating to the Ansible playbooks directory. This sequence is executed as the root user. ```Shell # as root: dnf install git-core -y dnf install ansible-core -y ansible-galaxy collection install ansible.posix git clone https://github.com/pmem/pmdk.git cd pmdk/utils/ansible ``` -------------------------------- ### Building PMDK Libraries (sh) Source: https://github.com/pmem/pmdk/blob/master/INSTALL.md This command initiates the default build process for the PMDK libraries using the 'make' utility. By default, it builds all components with the '-Werror' flag, treating compiler warnings as errors. ```sh make ``` -------------------------------- ### Rocky Linux: Running Initial Setup Playbook (Root) Source: https://github.com/pmem/pmdk/blob/master/utils/ansible/README.md Executes the `rockylinux-setup.yml` playbook as root to provision the system and create a new user `pmdkuser` with a specified password. A manual reboot might be required, after which the playbook is re-run to complete the setup. ```Shell # as root: ansible-playbook rockylinux-setup.yml --extra-vars "new_user=pmdkuser new_user_pass=pmdkpass" # reboot shall be performed only if the playbook requests to do it. reboot # ... cd pmdk/utils/ansible ansible-playbook rockylinux-setup.yml --extra-vars "new_user=pmdkuser new_user_pass=pmdkpass" ``` -------------------------------- ### Example: Using pmem_check_version for API Compatibility Source: https://github.com/pmem/pmdk/blob/master/doc/libpmem/libpmem.7.md This C code example demonstrates how to use pmem_check_version to ensure API compatibility between an application and the installed libpmem library. It utilizes compile-time defined PMEM_MAJOR_VERSION and PMEM_MINOR_VERSION to check if the library meets the application's requirements. If the returned 'reason' is not NULL, the version check failed, and the string provides details. ```C reason = pmem_check_version(PMEM_MAJOR_VERSION, PMEM_MINOR_VERSION); if (reason != NULL) { /* version check failed, reason string tells you why */ } ``` -------------------------------- ### OpenSUSE: Initial System Preparation (Root) Source: https://github.com/pmem/pmdk/blob/master/utils/ansible/README.md Prepares an OpenSUSE system by installing `git-core` and `ansible`, cloning the PMDK repository, and navigating to the Ansible playbooks directory. This sequence is executed as the root user. ```Shell # as root: zypper install git-core -y zypper install ansible -y git clone https://github.com/pmem/pmdk.git cd pmdk/utils/ansible ``` -------------------------------- ### Installing PMDK Libraries using Make Source: https://github.com/pmem/pmdk/blob/master/README.md This command executes the `install` target of the Makefile, typically used to copy compiled PMDK libraries and headers to system-wide locations. It requires superuser privileges (`sudo`) to write to protected directories. This step is optional and further details can be found in the `INSTALL.md` file. ```Shell sudo make install ``` -------------------------------- ### Example Pool Set Configuration File Source: https://github.com/pmem/pmdk/blob/master/doc/poolset/poolset.5.md Demonstrates a basic `poolset` file configuration. It specifies the `PMEMPOOLSET` header, the `NOHDRS` option, and three pool parts with their respective sizes and absolute pathnames, spanning different mount points. ```text PMEMPOOLSET OPTION NOHDRS 100G /mountpoint0/myfile.part0 200G /mountpoint1/myfile.part1 400G /mountpoint2/myfile.part2 ``` -------------------------------- ### Cloning PMDK Repository (sh) Source: https://github.com/pmem/pmdk/blob/master/INSTALL.md This command clones the PMDK source repository from GitHub and then changes the current directory into the newly cloned 'pmdk' directory, preparing for the build process. ```sh git clone https://github.com/pmem/pmdk cd pmdk ``` -------------------------------- ### Modifying PMDK Test Timeout (sh) Source: https://github.com/pmem/pmdk/blob/master/INSTALL.md This command runs PMDK tests and sets a custom timeout for the 'check' type tests. In this example, 'TEST_TIME=1m' configures the timeout to 1 minute, preventing tests from running indefinitely. ```sh make check TEST_TIME=1m ``` -------------------------------- ### Running a Subset of PMDK Tests (sh) Source: https://github.com/pmem/pmdk/blob/master/INSTALL.md This command executes a specific subset of PMDK tests by defining various parameters. 'TEST_TYPE=short' runs a quick set of tests, 'TEST_BUILD=debug' uses debug builds, and 'TEST_FS=pmem' specifies the filesystem type for testing. ```sh make check TEST_TYPE=short TEST_BUILD=debug TEST_FS=pmem ``` -------------------------------- ### Example Pool Set Configuration with Replicas Source: https://github.com/pmem/pmdk/blob/master/doc/poolset/poolset.5.md Illustrates a `poolset` file configuration that includes a local replica. It defines the primary pool parts and then a separate `REPLICA` section with its own parts, providing data mirroring for reliability. ```text PMEMPOOLSET 100G /mountpoint0/myfile.part0 200G /mountpoint1/myfile.part1 400G /mountpoint2/myfile.part2 # local replica REPLICA 500G /mountpoint3/mymirror.part0 200G /mountpoint4/mymirror.part1 ``` -------------------------------- ### Installing Ansible Core Packages Source: https://github.com/pmem/pmdk/blob/master/utils/ansible/README.md This snippet demonstrates how to install the `ansible-core` package on various Linux distributions (RockyLinux/dnf, OpenSUSE/zypper, Debian/apt) using their respective package managers. This is a prerequisite for running Ansible playbooks. ```sh sudo dnf install ansible-core # or sudo zypper install ansible # or sudo apt install ansible-core ``` -------------------------------- ### Example Pool Set File Name Source: https://github.com/pmem/pmdk/blob/master/doc/poolset/poolset.5.md Illustrates the typical naming convention for a persistent memory pool configuration file, which defines how a pool spans multiple memory devices or includes replicas. ```text mypool.set ``` -------------------------------- ### Starting PMDK Transactions with TX_BEGIN Variants in C Source: https://github.com/pmem/pmdk/blob/master/doc/libpmemobj/pmemobj_tx_begin.3.md These C macros initiate a new transaction in libpmemobj, similar to pmemobj_tx_begin(), but manage the jmp_buf internally for abort handling. TX_BEGIN() starts a basic transaction. TX_BEGIN_PARAM() allows for acquiring locks before the transaction or setting up a transaction stage callback, useful for multi-threaded contexts. TX_BEGIN_CB() specifically enables defining a callback function (cb) with an argument (arg) for transaction stage changes. ```C TX_BEGIN_PARAM(PMEMobjpool *pop, ...) TX_BEGIN_CB(PMEMobjpool *pop, cb, arg, ...) TX_BEGIN(PMEMobjpool *pop) ``` -------------------------------- ### Building PMDK with Address and UndefinedBehavior Sanitizers (sh) Source: https://github.com/pmem/pmdk/blob/master/INSTALL.md This command builds the PMDK libraries with AddressSanitizer and UndefinedBehaviorSanitizer enabled for enhanced testing. It also includes 'clobber' to clean previous builds and 'check' to run tests after building. ```sh make SANITIZE=address,undefined clobber check ``` -------------------------------- ### Building PMDK with Specific Werror Disabled (sh) Source: https://github.com/pmem/pmdk/blob/master/INSTALL.md This command builds the PMDK libraries while disabling a specific type of compiler warning, identified by '$(type-of-warning)'. This provides fine-grained control over which warnings are ignored during the build process. ```sh make EXTRA_CFLAGS="-Wno-error=$(type-of-warning)" ``` -------------------------------- ### Installing Ansible Posix Collection Source: https://github.com/pmem/pmdk/blob/master/utils/ansible/README.md This command installs the `ansible.posix` collection, which is required for running specific playbooks like `configure-pmem.yml` and `rockylinux-setup.yml`. It extends Ansible's capabilities with POSIX-specific modules. ```sh sudo ansible-galaxy collection install ansible.posix ``` -------------------------------- ### Checking Out a Specific PMDK Release (sh) Source: https://github.com/pmem/pmdk/blob/master/INSTALL.md This command checks out a specific stable release tag (e.g., '2.1.1') of the PMDK repository. This is an optional step for users who prefer to build a stable version rather than the latest development release. ```sh git checkout tags/2.1.1 ``` -------------------------------- ### Example of a Properly Formatted Git Commit Message Source: https://github.com/pmem/pmdk/blob/master/CODING_STYLE.md This example demonstrates a Git commit message that adheres to the specified PMDK conventions, including a concise summary line, a blank line separator, a detailed body with paragraphs and bullet points, and an issue reference at the end. ```Git doc: fix code formatting in man pages This section contains paragraph style text with complete English sentences. There can be as many paragraphs as necessary. - Bullet points are typically sentence fragments - The first word of the bullet point is usually capitalized and if the point is long, it is continued with a hanging indent - The sentence fragments don't typically end with a period Ref: pmem/issues#1 ``` -------------------------------- ### Building PMDK with Werror Disabled (sh) Source: https://github.com/pmem/pmdk/blob/master/INSTALL.md This command builds the PMDK libraries while disabling the '-Werror' flag, preventing the build from failing due to compiler warnings. This is useful in deployment environments where strict warning policies might be relaxed. ```sh make EXTRA_CFLAGS="-Wno-error" ``` -------------------------------- ### Disabling Valgrind Support in PMDK Build (sh) Source: https://github.com/pmem/pmdk/blob/master/INSTALL.md This command builds the PMDK libraries with support for Valgrind memory management tools explicitly disabled. By default, Valgrind support is enabled, but this flag allows users to opt out. ```sh make VALGRIND=0 ``` -------------------------------- ### Demonstrating ReorderPartial Engine Behavior Source: https://github.com/pmem/pmdk/blob/master/doc/pmreorder/pmreorder.1.md This snippet shows the ReorderPartial engine's behavior, which selects and checks consistency on a limited number of randomly chosen sequences. For an input (a, b, c), it provides examples of possible outputs like (b, c), (b), and (a, b, c), representing a subset of combinations. ```Text Example: input: (a, b, c) output: (b, c) (b) (a, b, c) ``` -------------------------------- ### Configuring Persistent Memory and Finalizing Setup Source: https://github.com/pmem/pmdk/blob/master/utils/ansible/README.md Configures persistent memory regions using `configure-pmem.yml` playbook, initially with `newRegions=true` to create new regions. A manual reboot is required, after which the playbook is re-run without `newRegions=true` to finalize the PMEM setup. This is run as `pmdkuser`. ```Shell ansible-playbook configure-pmem.yml --extra-vars "ansible_user=pmdkuser newRegions=true" # you will have to perform a reboot manually sudo reboot # and re-run the playbook without newRegions=true to finalize the setup ansible-playbook configure-pmem.yml --extra-vars "ansible_user=pmdkuser" ``` -------------------------------- ### Persisting Data to Memory-Mapped Persistent Memory in C Source: https://github.com/pmem/pmdk/blob/master/doc/libpmem/libpmem.7.md This C example demonstrates how to create and memory-map a persistent memory file, write a string to it, and then flush the changes to persistence. It uses `pmem_map_file` to map the file, `strcpy` to write data, and either `pmem_persist` (if `is_pmem` is true) or `pmem_msync` (otherwise) to ensure data durability. Finally, `pmem_unmap` is used to release the mapping. The example highlights the non-transactional nature of these operations. ```C #include #include #include #include #include #include #include #include #include /* using 4k of pmem for this example */ #define PMEM_LEN 4096 #define PATH "/pmem-fs/myfile" int main(int argc, char *argv[]) { char *pmemaddr; size_t mapped_len; int is_pmem; /* create a pmem file and memory map it */ if ((pmemaddr = pmem_map_file(PATH, PMEM_LEN, PMEM_FILE_CREATE, 0666, &mapped_len, &is_pmem)) == NULL) { perror("pmem_map_file"); exit(1); } /* store a string to the persistent memory */ strcpy(pmemaddr, "hello, persistent memory"); /* flush above strcpy to persistence */ if (is_pmem) pmem_persist(pmemaddr, mapped_len); else pmem_msync(pmemaddr, mapped_len); /* * Delete the mappings. The region is also * * automatically unmapped when the process is * * terminated. */ pmem_unmap(pmemaddr, mapped_len); } ``` -------------------------------- ### Example Usage of pmempool_check_version (C) Source: https://github.com/pmem/pmdk/blob/master/doc/libpmempool/libpmempool.7.md This code snippet demonstrates how to use `pmempool_check_version` with compile-time macros (`PMEMPOOL_MAJOR_VERSION`, `PMEMPOOL_MINOR_VERSION`) to check for library compatibility. It includes a conditional block to handle cases where the version check fails, indicating the reason. ```C reason = pmempool_check_version(PMEMPOOL_MAJOR_VERSION, PMEMPOOL_MINOR_VERSION); if (reason != NULL) { /* version check failed, reason string tells you why */ } ``` -------------------------------- ### Configuring pmreorder Engines for Specific Functions (JSON) Source: https://github.com/pmem/pmdk/blob/master/doc/pmreorder/pmreorder.1.md Provides an example of configuring reordering engines for specific libpmemobj API functions using a JSON file. This allows fine-grained control, such as disabling reordering for pmemobj_open while enabling partial reordering for pmemobj_memcpy_persist. ```JSON { "pmemobj_open":"NoReorderNoCheck", "pmemobj_memcpy_persist":"ReorderPartial" } ``` -------------------------------- ### Querying PMDK Version for Deb Packages Source: https://github.com/pmem/pmdk/blob/master/CONTRIBUTING.md This command is used on Debian-based Linux distributions (e.g., Ubuntu, Debian) to query the installed PMDK package. It displays information about the package, and the second string in its output typically represents the version number of the PMDK binary release. ```Shell dpkg-query -W pmdk ``` -------------------------------- ### Using pmempool Command-Line Tool Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool.1.md This snippet shows the basic syntax for invoking the `pmempool` command. It indicates that `pmempool` can be run with optional `--help` or `--version` flags, followed by a specific `` and its associated `[]`. This is the general entry point for all `pmempool` subcommands. ```Shell $ pmempool [--help] [--version] [] ``` -------------------------------- ### Querying PMDK Version for RPM Packages Source: https://github.com/pmem/pmdk/blob/master/CONTRIBUTING.md This command is used on RPM-based Linux distributions (e.g., Fedora, CentOS, RHEL) to query the installed PMDK package and display its full name, which includes the version number. It's useful for identifying the exact binary release. ```Shell rpm -q pmdk ``` -------------------------------- ### Getting Mapping Address in libpmem2 (C) Source: https://github.com/pmem/pmdk/blob/master/doc/libpmem2/pmem2_map_get_address.3.md This snippet defines the `pmem2_map_get_address` function, which is used to retrieve the base address of a memory mapping created by `pmem2_map_new`. It takes a pointer to a `pmem2_map` structure as input and returns a `void*` pointer to the start of the mapped memory area. ```C #include void *pmem2_map_get_address(struct pmem2_map *map); ``` -------------------------------- ### Defining a Custom Persistent Memory Layout (C) Source: https://github.com/pmem/pmdk/blob/master/doc/libpmemobj/pobj_layout_begin.3.md This example demonstrates how to declare a custom persistent memory layout named `mylayout` using `POBJ_LAYOUT_BEGIN` and `POBJ_LAYOUT_END`. It defines a root object of type `struct root` and two additional types, `struct node` and `struct foo`, using `POBJ_LAYOUT_TOID`. The snippet also includes the C struct definitions for `root` and `node`, showing how `TOID` is used to declare persistent pointers within these structures. This setup allows for type-safe access to objects within a persistent memory pool. ```C POBJ_LAYOUT_BEGIN(mylayout); POBJ_LAYOUT_ROOT(mylayout, struct root); POBJ_LAYOUT_TOID(mylayout, struct node); POBJ_LAYOUT_TOID(mylayout, struct foo); POBJ_LAYOUT_END(mylayout); struct root { TOID(struct node) node; }; struct node { TOID(struct node) next; TOID(struct foo) foo; }; ``` -------------------------------- ### Checking libpmemobj API Version in C Source: https://github.com/pmem/pmdk/blob/master/doc/libpmemobj/libpmemobj.7.md This snippet demonstrates how to verify if the installed libpmemobj library's API version is compatible with the application's requirements. It calls `pmemobj_check_version` using compile-time major and minor version macros. A non-NULL return value indicates a version mismatch, with the string detailing the reason. ```C reason = pmemobj_check_version(PMEMOBJ_MAJOR_VERSION, PMEMOBJ_MINOR_VERSION); if (reason != NULL) { /* version check failed, reason string tells you why */ } ``` -------------------------------- ### daxio Command Synopsis - Shell Source: https://github.com/pmem/pmdk/blob/master/doc/daxio/daxio.1.md This snippet presents the general command-line synopsis for the `daxio` utility, illustrating its basic usage pattern with placeholder options. ```Shell $ daxio [] ``` -------------------------------- ### Making a Local PMDK Release (Git/Bash) Source: https://github.com/pmem/pmdk/blob/master/RELEASE_STEPS.md This sequence of Git commands prepares the local PMDK repository for a new release. It removes the `GIT_VERSION` file, updates the `VERSION` file with the new release number, commits these changes, and creates a signed, annotated Git tag for the release. Signing the commit and tag (`-S`/`-s`) is recommended for authenticity. ```bash git rm GIT_VERSION echo $VERSION > VERSION git add VERSION git commit -a -S -m "common: $VERSION release" git tag -a -s -m "PMDK Version $VERSION" $VERSION ``` -------------------------------- ### Creating PMDK Source Archive (Git/Bash) Source: https://github.com/pmem/pmdk/blob/master/RELEASE_STEPS.md This command uses `git archive` to create a compressed tarball of the PMDK source code for the specified release version. The `--prefix` option ensures that the contents inside the archive are placed within a directory named `pmdk-$VERSION/`, which is useful for consistent extraction. ```bash git archive --prefix="pmdk-$VERSION/" -o pmdk-$VERSION.tar.gz $VERSION ``` -------------------------------- ### Removing Multiple Specific Pool Files - Bash Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool-rm.1.md This example demonstrates how to remove multiple individual persistent memory pool files by specifying their names as arguments to the `pmempool rm` command. ```Bash $ pmempool rm pool1.obj pool2.obj ``` -------------------------------- ### Display Help Message (-h, --help) - CLI Options Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool-info.1.md Prints a help message to the console, providing an overview of the command's usage and available options, and then exits the program. ```Shell -h, --help ``` -------------------------------- ### CTL Configuration String Format - Single Query Source: https://github.com/pmem/pmdk/blob/master/doc/pmem_ctl/pmem_ctl.5.md This snippet shows the structure of a single `ctl` query, consisting of an `entry_point` name and its corresponding `entry_point_argument`, separated by an equals sign. This is a fundamental building block for `PMEMOBJ_CONF` strings. ```Text entry_point=entry_point_argument ``` -------------------------------- ### Checking libpmempool API Version (C) Source: https://github.com/pmem/pmdk/blob/master/doc/libpmempool/libpmempool.7.md This C function signature defines `pmempool_check_version`, which allows applications to verify if the installed `libpmempool` supports a required API version by comparing major and minor version numbers. ```C const char *pmempool_check_version( unsigned major_required, unsigned minor_required); ``` -------------------------------- ### Setting Up PMDK Development Environment Source: https://github.com/pmem/pmdk/blob/master/utils/ansible/README.md This command executes an Ansible playbook to set up the PMDK software development environment on a target machine. It requires `TARGET_IP`, `ROOT_PASSWORD`, and the specific `SETUP_SCRIPT` (e.g., `opensuse-setup.yml` or `rockylinux-setup.yml`) as environment variables. It also creates a new user `pmdkuser` with `pmdkpass`. ```sh export TARGET_IP= # ip of the target export ROOT_PASSWORD= # a password of root on the target export SETUP_SCRIPT= # opensuse-setup.yml or rockylinux-setup.yml ansible-playbook -i $TARGET_IP, $SETUP_SCRIPT \ --extra-vars "host=all ansible_user=root ansible_password=$ROOT_PASSWORD \ new_user=pmdkuser new_user_pass=pmdkpass" ``` -------------------------------- ### Setting Up GitHub Actions Self-Hosted Runner Source: https://github.com/pmem/pmdk/blob/master/utils/ansible/README.md This Ansible playbook sets up a new server with persistent memory and a CI environment to function as a self-hosted runner for the `pmem/pmdk` repository. It requires environment variables for `TARGET_IP`, `USER_PASSWORD`, `GHA_TOKEN`, `HOST_NAME`, `LABELS`, and optional `VARS_GHA` for proxy settings. ```sh export TARGET_IP= # ip of the target export USER_PASSWORD= # a password on the target export GHA_TOKEN= # GitHub token generated for a new self-hosted runner export HOST_NAME= # host's name that will be visible on GitHub export LABELS= # rhel or opensuse export VARS_GHA= # e.g. proxy settings: http_proxy=http://proxy-dmz.{XXX}.com:911,https_proxy=http://proxy-dmz.{XXX}.com:912 ansible-playbook -i $TARGET_IP, configure-self-hosted-runner.yml --extra-vars \ "host=all ansible_user=pmdkuser ansible_password=$USER_PASSWORD \ runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA" ``` -------------------------------- ### Creating an Object Pool with Layout and Replicas Source: https://github.com/pmem/pmdk/blob/master/doc/poolset/poolset.5.md Command-line instruction to create an object pool using `pmempool`, specifying a custom layout (`--layout="mylayout"`) and referencing a `poolset` file (`myobjpool.set`) that includes replica definitions. This command sets up a mirrored persistent memory pool. ```bash $ pmempool create --layout="mylayout" obj myobjpool.set ``` -------------------------------- ### Demonstrating ReorderFull Engine Behavior Source: https://github.com/pmem/pmdk/blob/master/doc/pmreorder/pmreorder.1.md This snippet illustrates the comprehensive behavior of the ReorderFull engine, which generates and checks consistency for all possible store permutations. For an input (a, b, c), it lists every possible permutation and subset, highlighting its computationally expensive nature. ```Text Example: input: (a, b, c) output: () (a) (b) (c) (a, b) (a, c) (b, a) (b, c) (c, a) (c, b) (a, b, c) (a, c, b) (b, a, c) (b, c, a) (c, a, b) (c, b, a) ``` -------------------------------- ### Finalizing PMDK Release Package (Bash) Source: https://github.com/pmem/pmdk/blob/master/RELEASE_STEPS.md This set of commands finalizes the PMDK release package. It navigates into the extracted source directory, generates documentation (`make doc`), creates a `.skip-doc` file (likely to prevent redundant doc generation), and then creates the final gzipped tarball with root ownership/group. This package includes generated manpages. ```bash cd pmdk-$VERSION make doc touch .skip-doc cd .. tar czf pmdk-$VERSION.tar.gz pmdk-$VERSION/ --owner=root --group=root ``` -------------------------------- ### Removing Pool Files and the Pool Set File - Bash Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool-rm.1.md This example illustrates the use of the `-a` (or `--all`) option with `pmempool rm` to remove not only all pool files defined in `pool.set` but also the `pool.set` file itself. This provides a complete cleanup of the pool set. ```Bash $ pmempool rm -a pool.set ``` -------------------------------- ### pmempool create Command Syntax - Bash Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool-create.1.md This snippet shows the general syntax for the `pmempool create` command. It takes optional arguments for various settings, a pool type (currently only 'obj' is valid), and the target file path for the new pool. ```Bash $ pmempool create [] [] ``` -------------------------------- ### Synopsis of libpmemobj CTL Functions in C Source: https://github.com/pmem/pmdk/blob/master/doc/libpmemobj/pmemobj_ctl_get.3.md This snippet presents the function prototypes for pmemobj_ctl_get, pmemobj_ctl_set, and pmemobj_ctl_exec. These experimental functions allow querying, setting, and executing operations within the libpmemobj control (CTL) namespace. They require a PMEMobjpool pointer, a name string for the CTL entry point, and an optional arg pointer for data. ```C #include int pmemobj_ctl_get(PMEMobjpool *pop, const char *name, void *arg); (EXPERIMENTAL) int pmemobj_ctl_set(PMEMobjpool *pop, const char *name, void *arg); (EXPERIMENTAL) int pmemobj_ctl_exec(PMEMobjpool *pop, const char *name, void *arg); (EXPERIMENTAL) ``` -------------------------------- ### Including libpmem2 and Linking in C Source: https://github.com/pmem/pmdk/blob/master/doc/libpmem2/libpmem2.7.md This snippet demonstrates the necessary steps to integrate the libpmem2 library into a C application. It shows the preprocessor directive to include the main header file and the typical compiler command-line arguments required to link the library during the build process, making its functions available for use. ```C #include cc ... -lpmem2 ``` -------------------------------- ### Removing Pool Files from a Pool Set (Default) - Bash Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool-rm.1.md This example shows how to remove all pool files that are defined within a specified pool set file (`pool.set`), while keeping the pool set file itself intact. This is the default behavior when a pool set file is provided. ```Bash $ pmempool rm pool.set ``` -------------------------------- ### Source Poolset Configuration for Adding Replica (Configuration) Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool-transform.1.md This configuration defines the initial state of a pool set, consisting of a base pool with three parts and one replica with two parts. It serves as the input (`poolset_file_src`) for the `pmempool transform` command when adding a new replica. ```Configuration PMEMPOOLSET 20M /0/partfile1 20M /0/partfile2 25M /0/partfile3 REPLICA 40M /1/partfile1 20M /1/partfile2 ``` -------------------------------- ### Getting Mapping Size with libpmem2 in C Source: https://github.com/pmem/pmdk/blob/master/doc/libpmem2/pmem2_map_get_size.3.md This function retrieves the size of a previously created `libpmem2` memory mapping. It takes a pointer to a `pmem2_map` structure, which describes the mapping, and returns the size of the mapped area. This function is typically used after a mapping has been established using `pmem2_map_new`. ```C #include size_t pmem2_map_get_size(struct pmem2_map *map); ``` -------------------------------- ### Synopsis for pmempool feature command - Shell Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool-feature.1.md This snippet provides the general syntax for using the `pmempool feature` command. It shows that the command requires an action flag (`-e` for enable, `-d` for disable, or `-q` for query) followed by a `feature-name`, optional `options`, and a `file` argument representing the pool set. ```Shell $ pmempool feature (-e|-d|-q feature-name) [options] ``` -------------------------------- ### Checking libpmem API Version (pmem_check_version) Source: https://github.com/pmem/pmdk/blob/master/doc/libpmem/libpmem.7.md This function prototype for pmem_check_version allows applications to verify if the installed libpmem library supports the required API version. It takes the major and minor version numbers as arguments and returns NULL on success or a static string describing the reason for failure. ```C const char *pmem_check_version( unsigned major_required, unsigned minor_required); ``` -------------------------------- ### Print Root Object Information (-o, --root) - CLI Options Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool-info.1.md Displays detailed information specifically about the root object of the pool. The root object is typically the entry point for navigating the object store. ```Shell -o, --root ``` -------------------------------- ### CTL Configuration String Format - Query Sequence Source: https://github.com/pmem/pmdk/blob/master/doc/pmem_ctl/pmem_ctl.5.md This snippet illustrates the general format for a `ctl` configuration string, which is a sequence of individual queries separated by semicolons. This format is used when setting the `PMEMOBJ_CONF` environment variable. ```Text query0;query1;...;queryN ``` -------------------------------- ### Creating an Object Pool from a Pool Set File Source: https://github.com/pmem/pmdk/blob/master/doc/poolset/poolset.5.md Command-line instruction using `pmempool` to create a new object pool. It takes the `obj` type and the path to a `poolset` configuration file (`mypool.set`) as arguments, defining the pool's structure and parts. ```bash $ pmempool create obj mypool.set ``` -------------------------------- ### Checking a Specific Persistent Memory Pool File (Shell) Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool-check.1.md This example demonstrates how to check the consistency of a specific persistent memory pool file named 'pool.obj' using the `pmempool check` command. It will report whether the file is consistent or not, exiting with a zero value for consistency and a non-zero value otherwise. ```Shell $ pmempool check pool.obj ``` -------------------------------- ### Compiling and Linking with libpmempool (C) Source: https://github.com/pmem/pmdk/blob/master/doc/libpmempool/libpmempool.7.md This snippet illustrates the necessary include directive for the libpmempool header and the typical compilation command using `gcc` with the `-std=gnu99` flag, linking against `libpmempool` and `libpmem`. ```C #include cc -std=gnu99 ... -lpmempool -lpmem ``` -------------------------------- ### Specifying Clang-Format Path for Style Checks/Formatting Source: https://github.com/pmem/pmdk/blob/master/CONTRIBUTING.md This command allows contributors to explicitly specify the path to the `clang-format` executable when running `cstyle` or `format` make targets. This is useful in environments where multiple `clang-format` versions exist or the desired version is not in the default PATH. It ensures the correct formatter is used for C/C++ style enforcement. ```Shell $ make CLANG_FORMAT=/path/to/clang-format cstyle|format ``` -------------------------------- ### Getting Pool Handle by OID in libpmemobj (C) Source: https://github.com/pmem/pmdk/blob/master/doc/libpmemobj/oid_is_null.3.md The pmemobj_pool_by_oid function returns the handle to the persistent memory pool that contains the object identified by the given PMEMoid. It takes one parameter, 'oid', the PMEMoid of the object. This function is useful for operations that require the pool handle, such as allocating new objects within the same pool. ```C PMEMobjpool *pmemobj_pool_by_oid(PMEMoid oid); ``` -------------------------------- ### Synopsis for pmempool transform command (Shell) Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool-transform.1.md This snippet provides the general syntax for the `pmempool transform` command. It shows that the command requires a source poolset file and a destination poolset file, along with optional arguments to control its behavior. ```Shell pmempool transform [options] ``` -------------------------------- ### Retrieving Virtual Memory Reservation Address in libpmem2 (C) Source: https://github.com/pmem/pmdk/blob/master/doc/libpmem2/pmem2_vm_reservation_get_address.3.md This C function, pmem2_vm_reservation_get_address(), is designed to retrieve the starting address of a virtual memory reservation. It requires a pointer to a pmem2_vm_reservation structure, which must have been previously initialized using the pmem2_vm_reservation_new() function. The function returns a void* pointer to the beginning of the reserved virtual memory area. ```C #include void *pmem2_vm_reservation_get_address(struct pmem2_vm_reservation *rsv); ``` -------------------------------- ### Getting Pool Handle by Pointer in libpmemobj (C) Source: https://github.com/pmem/pmdk/blob/master/doc/libpmemobj/oid_is_null.3.md The pmemobj_pool_by_ptr function returns the handle to the persistent memory pool that contains the object pointed to by the given direct memory address. It takes one parameter, 'addr', a pointer to the object's data. This function is useful when you have a direct pointer and need to identify its containing persistent memory pool. ```C PMEMobjpool *pmemobj_pool_by_ptr(const void *addr); ``` -------------------------------- ### Uncompressing PMDK Source Archive (Bash) Source: https://github.com/pmem/pmdk/blob/master/RELEASE_STEPS.md These commands navigate to a specified path, move the created PMDK source archive into the current directory, and then extract its contents. This step is a prerequisite for further processing or verification of the package. ```bash cd && mv <...>/pmdk-$VERSION.tar.gz . tar -xvf pmdk-$VERSION.tar.gz ``` -------------------------------- ### Checking and Repairing PMEM Pool Consistency in C Source: https://github.com/pmem/pmdk/blob/master/doc/libpmempool/libpmempool.7.md This C example demonstrates how to use the libpmempool API to detect the type and check the consistency of a given persistent memory pool. It initializes a check context, performs the check and repair, and automatically answers 'yes' to all questions. The program exits with success if the pool is consistent or successfully repaired, otherwise it exits with an error. ```C #include #include #include #include #include #define PATH "./pmem-fs/myfile" #define CHECK_FLAGS (PMEMPOOL_CHECK_FORMAT_STR|PMEMPOOL_CHECK_REPAIR|\ PMEMPOOL_CHECK_VERBOSE) int main(int argc, char *argv[]) { PMEMpoolcheck *ppc; struct pmempool_check_status *status; enum pmempool_check_result ret; /* arguments for check */ struct pmempool_check_args args = { .path = PATH, .backup_path = NULL, .pool_type = PMEMPOOL_POOL_TYPE_DETECT, .flags = CHECK_FLAGS }; /* initialize check context */ if ((ppc = pmempool_check_init(&args, sizeof(args))) == NULL) { perror("pmempool_check_init"); exit(EXIT_FAILURE); } /* perform check and repair, answer 'yes' for each question */ while ((status = pmempool_check(ppc)) != NULL) { switch (status->type) { case PMEMPOOL_CHECK_MSG_TYPE_ERROR: printf("%s\n", status->str.msg); break; case PMEMPOOL_CHECK_MSG_TYPE_INFO: printf("%s\n", status->str.msg); break; case PMEMPOOL_CHECK_MSG_TYPE_QUESTION: printf("%s\n", status->str.msg); status->str.answer = "yes"; break; default: pmempool_check_end(ppc); exit(EXIT_FAILURE); } } /* finalize the check and get the result */ ret = pmempool_check_end(ppc); switch (ret) { case PMEMPOOL_CHECK_RESULT_CONSISTENT: case PMEMPOOL_CHECK_RESULT_REPAIRED: return 0; default: return 1; } } ``` -------------------------------- ### OpenSUSE: PMEM and GitHub Runner Configuration (pmdkuser) Source: https://github.com/pmem/pmdk/blob/master/utils/ansible/README.md Configures persistent memory and sets up a GitHub self-hosted runner on OpenSUSE. It involves running `configure-pmem.yml` twice (before and after reboot) and then `configure-self-hosted-runner.yml` with environment variables for the GitHub token, hostname, labels, and proxy settings. This is executed as `pmdkuser`. ```Shell # as pmdkuser: cd pmdk/utils/ansible ansible-playbook configure-pmem.yml --extra-vars "ansible_user=pmdkuser newRegions=true" sudo reboot # ... cd pmdk/utils/ansible # note - no newRegions=true when running the playbook after the reboot ansible-playbook configure-pmem.yml --extra-vars "ansible_user=pmdkuser" export GHA_TOKEN= # GitHub token generated for a new self-hosted runner export HOST_NAME=`hostname` export LABELS=opensuse export VARS_GHA=http_proxy=http://proxy-dmz.{XXX}.com:911,https_proxy=http://proxy-dmz.{XXX}.com:912 ansible-playbook configure-self-hosted-runner.yml -extra-vars \ "ansible_user=pmdkuser runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA" cd rm -rf pmdk ``` -------------------------------- ### Optimizing Multiple Persistent Memory Copies with PMEM_F_MEM_NODRAIN - C Source: https://github.com/pmem/pmdk/blob/master/doc/libpmem/pmem_memmove_persist.3.md This example shows how to use the `PMEM_F_MEM_NODRAIN` flag with `pmem_memcpy` to optimize multiple writes to persistent memory. By setting this flag, the `pmem_drain()` step is skipped for individual copy operations, allowing a single `pmem_drain()` call at the end to flush all pending stores from hardware buffers, improving performance for batch operations. ```C /* ... write several ranges to pmem ... */ pmem_memcpy(pmemdest1, src1, len1, PMEM_F_MEM_NODRAIN); pmem_memcpy(pmemdest2, src2, len2, PMEM_F_MEM_NODRAIN); /* ... */ /* wait for any pmem stores to drain from HW buffers */ pmem_drain(); ``` -------------------------------- ### Accessing First and Next PMEMobj Objects by Type (C) Source: https://github.com/pmem/pmdk/blob/master/doc/libpmemobj/pmemobj_first.3.md These C macros facilitate type-aware iteration over persistent memory objects within libpmemobj. POBJ_FIRST() and POBJ_FIRST_TYPE_NUM() retrieve the first object of a specified type or type number, respectively. POBJ_NEXT() and POBJ_NEXT_TYPE_NUM() get the next object of the same type as the provided object ID, simplifying traversal within typed collections. ```C POBJ_FIRST(PMEMobjpool *pop, TYPE) POBJ_FIRST_TYPE_NUM(PMEMobjpool *pop, uint64_t type_num) POBJ_NEXT(TOID oid) POBJ_NEXT_TYPE_NUM(PMEMoid oid) ``` -------------------------------- ### Displaying Basic Pool Information (Bash) Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool-info.1.md This command parses and prints general information about the `pool.obj` pool file. It provides a basic overview of the pool's structure and contents without detailed data dumps. ```Bash $ pmempool info pool.obj ``` -------------------------------- ### Publishing PMDK Release Tag (Git/Bash) Source: https://github.com/pmem/pmdk/blob/master/RELEASE_STEPS.md This command pushes the newly created Git tag for the PMDK release to the `upstream` remote repository. This makes the release tag publicly available on GitHub, marking the specific commit as a formal release version. ```bash git push upstream $VERSION ``` -------------------------------- ### Standard Memmove with Explicit Persistence in C Source: https://github.com/pmem/pmdk/blob/master/doc/libpmem2/pmem2_get_memmove_fn.3.md This example demonstrates how to achieve persistence for data copied using the standard `memmove` function. It first copies data from `src` to `dest` using `memmove`, then retrieves a persistence function (`pmem2_persist_fn`) for the given `map`, and finally explicitly flushes the `dest` range to persistent memory. This approach requires two distinct operations for copy and persistence. ```C memmove(dest, src, len); pmem2_persist_fn persist_fn = pmem2_get_persist_fn(map); persist_fn(dest, len); ``` -------------------------------- ### Creating pmemobj Pool by Inheriting Properties - Bash Source: https://github.com/pmem/pmdk/blob/master/doc/pmempool/pmempool-create.1.md This command creates a new `pmemobj` pool file named `new_pool.obj` whose size and other properties are inherited from an existing pool file, `pool.obj`. The `--inherit` option facilitates this cloning of properties. ```Bash $ pmempool create --inherit=pool.obj new_pool.obj ``` -------------------------------- ### Setting Memory Mapping Offset with pmem2_config_set_offset in C Source: https://github.com/pmem/pmdk/blob/master/doc/libpmem2/pmem2_config_set_offset.3.md This snippet defines the signature for the `pmem2_config_set_offset` function, which is used to configure the starting offset for memory mapping within a `pmem2_config` structure. It requires an initialized `pmem2_config` pointer and a `size_t` offset, which must be a multiple of the source's alignment. The function returns 0 on success or a negative error code on failure, such as `PMEM2_E_OFFSET_OUT_OF_RANGE` if the offset exceeds `INT64_MAX`. ```c #include struct pmem2_config; int pmem2_config_set_offset(struct pmem2_config *config, size_t offset); ``` -------------------------------- ### Retrieving Layout Name and Type Count (C) Source: https://github.com/pmem/pmdk/blob/master/doc/libpmemobj/pobj_layout_begin.3.md This snippet illustrates how to retrieve metadata about a previously declared persistent memory layout. It uses `POBJ_LAYOUT_NAME` to get the null-terminated string name of `mylayout` and `POBJ_LAYOUT_TYPES_NUM` to obtain the total count of types declared within that layout using `POBJ_LAYOUT_TOID`. This functionality is useful for debugging, logging, or dynamic introspection of the persistent memory pool's structure. ```C const char *layout_name = POBJ_LAYOUT_NAME(mylayout); int num_of_types = POBJ_LAYOUT_TYPES_NUM(mylayout); ``` -------------------------------- ### Running pmreorder for Consistency Checks Source: https://github.com/pmem/pmdk/blob/master/doc/pmreorder/pmreorder.1.md Illustrates a typical command-line execution of the pmreorder.py script. This command processes a store_log.log file, applies a default reordering engine, outputs results to pmreorder_out.log, and uses a checker_binary to validate consistency. ```Shell python pmreorder.py \ -l store_log.log \ -r NoReorderDoCheck \ -o pmreorder_out.log \ -c prog \ -x PMREORDER_MARKER_NAME=ReorderPartial \ -p checker_binary checker_parameter(s) ``` -------------------------------- ### Getting Logging Threshold Value in libpmemobj C Source: https://github.com/pmem/pmdk/blob/master/doc/libpmemobj/pmemobj_log_get_threshold.3.md This snippet shows the C function signature for `pmemobj_log_get_threshold`. It is used to retrieve the current logging threshold value for `libpmemobj`. The function takes an `enum pmemobj_log_threshold` to specify which threshold to query and a pointer to `enum pmemobj_log_level` where the retrieved value will be stored. On success, it returns 0 and populates `value`; on failure, it returns a non-zero value and sets `errno`. ```c #include int pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold, enum pmemobj_log_level *value); ``` -------------------------------- ### Configuring pmreorder Markers via Command Line Source: https://github.com/pmem/pmdk/blob/master/doc/pmreorder/pmreorder.1.md Illustrates how to configure pmreorder markers directly through the command line using the -x parameter. Multiple markers can be specified as a comma-separated list of MARKER_NAME=EngineType pairs, allowing custom reordering engine assignments. ```Shell PMREORDER_MARKER_NAME1=Marker1,PMREORDER_MARKER_NAME2=Marker2 ``` -------------------------------- ### Optimizing Multiple Persistent Memory Copies with PMEM2_F_MEM_NODRAIN in C Source: https://github.com/pmem/pmdk/blob/master/doc/libpmem2/pmem2_get_memmove_fn.3.md This example illustrates how to optimize multiple persistent memory copy operations by deferring the final drain step. It retrieves `pmem2_memcpy_fn` and `pmem2_drain_fn`, then performs several `memcpy_fn` calls using the `PMEM2_F_MEM_NODRAIN` flag to skip individual drains. A single `drain_fn()` call is made at the end to ensure all pending stores are flushed to persistent memory, improving performance for batch operations. ```C pmem2_memcpy_fn memcpy_fn = pmem2_get_memcpy_fn(map); pmem2_drain_fn drain_fn = pmem2_get_drain_fn(map); /* ... write several ranges to pmem ... */ memcpy_fn(pmemdest1, src1, len1, PMEM2_F_MEM_NODRAIN); memcpy_fn(pmemdest2, src2, len2, PMEM2_F_MEM_NODRAIN); /* ... */ /* wait for any pmem stores to drain from HW buffers */ drain_fn(); ```