Bug 525532

Summary: RFE: fallocate (preallocation) support
Product: [Fedora] Fedora Reporter: Eric Sandeen <esandeen>
Component: sambaAssignee: Guenther Deschner <gdeschner>
Status: CLOSED UPSTREAM QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: rawhideCC: gdeschner, mishu, ssorce
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-04-04 16:35:47 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Eric Sandeen 2009-09-24 17:53:07 UTC
Windows samba clients do a poor-man's preallocation by doing 1 byte writes on 64k boundaries (or something like that) which NTFS interprets to mean "preallocate space"

We have a generic interface to filesystem preallocation now, with the fallocate syscall.

A very, very simple patch to implement this looks something like:

--- a/source/configure.in
+++ b/source/configure.in
@@ -1052,6 +1052,7 @@ AC_CHECK_FUNCS(setlocale nl_langinfo)
 AC_CHECK_FUNCS(nanosleep)
 AC_CHECK_FUNCS(mlock munlock mlockall munlockall)
 AC_CHECK_FUNCS(memalign posix_memalign hstrerror)
+AC_CHECK_FUNCS(fallocate)
 AC_CHECK_HEADERS(sys/mman.h)
 # setbuffer, shmget, shm_open are needed for smbtorture
 AC_CHECK_FUNCS(setbuffer shmget shm_open)Index: samba-3.3.2/source/modules/vfs_default.c
--- samba-3.3.2.orig/source/modules/vfs_default.c
+++ samba-3.3.2/source/modules/vfs_default.c
@@ -714,6 +714,14 @@ static int strict_allocate_ftruncate(vfs
 	if (st.st_size > len)
 		return sys_ftruncate(fsp->fh->fd, len);
 
+	/* Growing */
+#if defined(HAVE_FALLOCATE)
+#include <linux/falloc.h>
+	if (!fallocate(fsp->fh->fd, 0, st.st_size, space_to_write))
+		return 0;
+	/* if glibc has fallocate but failed on this fs, go back to old way */
+#endif
+
 	/* available disk space is enough or not? */
 	if (lp_strict_allocate(SNUM(fsp->conn))){
 		SMB_BIG_UINT space_avail;

but this is a little suboptimal; at least on xfs, this multitude of fallocate calls actually has a lot of overhead.  If it were possible to batch up these instances into 1 big fallocate call, it could be a win.

Comment 1 Guenther Deschner 2010-10-08 14:27:08 UTC
Can you check this isnt already adressed upstream ? I see there is a vfs_prealloc module at least.

Comment 2 Fedora Admin XMLRPC Client 2010-10-08 14:42:38 UTC
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.

Comment 3 Eric Sandeen 2010-12-09 16:37:41 UTC
vfs_prealloc was specific to xfs, last time I looked.

In any case, I see there is movement upstream now,
http://lists.samba.org/archive/samba-technical/2010-December/075164.html

Comment 4 Eric Sandeen 2010-12-09 16:38:54 UTC
oh and FWIW, vfs_prealloc does:

Preallocate all files with the extension EXT to the size specified by BYTES. 

which is not really what we're after (one single preallocated size for all files...)

Comment 5 Simo Sorce 2011-04-04 16:35:47 UTC
Upstream has changed to do some fallocate() work already.
Closing this one as I think it does not apply anymore in this form. Please reopen if it still applies.