{"id":18016908,"url":"https://github.com/fitzgen/shuffling-allocator","last_synced_at":"2025-03-26T18:32:34.536Z","repository":{"id":54891064,"uuid":"312383622","full_name":"fitzgen/shuffling-allocator","owner":"fitzgen","description":null,"archived":false,"fork":false,"pushed_at":"2021-01-21T22:59:09.000Z","size":24,"stargazers_count":24,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-17T11:59:45.343Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fitzgen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-12T20:06:19.000Z","updated_at":"2024-08-24T19:19:45.000Z","dependencies_parsed_at":"2022-08-14T05:50:51.935Z","dependency_job_id":null,"html_url":"https://github.com/fitzgen/shuffling-allocator","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fshuffling-allocator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fshuffling-allocator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fshuffling-allocator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fshuffling-allocator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fitzgen","download_url":"https://codeload.github.com/fitzgen/shuffling-allocator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245713160,"owners_count":20660356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-10-30T04:19:39.968Z","updated_at":"2025-03-26T18:32:34.282Z","avatar_url":"https://github.com/fitzgen.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `shuffling-allocator`\n\nA shuffling allocator.\n\nThis crate provides the `ShufflingAllocator` type, which wraps an existing\nallocator and shuffles the order of heap allocations it yields, effectively\nrandomizing the placement of heap allocations.\n\nRandomizing the locations of heap allocations is useful for testing,\nbenchmarking, and performance evaluation. It helps you separate the\nperformance effects of a given code change from accidental heap object\nlocality and the effects this may have on performance due to memory caches\nin the CPU. This is the use case that this crate focuses on.\n\nWhile randomizing the locations of heap allocations can also be used for\ndefense-in-depth security, similar to ASLR, this crate is not written to\nsupport that use case. As a result, this crate may not be the right choice\nif your use case is the defense-in-depth security use case. Some trade offs\nand design decisions made in this crate's implementation might not be the\nchoices you want for your use case.\n\nThis crate is inspired by the allocator described in [*Stabilizer:\nStatistically Sound Performance Evaluation* by Curtsinger and\nBerger](https://people.cs.umass.edu/~emery/pubs/stabilizer-asplos13.pdf ).\n\n## How Does It Work?\n\nAn array of available objects for each size class is always\nmaintained. Allocating a new object involves making the allocation, choosing\na random index in the array, swapping the new allocation for `array[i]` and\nreturning the swapped out value. Freeing an object is similar: choose a\nrandom index in the array, swap the pointer being freed with `array[i]`, and\nthen use the underlying allocator to actually free the swapped out\npointer. The larger the array in the shuffling layer, the closer to truly\nrandomized heap allocations we get, but also the greater the\noverhead. Curtsinger and Berger found that arrays of size 256 gave good\nrandomization for acceptable overhead, and that is also the array size that\nthis crate uses.\n\n## Example\n\nWrap the system allocator in a `ShufflingAllocator`, randomizing the\nlocation of the system allocator's heap objects:\n\n```rust\nuse shuffling_allocator::ShufflingAllocator;\nuse std::alloc::System;\n\nstatic SHUFFLED_SYSTEM_ALLOC: ShufflingAllocator\u003cSystem\u003e =\n    shuffling_allocator::wrap!(\u0026System);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffitzgen%2Fshuffling-allocator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffitzgen%2Fshuffling-allocator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffitzgen%2Fshuffling-allocator/lists"}