# Fragmentation Aware Packing

Choose placements that preserve useful residual capacity.

- Repository: https://github.com/benchflow-ai/skillsbench (1888 stars)
- Category: Engineering
- License: Apache-2.0
- Last updated: 2026-10-24
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add benchflow-ai/skillsbench --skill fragmentation-aware-packing -g -a claude-code -y`
Codex: `npx skills add benchflow-ai/skillsbench --skill fragmentation-aware-packing -g -a codex -y`
Cursor: `npx skills add benchflow-ai/skillsbench --skill fragmentation-aware-packing -g -a cursor -y`
Gemini CLI: `npx skills add benchflow-ai/skillsbench --skill fragmentation-aware-packing -g -a gemini-cli -y`

## Description

Choose placements that preserve useful residual capacity. Use for bin packing, GPU sharing, accelerator placement, and multi-resource scheduling where stranded capacity hurts future fit.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Fragmentation-Aware Packing

Use this skill when several feasible placements exist and the choice affects future capacity.

## Core Idea

A placement is not good just because it fits. Good placements preserve useful residual capacity. With fractional GPUs, this often means packing small compatible jobs together while preserving whole or scarce GPU slots. The same idea applies to any slots, bins, or resources with discrete capacities.

## Marginal Fragmentation

For each feasible placement, compute a local before/after estimate:

1. Measure current free capacity by resource type and slot.
2. Copy the target machine or bin state.
3. Compute `fragmentation_before`.
4. Apply the candidate placement.
5. Compute `fragmentation_after`.
6. Set `marginal_fragmentation = fragmentation_after - fragmentation_before`.

```text
best = None

for placement in feasible_placements:
  target_before = copy(target_state)
  fragmentation_before = estimate_fragmentation(target_before, workload_types)
  target_after = apply(placement, target_before)
  fragmentation_after = estimate_fragmentation(target_after, workload_types)
  marginal_fragmentation = fragmentation_after - fragmentation_before
  score = weighted_action_score(
    marginal_fragmentation=marginal_fragmentation,
    other_component_deltas=estimate_other_deltas(placement)
  )
  best = lower_score(best, placement, score)

choose best
```

Respect hard feasibility first. Use `marginal_fragmentation` as an input to the weighted action score, not as the only decision rule.

## Estimating Fragmentation

When workload shape probabilities are available, such as `workload_types` from `cluster_config.json`, use them to estimate which free capacity is likely to be useful:

```text
fragmentation = 0

for workload_type in workload_types_from_cluster_config:
  if workload_type.gpu_type is incompatible with target.gpu_type:
    continue

The rest: https://github.com/benchflow-ai/skillsbench/blob/HEAD/tasks-extra/gpu-cluster-online-scheduling/environment/skills/fragmentation-aware-packing/SKILL.md
