pola-rs/polars · error

POLARS_MEMORY_PREFETCH=madvise_willneed is not supported by…

Error message

POLARS_MEMORY_PREFETCH=madvise_willneed is not supported by this system

What it means

Polars panics when POLARS_MEMORY_PREFETCH=madvise_willneed is set on a non-Unix platform. The madvise(2)-based WILLNEED prefetch strategy only exists on Unix systems, so get_memory_prefetch_func aborts at startup rather than silently ignoring the setting. This is a fail-fast configuration validation for an unsupported platform/env combination.

Solutions

  1. Remove POLARS_MEMORY_PREFETCH=madvise_willneed from the environment on non-Unix systems
  2. Unset the variable just for this process, e.g. env -u POLARS_MEMORY_PREFETCH on Unix or delete it in os.environ before importing polars
  3. Switch the value to a portable option such as prefetch_l2 or no_prefetch
  4. Use madvise_willneed only on Unix: conditionally set the var with sys.platform checks

Example fix

// before
os.environ["POLARS_MEMORY_PREFETCH"] = "madvise_willneed"
import polars as pl
// after
if sys.platform != "win32":
    os.environ["POLARS_MEMORY_PREFETCH"] = "madvise_willneed"
import polars as pl
Defensive patterns

Strategy: validation

Validate before calling

import os, sys
if "POLARS_MEMORY_PREFETCH" in os.environ and sys.platform == "win32":
    raise RuntimeError("POLARS_MEMORY_PREFETCH=madvise_willneed is unsupported on this platform")

Prevention

When it happens

Trigger: Setting the env var POLARS_MEMORY_PREFETCH=madvise_willneed (e.g. via ~/.bashrc, CI config, or python os.environ) and then calling begin_read / any memory-mapped read (e.g. scanning an IPC/parquet file) on Windows or another non-Unix target.

Common situations: Sharing env var exports across OSes; running the same config on Windows/macOS after tuning on Linux; copying a tuned Polars performance config into cross-platform CI.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/9cd942d4b53856af. Report an issue: GitHub.

Appendix: source

Thrown at crates/polars-utils/src/mem.rs:138

                #[cfg(target_family = "unix")]
                {
                    madvise_sequential
                }
                #[cfg(not(target_family = "unix"))]
                {
                    panic!(
                        "POLARS_MEMORY_PREFETCH=madvise_sequential is not supported by this system"
                    );
                }
            },
            Some("madvise_willneed") => {
                #[cfg(target_family = "unix")]
                {
                    madvise_willneed
                }
                #[cfg(not(target_family = "unix"))]
                {
                    panic!(
                        "POLARS_MEMORY_PREFETCH=madvise_willneed is not supported by this system"
                    );
                }
            },
            Some("madvise_populate_read") => {
                #[cfg(target_os = "linux")]
                {
                    madvise_populate_read
                }
                #[cfg(not(target_os = "linux"))]
                {
                    panic!(
                        "POLARS_MEMORY_PREFETCH=madvise_populate_read is not supported by this system"
                    );
                }
            },
            Some("force_populate_read") => force_populate_read,
            Some(v) => panic!("invalid value for POLARS_MEMORY_PREFETCH: {v}"),

View on GitHub (pinned to fe841f959e)