1

I'm wondering if there is a way to write a file in contiguous extent, to completely avoid fragmentation in certain file of the filesystems.

I mean, XFS filesystem under Linux.

Cœur
  • 37,241
  • 25
  • 195
  • 267
JosephITA
  • 502
  • 2
  • 11
  • 21
  • If you're that worried about performance, have you matched your IO pattern to your disk storage? For example, are you doing IO in ways that align with disk blocks and RAID segments? If you're not doing that, trying to out-think the optimizations that a fast file system like XFS does to improve performance probably isn't going to help your IO rates. – Andrew Henle Oct 20 '15 at 10:29
  • 1
    Sounds like premature optimisation. Why do you want this? Did you benchmark? – too honest for this site Oct 20 '15 at 11:55
  • I have to write file of 20MB, and due to increasing fragmentation I lost some piecese of information. – JosephITA Oct 20 '15 at 12:31
  • fragmentation shouldn't cause data loss... – Russ Schultz Oct 20 '15 at 12:52
  • ...I know...but if you have a lot of real time information to write on disk it may appen. – JosephITA Oct 20 '15 at 12:55
  • Ahh, you're not able to keep your throughput up. The problem might not be XFS or fragmentation (as you are thinking). What is your platform and storage hardware? What are your throughput requirements? How much buffering are you able to do in app space? – Russ Schultz Oct 20 '15 at 14:44
  • 1
    Ok,now it sounds like wrong application design or inappropriate hardware. **Iff** it really is a fragmentation problem, it is your app which facilitates that. Re-think your system design. – too honest for this site Oct 20 '15 at 16:59
  • How much RAM does your system have? Can you not simply buffer the data to solve a temporary mismatch between data in/out performance? – Clifford Oct 20 '15 at 17:12
  • The system can not be redesigned. It is not a problem of troughput because the problem occurs after several day of continuous use. It seems something realetd to free space left or similar. Thank you for the answers. – JosephITA Oct 21 '15 at 12:28

1 Answers1

2

In general, no - you have no direct control over the allocator.

You can use the fallocate(2) syscall to pre-allocate all blocks, and depending on free space available, that may give you contiguous blocks to write into.

(Note that you can check the actual fragmentation/layout of an existing file using the xfs_bmap command.)

Eric Sandeen
  • 141
  • 1
  • 5
  • yes, but there is no guarantee that fallocate pre-allocate contiguous block. This causes some delay in my video streaming/recording application. – JosephITA Sep 09 '16 at 08:47