Suppose you have a large file made up of a bunch of fixed size blocks. Each of these blocks contains some number of variable sized records. Each record must fit completely w
A modification of an on-line (to defragment in one pass) bounded space (the memory requirements) bin packing algorithm could probably work here.
See "Bin Packing Approximation Algorithms: Combinatorial Analysis" by Coffman et al.