{"id":16397534,"url":"https://github.com/marcoradocchia/linux-meminfo","last_synced_at":"2026-05-14T01:38:52.150Z","repository":{"id":214692914,"uuid":"707633190","full_name":"marcoradocchia/linux-meminfo","owner":"marcoradocchia","description":"An efficient, zero-allocations /proc/meminfo parsing library for Rust.","archived":false,"fork":false,"pushed_at":"2023-11-30T00:04:09.000Z","size":47,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-14T01:05:27.104Z","etag":null,"topics":["linux","meminfo","memory","parse","parser","parsing","zero-allocation","zero-allocations"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcoradocchia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"marcoradocchia"}},"created_at":"2023-10-20T10:16:16.000Z","updated_at":"2025-05-23T14:34:57.000Z","dependencies_parsed_at":"2024-01-03T01:01:25.408Z","dependency_job_id":null,"html_url":"https://github.com/marcoradocchia/linux-meminfo","commit_stats":null,"previous_names":["marcoradocchia/linux-meminfo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/marcoradocchia/linux-meminfo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoradocchia%2Flinux-meminfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoradocchia%2Flinux-meminfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoradocchia%2Flinux-meminfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoradocchia%2Flinux-meminfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcoradocchia","download_url":"https://codeload.github.com/marcoradocchia/linux-meminfo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoradocchia%2Flinux-meminfo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33006645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"ssl_error","status_checked_at":"2026-05-13T13:14:51.610Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linux","meminfo","memory","parse","parser","parsing","zero-allocation","zero-allocations"],"created_at":"2024-10-11T05:10:20.868Z","updated_at":"2026-05-14T01:38:52.134Z","avatar_url":"https://github.com/marcoradocchia.png","language":"Rust","funding_links":["https://github.com/sponsors/marcoradocchia"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1 align=\"center\"\u003eLinux MemInfo\u003c/h1\u003e\n\n  ![GitHub source size](https://img.shields.io/github/languages/code-size/marcoradocchia/linux-meminfo?color=ea6962\u0026logo=github)\n  ![GitHub open issues](https://img.shields.io/github/issues-raw/marcoradocchia/linux-meminfo?color=%23d8a657\u0026logo=github)\n  ![GitHub open pull requests](https://img.shields.io/github/issues-pr-raw/marcoradocchia/linux-meminfo?color=%2389b482\u0026logo=github)\n  ![GitHub sponsors](https://img.shields.io/github/sponsors/marcoradocchia?color=%23d3869b\u0026logo=github)\n  ![GitHub license](https://img.shields.io/github/license/marcoradocchia/linux-meminfo?color=%23e78a4e)\n  ![Crates.io downloads](https://img.shields.io/crates/d/linux-meminfo?label=crates.io%20downloads\u0026color=%23a9b665\u0026logo=rust)\n  ![Crates.io version](https://img.shields.io/crates/v/linux-meminfo?logo=rust\u0026color=%23d8a657)\n\u003c/div\u003e\n\nThis library provides easy and low level access to `meminfo`, the _pseudofile_\nplaced by the Linux kernel inside the `proc` _pseudo-filesystem_ (for more\ninformation, see the `proc`\n[manpage](https://man7.org/linux/man-pages/man5/proc.5.html)).\n\nThe public API is built around the `MemInfo` type, a struct responsible for\nretrieving memory-related information about the system. Calling its constructor\nopens the `/proc/meminfo` pseudofile and reads its data into an internal buffer.\nHaving `MemInfo` to own both the open file and a buffer of its data allows\nseparation of concerns between _reading_ from the pseudofile, _managing_ and\n_parsing_ the buffered data.\n\nThe parser implementation responsible for parsing `/proc/meminfo` entries\nworks exclusively on string slices, just owning a reference to the pseudofile\nbuffered bytes. This allows for efficient, **zero-allocation** parsing.\n\n## Examples\n\nThe following example shows the most basic usage of the `MemInfo` API. First\nwe construct a new instance, which translates to `/proc/meminfo` being opened\nand read into the internal buffer; then we call the `MemInfo::parse`, which\nreturns a **lazy** iterator over parsed entries, in this case represented by\nthe `MemInfoEntry` type. The iterator being lazy meaning it parses a new\nentry on each call to the `next` method. In other words: _you only pay for the\nentries you parse_.\n\n```rust\nuse std::error;\n\nuse meminfo::MemInfo;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn error::Error\u003e\u003e {\n    let mut meminfo = MemInfo::new()?;\n    let mut entries = meminfo.parse();\n\n    let mem_total = entries.next().unwrap();\n    assert_eq!(\"MemTotal\", mem_total.label());\n    assert_eq!(Some(\"kB\"), mem_total.unit());\n\n    println!(\"System's total usable RAM: {}kB\", mem_total.size()?);\n\n    Ok(())\n}\n```\n\nUsers may have distinct use cases that call for regular retrieval of a\nparticular set of entries within the `/proc/meminfo` pseudofile. The\n`MemInfo::parse_extended` efficiently addresses this requirement, extending\nparsed entries with additional information pertaining to the byte range they\noccupy in the file stream. This functionality allows users to selectively read\nand parse specific entries as needed. Also, this way, the internal buffer can\nbe shrank to the capacity required to read in such entries, reducing the runtime\nmemory footprint of the program.\n\n```rust\nuse std::io::SeekFrom;\nuse std::time::Duration;\nuse std::{error, thread};\n\nuse meminfo::{MemInfo, MemInfoError};\n\n#[derive(Debug)]\nstruct MemAvailable {\n    size: usize,\n    start_pos: usize,\n}\n\nimpl MemAvailable {\n    fn new(meminfo: \u0026mut MemInfo) -\u003e Result\u003cSelf, MemInfoError\u003e {\n        let mut entries = meminfo.parse_extended().skip(2);\n\n        let mem_available = entries.next().unwrap();\n        assert_eq!(\"MemAvailable\", mem_available.label());\n        assert_eq!(Some(\"kB\"), mem_available.unit());\n\n        let size = mem_available.size().unwrap();\n        let start_pos = mem_available.start_pos();\n        let capacity = mem_available.required_capacity();\n\n        drop(entries);\n        meminfo.clear();\n        meminfo.shrink_to(capacity);\n\n        Ok(MemAvailable { size, start_pos })\n    }\n\n    fn fetch(\u0026mut self, meminfo: \u0026mut MemInfo) -\u003e Result\u003c(), MemInfoError\u003e {\n        let seek_pos = SeekFrom::Start(self.start_pos as u64);\n        meminfo.seek(seek_pos)?;\n\n        meminfo.clear();\n        meminfo.read()?;\n\n        let entry = meminfo.parse().next().unwrap();\n        self.size = entry.size().unwrap();\n\n        Ok(())\n    }\n}\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn error::Error\u003e\u003e {\n    let mut meminfo = MemInfo::new()?;\n    let mut mem_available = MemAvailable::new(\u0026mut meminfo)?;\n\n    loop {\n        println!(\"System's available RAM: {}kB\", mem_available.size);\n        thread::sleep(Duration::from_secs(2));\n        mem_available.fetch(\u0026mut meminfo)?;\n    }\n}\n```\n\n## Usage\n\nTo use this library in your project, run the following command in your project\nroot directory:\n\n```sh\ncargo add linux-meminfo\n```\n\n## Features\n\nBy default, the `MemInfoEntry` and `MemInfoEntryExtended` constructors perform\nUTF-8 validation on `/proc/meminfo` parsed data. Malformed data would cause\na panic in this case. However, enabling the `utf8-unchecked` feature removes\nsuch validation, potentially increasing parsing performance. To achieve this,\nthe new constructors make use of unsafe code, thus the user should be aware\nthat malformed `/proc/meminfo` data would cause undefined behaviour.\n\nTo opt-in such feature, run the following command in your the project root\ndirectory:\n\n```sh\ncargo add linux-meminfo --features=utf8-unchecked\n```\n\n## License\n\nThis library is licensed under the terms of the [GPLv3](LICENSE) license.\n\n## Contributions\n\nAny contribution is welcome and encouraged.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcoradocchia%2Flinux-meminfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcoradocchia%2Flinux-meminfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcoradocchia%2Flinux-meminfo/lists"}