FallocateHole Punching Support for Ceph


Hole punching in file-systems is to mark a portion of a file as being unneeded and the associated storage to that file portion can then be freed. This is very useful for a file system being used as virtual machine image file storage. By virtue of hole punching, VMM could free host space while guest occupies less space. Hole punching has been implemented by xfs and btrfs etc. Given VM image storage is an important use case for Ceph, it is beneficial to equip Ceph with hole punching.


  • Li Wang (UbuntuKylin)

Interested Parties

  • Greg Farnum
  • Loic Dachary

Current Status

Under design

Detailed Description

It shoule be simple. Implement the file_operations fallocate(struct file *file, int mode, loff_t offset, loff_t len) call back function, support the argument FALLOC_FL_PUNCH_HOLE. It uses the metadata retrieved from mds and the offset as well as len to calculate the objects fit into the hole, and communicate with OSDs to delete those objects.


long ceph_fallocate(struct file *file, int mode, loff_t offset, loff_t length)


if (mode & (~ FALLOC_FL_PUNCH_HOLE))


if (!S_ISREG(inode->i_mode))


filemap_write_and_wait_range(mapping, offset, offset + length - 1);
first_page_offset = ((offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT) << PAGE_CACHE_SHIFT;
last_page_offset = (offset + length) >> PAGE_CACHE_SHIFT; << PAGE_CACHE_SHIFT;
truncate_pagecache_range(inode, first_page_offset, last_page_offset - 1);
zero out the non-object -aligned data in the objects at the start and tail of the hole
tell osd to delete the objects fit into the hole


Work items