Compaction is used while doing memory management. Physical memory can be managed or used by various ways like paging, multi-partition etc. Some problem is associated with every technique.
when OS uses multi-partition of physical memory, it divides into physical memory in multiple chunks and a process can reside in one of them if it is not occupied by some other process. since each process has its own time to finish, it may happen is the system a new process needs memory which is available wrt to whole memory point of view but not contiguous. In such scenarios, OS does compaction of already running process and make memory available for already waiting process.