Persistent preallocation in ext4
Subsystems (6)
cover Persistent preallocation in ext4
Please Note (especially <c> below):
----------------------------------
<a> This is being resubmitted as part of the recall for ext4 patches. <b> The patches are based on 2.6.20-rc5 kernel version.
<c> These patches require the "EXTENT OVERLAP BUGFIX" patch submitted by me earlier (on Jan 16th).
Description:
-----------
Persistent preallocation is a proposed new feature in ext4, which will allow user applications to preallocate blocks for a file. It is similar to posix_fallocate call, but does not initialize (write to) the blocks allocated (unlike fallocate).
This patch uses ioctl interface and returns "0" if the call succeeds, else returns the error number. Other approaches are discussed under "Outstanding Issues" section below.
There are two patches being submitted as part of this:
(1) The first patch implements the ioctl interface, which does the preallocation. The preallocated blocks are part of a new extent, which is marked "uninitialized". The MSB in ee_len (of ext4_extent datastructure) is used to mark an extent "uninitialized". It also takes care of preallocating through a hole and updating the file size accordingly.
(2) The second patch implements the support for writing to the uninitialized extent(s). This write may result in breaking down the uninitialized extent into one initialized extent and upto two uninitialized extents, depending on which part of the uninitialized extent is being written to. If all the blocks in the uninitialized extent are being written on, the extent is marked initialized and no split is required. This patch also takes care of merging the initialized extent with neighbouring ones, if possible.
Outstanding Issues:
------------------
(1) The final interface is yet to be decided. We have the option of chosing from one of these:
a> modifying posix_fallocate() in glibc
b> using fcntl
c> using ftruncate, or
d> using the ioctl interface.
If we go with ioctl interface, we need to chose the return
value from the ioctl. We should either return "0" for success and errno for failure, or we should be returning number of bytes preallocated.
(2) Also, we need to decide on what should happen in case of a partial success scenario. i.e. after few blocks get preallocated, we hit some error - say ENOSPC. Should the call just return the number of bytes preallocated, or should it "undo" the partial preallocation and then exit with error code ?
(3) Currently we only allow persistent preallocation on files that have extents enabled. It was considered a rare case where user may want preallocation on non-extent based file(s). And even if someone really wants to do this, it will be recommended to convert the file to the extent-based format first, and then do persistent preallocation on it.
Testing done:
------------
(1) Unit testing included preallocating blocks and writing to it. Preallocation through holes were also tested. Creation, splitting and merging of extents was observed through a modified (patched) version of debugfs (part of e2fsprogs). This modified version recognises and flags uninitialized extent(s) in the output/display.
(2) For stress testing, fsx-linux (from LTP) was patched and used. It was modified to call preallocation ioctl instead of ftuncate operations. It uncovered couple of bugs (extent overlap being one of them). These bugs have already been fixed here.
The patches for e2fsprogs and fsx-linux are available with me. I can post them if anyone is interested to try/test the preallocation patches. Also, I have a small test program/tool written which can be used for unit testing.
Thanks!
--
Regards,
Amit Arora
PATCH 1/2 ioctl and uninitialized extents
This patch implements the ioctl which may be used for persistent preallocation of blocks to an extent enabled file in ext4.
--- fs/ext4/extents.c | 125 ++++++++++++++++++++++++++-------------- fs/ext4/ioctl.c | 69 ++++++++++++++++++++++ include/linux/ext4_fs.h | 13 ++++ include/linux/ext4_fs_extents.h | 13 ++++ 4 files changed, 177 insertions(+), 43 deletions(-)
fs/ext4/extents.c +82 -43
@@ -283,7 +283,7 @@ static void ext4_ext_show_path(struct in }else if (path->p_ext) {ext_debug (" %d:%d:%llu " ,le32_to_cpu (path->p_ext->ee_block), -le16_to_cpu (path->p_ext->ee_len), +ext4_ext_get_actual_len (path->p_ext),ext_pblock (path->p_ext)); }else ext_debug (" []" );
@@ -306,7 +306,7 @@ static void ext4_ext_show_leaf(struct infor (i =0 ; i <le16_to_cpu (eh->eh_entries); i++, ex++) {ext_debug ("%d:%d:%llu " ,le32_to_cpu (ex->ee_block), -le16_to_cpu (ex->ee_len),ext_pblock (ex)); +ext4_ext_get_actual_len (ex),ext_pblock (ex)); }ext_debug ("\n" ); }
@@ -426,7 +426,7 @@ ext4_ext_binsearch(struct inode *inode,ext_debug (" -> %d:%llu:%d " ,le32_to_cpu (path->p_ext->ee_block),ext_pblock (path->p_ext), -le16_to_cpu (path->p_ext->ee_len)); +ext4_ext_get_actual_len (path->p_ext));#ifdef CHECK_BINSEARCH {
@@ -687,7 +687,7 @@ static int ext4_ext_split(handle_t *handext_debug ("move %d:%llu:%d in new leaf %llu\n" ,le32_to_cpu (path[depth].p_ext->ee_block),ext_pblock (path[depth].p_ext), -le16_to_cpu (path[depth].p_ext->ee_len), +ext4_ext_get_actual_len (path[depth].p_ext), newblock);/*memmove(ex++, path[depth].p_ext++, sizeof(struct ext4_extent));
@@ -1107,7 +1107,19 @@ static int ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, struct ext4_extent *ex2) { - if (le32_to_cpu(ex1->ee_block) + le16_to_cpu(ex1->ee_len) != + unsigned short ext1_ee_len, ext2_ee_len; + +/* +* Make sure that either both extents are uninitialized, or +* both are _not_. +*/ +if (ext4_ext_is_uninitialized (ex1) ^ext4_ext_is_uninitialized (ex2)) +return 0 ; + + ext1_ee_len =ext4_ext_get_actual_len (ex1); + ext2_ee_len =ext4_ext_get_actual_len (ex2); + +if (le32_to_cpu (ex1->ee_block) + ext1_ee_len !=le32_to_cpu (ex2->ee_block))return 0 ;
@@ -1116,14 +1128,14 @@ ext4_can_extents_be_merged(struct inode* as an RO_COMPAT feature, refuse to merge to extents if * this can result in the top bit of ee_len being set. */ -if (le16_to_cpu (ex1->ee_len) +le16_to_cpu (ex2->ee_len) >EXT_MAX_LEN ) +if (ext1_ee_len + ext2_ee_len >EXT_MAX_LEN )return 0 ;#ifdef AGRESSIVE_TEST if (le16_to_cpu (ex1->ee_len) >=4 )return 0 ;#endif -if (ext_pblock (ex1) +le16_to_cpu (ex1->ee_len) ==ext_pblock (ex2)) +if (ext_pblock (ex1) + ext1_ee_len ==ext_pblock (ex2))return 1 ;return 0 ; }
@@ -1145,7 +1157,7 @@ unsigned int ext4_ext_check_overlap(struunsigned int depth, len1; b1 =le32_to_cpu (newext->ee_block); - len1 =le16_to_cpu (newext->ee_len); + len1 =ext4_ext_get_actual_len (newext); depth =ext_depth (inode);if (!path[depth].p_ext) goto out;
@@ -1181,9 +1193,9 @@ int ext4_ext_insert_extent(handle_t *hanstruct ext4_extent *ex, *fex;struct ext4_extent *nearex;/* nearest extent */ struct ext4_ext_path *npath =NULL ; -int depth, len, err, next; +int depth, len, err, next, uninitialized =0 ; -BUG_ON (newext->ee_len ==0 ); +BUG_ON (ext4_ext_get_actual_len (newext) ==0 ); depth =ext_depth (inode); ex = path[depth].p_ext;BUG_ON (path[depth].p_hdr ==NULL );
@@ -1191,14 +1203,23 @@ int ext4_ext_insert_extent(handle_t *han/* try to insert block into found extent and return */ if (ex &&ext4_can_extents_be_merged (inode, ex, newext)) {ext_debug ("append %d block to %d:%d (from %llu)\n" , -le16_to_cpu (newext->ee_len), +ext4_ext_get_actual_len (newext),le32_to_cpu (ex->ee_block), -le16_to_cpu (ex->ee_len),ext_pblock (ex)); +ext4_ext_get_actual_len (ex),ext_pblock (ex)); err =ext4_ext_get_access (handle, inode, path + depth);if (err)return err; - ex->ee_len =cpu_to_le16 (le16_to_cpu (ex->ee_len) - +le16_to_cpu (newext->ee_len)); + +/* ext4_can_extents_be_merged should have checked that either +* both extents are uninitialized, or both aren't. Thus we +* need to check only one of them here. +*/ +if (ext4_ext_is_uninitialized (ex)) + uninitialized =1 ; + ex->ee_len =cpu_to_le16 (ext4_ext_get_actual_len (ex) + +ext4_ext_get_actual_len (newext)); +if (uninitialized) +ext4_ext_mark_uninitialized (ex); eh = path[depth].p_hdr; nearex = ex; goto merge;
@@ -1254,7 +1275,7 @@ has_space:ext_debug ("first extent in the leaf: %d:%llu:%d\n" ,le32_to_cpu (newext->ee_block),ext_pblock (newext), -le16_to_cpu (newext->ee_len)); +ext4_ext_get_actual_len (newext)); path[depth].p_ext =EXT_FIRST_EXTENT (eh); }else if (le32_to_cpu (newext->ee_block) >le32_to_cpu (nearex->ee_block)) {
@@ -1267,7 +1288,7 @@ has_space:"move %d from 0x%p to 0x%p\n" ,le32_to_cpu (newext->ee_block),ext_pblock (newext), -le16_to_cpu (newext->ee_len), +ext4_ext_get_actual_len (newext), nearex, len, nearex + 1, nearex + 2);memmove (nearex +2 , nearex +1 , len); }
@@ -1280,7 +1301,7 @@ has_space:"move %d from 0x%p to 0x%p\n" ,le32_to_cpu (newext->ee_block),ext_pblock (newext), -le16_to_cpu (newext->ee_len), +ext4_ext_get_actual_len (newext), nearex, len, nearex + 1, nearex + 2);memmove (nearex +1 , nearex, len); path[depth].p_ext = nearex;
@@ -1299,8 +1320,13 @@ merge:if (!ext4_can_extents_be_merged (inode, nearex, nearex +1 ))break ;/* merge with next extent! */ - nearex->ee_len =cpu_to_le16 (le16_to_cpu (nearex->ee_len) - +le16_to_cpu (nearex[1 ].ee_len)); +if (ext4_ext_is_uninitialized (nearex)) + uninitialized =1 ; + nearex->ee_len =cpu_to_le16 (ext4_ext_get_actual_len (nearex) + +ext4_ext_get_actual_len (nearex +1 )); +if (uninitialized) +ext4_ext_mark_uninitialized (nearex); +if (nearex +1 <EXT_LAST_EXTENT (eh)) { len = (EXT_LAST_EXTENT (eh) - nearex -1 ) *sizeof (struct ext4_extent );
@@ -1370,8 +1396,8 @@ int ext4_ext_walk_space(struct inode *in end =le32_to_cpu (ex->ee_block);if (block + num < end) end = block + num; - }else if (block >= -le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len)) { + }else if (block >=le32_to_cpu (ex->ee_block) + +ext4_ext_get_actual_len (ex)) {/* need to allocate space after found extent */ start = block; end = block + num;
@@ -1383,7 +1409,8 @@ int ext4_ext_walk_space(struct inode *in* by found extent */ start = block; - end =le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len); + end =le32_to_cpu (ex->ee_block) + +ext4_ext_get_actual_len (ex);if (block + num < end) end = block + num; exists =1 ;
@@ -1399,7 +1426,7 @@ int ext4_ext_walk_space(struct inode *in cbex.ec_type =EXT4_EXT_CACHE_GAP ; }else { cbex.ec_block =le32_to_cpu (ex->ee_block); - cbex.ec_len =le16_to_cpu (ex->ee_len); + cbex.ec_len =ext4_ext_get_actual_len (ex); cbex.ec_start =ext_pblock (ex); cbex.ec_type =EXT4_EXT_CACHE_EXTENT ; }
@@ -1472,15 +1499,15 @@ ext4_ext_put_gap_in_cache(struct inode *ext_debug ("cache gap(before): %lu [%lu:%lu]" , (unsigned long ) block, (unsigned long )le32_to_cpu (ex->ee_block), - (unsigned long )le16_to_cpu (ex->ee_len)); + (unsigned long )ext4_ext_get_actual_len (ex)); }else if (block >=le32_to_cpu (ex->ee_block) - +le16_to_cpu (ex->ee_len)) { + +ext4_ext_get_actual_len (ex)) { lblock =le32_to_cpu (ex->ee_block) - +le16_to_cpu (ex->ee_len); + +ext4_ext_get_actual_len (ex); len =ext4_ext_next_allocated_block (path);ext_debug ("cache gap(after): [%lu:%lu] %lu" , (unsigned long )le32_to_cpu (ex->ee_block), - (unsigned long )le16_to_cpu (ex->ee_len), + (unsigned long )ext4_ext_get_actual_len (ex), (unsigned long ) block);BUG_ON (len == lblock); len = len - lblock;
@@ -1610,12 +1637,12 @@ static int ext4_remove_blocks(handle_t * unsigned long from, unsigned long to) {struct buffer_head *bh; +unsigned short ee_len =ext4_ext_get_actual_len (ex);int i;#ifdef EXTENTS_STATS {struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb); -unsigned short ee_len =le16_to_cpu (ex->ee_len);spin_lock (&sbi->s_ext_stats_lock); sbi->s_ext_blocks += ee_len; sbi->s_ext_extents++;
@@ -1629,12 +1656,12 @@ static int ext4_remove_blocks(handle_t * }#endif if (from >=le32_to_cpu (ex->ee_block) - && to ==le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len) -1 ) { + && to ==le32_to_cpu (ex->ee_block) + ee_len -1 ) {/* tail removal */ unsigned long num;ext4_fsblk_t start; - num =le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len) - from; - start =ext_pblock (ex) +le16_to_cpu (ex->ee_len) - num; + num =le32_to_cpu (ex->ee_block) + ee_len - from; + start =ext_pblock (ex) + ee_len - num;ext_debug ("free last %lu blocks starting %llu\n" , num, start);for (i =0 ; i < num; i++) { bh =sb_find_get_block (inode->i_sb, start + i);
@@ -1642,12 +1669,12 @@ static int ext4_remove_blocks(handle_t * }ext4_free_blocks (handle, inode, start, num); }else if (from ==le32_to_cpu (ex->ee_block) - && to <=le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len) -1 ) { + && to <=le32_to_cpu (ex->ee_block) + ee_len -1 ) {printk ("strange request: removal %lu-%lu from %u:%u\n" , - from, to,le32_to_cpu (ex->ee_block),le16_to_cpu (ex->ee_len)); + from, to,le32_to_cpu (ex->ee_block), ee_len); }else {printk ("strange request: removal(2) %lu-%lu from %u:%u\n" , - from, to,le32_to_cpu (ex->ee_block),le16_to_cpu (ex->ee_len)); + from, to,le32_to_cpu (ex->ee_block), ee_len); }return 0 ; }
@@ -1661,7 +1688,7 @@ ext4_ext_rm_leaf(handle_t *handle, strucstruct ext4_extent_header *eh;unsigned a, b, block, num;unsigned long ex_ee_block; -unsigned short ex_ee_len; +unsigned short ex_ee_len, uninitialized =0 ;struct ext4_extent *ex;ext_debug ("truncate since %lu in leaf\n" , start);
@@ -1676,7 +1703,9 @@ ext4_ext_rm_leaf(handle_t *handle, struc ex =EXT_LAST_EXTENT (eh); ex_ee_block =le32_to_cpu (ex->ee_block); - ex_ee_len =le16_to_cpu (ex->ee_len); +if (ext4_ext_is_uninitialized (ex)) + uninitialized =1 ; + ex_ee_len =ext4_ext_get_actual_len (ex);while (ex >=EXT_FIRST_EXTENT (eh) && ex_ee_block + ex_ee_len > start) {
@@ -1744,6 +1773,8 @@ ext4_ext_rm_leaf(handle_t *handle, struc ex->ee_block =cpu_to_le32 (block); ex->ee_len =cpu_to_le16 (num); +if (uninitialized) +ext4_ext_mark_uninitialized (ex); err =ext4_ext_dirty (handle, inode, path + depth);if (err)
@@ -1753,7 +1784,7 @@ ext4_ext_rm_leaf(handle_t *handle, struc ext_pblock(ex)); ex--; ex_ee_block =le32_to_cpu (ex->ee_block); - ex_ee_len =le16_to_cpu (ex->ee_len); + ex_ee_len =ext4_ext_get_actual_len (ex); }if (correct_index && eh->eh_entries)
@@ -2029,7 +2060,7 @@ int ext4_ext_get_blocks(handle_t *handleif (ex) {unsigned long ee_block =le32_to_cpu (ex->ee_block);ext4_fsblk_t ee_start =ext_pblock (ex); -unsigned short ee_len =le16_to_cpu (ex->ee_len); +unsigned short ee_len;/* * Allow future support for preallocated extents to be added
@@ -2037,8 +2068,9 @@ int ext4_ext_get_blocks(handle_t *handle* Uninitialized extents are treated as holes, except that * we avoid (fail) allocating new blocks during a write. */ -if (ee_len >EXT_MAX_LEN ) +if (le16_to_cpu (ex->ee_len) >EXT_MAX_LEN ) goto out2; + ee_len =ext4_ext_get_actual_len (ex);/* if found extent covers block, simply return it */ if (iblock >= ee_block && iblock < ee_block + ee_len) { newblock = iblock - ee_block + ee_start;
@@ -2046,8 +2078,11 @@ int ext4_ext_get_blocks(handle_t *handle allocated = ee_len - (iblock - ee_block);ext_debug ("%d fit into %lu:%d -> %llu\n" , (int ) iblock, ee_block, ee_len, newblock); -ext4_ext_put_in_cache (inode, ee_block, ee_len, - ee_start,EXT4_EXT_CACHE_EXTENT ); +/* Do not put uninitialized extent in the cache */ +if (!ext4_ext_is_uninitialized (ex)) +ext4_ext_put_in_cache (inode, ee_block, + ee_len, ee_start, +EXT4_EXT_CACHE_EXTENT ); goto out; } }
@@ -2089,6 +2124,8 @@ int ext4_ext_get_blocks(handle_t *handle/* try to insert new extent into found leaf and return */ ext4_ext_store_pblock (&newex, newblock); newex.ee_len =cpu_to_le16 (allocated); +if (create ==EXT4_CREATE_UNINITIALIZED_EXT )/* Mark uninitialized */ +ext4_ext_mark_uninitialized (&newex); err =ext4_ext_insert_extent (handle, inode, path, &newex);if (err) goto out2;
@@ -2100,8 +2137,10 @@ int ext4_ext_get_blocks(handle_t *handle newblock =ext_pblock (&newex);__set_bit (BH_New, &bh_result->b_state); -ext4_ext_put_in_cache (inode, iblock, allocated, newblock, -EXT4_EXT_CACHE_EXTENT ); +/* Cache only when it is _not_ an uninitialized extent */ +if (create!=EXT4_CREATE_UNINITIALIZED_EXT ) +ext4_ext_put_in_cache (inode, iblock, allocated, newblock, +EXT4_EXT_CACHE_EXTENT ); out:if (allocated > max_blocks) allocated = max_blocks;
fs/ext4/ioctl.c +69 -0
81 lines not on this page · raw message
include/linux/ext4_fs.h +13 -0
@@ -102,6 +102,8 @@ EXT4_GOOD_OLD_FIRST_INO : \ (s)->s_first_ino)#endif +#define EXT4_BLOCK_ALIGN (size, blkbits) (((size)+(1 << blkbits)-1) & \ + (~((1 << blkbits)-1)))/* * Macro-instructions used to manage fragments
@@ -225,6 +227,16 @@ struct ext4_new_group_data {__u32 free_blocks_count; }; +/* The struct ext4_falloc_input in kernel, for EXT4_IOC_PREALLOCATE */ +struct ext4_falloc_input { +__u64 offset; +__u64 len; +}; + +/* Following is used by preallocation logic to tell get_blocks() that we +* want uninitialzed extents. +*/ +#define EXT4_CREATE_UNINITIALIZED_EXT 2/* * ioctl commands
@@ -242,6 +254,7 @@ struct ext4_new_group_data {#endif #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long)#define EXT4_IOC_SETRSVSZ _IOW('f', 6, long) +#define EXT4_IOC_PREALLOCATE _IOW('f', 9, struct ext4_falloc_input)/* * ioctl commands in 32 bit emulation
include/linux/ext4_fs_extents.h +13 -0
@@ -125,6 +125,19 @@ struct ext4_ext_path {#define EXT4_EXT_CACHE_EXTENT 2/* +* Macro-instructions to handle (mark/unmark/check/create) unitialized +* extents. Applications can issue an IOCTL for preallocation, which results +* in assigning unitialized extents to the file. +*/ +#define ext4_ext_mark_uninitialized (ext) ((ext)->ee_len |= \ + cpu_to_le16(0x8000)) +#define ext4_ext_is_uninitialized (ext) ((le16_to_cpu((ext)->ee_len))& \ + 0x8000) +#define ext4_ext_get_actual_len (ext) ((le16_to_cpu((ext)->ee_len))& \ + 0x7FFF) + + +/* * to be called by ext4_ext_walk_space() * negative retcode - error * positive retcode - signal for ext4_ext_walk_space(), see below
PATCH 2/2 support for writing to uninitialized extent
In reply to Amit K. AroraThis patch adds the support for writing to an uninitialized extent (the extent which was created as a result of persistent preallocation).
--- fs/ext4/extents.c | 228 +++++++++++++++++++++++++++++++++++----- include/linux/ext4_fs_extents.h | 1 2 files changed, 202 insertions(+), 27 deletions(-)
fs/ext4/extents.c +201 -27
@@ -1141,6 +1141,51 @@ ext4_can_extents_be_merged(struct inode }/* +* ext4_ext_try_to_merge: +* tries to merge the "ex" extent to the next extent in the tree. +* It always tries to merge towards right. If you want to merge towards +* left, pass "ex - 1" as argument instead of "ex". +* Returns 0 if the extents (ex and ex+1) were _not_ merged and returns +* 1 if they got merged. +*/ +int ext4_ext_try_to_merge (struct inode *inode, +struct ext4_ext_path *path, +struct ext4_extent *ex) +{ +struct ext4_extent_header *eh; +unsigned int depth, len; +int merge_done=0 , uninitialized =0 ; + + depth =ext_depth (inode); +BUG_ON (path[depth].p_hdr ==NULL ); + eh = path[depth].p_hdr; + +while (ex <EXT_LAST_EXTENT (eh)) { +if (!ext4_can_extents_be_merged (inode, ex, ex +1 )) +break ; +/* merge with next extent! */ +if (ext4_ext_is_uninitialized (ex)) + uninitialized =1 ; + ex->ee_len =cpu_to_le16 (ext4_ext_get_actual_len (ex) + +ext4_ext_get_actual_len (ex +1 )); +if (uninitialized) +ext4_ext_mark_uninitialized (ex); + +if (ex +1 <EXT_LAST_EXTENT (eh)) { + len = (EXT_LAST_EXTENT (eh) - ex -1 ) + *sizeof (struct ext4_extent ); +memmove (ex +1 , ex +2 , len); + } + eh->eh_entries =cpu_to_le16 (le16_to_cpu (eh->eh_entries)-1 ); + merge_done =1 ; +BUG_ON (eh->eh_entries ==0 ); + } + +return merge_done; +} + + +/* * ext4_ext_check_overlap: * check if a portion of the "newext" extent overlaps with an * existing extent.
@@ -1316,25 +1361,7 @@ has_space: merge:/* try to merge extents to the right */ -while (nearex <EXT_LAST_EXTENT (eh)) { -if (!ext4_can_extents_be_merged (inode, nearex, nearex +1 )) -break ; -/* merge with next extent! */ -if (ext4_ext_is_uninitialized (nearex)) - uninitialized =1 ; - nearex->ee_len =cpu_to_le16 (ext4_ext_get_actual_len (nearex) - +ext4_ext_get_actual_len (nearex +1 )); -if (uninitialized) -ext4_ext_mark_uninitialized (nearex); - -if (nearex +1 <EXT_LAST_EXTENT (eh)) { - len = (EXT_LAST_EXTENT (eh) - nearex -1 ) - *sizeof (struct ext4_extent ); -memmove (nearex +1 , nearex +2 , len); - } - eh->eh_entries =cpu_to_le16 (le16_to_cpu (eh->eh_entries)-1 ); -BUG_ON (eh->eh_entries ==0 ); - } +ext4_ext_try_to_merge (inode, path, nearex);/* try to merge extents to the left */
@@ -1999,15 +2026,149 @@ void ext4_ext_release(struct super_block#endif } +/* +* ext4_ext_convert_to_initialized: +* this function is called by ext4_ext_get_blocks() if someone tries to write +* to an uninitialized extent. It may result in splitting the uninitialized +* extent into multiple extents (upto three). Atleast one initialized extent +* and atmost two uninitialized extents can result. +* There are three possibilities: +* a> No split required: Entire extent should be initialized. +* b> Split into two extents: Only one end of the extent is being written to. +* c> Split into three extents: Somone is writing in middle of the extent. +*/ +int ext4_ext_convert_to_initialized (handle_t *handle,struct inode *inode, +struct ext4_ext_path *path, +ext4_fsblk_t iblock, +unsigned long max_blocks) +{ +struct ext4_extent *ex, *ex1 =NULL , *ex2 =NULL , *ex3 =NULL , newex; +struct ext4_extent_header *eh; +unsigned int allocated, ee_block, ee_len, depth; +ext4_fsblk_t newblock; +int err =0 , ret =0 ; + + depth =ext_depth (inode); + eh = path[depth].p_hdr; + ex = path[depth].p_ext; + ee_block =le32_to_cpu (ex->ee_block); + ee_len =ext4_ext_get_actual_len (ex); + allocated = ee_len - (iblock - ee_block); + newblock = iblock - ee_block +ext_pblock (ex); + ex2 = ex; + +/* ex1: ee_block to iblock - 1 : uninitialized */ +if (iblock > ee_block) { + ex1 = ex; + ex1->ee_len =cpu_to_le16 (iblock - ee_block); +ext4_ext_mark_uninitialized (ex1); + ex2 = &newex; + } +/* for sanity, update the length of the ex2 extent before +* we insert ex3, if ex1 is NULL. This is to avoid temporary +* overlap of blocks. +*/ +if (!ex1 && allocated > max_blocks) + ex2->ee_len =cpu_to_le16 (max_blocks); +/* ex3: to ee_block + ee_len : uninitialised */ +if (allocated > max_blocks) { +unsigned int newdepth; + ex3 = &newex; + ex3->ee_block =cpu_to_le32 (iblock + max_blocks); +ext4_ext_store_pblock (ex3, newblock + max_blocks); + ex3->ee_len =cpu_to_le16 (allocated - max_blocks); +ext4_ext_mark_uninitialized (ex3); + err =ext4_ext_insert_extent (handle, inode, path, ex3); +if (err) + goto out; +/* The depth, and hence eh & ex might change +* as part of the insert above. +*/ + newdepth =ext_depth (inode); +if (newdepth != depth) + { + depth=newdepth; + path =ext4_ext_find_extent (inode, iblock,NULL ); +if (IS_ERR (path)) { + err =PTR_ERR (path); + path =NULL ; + goto out; + } + eh = path[depth].p_hdr; + ex = path[depth].p_ext; +if (ex2 != &newex) + ex2 = ex; + } + allocated = max_blocks; + } +/* If there was a change of depth as part of the +* insertion of ex3 above, we need to update the length +* of the ex1 extent again here +*/ +if (ex1 && ex1 != ex) { + ex1 = ex; + ex1->ee_len =cpu_to_le16 (iblock - ee_block); +ext4_ext_mark_uninitialized (ex1); + ex2 = &newex; + } +/* ex2: iblock to iblock + maxblocks-1 : initialised */ + ex2->ee_block =cpu_to_le32 (iblock); + ex2->ee_start = newblock; +ext4_ext_store_pblock (ex2, newblock); + ex2->ee_len =cpu_to_le16 (allocated); +if (ex2 != ex) + goto insert; +if ((err =ext4_ext_get_access (handle, inode, path + depth))) + goto out; +/* New (initialized) extent starts from the first block +* in the current extent. i.e., ex2 == ex +* We have to see if it can be merged with the extent +* on the left. +*/ +if (ex2 >EXT_FIRST_EXTENT (eh)) { +/* To merge left, pass "ex2 - 1" to try_to_merge(), +* since it merges towards right _only_. +*/ + ret =ext4_ext_try_to_merge (inode, path, ex2 -1 ); +if (ret) { + err =ext4_ext_correct_indexes (handle, inode, path); +if (err) + goto out; + depth =ext_depth (inode); + ex2--; + } + } +/* Try to Merge towards right. This might be required +* only when the whole extent is being written to. +* i.e. ex2==ex and ex3==NULL. +*/ +if (!ex3) { + ret =ext4_ext_try_to_merge (inode, path, ex2); +if (ret) { + err =ext4_ext_correct_indexes (handle, inode, path); +if (err) + goto out; + } + } +/* Mark modified extent as dirty */ + err =ext4_ext_dirty (handle, inode, path + depth); + goto out; +insert: + err =ext4_ext_insert_extent (handle, inode, path, &newex); +out: +return err ? err : allocated; +} +int ext4_ext_get_blocks (handle_t *handle,struct inode *inode,ext4_fsblk_t iblock,unsigned long max_blocks,struct buffer_head *bh_result,int create,int extend_disksize) {struct ext4_ext_path *path =NULL ; +struct ext4_extent_header *eh;struct ext4_extent newex, *ex;ext4_fsblk_t goal, newblock; -int err =0 , depth; +int err =0 , depth, ret;unsigned long allocated =0 ;__clear_bit (BH_New, &bh_result->b_state);
@@ -2055,6 +2216,7 @@ int ext4_ext_get_blocks(handle_t *handle* this is why assert can't be put in ext4_ext_find_extent() */ BUG_ON (path[depth].p_ext ==NULL && depth !=0 ); + eh = path[depth].p_hdr; ex = path[depth].p_ext;if (ex) {
@@ -2063,13 +2225,9 @@ int ext4_ext_get_blocks(handle_t *handleunsigned short ee_len;/* -* Allow future support for preallocated extents to be added -* as an RO_COMPAT feature: * Uninitialized extents are treated as holes, except that -* we avoid (fail) allocating new blocks during a write. +* we split out initialized portions during a write. */ -if (le16_to_cpu (ex->ee_len) >EXT_MAX_LEN ) - goto out2; ee_len =ext4_ext_get_actual_len (ex);/* if found extent covers block, simply return it */ if (iblock >= ee_block && iblock < ee_block + ee_len) {
@@ -2078,12 +2236,27 @@ int ext4_ext_get_blocks(handle_t *handle allocated = ee_len - (iblock - ee_block);ext_debug ("%d fit into %lu:%d -> %llu\n" , (int ) iblock, ee_block, ee_len, newblock); +/* Do not put uninitialized extent in the cache */ -if (!ext4_ext_is_uninitialized (ex)) +if (!ext4_ext_is_uninitialized (ex)) {ext4_ext_put_in_cache (inode, ee_block, ee_len, ee_start,EXT4_EXT_CACHE_EXTENT ); - goto out; + goto out; + } +if (create ==EXT4_CREATE_UNINITIALIZED_EXT ) + goto out; +if (!create) + goto out2; + + ret =ext4_ext_convert_to_initialized (handle, inode, + path, iblock, + max_blocks); +if (ret <=0 ) + goto out2; +else + allocated = ret; + goto outnew; } }
@@ -2135,6 +2308,7 @@ int ext4_ext_get_blocks(handle_t *handle/* previous routine could use block we allocated */ newblock =ext_pblock (&newex); +outnew:__set_bit (BH_New, &bh_result->b_state);/* Cache only when it is _not_ an uninitialized extent */
include/linux/ext4_fs_extents.h +1 -0
@@ -203,6 +203,7 @@ ext4_ext_invalidate_cache(struct inode *extern int ext4_extent_tree_init (handle_t *,struct inode *);extern int ext4_ext_calc_credits_for_insert (struct inode *,struct ext4_ext_path *); +extern int ext4_ext_try_to_merge (struct inode *,struct ext4_ext_path *,struct ext4_extent *);extern unsigned int ext4_ext_check_overlap (struct inode *,struct ext4_extent *,struct ext4_ext_path *);extern int ext4_ext_insert_extent (handle_t *,struct inode *,struct ext4_ext_path *,struct ext4_extent *);extern int ext4_ext_walk_space (struct inode *,unsigned long ,unsigned long ,ext_prepare_callback ,void *);
Quoted 9 lines · Amit K. Arora
Outstanding Issues:
------------------
(1) The final interface is yet to be decided. We have the option of chosing from one of these:
a> modifyingposix_fallocate()in glibc
b> using fcntl
c> using ftruncate, or
d> using the ioctl interface.
Quoted 5 lines
If we go with ioctl interface, we need to chose the return
value from the ioctl. We should either return "0" for success and errno for failure, or we should be returning number of bytes preallocated.
Now I am more prefer just return 0 for success. Returning the number of bytes preallocated back to userspace might be helpful in the case when the specified window contains blocks already being allocated, but this should not be a common case.
Quoted 6 lines
(2) Also, we need to decide on what should happen in case of a partial success scenario. i.e. after few blocks get preallocated, we hit some error - say ENOSPC. Should the call just return the number of bytes preallocated, or should it "undo" the partial preallocation and then exit with error code ?
I think we should try to avoid this partial preallocation at the first place. Probably checking the number of free blocks before calling ext4_ext_get_blocks() and returns -ENOSPC if there isn't enough free blocks to allocate. Otherwise, if it still hits ENOSPC error, I think it doesn't hurt to leave the partial preallocated blocks there.
Cheers,
Mingming
Quoted 17 lines · Mingming Cao
Quoted 9 lines · Amit K. Arora
Outstanding Issues:
------------------
(1) The final interface is yet to be decided. We have the option of chosing from one of these:
a> modifyingposix_fallocate()in glibc
b> using fcntl
c> using ftruncate, or
d> using the ioctl interface.Quoted 5 lines
If we go with ioctl interface, we need to chose the return
value from the ioctl. We should either return "0" for success and errno for failure, or we should be returning number of bytes preallocated.
Quoted 4 lines
Now I am more prefer just return 0 for success. Returning the number of bytes preallocated back to userspace might be helpful in the case when the specified window contains blocks already being allocated, but this should not be a common case.
I tend to agree; I'm not exactly sure what the "bytes/blocks allocated" return would be useful for? What would the caller do with this information?
Also, is ftruncate really even an option for this interface? Wouldn't that mean the end of sparse files?
Thanks,
-Eric
Quoted 10 lines · Mingming Cao
Quoted 4 lines · Amit K. Arora
If we go with ioctl interface, we need to chose the return
value from the ioctl. We should either return "0" for success and errno for failure, or we should be returning number of bytes preallocated.Now I am more prefer just return 0 for success. Returning the number of bytes preallocated back to userspace might be helpful in the case when the specified window contains blocks already being allocated, but this should not be a common case.
Agreed. Even xfs preallocation ioctl and posix_fallocate return 0 on success.
Quoted 11 lines
Quoted 6 lines
(2) Also, we need to decide on what should happen in case of a partial success scenario. i.e. after few blocks get preallocated, we hit some error - say ENOSPC. Should the call just return the number of bytes preallocated, or should it "undo" the partial preallocation and then exit with error code ?
I think we should try to avoid this partial preallocation at the first place. Probably checking the number of free blocks before calling
ext4_ext_get_blocks()and returns-ENOSPCif there isn't enough free blocks to allocate. Otherwise, if it still hits ENOSPC error, I think it doesn't hurt to leave the partial preallocated blocks there.
True. But, there might be a small issue with this. Before calling ext4_ext_get_blocks(), we really don't know how many of the requested blocks are already allocated. Consider a scenario where out of 100 blocks requested for preallocation, say, only 10 need to be physically allocated (90 being already allocated to the file). Now, we will be checking for 100 free blocks in the filesystem, whereas ideally we should be checking for only 10.
--
Regards,
Amit Arora
Quoted 4 lines · Amit K. Arora
The patches for e2fsprogs and fsx-linux are available with me. I can post them if anyone is interested to try/test the preallocation patches. Also, I have a small test program/tool written which can be used for unit testing.
Here is the patch to e2fsprogs-1.39, with patches for ext4 already applied. It makes e2fsprogs tools recognize uninitialized extents. This is only for testing purpose as of now and it might need some fine-tuning, before it can be really be submitted.
This patch also enables "EXT_DEBUG" flag to display debug information (e.g. extent details).
--- lib/ext2fs/bmap.c | 3 +- lib/ext2fs/ext4_extents.h | 12 +++++++++- lib/ext2fs/extents.c | 55 ++++++++++++++++++++++++++++------------------ 3 files changed, 47 insertions(+), 23 deletions(-)
lib/ext2fs/bmap.c +2 -1
@@ -45,7 +45,8 @@ ex =EXT_FIRST_EXTENT (eh);for (i =0 ; i < eh->eh_entries; i++, ex++) {if ((ex->ee_block <= block) && - (block < ex->ee_block + ex->ee_len)) { + (block < ex->ee_block + +ext4_ext_get_actual_len (ex))) { *phys_blk =EXT4_EE_START (ex) + (block - ex->ee_block);return 0 ;
lib/ext2fs/ext4_extents.h +11 -1
@@ -37,7 +37,7 @@* if EXT_DEBUG is defined you can use 'extdebug' mount option * to get lots of info what's going on */ -//#define EXT_DEBUG +#define EXT_DEBUG #ifdef EXT_DEBUG #define ext_debug(tree,fmt,a...) \ do { \
@@ -170,6 +170,16 @@#define EXT_ASSERT (__x__) if (!(__x__)) BUG(); +/* +* Macro-instructions used to handle (mark/unmark/check/create) unitialized +* extents. Applications can issue an IOCTL for preallocation, which results +* in assigning unitialized extents to the file +*/ +#define EXT4_CREATE_UNINITIALIZED_EXT 2 +#define ext4_ext_mark_uninitialized (ext) ((ext)->ee_len |= 0x8000) +#define ext4_ext_is_uninitialized (ext) ((ext)->ee_len & 0x8000) +#define ext4_ext_get_actual_len (ext) ((ext)->ee_len & 0x7FFF) +/* * this structure is used to gather extents from the tree via ioctl
lib/ext2fs/extents.c +34 -21
144 lines not on this page · raw message
--
Regards,
Amit Arora
Re: patch for fsx-linux
In reply to Amit K. AroraQuoted 4 lines · Amit K. Arora
The patches for e2fsprogs and fsx-linux are available with me. I can post them if anyone is interested to try/test the preallocation patches. Also, I have a small test program/tool written which can be used for unit testing.
Here is the test patch for fsx-linux in LTP testsuite (version ltp-full-20061121). This makes fsx call doprealloc (which does preallocation ioctl) instead of dotruncate. Again, this is just for testing (of persistent preallocation patches) purpose.
--- testcases/kernel/fs/fsx-linux/fsx-linux.c | 90 ++++++++++++++++++++++++++++-- 1 files changed, 84 insertions(+), 6 deletions(-)
testcases/kernel/fs/fsx-linux/fsx-linux.c +84 -6
@@ -94,6 +94,7 @@ char *good_buf; /* a pointer to the cochar *temp_buf;/* a pointer to the current data */ char *fname;/* name of our test file */ int fd;/* fd for our test file */ +int block_size;/* block size*/ off_t file_size =0 ;off_t biggest =0 ;
@@ -115,6 +116,8 @@ int truncbdy = 1; /* -t flag */int writebdy =1 ;/* -w flag */ long monitorstart =-1 ;/* -m flag */ long monitorend =-1 ;/* -m flag */ +int prealloc =0 ;/* -x flag */ +int ext4 =0 ;/* -x flag */ int lite =0 ;/* -L flag */ long numops =-1 ;/* -N flag */ int randomoplen =1 ;/* -O flag disables it */
@@ -355,6 +358,19 @@ check_buffers(unsigned offset, unsigned } } +int +get_block_size (void ) +{ +struct stat statbuf; + +if (fstat (fd, &statbuf)) { +prterr ("get_block_size: fstat" ); +report_failure (115 ); + } + +return statbuf.st_blksize; +} +void check_size (void )
@@ -628,6 +644,47 @@ domapwrite(unsigned offset, unsigned siz } } +#define EXT4_IOC_FALLOCATE 0x40106609 +void +doprealloc (unsigned size) +{ +int ret; +struct ext4_falloc_input { +unsigned long long offset; +unsigned long long len; + } input; + +if (!size) { +prt ("skipping zero size preallocation\n" ); +return ; + } + +if (!ext4) { +prt ("doprealloc: Preallocation currently supported " +"on ext4 _only_\n" ); +return ; + } + + input.offset =0 ; + input.len = (unsigned long long )size; + +if (testcalls <= simulatedopcount) +return ; + +if (progressinterval && testcalls % progressinterval ==0 || + debug && (monitorstart ==-1 || monitorend ==-1 || + size <= monitorend)) +prt ("%lu trunc\tfrom 0x0 to 0x%x\n" , testcalls, size); + + ret =ioctl (fd,EXT4_IOC_FALLOCATE , &input); +if (ret <0 ) { +prt ("ioctl: %x\n" , size); +prterr ("doprealloc: ioctl" ); +report_failure (160 ); + }else +if (size > file_size) + file_size = (size + block_size -1 ) & (~(block_size -1 )); +}void dotruncate (unsigned size)
@@ -679,7 +736,7 @@ writefileimage()prt ("short write: 0x%x bytes instead of 0x%qx\n" , iret, (unsigned long long )file_size);report_failure (172 ); - } + }if (lite ?0 :ftruncate (fd, file_size) ==-1 ) {prt ("ftruncate2: %qx\n" , (unsigned long long )file_size);prterr ("writefileimage: ftruncate" );
@@ -742,13 +799,15 @@ test(void)* TRUNCATE: op = 3 * MAPWRITE: op = 3 or 4 */ -if (lite ?0 : op ==3 && (style &1 ) ==0 )/* vanilla truncate? */ -dotruncate (random () % maxfilelen); +if (lite ?0 : op ==3 && (style &1 ) ==0 ) {/* vanilla truncate? */ + size =random () % maxfilelen; + (prealloc) ?doprealloc (size) :dotruncate (size); + }else {if (randomoplen) size =random () % (maxoplen+1 );if (lite ?0 : op ==3 ) -dotruncate (size); + (prealloc) ?doprealloc (size) :dotruncate (size);else { offset =random ();if (op ==1 || op == (lite ?3 :4 )) {
@@ -777,6 +836,7 @@ test(void)check_size ();if (closeopen)docloseopen (); + }
@@ -795,7 +855,7 @@ voidusage (void) { fprintf(stdout, "usage: %s", - "fsx [-dnqLOW] [-b opnum] [-c Prob] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] fname\n\ + "fsx [-dnqLOW] [-b opnum] [-c Prob] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-x xfs/ext4] [-D startingop] [-N numops] [-P dirpath] [-S seed] fname\n\ -b opnum: beginning operation number (default 1)\n\ -c P: 1 in P chance of file close+open at each op (default infinity)\n\ -d: debug output for all operations\n\
@@ -809,6 +869,7 @@ usage(void) -s style: 1 gives smaller truncates (default 0)\n\ -t truncbdy: 4096 would make truncates page aligned (default 1)\n\ -w writebdy: 4096 would make writes page aligned (default 1)\n\ + -x ext4/xfs: Do preallocate. filesystem can be either xfs, or ext4\n\ -D startingop: debug output starting at specified operation\n\ -L: fsxLite - no file creations & no file size changes\n\ -N numops: total # operations to do (default infinity)\n\
@@ -869,7 +930,7 @@ main(int argc, char **argv)setvbuf (stdout, (char *)0 , _IOLBF,0 );/* line buffered stdout */ -while ((ch =getopt (argc, argv,"b:c:dl:m:no:p:qr:s:t:w:D:LN:OP:RS:W" )) +while ((ch =getopt (argc, argv,"b:c:dl:m:no:p:qr:s:t:w:x:D:LN:OP:RS:W" )) !=EOF )switch (ch) {case 'b' :
@@ -946,6 +1007,17 @@ main(int argc, char **argv)if (writebdy <=0 )usage ();break ; +case 'x' : + prealloc =1 ; +if (!strcmp (optarg,"ext4" )) + ext4 =1 ; +printf ("ext4 = %u\n" , ext4); +if (!ext4 &&strcmp (optarg,"xfs" )) +usage (); +/* If we are here, ext4==1 signifies ext4 filesystem, +else it signifies xfs filesystem */ + +break ;case 'D' : debugstart =getnum (optarg, &endp);if (debugstart <1 )
@@ -1015,6 +1087,12 @@ main(int argc, char **argv)prterr (fname);exit (91 ); } + + block_size =get_block_size (); + +if (prealloc) +doprealloc (maxfilelen); +strncat (goodfile, fname,256 );strcat (goodfile,".fsxgood" ); fsxgoodfd =open (goodfile,O_RDWR |O_CREAT |O_TRUNC ,0666 );
--
Regards,
Amit Arora
Re: small tool for unit testing
In reply to Amit K. AroraQuoted 4 lines · Amit K. Arora
The patches for e2fsprogs and fsx-linux are available with me. I can post them if anyone is interested to try/test the preallocation patches. Also, I have a small test program/tool written which can be used for unit testing.
Here is a small test program/tool which can be used to preallocate blocks and write to these preallocated blocks.
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<errno.h>
#define _IOC_NRBITS 8 #define _IOC_TYPEBITS 8 #define _IOC_SIZEBITS 14 #define _IOC_DIRBITS 2
#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
#define _IOC_NRSHIFT 0 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
/*
* Direction bits.
*/
#define _IOC_WRITE 1U
#define _IOC(dir,type,nr,size) \
(((dir) << _IOC_DIRSHIFT) | \
((type) << _IOC_TYPESHIFT) | \
((nr) << _IOC_NRSHIFT) | \
((size) << _IOC_SIZESHIFT))/* provoke compile error for invalid uses of size argument */ extern unsigned int __invalid_size_argument_for_IOC;
#define _IOC_TYPECHECK(t) \
((sizeof(t) == sizeof(t[1]) && \
sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
sizeof(t) : __invalid_size_argument_for_IOC)/* used to create numbers */
#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
#define EXT4_IOC_PREALLOCATE _IOW('f', 9, struct ext4_falloc_input)
struct ext4_falloc_input {
unsigned long long offset;
unsigned long long len;
};int do_prealloc(char* fname, struct ext4_falloc_input input) {
int ret, fd = open(fname, O_CREAT|O_RDWR, 0666);
if(fd<0) {
printf("Error opening file %s\n", fname);
return 1;
}printf("%s : Trying to preallocate blocks (offset=%llu, len=%llu)\n",
fname, input.offset, input.len);
ret = ioctl(fd, EXT4_IOC_PREALLOCATE, &input);
if(ret <0) {
printf("IOCTL: received error %d, ret=%d\n", errno, ret);
close(fd);
exit(1); }
printf("IOCTL succedded ! ret=%d\n", ret);
close(fd);
}
int do_write(char* fname, struct ext4_falloc_input input) {
int ret, fd;
char *buf;
buf = (char *)malloc(input.len);
fd = open(fname, O_CREAT|O_RDWR, 0666);
if(fd<0) {
printf("Error opening file %s\n", fname);
return 1;
}printf("%s : Trying to write to file (offset=%llu, len=%llu)\n",
fname, input.offset, input.len);
ret = lseek(fd, input.offset, SEEK_SET);
if(ret != input.offset) {
printf("lseek() failed error=%d, ret=%d\n", errno, ret);
close(fd);
return(1);
}
ret = write(fd, buf, input.len);
if(ret != input.len) {
printf("write() failed error=%d, ret=%d\n", errno, ret);
close(fd);
return(1);
} printf("Write succedded ! Written %llu bytes ret=%d\n", input.len, ret); close(fd);
}
int main(int argc, char **argv)
{
struct ext4_falloc_input input;
int ret = 1, fd;
char *fname;
if(argc<5) {
printf("%s <CMD: prealloc/write> <filename-with-path> <offset> <length>\n", argv[0]);
exit(1);}
fname = argv[2];
input.offset=(unsigned long long)atol(argv[3]);;
input.len=(unsigned long long)atol(argv[4]);
if(input.offset<0 || input.len<= 0) {
printf("%s: Invalid arguments.\n", argv[0]);
exit(1);
} if(!strcmp(argv[1], "prealloc"))
ret = do_prealloc(fname, input);
else if(!strcmp(argv[1], "write"))
ret = do_write(fname, input);
else
printf("%s: Invalid arguments.\n", argv[0]); return ret;
}
--
Regards,
Amit Arora
Testing ext4 persistent preallocation patches for 64 bit features
In reply to Amit K. AroraI plan to test the persistent preallocation patches on a huge sparse device, to know if >32 bit physical block numbers (upto 48bit) behave as expected. I have following questions for this and will appreciate suggestions here:
a) What should be the sparse device size which I should use for testing? Should a size of > 8TB (say, 100 TB) be enough ?
The physical device (backing store device) size I can have is upto 70GB.
b) How do I test allocation of >32 bit physical block numbers ? I can not fill > 8TB, since the physical storage available with me is just 70GB.
c) Do I need to put some hack in the filesystem code for above (to allocate >32 bit physical block numbers) ?
Any further ideas on how to test this will help. Thanks!
--
Regards,
Amit Arora
Re: Testing ext4 persistent preallocation patches for 64 bit features
Quoted 3 lines · Amit K. Arora
I plan to test the persistent preallocation patches on a huge sparse device, to know if >32 bit physical block numbers (upto 48bit) behave as expected.
Thanks!
Quoted 6 lines
I have following questions for this and will appreciate
suggestions here:c) Do I need to put some hack in the filesystem code for above (to allocate >32 bit physical block numbers) ?
I had a ext3 hack patch before to allow application specify which block group is the targeted block allocation group,using ioctl command, so to allocate >32 bit physical block numbers it just set the target block group beyond 2**(32-15) = 2**17. patch is below..
BTW, have you considered
- move the preallocation code in ioctl to a seperate function, and call that function from ioctl? That way we could easily switch to posix_falloc later.
- Test preallocation with mapped IO?
- disable preallocation if the filesystem free blocks is under some low watermarks, to save space for near future real block allocation?
- is de-preallocation something worth doing?
Mingming
---
linux-2.6.16-ming/fs/ext3/balloc.c | 24 ++++++++++++++--------- linux-2.6.16-ming/fs/ext3/ioctl.c | 29 ++++++++++++++++++++++++++++ linux-2.6.16-ming/include/linux/ext3_fs.h | 1 linux-2.6.16-ming/include/linux/ext3_fs_i.h | 1 4 files changed, 46 insertions(+), 9 deletions(-)
fs/ext3/ioctl.c renamed from fs/ext3/ioctl.c~ext3_set_alloc_blk_group_hack +29 -0
@@ -22,6 +22,7 @@ int ext3_ioctl (struct inode * inode, ststruct ext3_inode_info *ei =EXT3_I (inode);unsigned int flags;unsigned short rsv_window_size; +unsigned int blk_group;ext3_debug ("cmd = %u, arg = %lu\n" , cmd, arg);
@@ -193,6 +194,34 @@ flags_err:mutex_unlock (&ei->truncate_mutex);return 0 ; } +case EXT3_IOC_SETALLOCBLKGRP : { + +if (!test_opt (inode->i_sb,RESERVATION ) ||!S_ISREG (inode->i_mode)) +return -ENOTTY ; + +if (IS_RDONLY (inode)) +return -EROFS ; + +if ((current->fsuid != inode->i_uid) && !capable (CAP_FOWNER )) +return -EACCES ; + +if (get_user (blk_group, (int __user *)arg)) +return -EFAULT ; + +/* +* need to allocate reservation structure for this inode +* before set the window size +*/ +mutex_lock (&ei->truncate_mutex); +if (!ei->i_block_alloc_info) +ext3_init_block_alloc_info (inode); + +if (ei->i_block_alloc_info){ + ei->i_block_alloc_info->goal_block_group = blk_group; + } +mutex_unlock (&ei->truncate_mutex); +return 0 ; + }case EXT3_IOC_GROUP_EXTEND : {unsigned long n_blocks_count;struct super_block *sb = inode->i_sb;
include/linux/ext3_fs.h renamed from include/linux/ext3_fs.h~ext3_set_alloc_blk_group_hack +1 -0
@@ -238,6 +238,7 @@ struct ext3_new_group_data {#endif #define EXT3_IOC_GETRSVSZ _IOR('f', 5, long)#define EXT3_IOC_SETRSVSZ _IOW('f', 6, long) +#define EXT3_IOC_SETALLOCBLKGRP _IOW('f', 9, long)/* * Mount options
include/linux/ext3_fs_i.h renamed from include/linux/ext3_fs_i.h~ext3_set_alloc_blk_group_hack +1 -0
@@ -51,6 +51,7 @@ struct ext3_block_alloc_info {* allocation when we detect linearly ascending requests. */ __u32 last_alloc_physical_block; +__u32 goal_block_group; };#define rsv_start rsv_window._rsv_start
fs/ext3/balloc.c renamed from fs/ext3/balloc.c~ext3_set_alloc_blk_group_hack +15 -9
@@ -285,6 +285,7 @@ void ext3_init_block_alloc_info(struct i rsv->rsv_alloc_hit =0 ; block_i->last_alloc_logical_block =0 ; block_i->last_alloc_physical_block =0 ; + block_i->goal_block_group =0 ; } ei->i_block_alloc_info = block_i; }
@@ -1263,15 +1264,20 @@ unsigned long ext3_new_blocks(handle_t * *errp = -ENOSPC ; goto out; } - -/* -* First, test whether the goal block is free. -*/ -if (goal <le32_to_cpu (es->s_first_data_block) || - goal >=le32_to_cpu (es->s_blocks_count)) - goal =le32_to_cpu (es->s_first_data_block); - group_no = (goal -le32_to_cpu (es->s_first_data_block)) / -EXT3_BLOCKS_PER_GROUP (sb); +if (block_i->goal_block_group) { + group_no = block_i->goal_block_group; + goal =le32_to_cpu (EXT3_SB (sb)->s_es->s_first_data_block) + group_no *EXT3_BLOCKS_PER_GROUP (sb); + block_i->goal_block_group =0 ; + }else { +/* +* First, test whether the goal block is free. +*/ +if (goal <le32_to_cpu (es->s_first_data_block) || + goal >=le32_to_cpu (es->s_blocks_count)) + goal =le32_to_cpu (es->s_first_data_block); + group_no = (goal -le32_to_cpu (es->s_first_data_block)) / +EXT3_BLOCKS_PER_GROUP (sb); + } gdp =ext3_get_group_desc (sb, group_no, &gdp_bh);if (!gdp) goto io_error;
_
Re: Testing ext4 persistent preallocation patches for 64 bit features
Quoted 19 lines · Mingming Cao
Quoted 3 lines · Amit K. Arora
I plan to test the persistent preallocation patches on a huge sparse device, to know if >32 bit physical block numbers (upto 48bit) behave as expected.
Thanks!
Quoted 6 lines
I have following questions for this and will appreciate
suggestions here:c) Do I need to put some hack in the filesystem code for above (to allocate >32 bit physical block numbers) ?
I had a ext3 hack patch before to allow application specify which block group is the targeted block allocation group,using ioctl command, so to allocate >32 bit physical block numbers it just set the target block group beyond 2**(32-15) = 2**17. patch is below..
Quoted 4 lines
BTW, have you considered
- move the preallocation code in ioctl to a seperate function, and call that function from ioctl? That way we could easily switch toposix_falloclater.
Good suggestion.
Quoted 3 lines
- Test preallocation with mapped IO?
- disable preallocation if the filesystem free blocks is under some low watermarks, to save space for near future real block allocation?
A policy decision like this is probably worth a discussion during today's call.
Quoted 1 line
- is de-preallocation something worth doing?
Wouldn't truncate do that ?
Or you thinking of something like hole punching ?
Regards
Suparna
Quoted 128 lines
Mingming
---
linux-2.6.16-ming/fs/ext3/balloc.c | 24 ++++++++++++++--------- linux-2.6.16-ming/fs/ext3/ioctl.c | 29 ++++++++++++++++++++++++++++ linux-2.6.16-ming/include/linux/ext3_fs.h | 1 linux-2.6.16-ming/include/linux/ext3_fs_i.h | 1 4 files changed, 46 insertions(+), 9 deletions(-)diff -puN
fs/ext3/ioctl.c~ext3_set_alloc_blk_group_hackfs/ext3/ioctl.cfs/ext3/ioctl.c renamed from fs/ext3/ioctl.c~ext3_set_alloc_blk_group_hack +29
-0@@ -22,6 +22,7 @@ int ext3_ioctl (struct inode * inode, ststruct ext3_inode_info *ei =EXT3_I (inode);unsigned int flags;unsigned short rsv_window_size; +unsigned int blk_group;ext3_debug ("cmd = %u, arg = %lu\n" , cmd, arg);@@ -193,6 +194,34 @@ flags_err:mutex_unlock (&ei->truncate_mutex);return 0 ; } +case EXT3_IOC_SETALLOCBLKGRP : { + +if (!test_opt (inode->i_sb,RESERVATION ) ||!S_ISREG (inode->i_mode)) +return -ENOTTY ; + +if (IS_RDONLY (inode)) +return -EROFS ; + +if ((current->fsuid != inode->i_uid) && !capable (CAP_FOWNER )) +return -EACCES ; + +if (get_user (blk_group, (int __user *)arg)) +return -EFAULT ; + +/* +* need to allocate reservation structure for this inode +* before set the window size +*/ +mutex_lock (&ei->truncate_mutex); +if (!ei->i_block_alloc_info) +ext3_init_block_alloc_info (inode); + +if (ei->i_block_alloc_info){ + ei->i_block_alloc_info->goal_block_group = blk_group; + } +mutex_unlock (&ei->truncate_mutex); +return 0 ; + }case EXT3_IOC_GROUP_EXTEND : {unsigned long n_blocks_count;struct super_block *sb = inode->i_sb;diff -puN
include/linux/ext3_fs.h~ext3_set_alloc_blk_group_hackinclude/linux/ext3_fs.hinclude/linux/ext3_fs.h renamed from include/linux/ext3_fs.h~ext3_set_alloc_blk_group_hack +1
-0@@ -238,6 +238,7 @@ struct ext3_new_group_data {#endif #define EXT3_IOC_GETRSVSZ _IOR('f', 5, long)#define EXT3_IOC_SETRSVSZ _IOW('f', 6, long) +#define EXT3_IOC_SETALLOCBLKGRP _IOW('f', 9, long)/* * Mount options diff -puN
include/linux/ext3_fs_i.h~ext3_set_alloc_blk_group_hackinclude/linux/ext3_fs_i.hinclude/linux/ext3_fs_i.h renamed from include/linux/ext3_fs_i.h~ext3_set_alloc_blk_group_hack +1
-0@@ -51,6 +51,7 @@ struct ext3_block_alloc_info {* allocation when we detect linearly ascending requests. */ __u32 last_alloc_physical_block; +__u32 goal_block_group; };#define rsv_start rsv_window._rsv_startdiff -puN
fs/ext3/balloc.c~ext3_set_alloc_blk_group_hackfs/ext3/balloc.cfs/ext3/balloc.c renamed from fs/ext3/balloc.c~ext3_set_alloc_blk_group_hack +15
-9@@ -285,6 +285,7 @@ void ext3_init_block_alloc_info(struct i rsv->rsv_alloc_hit =0 ; block_i->last_alloc_logical_block =0 ; block_i->last_alloc_physical_block =0 ; + block_i->goal_block_group =0 ; } ei->i_block_alloc_info = block_i; }@@ -1263,15 +1264,20 @@ unsigned long ext3_new_blocks(handle_t * *errp = -ENOSPC ; goto out; } - -/* -* First, test whether the goal block is free. -*/ -if (goal <le32_to_cpu (es->s_first_data_block) || - goal >=le32_to_cpu (es->s_blocks_count)) - goal =le32_to_cpu (es->s_first_data_block); - group_no = (goal -le32_to_cpu (es->s_first_data_block)) / -EXT3_BLOCKS_PER_GROUP (sb); +if (block_i->goal_block_group) { + group_no = block_i->goal_block_group; + goal =le32_to_cpu (EXT3_SB (sb)->s_es->s_first_data_block) + group_no *EXT3_BLOCKS_PER_GROUP (sb); + block_i->goal_block_group =0 ; + }else { +/* +* First, test whether the goal block is free. +*/ +if (goal <le32_to_cpu (es->s_first_data_block) || + goal >=le32_to_cpu (es->s_blocks_count)) + goal =le32_to_cpu (es->s_first_data_block); + group_no = (goal -le32_to_cpu (es->s_first_data_block)) / +EXT3_BLOCKS_PER_GROUP (sb); + } gdp =ext3_get_group_desc (sb, group_no, &gdp_bh);if (!gdp) goto io_error;_
-
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Suparna Bhattacharya ([email protected]) Linux Technology Center IBM Software Lab, India
Re: Testing ext4 persistent preallocation patches for 64 bit features
Quoted 7 lines · Suparna Bhattacharya
Quoted 2 lines · Mingming Cao
- disable preallocation if the filesystem free blocks is under some low watermarks, to save space for near future real block allocation?
A policy decision like this is probably worth a discussion during today's call.
Quoted 1 line
- is de-preallocation something worth doing?
As discussed in the call - I don't think we can remove preallocations. The whole point of database preallocation is to guarantee that this space is available in the filesystem when writing into a file at random offsets (which would otherwise be sparse).
Similarly, persistent preallocation shouldn't be considered differently than an efficient way of doing zero filling of blocks. At least that is my understanding... Is this code implementing the "uninitialized extents" for databases (via explicit preallocation via fallocate/ioctl) so that they don't have to zero-fill large files, or is there also automatic preallocation of space to files (e.g. for O_APPEND files)?
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Re: Testing ext4 persistent preallocation patches for 64 bit features
Quoted 14 lines · Andreas Dilger
Quoted 7 lines · Suparna Bhattacharya
Quoted 2 lines · Mingming Cao
- disable preallocation if the filesystem free blocks is under some low watermarks, to save space for near future real block allocation?
A policy decision like this is probably worth a discussion during today's call.
Quoted 1 line
- is de-preallocation something worth doing?
As discussed in the call - I don't think we can remove preallocations. The whole point of database preallocation is to guarantee that this space is available in the filesystem when writing into a file at random offsets (which would otherwise be sparse).
Quoted 6 lines
Similarly, persistent preallocation shouldn't be considered differently than an efficient way of doing zero filling of blocks. At least that is my understanding... Is this code implementing the "uninitialized extents" for databases (via explicit preallocation via fallocate/ioctl) so that they don't have to zero-fill large files, or is there also automatic preallocation of space to files (e.g. for
O_APPENDfiles)?
You are right. There is no automatic preallocation of space being done here. This code just implements the explicit (persistent) preallocation of blocks via ioctl.
--
Regards,
Amit Arora
Re: Testing ext4 persistent preallocation patches for 64 bit features
In reply to Mingming CaoQuoted 7 lines · Mingming Cao
Quoted 2 lines · Amit K. Arora
c) Do I need to put some hack in the filesystem code for above (to allocate >32 bit physical block numbers) ?
I had a ext3 hack patch before to allow application specify which block group is the targeted block allocation group,using ioctl command, so to allocate >32 bit physical block numbers it just set the target block group beyond 2**(32-15) = 2**17. patch is below..
Thanks for the patch!
Quoted 4 lines
BTW, have you considered
- move the preallocation code in ioctl to a seperate function, and call that function from ioctl? That way we could easily switch toposix_falloclater.
OK.
Quoted 1 line
- Test preallocation with mapped IO?
I haven't done that yet. Will test it out too. Thanks!
--
Regards,
Amit Arora
Quoted 7 lines · On Wed, 17 Jan 2007 15:16:58 +0530 "Amit K. Arora" <[email protected]>…
(1) The final interface is yet to be decided. We have the option of chosing from one of these:
a> modifyingposix_fallocate()in glibc
b> using fcntl
c> using ftruncate, or
d> using the ioctl interface.
I'd suggest we add a new syscall, which implements the posix_fallocate() API as per the relevant specs. We can work the final details out with Ulrich and I'm sure that glibc's posix_fallocate() will start using the syscall if it is available.
Actually, we should implement
asmlinkage long sys_fallocate(int fd, loff_t offset, loff_t len);
note: loff_t, not off_t.
This probably means that we'll need to implement file_operations.fallocate().
It wouldn't surprise me if XFS was able to implement fallocate() too.
RFC 1/1 Heads up on sys_fallocate()
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call sys_fallocate() and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:
asmlinkage long sys_fallocate(int fd, loff_t offset, loff_t len);
As we are developing and testing the required patches, we decided to post a preliminary patch and get inputs from the community to give it a right direction and shape. First, a little description on the feature.
Persistent preallocation is a file system feature using which an application (say, relational database servers) can explicitly preallocate blocks to a particular file. This feature can be used to reserve space for a file to get mainly the following benefits:
1> contiguity - less defragmentation and thus faster access speed, and 2> guarantee for a minimum space availibility (depending on how many blocks were preallocated) for the file, even if the filesystem becomes full.
XFS already has an implementation for this, using an ioctl interface. And, ext4 is now coming up with this feature. In coming time we may see a few more file systems implementing this. Thus, it makes sense to have a more standard interface for this, like this new system call.
Here is the initial and incomplete version of the patch, which can be used for the discussion, till we come up with a set of more complete patches.
--- arch/i386/kernel/syscall_table.S | 1 + fs/ext4/file.c | 1 + fs/open.c | 18 ++++++++++++++++++ include/asm-i386/unistd.h | 3 ++- include/linux/fs.h | 1 + include/linux/syscalls.h | 1 + 6 files changed, 24 insertions(+), 1 deletion(-)
arch/i386/kernel/syscall_table.S +1 -0
@@ -319,3 +319,4 @@ ENTRY(sys_call_table) .long sys_move_pages .long sys_getcpu .long sys_epoll_pwait + .long sys_fallocate /* 320 */
fs/ext4/file.c +1 -0
@@ -135,5 +135,6 @@ struct inode_operations ext4_file_inode_ .removexattr = generic_removexattr, #endif .permission = ext4_permission, + .fallocate = ext4_fallocate, };
fs/open.c +18 -0
@@ -350,6 +350,24 @@ asmlinkage long sys_ftruncate64(unsigned }#endif +asmlinkage long sys_fallocate (int fd,loff_t offset,loff_t len) +{ +struct file *file; +struct inode *inode; +long ret = -EINVAL ; + file =fget (fd); +if (!file) + goto out; + inode = file->f_path.dentry->d_inode; +if (inode->i_op && inode->i_op->fallocate) + ret = inode->i_op->fallocate (inode, offset, len); +else + ret = -ENOTTY ; +fput (file); +out: +return ret; +} +/* * access() needs to use the real uid/gid, not the effective uid/gid. * We do this by temporarily clearing all FS-related capabilities and
include/asm-i386/unistd.h +2 -1
@@ -325,10 +325,11 @@#define __NR_move_pages 317#define __NR_getcpu 318#define __NR_epoll_pwait 319 +#define __NR_fallocate 320#ifdef __KERNEL__ -#define NR_syscalls 320 +#define NR_syscalls 321#define __ARCH_WANT_IPC_PARSE_VERSION#define __ARCH_WANT_OLD_READDIR
include/linux/fs.h +1 -0
@@ -1124,6 +1124,7 @@ struct inode_operations {ssize_t (*listxattr) (struct dentry *,char *,size_t );int (*removexattr) (struct dentry *,const char *);void (*truncate_range)(struct inode *,loff_t ,loff_t ); +long (*fallocate)(struct inode *,loff_t ,loff_t ); };struct seq_file ;
include/linux/syscalls.h +1 -0
@@ -602,6 +602,7 @@ asmlinkage long sys_get_robust_list(intasmlinkage long sys_set_robust_list (struct robust_list_head __user *head,size_t len);asmlinkage long sys_getcpu (unsigned __user *cpu,unsigned __user *node,struct getcpu_cache __user *cache); +asmlinkage long sys_fallocate (int fd,loff_t offset,loff_t len);int kernel_execve (const char *filename,char *const argv[],char *const envp[]);
--
Regards,
Amit Arora
Re: [RFC] Heads up on sys_fallocate()
Quoted 7 lines · Amit K. Arora
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);
One thing I'd like to see is a cmd argument as well, to allow for example allocation vs. reservation (i.e. allocating blocks vs. simply reserving a number), as well as the inverse of those functions (un-reservation, de-allocation)?
If the allocation interface allows allocation/reservation within arbitrary ranges, if the only way to un-allocate is via a truncate, that's pretty asymmetric.
-Eric
Re: [RFC] Heads up on sys_fallocate()
In reply to Amit K. AroraQuoted 29 lines · Amit K. Arora
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);As we are developing and testing the required patches, we decided to post a preliminary patch and get inputs from the community to give it a right direction and shape. First, a little description on the feature.
Persistent preallocation is a file system feature using which an application (say, relational database servers) can explicitly preallocate blocks to a particular file. This feature can be used to reserve space for a file to get mainly the following benefits:
1> contiguity - less defragmentation and thus faster access speed, and 2> guarantee for a minimum space availibility (depending on how many blocks were preallocated) for the file, even if the filesystem becomes full.XFS already has an implementation for this, using an ioctl interface. And, ext4 is now coming up with this feature. In coming time we may see a few more file systems implementing this. Thus, it makes sense to have a more standard interface for this, like this new system call.
Here is the initial and incomplete version of the patch, which can be used for the discussion, till we come up with a set of more complete patches.
Quoted 8 lines
--- arch/i386/kernel/syscall_table.S | 1 + fs/ext4/file.c | 1 + fs/open.c | 18 ++++++++++++++++++ include/asm-i386/unistd.h | 3 ++- include/linux/fs.h | 1 + include/linux/syscalls.h | 1 + 6 files changed, 24 insertions(+), 1 deletion(-)
I certainly agree that we want something like this.
posix_fallocate() is the glibc interface we want to be compatible with (which your definition is, AFAICS).
Jeff
Re: [RFC] Heads up on sys_fallocate()
Quoted 4 lines · Jeff Garzik
I certainly agree that we want something like this.
posix_fallocate()is the glibc interface we want to be compatible with (which your definition is, AFAICS).
This would be great for Samba. Windows clients do this a lot....
Jeremy.
Re: [RFC] Heads up on sys_fallocate()
In reply to Amit K. Arorafs/open.c asmlinkage long sys_ftruncate64(unsigned · line 365
Quoted 4 lines · Amit K. Arora
fs/open.c +4
-0+if (inode->i_op && inode->i_op->fallocate) + ret = inode->i_op->fallocate (inode, offset, len); +else + ret = -ENOTTY ;
You can only allocate space on typewriters? ;)
J
Re: [RFC] Heads up on sys_fallocate()
Quoted 7 lines · On Thu, 01 Mar 2007 13:14:32 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 365
Quoted 4 lines · Amit K. Arora
fs/open.c +4
-0+if (inode->i_op && inode->i_op->fallocate) + ret = inode->i_op->fallocate (inode, offset, len); +else + ret = -ENOTTY ;You can only allocate space on typewriters? ;)
A lot of people get confused about -ENOTTY, but it is the return for attempting to use an ioctl on the wrong type of object, so this appears to be quite correct.
Re: [RFC] Heads up on sys_fallocate()
Quoted 3 lines · Alan
A lot of people get confused about
-ENOTTY, but it is the return for attempting to use an ioctl on the wrong type of object, so this appears to be quite correct.
This is a syscall though; ENOSYS is probably a better match.
J
Re: [RFC] Heads up on sys_fallocate()
Quoted 6 lines · On Thu, 01 Mar 2007 14:05:36 -0800 Jeremy Fitzhardinge <[email protected]> wrote:
Quoted 3 lines · Alan
A lot of people get confused about
-ENOTTY, but it is the return for attempting to use an ioctl on the wrong type of object, so this appears to be quite correct.This is a syscall though; ENOSYS is probably a better match.
ENOSYS indicates quite different things and ENOTTY is also used for syscalls. I still think ENOTTY is correct.
Re: [RFC] Heads up on sys_fallocate()
Quoted 3 lines · Alan
ENOSYS indicates quite different things and ENOTTY is also used for syscalls. I still think ENOTTY is correct.
Yes, ENOSYS tends to me "operation flat out not support" rather than "not on this object". I think we can do better than ENOTTY though - ENOTSUP for example (modulo the confusion over EOPNOTSUPP).
(You can tell the patch has very little real substance if we're arguing over errnos at this point :)
J
Re: [RFC] Heads up on sys_fallocate()
In reply to Amit K. AroraQuoted 6 lines · On Fri, 2 Mar 2007 00:04:45 +0530 "Amit K. Arora" <[email protected]>…
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);
It is intended that glibc use this same syscall for both posix_fallocate() and posix_fallocate64().
I'd agree with Eric on the "command" flag extension.
That new argument might need to come after "fd" - ARM has funny requirements on syscall arg padding and layout.
Quoted 7 lines
fs/open.c +7
-0+asmlinkage long sys_fallocate (int fd,loff_t offset,loff_t len) +{ +struct file *file; +struct inode *inode; +long ret = -EINVAL ; + file =fget (fd); +if (!file)
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 369
Quoted 10 lines
fs/open.c +10
-0+ goto out; + inode = file->f_path.dentry->d_inode; +if (inode->i_op && inode->i_op->fallocate) + ret = inode->i_op->fallocate (inode, offset, len); +else + ret = -ENOTTY ; +fput (file); +out: +return ret; +}
Please always put a blank line between the variable definitions and the first statement.
Please always use hard tabs, not bunch-of-spaces. This seems to happening rather a lot in the ext4 patches. It's a trivial thing, but also trivial to fix. A grep across the diffs is needed.
ENOTTY is a bit unconventional - we often use EINVAL for this sort of thing. But EINVAL has other meanings for posix_fallocate() and isn't really appropriate here anyway. So I'm not sure what would be better...
Re: [RFC] Heads up on sys_fallocate()
Quoted 8 lines · Andrew Morton
Quoted 5 lines · On Fri, 2 Mar 2007 00:04:45 +0530 "Amit K. Arora" <[email protected]>…
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:
Quoted 4 lines
Quoted 1 line
asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);...
I'd agree with Eric on the "command" flag extension.
Seems like a separate syscall would be better, "command" sounds a bit ioctl like, especially if that command is passed into the filesystems..
cheers.
Signature · 1 line
Nathan
Re: [RFC] Heads up on sys_fallocate()
Quoted 12 lines · Nathan Scott
Quoted 11 lines · Andrew Morton
Quoted 6 lines · On Fri, 2 Mar 2007 00:04:45 +0530 "Amit K. Arora" <[email protected]>…
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);...
Quoted 8 lines
Quoted 1 line
I'd agree with Eric on the "command" flag extension.
Seems like a separate syscall would be better, "command" sounds a bit ioctl like, especially if that command is passed into the filesystems..
cheers.
I'm fine with that too, I'd just like the functionality :)
-Eric
Re: [RFC] Heads up on sys_fallocate()
In reply to Andrew MortonQuoted 3 lines
That new argument might need to come after "fd" - ARM has funny requirements on syscall arg padding and layout.
FYI the 32bit ppc ABI does too, from arch/powerpc/kernel/sys_ppc32.c:
/*
* long long munging:
* The 32 bit ABI passes long longs in an odd even register pair. */
and the first argument in a function call is in r3.
Anton
Re: [RFC] Heads up on sys_fallocate()
In reply to Andrew MortonQuoted 17 lines · Andrew Morton
Quoted 14 lines · On Fri, 2 Mar 2007 00:04:45 +0530 "Amit K. Arora" <[email protected]>…
fs/open.c +14
-0+asmlinkage long sys_fallocate (int fd,loff_t offset,loff_t len) +{ +struct file *file; +struct inode *inode; +long ret = -EINVAL ; + file =fget (fd); +if (!file) + goto out; + inode = file->f_path.dentry->d_inode; +if (inode->i_op && inode->i_op->fallocate) + ret = inode->i_op->fallocate (inode, offset, len); +else + ret = -ENOTTY ; +fput (file);
Quoted 8 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 369
Quoted 3 lines
fs/open.c +3
-0+out: +return ret; +}ENOTTY is a bit unconventional - we often use EINVAL for this sort of thing. But EINVAL has other meanings for
posix_fallocate()and isn't really appropriate here anyway. So I'm not sure what would be better...
Would EINVAL (or whatever) make it back to the caller of posix_fallocate(), or would glibc fall back to its current implementation?
Forgive me if I haven't put enough thought into it, but would it be useful to create a generic_fallocate() that writes zeroed pages for any non-existent pages in the range? I don't know how glibc currently implements posix_fallocate(), but maybe the kernel could do it more efficiently, even in generic code. Maybe we don't care, since the major file systems can probably do something better in their own code.
Signature · 2 lines
David Kleikamp IBM Linux Technology Center
Re: [RFC] Heads up on sys_fallocate()
In reply to Nathan ScottQuoted 9 lines · On Fri, 02 Mar 2007 09:40:54 +1100 Nathan Scott <[email protected]> wrote:
Quoted 8 lines · Andrew Morton
Quoted 5 lines · On Fri, 2 Mar 2007 00:04:45 +0530 "Amit K. Arora" <[email protected]>…
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);...
I'd agree with Eric on the "command" flag extension.
Seems like a separate syscall would be better, "command" sounds a bit ioctl like, especially if that command is passed into the filesystems..
madvise, fadvise, lseek, etc seem to work OK.
I get repeatedly traumatised by patch rejects whenever a new syscall gets added, so I'm biased.
The advantage of a command flag is that we can add new modes in the future without causing lots of churn, waiting for arch maintainers to catch up, potentially adding new compat code, etc.
Rename it to "mode"? ;)
I'm inclined to merge this patch nice and early, so the syscall number is stabilised. Otherwise the people who are working on out-of-tree code (ie:
ext4) will have to keep playing catchup.
Re: [RFC] Heads up on sys_fallocate()
In reply to Dave KleikampQuoted 31 lines · On Thu, 01 Mar 2007 22:44:16 +0000 Dave Kleikamp <[email protected]>…
Quoted 17 lines · Andrew Morton
Quoted 14 lines · On Fri, 2 Mar 2007 00:04:45 +0530 "Amit K. Arora" <[email protected]>…
fs/open.c +14
-0+asmlinkage long sys_fallocate (int fd,loff_t offset,loff_t len) +{ +struct file *file; +struct inode *inode; +long ret = -EINVAL ; + file =fget (fd); +if (!file) + goto out; + inode = file->f_path.dentry->d_inode; +if (inode->i_op && inode->i_op->fallocate) + ret = inode->i_op->fallocate (inode, offset, len); +else + ret = -ENOTTY ; +fput (file);Quoted 8 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 369
Quoted 3 lines
fs/open.c +3
-0+out: +return ret; +}ENOTTY is a bit unconventional - we often use EINVAL for this sort of thing. But EINVAL has other meanings for
posix_fallocate()and isn't really appropriate here anyway. So I'm not sure what would be better...Would EINVAL (or whatever) make it back to the caller of
posix_fallocate(), or would glibc fall back to its current implementation?
Quoted 6 lines
Forgive me if I haven't put enough thought into it, but would it be useful to create a
generic_fallocate()that writes zeroed pages for any non-existent pages in the range? I don't know how glibc currently implementsposix_fallocate(), but maybe the kernel could do it more efficiently, even in generic code. Maybe we don't care, since the major file systems can probably do something better in their own code.
Given that glibc already implements fallocate for all filesystems, it will need to continue to do so for filesystems which don't implement this syscall - otherwise applications would start breaking.
However with this kernel change, glibc will need to look at the errno, so that it can correctly propagate EIO, ENOSPC and whatever. So we will need to return a reliable and stable and sensible value so that glibc knows when it should emulate and when it should propagate.
Perhaps Ulrich can comment.
Re: [RFC] Heads up on sys_fallocate()
Quoted 41 lines · Andrew Morton
Quoted 31 lines · On Thu, 01 Mar 2007 22:44:16 +0000 Dave Kleikamp <[email protected]>…
Quoted 17 lines · Andrew Morton
Quoted 14 lines · On Fri, 2 Mar 2007 00:04:45 +0530 "Amit K. Arora" <[email protected]>…
fs/open.c +14
-0+asmlinkage long sys_fallocate (int fd,loff_t offset,loff_t len) +{ +struct file *file; +struct inode *inode; +long ret = -EINVAL ; + file =fget (fd); +if (!file) + goto out; + inode = file->f_path.dentry->d_inode; +if (inode->i_op && inode->i_op->fallocate) + ret = inode->i_op->fallocate (inode, offset, len); +else + ret = -ENOTTY ; +fput (file);Quoted 8 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 369
Quoted 3 lines
fs/open.c +3
-0+out: +return ret; +}ENOTTY is a bit unconventional - we often use EINVAL for this sort of thing. But EINVAL has other meanings for
posix_fallocate()and isn't really appropriate here anyway. So I'm not sure what would be better...Would EINVAL (or whatever) make it back to the caller of
posix_fallocate(), or would glibc fall back to its current implementation?Quoted 6 lines
Forgive me if I haven't put enough thought into it, but would it be useful to create a
generic_fallocate()that writes zeroed pages for any non-existent pages in the range? I don't know how glibc currently implementsposix_fallocate(), but maybe the kernel could do it more efficiently, even in generic code. Maybe we don't care, since the major file systems can probably do something better in their own code.
Quoted 3 lines
Given that glibc already implements fallocate for all filesystems, it will need to continue to do so for filesystems which don't implement this syscall - otherwise applications would start breaking.
I didn't make it clear, but my point was to call generic_fallocate if the file system did not define i_op->allocate().
if (inode->i_op && inode->i_op->fallocate)
ret = inode->i_op->fallocate(inode, offset, len); else ret = generic_fallocate(inode, offset, len);
I'm not sure it's worth the effort, but I thought I'd throw the idea out there.
Signature · 2 lines
David Kleikamp IBM Linux Technology Center
Re: [RFC] Heads up on sys_fallocate()
In reply to Amit K. AroraAmit K. Arora wrote:
Might want more error checking in there, something like (rough cut)... (or is some of this glibc's job?)
Quoted 24 lines
(quoted diff) +24
-0+asmlinkage long sys_fallocate(int fd, loff_t offset, loff_t len) +{ + struct file *file; + struct inode *inode; + long ret; + + ret = -EINVAL; + if (len == 0 || offset < 0) + goto out; + ret = -EBADF; + file = fget(fd); + if (!file) + goto out; + if (!(file->f_mode & FMODE_WRITE)) + goto out_fput; + inode = file->f_path.dentry->d_inode; + ret = -ESPIPE; + if (S_ISFIFO(inode->i_mode)) + goto out_fput; + ret = -ENODEV; + if (!S_ISREG(inode->i_mode)) + goto out_fput; + ret = -EFBIG; + if (offset + len > inode->i_sb->s_maxbytes)
Review
Quoted 10 lines
(quoted diff) +10
-0+ goto out_fput; + if (inode->i_op && inode->i_op->fallocate) + ret = inode->i_op->fallocate(inode, offset, len); + else + ret = -ENOTTY; +out_fput: + fput(file); +out: + return ret; +}
which would keep things in line with posix_fallocate's specified errors, too?
-Eric
Re: [RFC] Heads up on sys_fallocate()
In reply to Amit K. AroraQuoted 10 lines · Amit K. Arora
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);As we are developing and testing the required patches, we decided to post a preliminary patch and get inputs from the community to give it a right direction and shape. First, a little description on the feature.
Thanks a lot, this has been long overdue.
Please don't forget to Cc the XFS list to keep developers of the only Linux filesystem supporting persistant allocations for a long time :)
Various people will beat you up for the above syscall as lots of architectures really want 64bit arguments aligned in a proper way, e.g. you at least need a pad after 'int fd'. Then again I already have suggestions for filling up that slot with useful information:
- you really want a whence argument as to lseek, as it makes a lot of sense for applications to allocate from the end of the file or the current file positions. The existing XFS ioctl already has this, and it's trivial to support this in any preallocation implementation I could imagine.
- we should think about having a flag value for which kind of preallocation we want. XFS currently has two:
ALLOCSP which updates the inode size and physically zeroes blocks RESVSP which does not update inode size but creates and unwritten
extent
the current posix_fallocate semantics are somewhere in the middle, as it requires and update to the inode size, but does not specify at all what happens if you read from the newly allocated space. And yes, as and heads up to developers implementing this feature on new filesystems: don't just return new blocks, that's a gapping security hole :)
Quoted 7 lines
fs/open.c +7
-0+asmlinkage long sys_fallocate (int fd,loff_t offset,loff_t len) +{ +struct file *file; +struct inode *inode; +long ret = -EINVAL ; + file =fget (fd); +if (!file)
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 369
Quoted 10 lines
fs/open.c +10
-0+ goto out; + inode = file->f_path.dentry->d_inode; +if (inode->i_op && inode->i_op->fallocate) + ret = inode->i_op->fallocate (inode, offset, len); +else + ret = -ENOTTY ; +fput (file); +out: +return ret; +}
This should use fget_light, and I'm sure the code could be written in a slightly more readable:
asmlinkage long sys_fallocate(int fd, loff_t offset, loff_t len)
{
struct file *file = fget(fd);
ret = -EINVAL;
if (file)
struct inode *inode = file->f_path.dentry->d_inode;
if (inode->i_op && inode->i_op->fallocate)
ret = inode->i_op->fallocate(inode, offset, len);
else
ret = -ENOTTY;
fput(file);
}
return ret;
}p.s. you reference ext4_fallocate in the patch but don't actually introduce it, it definitively won't compile as-is :)
Re: [RFC] Heads up on sys_fallocate()
In reply to Dave KleikampQuoted 10 lines · Dave Kleikamp
Would EINVAL (or whatever) make it back to the caller of
posix_fallocate(), or would glibc fall back to its current implementation?Forgive me if I haven't put enough thought into it, but would it be useful to create a
generic_fallocate()that writes zeroed pages for any non-existent pages in the range? I don't know how glibc currently implementsposix_fallocate(), but maybe the kernel could do it more efficiently, even in generic code. Maybe we don't care, since the major file systems can probably do something better in their own code.
I'd be more happy to have the write out zeroes loop in glibc. And glibc needs to have it anyway, for older kernels.
Re: [RFC] Heads up on sys_fallocate()
In reply to Eric SandeenQuoted 4 lines · Eric Sandeen
Amit K. Arora wrote:
Might want more error checking in there, something like (rough cut)... (or is some of this glibc's job?)
Yeah, we need to have this checks. We can't rely on userspace not passing arguments that might corrupt your filesystem or let you escalate privilegues.
Quoted 2 lines
which would keep things in line with posix_fallocate's specified errors, too?
Yes, very good idea.
Re: [RFC] Heads up on sys_fallocate()
In reply to Amit K. AroraQuoted 7 lines · Amit K. Arora
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);
I am wondering about return values from this syscall ? Is it supposed to return the number of bytes allocated ? What about partial allocations ? What about if the blocks already exists ? What would be return values in those cases ?
Just curious .. What does posix_fallocate() return ?
Thanks,
Badari
Quoted 1 line
Re: [RFC] Heads up on sys_fallocate()
Quoted 1 line · On Thu, 01 Mar 2007 22:03:55 -0800 Badari Pulavarty <[email protected]> wrote:
Just curious .. What does
posix_fallocate()return ?
bookmark this:
http://www.opengroup.org/onlinepubs/009695399/nfindex.html
Upon successful completion, posix_fallocate() shall return zero; otherwise, an error number shall be returned to indicate the error.
Re: [RFC] Heads up on sys_fallocate()
In reply to Andrew MortonQuoted 1 line · Andrew Morton
Perhaps Ulrich can comment.
I was out of town, hence the delay.
I think that if there is no support for the syscall the correct answer is to return ENOSYS. In this case the current userlevel code would be used and ENOSYS is also used to trigger the use of the compat code in glibc in case the syscall does not exist at all.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [RFC] Heads up on sys_fallocate()
In reply to Eric SandeenQuoted 8 lines · Eric Sandeen
One thing I'd like to see is a cmd argument as well, to allow for example allocation vs. reservation (i.e. allocating blocks vs. simply reserving a number), as well as the inverse of those functions (un-reservation, de-allocation)?
If the allocation interface allows allocation/reservation within arbitrary ranges, if the only way to un-allocate is via a truncate, that's pretty asymmetric.
I'd rather we just get the oft-discussed punch() syscall instead. This is really what "unallocate" would do for persistent allocations and it would be useful for files that were not preallocated.
For filesystems that don't implement punch glibc() would do zero-filling of the punched area I guess (to make it equivalent to reading from a hole in the file).
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Re: [RFC] Heads up on sys_fallocate()
Quoted 6 lines · Andreas Dilger
Quoted 5 lines · Eric Sandeen
One thing I'd like to see is a cmd argument as well, to allow for example allocation vs. reservation (i.e. allocating blocks vs. simply reserving a number), as well as the inverse of those functions (un-reservation, de-allocation)?
Quoted 7 lines
Quoted 3 lines
If the allocation interface allows allocation/reservation within arbitrary ranges, if the only way to un-allocate is via a truncate, that's pretty asymmetric.
I'd rather we just get the oft-discussed
punch()syscall instead. This is really what "unallocate" would do for persistent allocations and it would be useful for files that were not preallocated.
I can see a difference though. punch() would throw away written data as well as pre-allocated-but-never-written-to data. I can see where a user might preallocate a large file and do a lot of random writes. At some point, he decides the file isn't going to grow much more, so let's free up the remaining pre-allocated blocks. This makes even more sense with reservation.
The alternative would be to have punch() take a flag to specify if only preallocated or reserved blocks should be freed.
Quoted 4 lines
For filesystems that don't implement punch
glibc()would do zero-filling of the punched area I guess (to make it equivalent to reading from a hole in the file).
Or it could just fail. Writing zeroes may be really slow and not give the caller any benefit. (The intention was to free blocks back to the file system.)
Shaggy
Signature · 2 lines
David Kleikamp IBM Linux Technology Center
Re: [RFC] Heads up on sys_fallocate()
In reply to Andrew MortonQuoted 1 line · Amit
asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);
Quoted 10 lines · Andrew Morton
Quoted 1 line · On Thu, 01 Mar 2007 22:03:55 -0800 Badari Pulavarty <[email protected]> wrote:
Just curious .. What does
posix_fallocate()return ?bookmark this:
http://www.opengroup.org/onlinepubs/009695399/nfindex.html
Upon successful completion,
posix_fallocate()shall return zero; otherwise, an error number shall be returned to indicate the error.
Then there's no need for sys_allocate to return a long.
Signature · 2 lines
David Kleikamp IBM Linux Technology Center
Re: [RFC] Heads up on sys_fallocate()
In reply to Dave KleikampQuoted 8 lines · Dave Kleikamp
Quoted 4 lines
Given that glibc already implements fallocate for all filesystems, it will need to continue to do so for filesystems which don't implement this syscall - otherwise applications would start breaking.
I didn't make it clear, but my point was to call
generic_fallocateif the file system did not definei_op->allocate().
Quoted 7 lines
if (
inode->i_op&&inode->i_op->fallocate)ret = inode->i_op->fallocate(inode, offset, len); else ret = generic_fallocate(inode, offset, len);I'm not sure it's worth the effort, but I thought I'd throw the idea out there.
Writing zeroes using glibc emu most likely means write() -- so generic_fallocate should be preferable (think splice). Or does glibc use mmap() and it's all different?
Jan
Re: [RFC] Heads up on sys_fallocate()
In reply to Badari PulavartyQuoted 8 lines · Badari Pulavarty
Quoted 5 lines · Amit K. Arora
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:
Quoted 4 lines
Quoted 2 lines
asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);I am wondering about return values from this syscall ? Is it supposed to return the number of bytes allocated ? What about partial allocations ?
If you don't have enough blocks to cover the request, you should probably just return -ENOSPC, not a partial allocation.
Quoted 2 lines
What about if the
blocks already exists ? What would be return values in those cases ?
0 on success, other normal errors oetherwise..
If asked for a range that includes already-allocated blocks, you just allocate any non-allocated blocks in the range, I think.
-Eric
Re: [RFC] Heads up on sys_fallocate()
In reply to Dave KleikampQuoted 1 line · Dave Kleikamp
Then there's no need for
sys_allocateto return a long.
Every syscall must return a long. Otherwise you can have problems on 64-bit archs.
Re: [RFC] Heads up on sys_fallocate()
In reply to Eric SandeenQuoted 9 lines · Eric Sandeen
Quoted 8 lines · Badari Pulavarty
Quoted 5 lines · Amit K. Arora
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);I am wondering about return values from this syscall ? Is it supposed to return the
number of bytes allocated ? What about partial allocations ?If you don't have enough blocks to cover the request, you should probably just return
-ENOSPC, not a partial allocation.
That could be challenging, when multiple writers are working in parallel. You may not be able to return -ENOSPC, till you fail the allocation (for filesystems which alllocates a block at a time).
Quoted 9 lines
Quoted 4 lines
What about
if the
blocks already exists ? What would be return values in those cases ?0 on success, other normal errors oetherwise..
If asked for a range that includes already-allocated blocks, you just allocate any non-allocated blocks in the range, I think.
Yes. What I was trying to figure out is, if there is a requirement that interface need to return exact number of bytes it *really* allocated (like write() or read()). I can't think of any, but just wanted to through it out..
BTW, what is the interface for finding out what is the size of the pre-allocated file ?
Thanks,
Badari
Re: [RFC] Heads up on sys_fallocate()
Quoted 7 lines · On Fri, 02 Mar 2007 08:13:00 -0800 Badari Pulavarty <[email protected]> wrote:
Quoted 7 lines
Quoted 4 lines
What about
if the
blocks already exists ? What would be return values in those cases ?0 on success, other normal errors oetherwise..
Quoted 7 lines
Quoted 2 lines
If asked for a range that includes already-allocated blocks, you just allocate any non-allocated blocks in the range, I think.
Yes. What I was trying to figure out is, if there is a requirement that interface need to return exact number of bytes it *really* allocated (like
write()orread()). I can't think of any, but just wanted to through it out..
Hopefully not, because posix didn't anticipate that.
We could of course return a positive number on success, but it'd get tricky on 32-bit machines.
Quoted 2 lines
BTW, what is the interface for finding out what is the size of the pre-allocated file ?
stat.st_blocks?
Re: [RFC] Heads up on sys_fallocate()
In reply to Badari PulavartyQuoted 2 lines · Badari Pulavarty
BTW, what is the interface for finding out what is the size of the pre-allocated file ?
With XFS at least, "du," "stat," etc tell you a little:
[root@magnesium test]# touch resvsp [root@magnesium test]# xfs_io resvsp xfs_io> resvsp 0 10g
The file is 0 length, but is using 10g of blocks:
(with posix_fallocate this would move the size out to 10g as well)
[root@magnesium test]# ls -lh resvsp -rw-r--r-- 1 root root 0 Nov 28 14:11 resvsp [root@magnesium test]# du -hc resvsp
10G resvsp
10G total
[root@magnesium test]# stat resvsp
File: `resvsp'
Size: 0 Blocks: 20971520 IO Block: 4096 regular
empty file
Device: 81eh/2078d Inode: 186 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
xfs also has an interface to find out what allocations are where:
if you reserve some ranges not starting at 0...
[root@magnesium test]# xfs_io resvsp xfs_io> resvsp 1g 1gxfs_io> resvsp 3g 1gxfs_io> resvsp 5g 1gxfs_io> quit
[root@magnesium test]# xfs_bmap -v resvsp
resvsp:
EXT: FILE-OFFSET BLOCK-RANGE AG AG-OFFSET
TOTAL FLAGS
0: [0..2097151]: hole
2097152
1: [2097152..4194303]: 42392..2139543 0 (42392..2139543)
2097152 10000
2: [4194304..6291455]: hole
2097152
3: [6291456..8388607]: 4236696..6333847 0 (4236696..6333847)
2097152 10000
4: [8388608..10485759]: hole
2097152
5: [10485760..12582911]: 8431000..10528151 0 (8431000..10528151)
2097152 10000
The flags of 10000 mean that these extents is preallocated/unwritten.
I suppose outside of XFS, FIBMAP is your best bet, but that won't tell you what is preallocated vs. allocated/written....
-Eric
Re: [RFC] Heads up on sys_fallocate()
In reply to Dave KleikampQuoted 52 lines · Dave Kleikamp
Quoted 42 lines · Andrew Morton
Quoted 31 lines · On Thu, 01 Mar 2007 22:44:16 +0000 Dave Kleikamp <[email protected]>…
Quoted 16 lines · Andrew Morton
Quoted 13 lines · On Fri, 2 Mar 2007 00:04:45 +0530 "Amit K. Arora" <[email protected]>…
fs/open.c +13
-0+asmlinkage long sys_fallocate (int fd,loff_t offset,loff_t len) +{ +struct file *file; +struct inode *inode; +long ret = -EINVAL ; + file =fget (fd); +if (!file) + goto out; + inode = file->f_path.dentry->d_inode; +if (inode->i_op && inode->i_op->fallocate) + ret = inode->i_op->fallocate (inode, offset, len); +else + ret = -ENOTTY ;Quoted 8 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 369
Quoted 4 lines
fs/open.c +4
-0+fput (file); +out: +return ret; +}ENOTTY is a bit unconventional - we often use EINVAL for this sort of thing. But EINVAL has other meanings for
posix_fallocate()and isn't really appropriate here anyway. So I'm not sure what would be better...Would EINVAL (or whatever) make it back to the caller of
posix_fallocate(), or would glibc fall back to its current implementation?Quoted 6 lines
Forgive me if I haven't put enough thought into it, but would it be useful to create a
generic_fallocate()that writes zeroed pages for any non-existent pages in the range? I don't know how glibc currently implementsposix_fallocate(), but maybe the kernel could do it more efficiently, even in generic code. Maybe we don't care, since the major file systems can probably do something better in their own code.Quoted 3 lines
Given that glibc already implements fallocate for all filesystems, it will need to continue to do so for filesystems which don't implement this syscall - otherwise applications would start breaking.
I didn't make it clear, but my point was to call
generic_fallocateif the file system did not definei_op->allocate().
Quoted 8 lines
if (
inode->i_op&&inode->i_op->fallocate)ret = inode->i_op->fallocate(inode, offset, len); else ret = generic_fallocate(inode, offset, len);I'm not sure it's worth the effort, but I thought I'd throw the idea out there.
I think this is useful.
Mingming
Re: [RFC] Heads up on sys_fallocate()
In reply to Andrew MortonQuoted 29 lines · Andrew Morton
Quoted 13 lines · On Fri, 02 Mar 2007 09:40:54 +1100 Nathan Scott <[email protected]> wrote:
Quoted 11 lines · Andrew Morton
Quoted 6 lines · On Fri, 2 Mar 2007 00:04:45 +0530 "Amit K. Arora" <[email protected]>…
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);Quoted 8 lines
Quoted 3 lines
...
I'd agree with Eric on the "command" flag extension.
Seems like a separate syscall would be better, "command" sounds a bit ioctl like, especially if that command is passed into the filesystems..
madvise, fadvise, lseek, etc seem to work OK.
Quoted 9 lines
I get repeatedly traumatised by patch rejects whenever a new syscall gets added, so I'm biased.
The advantage of a command flag is that we can add new modes in the future without causing lots of churn, waiting for arch maintainers to catch up, potentially adding new compat code, etc.
Rename it to "mode"? ;)
I am wondering if it is useful to add another mode to advise block allocation policy? Something like indicating which physical block/block group to allocate from (goal), and whether ask for strict contigous blocks. This will help preallocation or reservation to choose the right blocks for the file.
Right now neither ext4 preallocation implementation or reservation are guranteed to allocate/reserve contigugous extents. If the application told it so, it could do more searching to satisfy the requirement.
Or fadvise is the right interface?
Mingming
Quoted 4 lines
I'm inclined to merge this patch nice and early, so the syscall number is stabilised. Otherwise the people who are working on out-of-tree code (ie:
ext4) will have to keep playing catchup.
Re: [RFC] Heads up on sys_fallocate()
In reply to Christoph HellwigQuoted 9 lines · On Friday 02 March 2007 00:38:19 Christoph Hellwig wrote:
Quoted 6 lines
Forgive me if I haven't put enough thought into it, but would it be useful to create a
generic_fallocate()that writes zeroed pages for any non-existent pages in the range? I don't know how glibc currently implementsposix_fallocate(), but maybe the kernel could do it more efficiently, even in generic code. Maybe we don't care, since the major file systems can probably do something better in their own code.I'd be more happy to have the write out zeroes loop in glibc. And glibc needs to have it anyway, for older kernels.
A generic_fallocate makes sense to me iff we can do it in the kernel more significantly more efficiently than in glibc, e.g. by using only a single page in page cache instead of one for each page to be preallocated.
If glibc is smart enough to do an optimal implementation, I fully agree with you.
Arnd <><
Re: [RFC] Heads up on sys_fallocate()
Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · On Friday 02 March 2007 00:38:19 Christoph Hellwig wrote:
Quoted 6 lines
Forgive me if I haven't put enough thought into it, but would it be useful to create a
generic_fallocate()that writes zeroed pages for any non-existent pages in the range? I don't know how glibc currently implementsposix_fallocate(), but maybe the kernel could do it more efficiently, even in generic code. Maybe we don't care, since the major file systems can probably do something better in their own code.I'd be more happy to have the write out zeroes loop in glibc. And glibc needs to have it anyway, for older kernels.
Quoted 6 lines
A
generic_fallocatemakes sense to me iff we can do it in the kernel more significantly more efficiently than in glibc, e.g. by using only a single page in page cache instead of one for each page to be preallocated.If glibc is smart enough to do an optimal implementation, I fully agree with you.
glibc cannot ever be smart enough because a file system driver will always know better and be able to do things in a much more optimized way.
For example on NTFS fallocate() only needs to involve the setting of a few bits in the volume block allocation bitmap (one bit for each logical block being allocated) and update the extent map in the on-disk inode to reflect that those blocks are now allocated to the inode. Then it just needs to update the allocated size and optionally the data size (if fallocate wants to increase the file size rather than just the allocated size). And that is it. No zeroing needs to happen at all because we have not updated the initialized size of the inode!
glibc can only dream of an implementation like this. (-;
Best regards,
Anton
Signature · 3 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer, http://www.linux-ntfs.org/
Re: [RFC] Heads up on sys_fallocate()
Quoted 5 lines · Anton Altaparmakov
Quoted 5 lines
A
generic_fallocatemakes sense to me iff we can do it in the kernel more significantly more efficiently than in glibc, e.g. by using only a single page in page cache instead of one for each page to be preallocated.
Quoted 7 lines
Quoted 3 lines
If glibc is smart enough to do an optimal implementation, I fully agree
with you.glibc cannot ever be smart enough because a file system driver will always know better and be able to do things in a much more optimized way.
Ok, that's not what I meant. It's obvious that the file system itself can do better than both VFS and glibc. The question is whether VFS can be better than glibc on file systems that don't offer their own implementation of the fallocate operation.
Arnd <><
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC] Heads up on sys_fallocate()
In reply to Anton AltaparmakovQuoted 2 lines · Anton Altaparmakov
And that is it. No zeroing needs to happen at all because we have not updated the initialized size of the inode!
When you do it like this, who can the kernel/filesystem *guarantee* that when the data is written there actually is room on the harddrive?
What you described seems like using truncate/ftruncate to increase the file's size. That is not at all what posix_fallocate is for. posix_fallocate must make sure that the requested blocks on the disk are reserved (allocated) for the file's use and that at no point in the future will, say, a msync() fail because a mmap(MAP_SHARED) page has been written to.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [RFC] Heads up on sys_fallocate()
Hi,
Quoted 6 lines · Ulrich Drepper
Quoted 2 lines · Anton Altaparmakov
And that is it. No zeroing needs to happen at all because we have not updated the initialized size of the inode!
When you do it like this, who can the kernel/filesystem *guarantee* that when the data is written there actually is room on the harddrive?
The blocks are allocated so of course it is guaranteed. Subsequent writes to this file will not generate any allocations thus allocations cannot fail. (-:
Quoted 6 lines
What you described seems like using truncate/ftruncate to increase the file's size. That is not at all what
posix_fallocateis for.posix_fallocatemust make sure that the requested blocks on the disk are reserved (allocated) for the file's use and that at no point in the future will, say, amsync()fail because ammap(MAP_SHARED)page has been written to.
No that is different. I described performing the allocations in the volume bitmap, i.e. for each allocated block the corresponding "in use" bit is set in the bitmap (NTFS uses a linear bitmap where byte 0, bit 0 == physical block 0 of volume, byte 0, bit 1 == physical block 1 of volume, ... byte 1, bit 0 == block 8 of volume, ...).
Also I described updating the extent map of the inode such that it describes the physical blocks as belonging to the file, thus you would have "logical file block X corresponds to physical block Y on volume" entries entered into the extent map of the inode and they would describe the just allocated blocks.
Finally I described updating the allocated size in the inode which basically says "there are that many bytes worth of blocks allocated to this inode".
And optionally I described updating the data size in the inode which basically says "this file has size Z bytes".
And I specifically did NOT update the initialized size in the inode thus it will remain at its old value thus all new allocated blocks will be considered as present but not initialized thus a read will always return zero whilst a write will do the right thing and pad with zeroes as necessary (if the write is smaller than the block size, etc).
Note that you are right that this is like truncate in NTFS for non-sparse enabled inodes/volumes.
But for sparse ones, instead of doing any allocations in the bitmap and entering them in the extent map, you would simply add a single entry to the extent map that says "X blocks allocated starting at logical block Y corresponding to no physical blocks, i.e. they are sparse". You would then also update the allocated size and data size as above and now you can even (but do not have to) update the initialized size to be equal to the data size as the file can be considered fully initialized because it is sparse. As an implementation detail this truncate operation would not modify the compressed size of the inode (i.e. the really used on-disk space, i.e. what you get from running "du" as that does not change when you add sparse blocks) whilst the fallocate described above would update the compressed size (if the file is sparse or compressed - there is no compressed size in the inode if the inode is not sparse/compressed) because the file now occupies more blocks on disk even if they are actually not initialized.
Best regards,
Anton
Signature · 3 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer, http://www.linux-ntfs.org/
Re: [RFC] Heads up on sys_fallocate()
In reply to Ulrich DrepperQuoted 10 lines · Ulrich Drepper
When you do it like this, who can the kernel/filesystem *guarantee* that when the data is written there actually is room on the harddrive?
What you described seems like using truncate/ftruncate to increase the file's size. That is not at all what
posix_fallocateis for.posix_fallocatemust make sure that the requested blocks on the disk are reserved (allocated) for the file's use and that at no point in the future will, say, amsync()fail because ammap(MAP_SHARED)page has been written to.
That actually causes an interesting problem for compressing filesystems. The space consumed by blocks depends on their contents and how well it compresses. At the moment, the only option I see to support posix_fallocate for LogFS is to set an inode flag disabling compression, then allocate the blocks.
But if the file already contains large amounts of compressed data, I have a problem. Disabling compression for a range within a file is not supported, so I can only return an error. But which one?
Jörn
Signature · 6 lines
A surrounded army must be given a way out. -- Sun Tzu - To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC] Heads up on sys_fallocate()
Quoted 23 lines · Jörn Engel
Quoted 5 lines · Ulrich Drepper
When you do it like this, who can the kernel/filesystem *guarantee* that
when the data is written there actually is room on the harddrive?Quoted 8 lines
What you described seems like using truncate/ftruncate to increase the
file's size. That is not at all whatposix_fallocateis for.posix_fallocatemust make sure that the requested blocks on the disk are
reserved (allocated) for the file's use and that at no point in the future will, say, amsync()fail because ammap(MAP_SHARED)page has been written to.That actually causes an interesting problem for compressing filesystems.
The space consumed by blocks depends on their contents and how well it compresses. At the moment, the only option I see to supportposix_fallocatefor LogFS is to set an inode flag disabling compression,
then allocate the blocks.
Quoted 4 lines
But if the file already contains large amounts of compressed data, I have a problem. Disabling compression for a range within a file is not
supported, so I can only return an error. But which one?
I don't know how your compression algorithm works but at least on NTFS that bit is easy: you allocate the blocks and mark them as allocated then the compression engine will write non-compressed data to those blocks. Basically it works like this "does compression block X have any sparse blocks?". If the answer is "yes" the block is treated as compressed data and if the answer is "no" the block is treated as uncompressed data. This means that if the data cannot be compressed (and in some cases if the data compressed is bigger than the data uncompressed) the data is stored non-compressed. That is the most space efficient method to do things.
An alternative would be to allocate blocks and then when the data is written perform the compression and free any blocks you do not need any more because the data has shrunk sufficiently. Depending on the implementation details this could potentially create horrible fragmentation as you would allocate a large consecutive region and then go and drop random blocks from that region thus making the file fragmented.
Best regards,
Anton
Signature · 3 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer, http://www.linux-ntfs.org/
Re: [RFC] Heads up on sys_fallocate()
Quoted 41 lines · Anton Altaparmakov
Quoted 24 lines · Jörn Engel
Quoted 5 lines · Ulrich Drepper
When you do it like this, who can the kernel/filesystem *guarantee* that
when the data is written there actually is room on the harddrive?Quoted 8 lines
What you described seems like using truncate/ftruncate to increase the
file's size. That is not at all whatposix_fallocateis for.posix_fallocatemust make sure that the requested blocks on the disk are
reserved (allocated) for the file's use and that at no point in the future will, say, amsync()fail because ammap(MAP_SHARED)page has been written to.That actually causes an interesting problem for compressing filesystems.
The space consumed by blocks depends on their contents and how well it
compresses. At the moment, the only option I see to supportposix_fallocatefor LogFS is to set an inode flag disabling compression,
then allocate the blocks.Quoted 4 lines
But if the file already contains large amounts of compressed data, I have a problem. Disabling compression for a range within a file is not
supported, so I can only return an error. But which one?I don't know how your compression algorithm works but at least on NTFS that bit is easy: you allocate the blocks and mark them as allocated then the compression engine will write non-compressed data to those blocks. Basically it works like this "does compression block X have any sparse blocks?". If the answer is "yes" the block is treated as compressed data and if the answer is "no" the block is treated as uncompressed data. This means that if the data cannot be compressed (and in some cases if the data compressed is bigger than the data uncompressed) the data is stored non-compressed. That is the most space efficient method to do things.
Quoted 7 lines
An alternative would be to allocate blocks and then when the data is written perform the compression and free any blocks you do not need any more because the data has shrunk sufficiently. Depending on the implementation details this could potentially create horrible fragmentation as you would allocate a large consecutive region and then go and drop random blocks from that region thus making the file fragmented.
And another thing you could do (best if you support journalling) would be to do the allocation and hang the details off the inode on a "preallocation list" of some kind and then as the data gets written use blocks from the preallocation list as you go along. This would avoid the fragmentation issue for example. You could then free the surplus blocks when the whole range of the file being covered by the preallocation list has been written to and/or when the file is closed for the last time (drop_inode/delete_inode).
Best regards,
Anton
Signature · 3 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer, http://www.linux-ntfs.org/
Re: [RFC] Heads up on sys_fallocate()
In reply to Jörn EngelQuoted 9 lines · Jörn Engel
That actually causes an interesting problem for compressing filesystems. The space consumed by blocks depends on their contents and how well it compresses. At the moment, the only option I see to support
posix_fallocatefor LogFS is to set an inode flag disabling compression, then allocate the blocks.But if the file already contains large amounts of compressed data, I have a problem. Disabling compression for a range within a file is not supported, so I can only return an error. But which one?
Using the current glibc implementation on a compressed file system ideally should be a very expensive no-op because you won't actually allocate much space for a file when writing zeroes to it. You also don't benefit of a contiguous allocation in logfs, since flash has uniform seek times over all the medium.
I'd suggest you implement posix_fallocate as an real nop and just return success without doing anything. You could also return ENOSPC in case the blocks requested by posix_fallocate don't fit on the medium without compression, but that is more or less just guesswork (like statfs is).
Arnd <><
Re: [RFC] Heads up on sys_fallocate()
In reply to Anton AltaparmakovQuoted 7 lines · Anton Altaparmakov
An alternative would be to allocate blocks and then when the data is written perform the compression and free any blocks you do not need any more because the data has shrunk sufficiently. Depending on the implementation details this could potentially create horrible fragmentation as you would allocate a large consecutive region and then go and drop random blocks from that region thus making the file fragmented.
Unfortunately, this is not as easy on logfs, because there is no point in allocating a block when there is no data to write into it. Fragmentation on flash media is free, but you can never modify a block in place without erasing it first. This means it will always be written to a new location on the next write access.
One option that might work (similar to what you describe in your other mail) is to have a per-inode count of reserved blocks, without allocating specific blocks for them. The journal then needs to maintain the number of total reserved blocks for all files and keep that in sync with blocks that were reserved for specific inodes.
Arnd <><
Re: [RFC] Heads up on sys_fallocate()
In reply to Anton AltaparmakovQuoted 3 lines · Anton Altaparmakov
glibc cannot ever be smart enough because a file system driver will always know better and be able to do things in a much more optimized way.
Please read the thread again. That is not what anyone proposed. The issues we're discussing is whether fallback for a filesystem that does not support preallocation natively should be done in kernelspace or in userspace.
Re: [RFC] Heads up on sys_fallocate()
In reply to Arnd BergmannQuoted 11 lines · Arnd Bergmann
Using the current glibc implementation on a compressed file system ideally should be a very expensive no-op because you won't actually allocate much space for a file when writing zeroes to it. You also don't benefit of a contiguous allocation in logfs, since flash has uniform seek times over all the medium.
I'd suggest you implement
posix_fallocateas an real nop and just return success without doing anything. You could also return ENOSPC in case the blocks requested byposix_fallocatedon't fit on the medium without compression, but that is more or less just guesswork (like statfs is).
Quoting POSIX_FALLOCATE(3):
The function posix_fallocate() ensures that disk space is allocated for the file referred to by the descriptor fd for the bytes in the range starting at offset and continuing for len bytes. After a successful call to posix_fallocate(), subsequent writes to bytes in the specified range are guaranteed not to fail because of lack of disk space.
If the size of the file is less than offset+len, then the file is increased to this size; otherwise the file size is left unchanged.
Afaics, the (main) purpose of this function is not to decrease fragmentation but to ensure mmap() won't cause any problems because the medium fills up. That problem exists for LogFS as well, once rw mmap() is supported.
Simply returning success without doing anything would be a bug. -ENOSPC is a better choice, but still a lame implementation. And falling back on libc to write zeroes in a loop is an exercise in futility.
Does the allocation have to be persistent beyond lifetime of the file descriptor? It would be fairly simple to support the write guarantee while the file is open (or rather the inode remains cached) and drop it afterwards.
Jörn
Signature · 3 lines
"[One] doesn't need to know [...] how to cause a headache in order to take an aspirin." -- Scott Culp, Manager of the Microsoft Security Response Center, 2001
Re: [RFC] Heads up on sys_fallocate()
In reply to Anton AltaparmakovQuoted 2 lines · Anton Altaparmakov
I don't know how your compression algorithm works [...]
LogFS is designed for flash media, so it does not have to worry much about reducing disk seeks. It is log-structured, which simplifies compression further.
When writing a block, it basically compresses it and appends it to the log. Writes only have to be byte-aligned, so no space is lost for padding.
The bad news for posix_fallocate() is that even if libc is smart enough to write random data, mmap() can still cause problems. If the VM decides to write a given page twice, the second write compresses better and the medium has filled up between the two writes, the users will have fun.
Jörn
Signature · 6 lines
Joern's library part 9: http://www.scl.ameslab.gov/Publications/Gus/TwelveWays.html - To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Jan Kara
reviewerRe: [RFC] Heads up on sys_fallocate()
In reply to Mingming CaoQuoted 36 lines
Quoted 36 lines
Quoted 13 lines · On Fri, 02 Mar 2007 09:40:54 +1100 Nathan Scott <[email protected]> wrote:
Quoted 11 lines · Andrew Morton
Quoted 6 lines · On Fri, 2 Mar 2007 00:04:45 +0530 "Amit K. Arora" <[email protected]>…
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);Quoted 8 lines
Quoted 3 lines
...
I'd agree with Eric on the "command" flag extension.
Seems like a separate syscall would be better, "command" sounds a bit ioctl like, especially if that command is passed into the filesystems..
madvise, fadvise, lseek, etc seem to work OK.
I get repeatedly traumatised by patch rejects whenever a new syscall gets added, so I'm biased.
The advantage of a command flag is that we can add new modes in the future without causing lots of churn, waiting for arch maintainers to catch up, potentially adding new compat code, etc.
Quoted 7 lines
Quoted 2 lines
Rename it to "mode"? ;)
I am wondering if it is useful to add another mode to advise block allocation policy? Something like indicating which physical block/block group to allocate from (goal), and whether ask for strict contigous blocks. This will help preallocation or reservation to choose the right blocks for the file.
Yes, I also think this would be useful so you can "guide"
preallocation for things like defragmentation (e.g. preallocate space for the file being defragmented and move the file to it).
Honza
Signature · 2 lines
Jan Kara <[email protected]> SuSE CR Labs
Re: [RFC] Heads up on sys_fallocate()
In reply to Arnd BergmannQuoted 6 lines · Arnd Bergmann
Quoted 2 lines
I'd be more happy to have the write out zeroes loop in glibc. ?And glibc needs to have it anyway, for older kernels.
A
generic_fallocatemakes sense to me iff we can do it in the kernel more significantly more efficiently than in glibc, e.g. by using only a single page in page cache instead of one for each page to be preallocated.
We can't do that with the current page cache interfaces. But what might make sense is to have a block_dump_prealloc that takes a get_block callback to do what you propose. It still wouldn't be entirely generic, but would allow block based filesystems to do a not entirely dumb implementation.
Theodore Tso
maintainerRe: [RFC] Heads up on sys_fallocate()
In reply to Anton AltaparmakovQuoted 6 lines · Anton Altaparmakov
And I specifically did NOT update the initialized size in the inode thus it will remain at its old value thus all new allocated blocks will be considered as present but not initialized thus a read will always return zero whilst a write will do the right thing and pad with zeroes as necessary (if the write is smaller than the block size, etc).
Anton,
You're describing a method of doing in-advance preallocation
where the filesystem format explicitly has support for this kind of feature in a way that doesn't require pre-zeroing the data blocks in question.
The question which this subthread was concerned about was
whether the kernel should get involved in initializing datablocks in the case where the filesystem format does not have this support, or whether this functionality should continue to be done in userspace. Given that glibc already has to support this for older kernels, I would argue that there's no point putting in generic support for filesystem that can't support a more advanced way of doing things.
Regards,
- Ted
Re: [RFC] Heads up on sys_fallocate()
Quoted 8 lines · Theodore Tso
Quoted 6 lines · Anton Altaparmakov
And I specifically did NOT update the initialized size in the inode thus it will remain at its old value thus all new allocated blocks will be considered as present but not initialized thus a read will always return zero whilst a write will do the right thing and pad with zeroes as necessary (if the write is smaller than the block size, etc).
Quoted 4 lines
You're describing a method of doing in-advance preallocation
where the filesystem format explicitly has support for this kind of feature in a way that doesn't require pre-zeroing the data blocks in question.
Indeed.
Quoted 7 lines
The question which this subthread was concerned about was
whether the kernel should get involved in initializing datablocks in the case where the filesystem format does not have this support, or whether this functionality should continue to be done in userspace. Given that glibc already has to support this for older kernels, I would argue that there's no point putting in generic support for filesystem that can't support a more advanced way of doing things.
Yes, I understood that after I had sent my post... And yes, I would agree. If glibc already does this there does not appear to be any value in just moving existing functionality into the kernel. Simply let "dumb" file systems return ENOSYS and let glibc do it... And any FS which can do it better can implement the function and then glibc should not go anywhere near it.
Best regards,
Anton
Signature · 3 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer, http://www.linux-ntfs.org/
Re: [RFC] Heads up on sys_fallocate()
In reply to Jörn EngelQuoted 2 lines · Jörn Engel
Does the allocation have to be persistent beyond lifetime of the file descriptor?
Of course. You call posix_fallocate once for the lifetime of the file when it is created to ensure that all future uses will work.
It seems your filesystem will not be able to support this unless compression is turned off.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [RFC] Heads up on sys_fallocate()
In reply to Jörn EngelQuoted 2 lines · Jörn Engel
The bad news for
posix_fallocate()is that even if libc is smart enough to write random data,mmap()can still cause problems.
This is not smart, quite to the contrary. The standard guarantees that all not-yet-written-to places in the file are zero. And if a block has already been written posix_fallocate cannot change it.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [RFC] Heads up on sys_fallocate()
In reply to Theodore TsoQuoted 3 lines · Theodore Tso
Given that glibc already has to support this for older kernels, I would argue that there's no point putting in generic support for filesystem that can't support a more advanced way of doing things.
Well, I'm sure the kernel can do better than the code we have in libc now. The kernel has access to the bitmasks which say which blocks have already been allocated. The libc code does not and we have to be very simple-minded and simply touch every block. And this means reading it and then writing it back. The kernel would know when the reading part is not necessary. Add to then the block granularity (we use f_bsize as returned from fstatfs but that's not the best value in some cases) and you have compelling data to have generic code in the kernel. Then libc implementation can then go away completely which is a good thing.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [RFC] Heads up on sys_fallocate()
In reply to Ulrich DrepperQuoted 6 lines · Ulrich Drepper
Quoted 2 lines · Jörn Engel
Does the allocation have to be persistent beyond lifetime of the file descriptor?
Of course. You call
posix_fallocateonce for the lifetime of the file when it is created to ensure that all future uses will work.
That part is not quite clear from the manpage but I trust most people would assume the same.
Quoted 2 lines
It seems your filesystem will not be able to support this unless compression is turned off.
Correct. Compression needs to be turned off for a file, if posix_fallocate(3) is to succeed. What I could do is disable compression (meaning that no data written in the future will be compressed) and rewrite all blocks within the given range.
Still, it is quite obvious that noone designing this interface has lost much thought to compressing filesystems. Whatever I can come up with will either be incompatible or some sort of hack. :(
Jörn
Signature · 7 lines
Courage is not the absence of fear, but rather the judgement that something else is more important than fear. -- Ambrose Redmoon - To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC] Heads up on sys_fallocate()
In reply to Ulrich DrepperQuoted 8 lines · Ulrich Drepper
Quoted 3 lines · Theodore Tso
Given that glibc already has to support this for older kernels, I would argue that there's no point putting in generic support for filesystem that can't support a more advanced way of doing things.
Well, I'm sure the kernel can do better than the code we have in libc now. The kernel has access to the bitmasks which say which blocks have already been allocated.
The layer of the kernel where a totally generic fallback would be implemented does not have access to this information. We could do a mostly generic helper for block filesystems that allows to implement fallocate this way without a lot of their own code.
Re: [RFC] Heads up on sys_fallocate()
In reply to Jörn EngelQuoted 5 lines · Jörn Engel
Quoted 2 lines
Of course. You call
posix_fallocateonce for the lifetime of the file when it is created to ensure that all future uses will work.That part is not quite clear from the manpage but I trust most people would assume the same.
Not only that, it is what this function is for. In the POSIX committee we've looked at the functions in detail before adding them, even if some information is not in the man page but instead in the Rationale.
Quoted 2 lines
Still, it is quite obvious that noone designing this interface has lost much thought to compressing filesystems.
You already have problems with supporting the functionality posix_fallocate is supporting. You cannot reliably support MAP_SHARED files if all of a sudden the compression causes and expansion of a block and that causes a ENOSPC error. So, don't expect pity. This is a function in support of a real and reliable implementation of memory mapped files. You don't use MAP_SHARED on such filesystems, it'll eat your kittens sooner or later anyway.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Theodore Tso
maintainerRe: [RFC] Heads up on sys_fallocate()
In reply to Ulrich DrepperQuoted 9 lines · Ulrich Drepper
Well, I'm sure the kernel can do better than the code we have in libc now. The kernel has access to the bitmasks which say which blocks have already been allocated. The libc code does not and we have to be very simple-minded and simply touch every block. And this means reading it and then writing it back. The kernel would know when the reading part is not necessary. Add to then the block granularity (we use
f_bsizeas returned from fstatfs but that's not the best value in some cases) and you have compelling data to have generic code in the kernel. Then libc implementation can then go away completely which is a good thing.
You have a very good point; indeed since we don't export an interface which allows userspace to determine whether or not a block is in use, that does mean a huge amount of churn in the page cache. So maybe it would be worth doing in the kernel as a result, although the libc implementation still wouldn't be able to go away for long time due to the need to be backwards compatible with older kernels that didn't have this support.
Regards,
- Ted
Re: [RFC] Heads up on sys_fallocate()
Quoted 4 lines · Theodore Tso
[...] although the libc
implementation still wouldn't be able to go away for long time due to the need to be backwards compatible with older kernels that didn't have this support.
It's better than that. If somebody compiles glibc to not run on older kernels at all (tested at runtime) then the code is dropped. E.g., the current Fedora glibc does not support 2.6.8 or earlier.
So, don't let the compat code be a factor in the decision making.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [RFC] Heads up on sys_fallocate()
In reply to Jan KaraQuoted 42 lines · Jan Kara
Quoted 42 lines
Quoted 41 lines
Quoted 15 lines · On Fri, 02 Mar 2007 09:40:54 +1100 Nathan Scott <[email protected]> wrote:
Quoted 12 lines · Andrew Morton
Quoted 6 lines · On Fri, 2 Mar 2007 00:04:45 +0530 "Amit K. Arora" <[email protected]>…
This is to give a heads up on few patches that we will be soon coming up with. These patches implement a new system call
sys_fallocate()and a new inode operation "fallocate", for persistent preallocation. The new system call, as Andrew suggested, will look like:asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len);Quoted 8 lines
Quoted 3 lines
...
I'd agree with Eric on the "command" flag extension.
Seems like a separate syscall would be better, "command" sounds a bit ioctl like, especially if that command is passed into the filesystems..
madvise, fadvise, lseek, etc seem to work OK.
I get repeatedly traumatised by patch rejects whenever a new syscall gets added, so I'm biased.
The advantage of a command flag is that we can add new modes in the future without causing lots of churn, waiting for arch maintainers to catch up, potentially adding new compat code, etc.
Rename it to "mode"? ;)
Quoted 7 lines
Quoted 1 line
I am wondering if it is useful to add another mode to advise block allocation policy? Something like indicating which physical block/block group to allocate from (goal), and whether ask for strict contigous blocks. This will help preallocation or reservation to choose the right blocks for the file.
Yes, I also think this would be useful so you can "guide"
preallocation for things like defragmentation (e.g. preallocate space for the file being defragmented and move the file to it).Honza
Yep, I think it makes sense to use preallocation for defragmentation.
After all both preallocation and defragmentation shall call underlying filesystem multiple block allocator to try to allocate a chunk of contiguous blocks on disk. ext4 online defrag implementation by Takashi already support to choose a "goal" allocation block to guide the ext4 block allocator to place the defraged file is a specific location.
Passing a little bit more hint to sys_fallocate() (i.e, goal block, and/or whether the goal block is important over the size of prealloc extent), might make it more useful for the orginial goal (get contigous and guranteed blocks) and for defragmentation.
Regards,
Mingming
Re: [RFC] Heads up on sys_fallocate()
In reply to Jan KaraQuoted 8 lines · Jan Kara
Quoted 5 lines
I am wondering if it is useful to add another mode to advise block allocation policy? Something like indicating which physical block/block group to allocate from (goal), and whether ask for strict contigous blocks. This will help preallocation or reservation to choose the right blocks for the file.
Yes, I also think this would be useful so you can "guide"
preallocation for things like defragmentation (e.g. preallocate space for the file being defragmented and move the file to it).
Hints & policies for allocation would certainly be useful, but I think they belong outside this interface. i.e. you could flag an inode for whatever allocation you choose, and -then- call posix_fallocate so that the allocator will take the hints you've given it.
See also this blurb from the posix_fallocate definition:
"It is implementation-defined whether a previous posix_fadvise() call influences allocation strategy."
FWIW I don't see a lot of point in asking for "strict contiguous blocks"
- the allocator will presumeably try to do this in any case, and I'm not sure when you would want to fail if you get more than one extent...?
-Eric
Re: [RFC] Heads up on sys_fallocate()
In reply to Jörn EngelQuoted 4 lines · Jörn Engel
Does the allocation have to be persistent beyond lifetime of the file descriptor? It would be fairly simple to support the write guarantee while the file is open (or rather the inode remains cached) and drop it afterwards.
"The posix_fallocate() function shall ensure that any required storage for regular file data starting at offset and continuing for len bytes is allocated on the file system storage media."
I interpret "on the storage media" to mean that it is persistent.
-Eric
Re: [RFC] Heads up on sys_fallocate()
In reply to Mingming CaoQuoted 11 lines · Mingming Cao
Yep, I think it makes sense to use preallocation for defragmentation. After all both preallocation and defragmentation shall call underlying filesystem multiple block allocator to try to allocate a chunk of contiguous blocks on disk. ext4 online defrag implementation by Takashi already support to choose a "goal" allocation block to guide the ext4 block allocator to place the defraged file is a specific location.
Passing a little bit more hint to
sys_fallocate()(i.e, goal block, and/or whether the goal block is important over the size of prealloc extent), might make it more useful for the orginial goal (get contigous and guranteed blocks) and for defragmentation.
fallocate with the whence argument and flags is already quite complicated, I'd rather have another call for placement decisions, that would be called on an fd to do placement decissions for any further allocations (prealloc, write, etc)
Re: [RFC] Heads up on sys_fallocate()
Quoted 4 lines · Christoph Hellwig
fallocate with the whence argument and flags is already quite complicated, I'd rather have another call for placement decisions, that would be called on an fd to do placement decissions for any further allocations (prealloc, write, etc)
Yes, posix_fallocate shouldn't be made more complicated. But I don't understand why requesting linear layout of the blocks should be an option. It's always an advantage if the blocks requested this way are linear on disk. So, the kernel should always do its best to make this happen, without needing an additional option.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Jan Kara
reviewerRe: [RFC] Heads up on sys_fallocate()
Quoted 11 lines · Ulrich Drepper
Quoted 4 lines · Christoph Hellwig
fallocate with the whence argument and flags is already quite complicated, I'd rather have another call for placement decisions, that would be called on an fd to do placement decissions for any further allocations (prealloc, write, etc)
Yes,
posix_fallocateshouldn't be made more complicated. But I don't understand why requesting linear layout of the blocks should be an option. It's always an advantage if the blocks requested this way are linear on disk. So, the kernel should always do its best to make this happen, without needing an additional option.
Actually, it's not that simple. You want linear layout of blocks you are
going to read. That is not necessary a linear layout of blocks in a single file - trace sometime a start of some complicated app like KDE. You find it's seeking like a hell because it needs a few blocks from a ton of distinct files (shared libs, config files, etc). As these files are mostly read only, it's advantageous to interleave them on disk or at least keep them close.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SuSE CR Labs
Re: [RFC] Heads up on sys_fallocate()
In reply to Ulrich DrepperQuoted 11 lines · Ulrich Drepper
Quoted 4 lines · Christoph Hellwig
fallocate with the whence argument and flags is already quite complicated, I'd rather have another call for placement decisions, that would be called on an fd to do placement decissions for any further allocations (prealloc, write, etc)
Yes,
posix_fallocateshouldn't be made more complicated. But I don't understand why requesting linear layout of the blocks should be an option. It's always an advantage if the blocks requested this way are linear on disk. So, the kernel should always do its best to make this happen, without needing an additional option.
There are HPC workloads where you have multi writers on multiple machines that write to different parts of a file. You preferably want each of those regions in separate allocation groups. (Or tell the customers to use separate files for the regions..)
Re: [RFC] Heads up on sys_fallocate()
In reply to Ulrich DrepperQuoted 6 lines · Ulrich Drepper
Quoted 4 lines · Christoph Hellwig
fallocate with the whence argument and flags is already quite complicated, I'd rather have another call for placement decisions, that would be called on an fd to do placement decissions for any further allocations (prealloc, write, etc)
Quoted 6 lines
Yes,
posix_fallocateshouldn't be made more complicated. But I don't understand why requesting linear layout of the blocks should be an option. It's always an advantage if the blocks requested this way are linear on disk. So, the kernel should always do its best to make this happen, without needing an additional option.
Agreed on both points. The hints would be for things like start block, or speculative EOF preallocation, not contiguity, which I think should always be the goal.
-Eric
Re: [RFC] Heads up on sys_fallocate()
In reply to Jan KaraQuoted 11 lines · Jan Kara
Quoted 10 lines · Ulrich Drepper
Quoted 4 lines · Christoph Hellwig
fallocate with the whence argument and flags is already quite complicated, I'd rather have another call for placement decisions, that would be called on an fd to do placement decissions for any further allocations (prealloc, write, etc)
Yes,
posix_fallocateshouldn't be made more complicated. But I don't understand why requesting linear layout of the blocks should be an option. It's always an advantage if the blocks requested this way are linear on disk. So, the kernel should always do its best to make this happen, without needing an additional option.
Quoted 7 lines
Actually, it's not that simple. You want linear layout of blocks you are
going to read. That is not necessary a linear layout of blocks in a single file - trace sometime a start of some complicated app like KDE. You find it's seeking like a hell because it needs a few blocks from a ton of distinct files (shared libs, config files, etc). As these files are mostly read only, it's advantageous to interleave them on disk or at least keep them close.
At some point shouldn't the apps be fixed, rather than do crazy things with the filesystem? :)
-Eric
Jan Kara
reviewerRe: [RFC] Heads up on sys_fallocate()
Quoted 20 lines · Eric Sandeen
Quoted 11 lines · Jan Kara
Quoted 10 lines · Ulrich Drepper
Quoted 4 lines · Christoph Hellwig
fallocate with the whence argument and flags is already quite complicated, I'd rather have another call for placement decisions, that would be called on an fd to do placement decissions for any further allocations (prealloc, write, etc)
Yes,
posix_fallocateshouldn't be made more complicated. But I don't understand why requesting linear layout of the blocks should be an option. It's always an advantage if the blocks requested this way are linear on disk. So, the kernel should always do its best to make this happen, without needing an additional option.Quoted 7 lines
Actually, it's not that simple. You want linear layout of blocks you are
going to read. That is not necessary a linear layout of blocks in a single file - trace sometime a start of some complicated app like KDE. You find it's seeking like a hell because it needs a few blocks from a ton of distinct files (shared libs, config files, etc). As these files are mostly read only, it's advantageous to interleave them on disk or at least keep them close.
Quoted 2 lines
At some point shouldn't the apps be fixed, rather than do crazy things with the filesystem? :)
Yes :) That's basically what we told KDE developpers when they were
complaining ;) But it's hard to fix it for them too (because of some desktop specs requiring lots of different text config files which can change anytime - don't ask me who designed it). Moreover for example for loading shared libraries from which you need just a few blocks scattered all over the place the problem is in ELF itself.
I'll probably first write some userspace fs-reorganizer to find out how
much these changes in layout are able to give you in performance (i.e. whether it's worth the effort of more complicated kernel online defragmenter).
Honza
Signature · 2 lines
Jan Kara <[email protected]> SuSE CR Labs
Re: [RFC] Heads up on sys_fallocate()
Quoted 5 lines · Jan Kara
I'll probably first write some userspace fs-reorganizer to find out how
much these changes in layout are able to give you in performance (i.e. whether it's worth the effort of more complicated kernel online defragmenter).
Have tried profiling the read accesses and prereading them asynchronously on startup? That appears to have improved E17 a lot. See http://lca2007.linux.org.au/talk/101 (and watch the video).
Jörn
Signature · 4 lines
The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague. -- Edsger W. Dijkstra
Re: [RFC] Heads up on sys_fallocate()
In reply to Eric SandeenQuoted 14 lines · Eric Sandeen
Quoted 6 lines · Ulrich Drepper
Quoted 4 lines · Christoph Hellwig
fallocate with the whence argument and flags is already quite complicated, I'd rather have another call for placement decisions, that would be called on an fd to do placement decissions for any further allocations (prealloc, write, etc)
Quoted 6 lines
Yes,
posix_fallocateshouldn't be made more complicated. But I don't understand why requesting linear layout of the blocks should be an option. It's always an advantage if the blocks requested this way are linear on disk. So, the kernel should always do its best to make this happen, without needing an additional option.
Quoted 3 lines
Agreed on both points. The hints would be for things like start block, or speculative EOF preallocation, not contiguity, which I think should always be the goal.
ISTR having had this discussion before ;)
About guided preallocation for defrag:
http://marc.info/?t=116247859500001&r=1&w=2
e.g.: The sorts of policies we need for effective use of preallocation:
http://marc.info/?l=linux-fsdevel&m=116184475308164&w=2
http://marc.info/?l=linux-fsdevel&m=116278169519095&w=2
Cheers,
Dave.
Signature · 3 lines
Dave Chinner Principal Engineer SGI Australian Software Group
RFC PATCH 1/1 sys_fallocate() system call
In reply to Amit K. AroraFirst of all, thanks for the overwhelming response!
Based on the suggestions received, I have added a new parameter to the sys_fallocate() system call - an interger called "mode", just after the "fd". Now the system call looks like this:
asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len)
Currently we have two modes FA_ALLOCATE and FA_DEALLOCATE, for preallocation and deallocation of preallocated blocks respectively. More modes can be added, when required. And these modes can be renamed, since I am sure these are no way the best ones ! :)
Attached below is the patch which implements this system call. It has been currently implemented and tested on i386, ppc64 and x86_64 architectures. I am facing some problems while trying to implement this on s390, and thus the delay. While I try to get it right on s390(x), we thought of posting this patch, so that we can save some time. Parallely we will work on getting the patch work on s390, and probably it will come as a separate patch.
ToDos:
=====
Following is pending:
1> Implementation on other architectures (other than i386, x86_64 and
ppc64) like s390(x)
2> A generic file system operation to handle fallocate
(generic_fallocate), for filesystems that do _not_ have the fallocate inode operation implemented.
3> ext4 patches that support fallocate inode operation are ready. I
plan to submit those separately to just ext4 mailing list.
4> Changes to glibc, so that posix_fallocate() and posix_fallocate64()
call fallocate() system call
5> Changes to XFS to implement the fallocate inode operation
--- arch/i386/kernel/syscall_table.S | 1 arch/x86_64/kernel/functionlist | 1 fs/open.c | 41 +++++++++++++++++++++++++++++++++++++++ include/asm-i386/unistd.h | 3 +- include/asm-powerpc/systbl.h | 1 include/asm-powerpc/unistd.h | 3 +- include/asm-x86_64/unistd.h | 4 ++- include/linux/fs.h | 7 ++++++ include/linux/syscalls.h | 1 9 files changed, 59 insertions(+), 3 deletions(-)
arch/i386/kernel/syscall_table.S +1 -0
@@ -319,3 +319,4 @@ ENTRY(sys_call_table) .long sys_move_pages .long sys_getcpu .long sys_epoll_pwait + .long sys_fallocate /* 320 */
fs/open.c +41 -0
47 lines not on this page · raw message
include/asm-i386/unistd.h +2 -1
@@ -325,10 +325,11 @@#define __NR_move_pages 317#define __NR_getcpu 318#define __NR_epoll_pwait 319 +#define __NR_fallocate 320#ifdef __KERNEL__ -#define NR_syscalls 320 +#define NR_syscalls 321#define __ARCH_WANT_IPC_PARSE_VERSION#define __ARCH_WANT_OLD_READDIR
include/linux/fs.h +7 -0
@@ -263,6 +263,12 @@ extern int dir_notify_enable;#define SYNC_FILE_RANGE_WRITE 2#define SYNC_FILE_RANGE_WAIT_AFTER 4 +/* +* fallocate() modes +*/ +#define FA_ALLOCATE 0x1 +#define FA_DEALLOCATE 0x2 +#ifdef __KERNEL__#include <linux/linkage.h>
@@ -1124,6 +1130,7 @@ struct inode_operations {ssize_t (*listxattr) (struct dentry *,char *,size_t );int (*removexattr) (struct dentry *,const char *);void (*truncate_range)(struct inode *,loff_t ,loff_t ); +int (*fallocate)(struct inode *,int ,loff_t ,loff_t ); };struct seq_file ;
include/linux/syscalls.h +1 -0
@@ -602,6 +602,7 @@ asmlinkage long sys_get_robust_list(intasmlinkage long sys_set_robust_list (struct robust_list_head __user *head,size_t len);asmlinkage long sys_getcpu (unsigned __user *cpu,unsigned __user *node,struct getcpu_cache __user *cache); +asmlinkage long sys_fallocate (int fd,int mode,loff_t offset,loff_t len);int kernel_execve (const char *filename,char *const argv[],char *const envp[]);
include/asm-x86_64/unistd.h +3 -1
@@ -619,8 +619,10 @@ __SYSCALL(__NR_sync_file_range, sys_sync __SYSCALL(__NR_vmsplice, sys_vmsplice)#define __NR_move_pages 279 __SYSCALL(__NR_move_pages, sys_move_pages) +#define __NR_fallocate 280 +__SYSCALL(__NR_fallocate, sys_fallocate) -#define __NR_syscall_max __NR_move_pages +#define __NR_syscall_max __NR_fallocate#ifndef __NO_STUBS#define __ARCH_WANT_OLD_READDIR
include/asm-powerpc/unistd.h +2 -1
@@ -324,10 +324,11 @@#define __NR_get_robust_list 299#define __NR_set_robust_list 300#define __NR_move_pages 301 +#define __NR_fallocate 302#ifdef __KERNEL__ -#define __NR_syscalls 302 +#define __NR_syscalls 303#define __NR__exit __NR_exit#define NR_syscalls __NR_syscalls
arch/x86_64/kernel/functionlist +1 -0
@@ -932,6 +932,7 @@ *(.text.sys_getitimer) *(.text.sys_getgroups) *(.text.sys_ftruncate) +*(.text.sys_fallocate) *(.text.sysfs_lookup) *(.text.sys_exit_group) *(.text.stub_fork)
include/asm-powerpc/systbl.h +1 -0
@@ -305,3 +305,4 @@ SYSCALL_SPU(faccessat) COMPAT_SYS_SPU(get_robust_list) COMPAT_SYS_SPU(set_robust_list) COMPAT_SYS(move_pages) +SYSCALL(fallocate)
--
Regards,
Amit Arora
Re: [RFC][PATCH] sys_fallocate() system call
Quoted 13 lines · Amit K. Arora
First of all, thanks for the overwhelming response!
Based on the suggestions received, I have added a new parameter to the
sys_fallocate()system call - an interger called "mode", just after the "fd". Now the system call looks like this:asmlinkage long
sys_fallocate(int fd, int mode, loff_t offset, loff_t len)Currently we have two modes
FA_ALLOCATEandFA_DEALLOCATE, for preallocation and deallocation of preallocated blocks respectively. More modes can be added, when required. And these modes can be renamed, since I am sure these are no way the best ones ! :)
Quoted 7 lines
Attached below is the patch which implements this system call. It has been currently implemented and tested on i386, ppc64 and
x86_64architectures. I am facing some problems while trying to implement this on s390, and thus the delay. While I try to get it right on s390(x), we thought of posting this patch, so that we can save some time. Parallely we will work on getting the patch work on s390, and probably it will come as a separate patch.
What's the problem you face on s390? If it's just the compat wrapper, you may look at sys_sync_file_range_wrapper. Or I will send a patch if needed.
Re: [RFC][PATCH] sys_fallocate() system call
In reply to Amit K. Arorafs/open.c asmlinkage long sys_ftruncate64(unsigned · line 354
Quoted 7 lines
on s390, and thus the delay. While I try to get it right on s390(x), we thought of posting this patch, so that we can save some time. Parallely we will work on getting the patch work on s390, and probably it will come as a separate patch.
fs/open.c +2
-0+asmlinkage long sys_fallocate (int fd,int mode,loff_t offset,loff_t len) +{
There is something here that will not work on s390 (31bit): the arguments would end up in:
fd -> r2
mode -> r3
offset -> r4 + r5
len -> r6 + second halve on stack
But the s390 ABI says that a long long will be put into two consecutive registers if the first register is smaller than 6, or it will be put completely on the stack. So both 32 bit parts of len will end up on the stack. That would make it a syscall with seven arguments which we currently don't support on s390. There is no way to access the second half of len from kernel space and that is why it is not working for you.
So you either rearrange the parameters or convert the loff_t's to pointers.
e.g.
asmlinkage long sys_fallocate(int fd, loff_t offset, loff_t len, int mode)
would work even on s390 ;)
Re: [RFC][PATCH] sys_fallocate() system call
In reply to Amit K. Arorainclude/asm-powerpc/systbl.h SYSCALL_SPU(faccessat) · line 308
Quoted 11 lines · On Fri, 16 Mar 2007 20:01:01 +0530 "Amit K. Arora" <[email protected]>…
include/linux/syscalls.h +1
-0+asmlinkage long sys_fallocate (int fd,int mode,loff_t offset,loff_t len);include/asm-powerpc/systbl.h +1
-0@@ -305,3 +305,4 @@ SYSCALL_SPU(faccessat) COMPAT_SYS_SPU(get_robust_list) COMPAT_SYS_SPU(set_robust_list) COMPAT_SYS(move_pages) +SYSCALL(fallocate)
It is going to need to be a COMPAT_SYS call in powerpc because 32 bit powerpc will pass the two loff_t's in pairs of registers while 64bit passes them in one register each.
--
Cheers,
Stephen Rothwell [email protected]
http://www.canb.auug.org.au/~sfr/
Re: [RFC][PATCH] sys_fallocate() system call
In reply to Heiko CarstensQuoted 7 lines · Heiko Carstens
So you either rearrange the parameters or convert the loff_t's to pointers.
e.g.
asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len, int mode)would work even on s390 ;)
... but wouldn't work on 32-bit powerpc. :( We would end up with a pad argument between fd and offset, giving 7 arguments in all (counting the loff_t's as 2), but we only support 6.
Paul.
Re: [RFC][PATCH] sys_fallocate() system call
Quoted 3 lines · Paul Mackerras
... but wouldn't work on 32-bit powerpc. :( We would end up with a pad argument between fd and offset, giving 7 arguments in all (counting the loff_t's as 2), but we only support 6.
Ditto mips and parisc.
Re: [RFC][PATCH] sys_fallocate() system call
In reply to Heiko CarstensQuoted 7 lines · Heiko Carstens
Quoted 1 line
+asmlinkage long
sys_fallocate(int fd, int mode, loff_t offset, loff_t len)e.g.
asmlinkage long
sys_fallocate(int fd, loff_t offset, loff_t len, int mode)would work even on s390 ;)
How about:
asmlinkage long sys_fallocate(int fd, int mode, u32 off_low, u32 off_high,
u32 len_low, u32 len_high);
That way we all suffer equally ...
Re: [RFC][PATCH] sys_fallocate() system call
In reply to Matthew WilcoxQuoted 6 lines · Matthew Wilcox
Quoted 3 lines · Paul Mackerras
... but wouldn't work on 32-bit powerpc. :( We would end up with a pad argument between fd and offset, giving 7 arguments in all (counting the loff_t's as 2), but we only support 6.
Ditto mips and parisc.
Can't be. Or: mips supports 7 arguments and parisc doesn't pad. Otherwise they couldn't have wired up
sys_sync_file_range(int fd, loff_t offset, loff_t nbytes, unsigned int flags)
But from what I read, it's currently not possible for 32-bit powerpc to wire up the already present sync_file_range system call.
Re: [RFC][PATCH] sys_fallocate() system call
Quoted 5 lines · On Sat, 17 Mar 2007 15:30:43 +0100 Heiko Carstens <[email protected]>…
sys_sync_file_range(int fd, loff_t offset, loff_t nbytes, unsigned int flags)But from what I read, it's currently not possible for 32-bit powerpc to wire up the already present
sync_file_rangesystem call.
32bit native is fine (as the ABI in user mode is the same as that in the kernel). For 32bit on a 64bit kernel you need the arch specific comapt routine that I used in the patch I posteda little while ago,
--
Cheers,
Stephen Rothwell [email protected]
http://www.canb.auug.org.au/~sfr/
Re: [RFC][PATCH] sys_fallocate() system call
Quoted 9 lines · On Sun, 18 Mar 2007 01:38:38 +1100 Stephen Rothwell <[email protected]>…
Quoted 5 lines · On Sat, 17 Mar 2007 15:30:43 +0100 Heiko Carstens <[email protected]>…
sys_sync_file_range(int fd, loff_t offset, loff_t nbytes, unsigned int flags)But from what I read, it's currently not possible for 32-bit powerpc to wire up the already present
sync_file_rangesystem call.32bit native is fine (as the ABI in user mode is the same as that in the
Sorry, I take that back ...
--
Cheers,
Stephen Rothwell [email protected]
http://www.canb.auug.org.au/~sfr/
Re: [RFC][PATCH] sys_fallocate() system call
In reply to Amit K. AroraQuoted 7 lines · Amit K. Arora
Attached below is the patch which implements this system call. It has been currently implemented and tested on i386, ppc64 and
x86_64architectures. I am facing some problems while trying to implement this on s390, and thus the delay. While I try to get it right on s390(x), we thought of posting this patch, so that we can save some time. Parallely we will work on getting the patch work on s390, and probably it will come as a separate patch.
I suggest reading the very end of arch/arm/kernel/sys_arm.c; I'd rather avoid adding more and more hacks like that to the kernel if at all possible.
One solution (already mentioned elsewhere) is that we start avoiding passing 64-bit arguments and instead pass two 32-bit instead. This nicely avoids the alignment restrictions for 64-bit args in ABIs.
(The issue for ARM is that with anything other than the "fd, mode, offset, len" layout we will have to deal with different ABI argument layouts, or implement our own wrapper function as done for sys_arm_sync_file_range.)
I think the problem comes down to "what is the argument layout which causes the least amount of problems for the complete set of architectures." For ARM, that's the "fd, mode, offset, len" layout.
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of:
Re: [RFC][PATCH] sys_fallocate() system call
In reply to Heiko CarstensQuoted 22 lines · Heiko Carstens
Quoted 13 lines · Amit K. Arora
First of all, thanks for the overwhelming response!
Based on the suggestions received, I have added a new parameter to the
sys_fallocate()system call - an interger called "mode", just after the "fd". Now the system call looks like this:asmlinkage long
sys_fallocate(int fd, int mode, loff_t offset, loff_t len)Currently we have two modes
FA_ALLOCATEandFA_DEALLOCATE, for preallocation and deallocation of preallocated blocks respectively. More modes can be added, when required. And these modes can be renamed, since I am sure these are no way the best ones ! :)Quoted 7 lines
Attached below is the patch which implements this system call. It has been currently implemented and tested on i386, ppc64 and
x86_64architectures. I am facing some problems while trying to implement this on s390, and thus the delay. While I try to get it right on s390(x), we thought of posting this patch, so that we can save some time. Parallely we will work on getting the patch work on s390, and probably it will come as a separate patch.
Quoted 2 lines
What's the problem you face on s390? If it's just the compat wrapper, you may look at
sys_sync_file_range_wrapper. Or I will send a patch if needed.
Hi Heiko,
Yes, the problem was adding compat wrapper for this. I will appreciate your help in writing it. Only thing is that we might have to wait till the order of the arguments is decided upon. Thanks!
--
Regards,
Amit Arora
Re: [RFC][PATCH] sys_fallocate() system call
In reply to Stephen RothwellQuoted 5 lines · Stephen Rothwell
Quoted 4 lines · On Fri, 16 Mar 2007 20:01:01 +0530 "Amit K. Arora" <[email protected]>…
+asmlinkage long
sys_fallocate(int fd, int mode, loff_t offset, loff_t len);
Quoted 11 lines
include/asm-powerpc/systbl.h SYSCALL_SPU(faccessat) · line 308
Quoted 7 lines
include/asm-powerpc/systbl.h +1
-0@@ -305,3 +305,4 @@ SYSCALL_SPU(faccessat) COMPAT_SYS_SPU(get_robust_list) COMPAT_SYS_SPU(set_robust_list) COMPAT_SYS(move_pages) +SYSCALL(fallocate)It is going to need to be a
COMPAT_SYScall in powerpc because 32 bit powerpc will pass the two loff_t's in pairs of registers while 64bit passes them in one register each.
Ok. Will make that change, unless it is decided to pass each loff_t argument as two "u32"s. Thanks!
--
Regards,
Amit Arora
Re: [RFC][PATCH] sys_fallocate() system call
In reply to Amit K. AroraQuoted 4 lines · Amit K. Arora
Quoted 3 lines · Heiko Carstens
Quoted 2 lines · Amit K. Arora
asmlinkage long
sys_fallocate(int fd, int mode, loff_t offset, loff_t len)
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Currently we have two modes
FA_ALLOCATEandFA_DEALLOCATE, for preallocation and deallocation of preallocated blocks respectively. More modes can be added, when required. And these modes can be renamed, since I am sure these are no way the best ones ! :)Yes, the problem was adding compat wrapper for this. I will appreciate your help in writing it. Only thing is that we might have to wait till the order of the arguments is decided upon. Thanks!
There is probably not much choice. If you want to stay with the loff_t arguments it won't work on 31-bit s390 or 32-bit powerpc dependent on the order of the arguments.
So you should go for what Matthew Wilcox suggested:
asmlinkage long sys_fallocate(int fd, int mode, u32 off_low, u32 off_high,
u32 len_low, u32 len_high);
That way it will work an all architectures and in addition no architecture has to do some magic to combine the splitted 64 bit arguments in compat mode.
Re: [RFC][PATCH] sys_fallocate() system call
In reply to Matthew WilcoxQuoted 6 lines · Matthew Wilcox
How about:
asmlinkage long sys_fallocate(int fd, int mode, u32
off_low, u32off_high,u32 len_low, u32 len_high);That way we all suffer equally ...
As suggested by you and Russel, I have made this change to the patch. Here is how it looks like now. Please let me know if anyone has concerns about passing arguments this way (breaking each "loff_t" into two "u32"s).
--- arch/i386/kernel/syscall_table.S | 1 arch/x86_64/kernel/functionlist | 1 fs/open.c | 46 +++++++++++++++++++++++++++++++++++++++ include/asm-i386/unistd.h | 3 +- include/asm-powerpc/systbl.h | 1 include/asm-powerpc/unistd.h | 3 +- include/asm-x86_64/unistd.h | 4 ++- include/linux/fs.h | 7 +++++ include/linux/syscalls.h | 2 + 9 files changed, 65 insertions(+), 3 deletions(-)
arch/i386/kernel/syscall_table.S +1 -0
@@ -319,3 +319,4 @@ ENTRY(sys_call_table) .long sys_move_pages .long sys_getcpu .long sys_epoll_pwait + .long sys_fallocate /* 320 */
fs/open.c +46 -0
52 lines not on this page · raw message
include/asm-i386/unistd.h +2 -1
@@ -325,10 +325,11 @@#define __NR_move_pages 317#define __NR_getcpu 318#define __NR_epoll_pwait 319 +#define __NR_fallocate 320#ifdef __KERNEL__ -#define NR_syscalls 320 +#define NR_syscalls 321#define __ARCH_WANT_IPC_PARSE_VERSION#define __ARCH_WANT_OLD_READDIR
include/linux/fs.h +7 -0
@@ -263,6 +263,12 @@ extern int dir_notify_enable;#define SYNC_FILE_RANGE_WRITE 2#define SYNC_FILE_RANGE_WAIT_AFTER 4 +/* +* fallocate() modes +*/ +#define FA_ALLOCATE 0x1 +#define FA_DEALLOCATE 0x2 +#ifdef __KERNEL__#include <linux/linkage.h>
@@ -1124,6 +1130,7 @@ struct inode_operations {ssize_t (*listxattr) (struct dentry *,char *,size_t );int (*removexattr) (struct dentry *,const char *);void (*truncate_range)(struct inode *,loff_t ,loff_t ); +int (*fallocate)(struct inode *,int ,loff_t ,loff_t ); };struct seq_file ;
include/linux/syscalls.h +2 -0
@@ -602,6 +602,8 @@ asmlinkage long sys_get_robust_list(intasmlinkage long sys_set_robust_list (struct robust_list_head __user *head,size_t len);asmlinkage long sys_getcpu (unsigned __user *cpu,unsigned __user *node,struct getcpu_cache __user *cache); +asmlinkage long sys_fallocate (int fd,int mode,u32 off_low,u32 off_high, +u32 len_low,u32 len_high);int kernel_execve (const char *filename,char *const argv[],char *const envp[]);
include/asm-x86_64/unistd.h +3 -1
@@ -619,8 +619,10 @@ __SYSCALL(__NR_sync_file_range, sys_sync __SYSCALL(__NR_vmsplice, sys_vmsplice)#define __NR_move_pages 279 __SYSCALL(__NR_move_pages, sys_move_pages) +#define __NR_fallocate 280 +__SYSCALL(__NR_fallocate, sys_fallocate) -#define __NR_syscall_max __NR_move_pages +#define __NR_syscall_max __NR_fallocate#ifndef __NO_STUBS#define __ARCH_WANT_OLD_READDIR
include/asm-powerpc/unistd.h +2 -1
@@ -324,10 +324,11 @@#define __NR_get_robust_list 299#define __NR_set_robust_list 300#define __NR_move_pages 301 +#define __NR_fallocate 302#ifdef __KERNEL__ -#define __NR_syscalls 302 +#define __NR_syscalls 303#define __NR__exit __NR_exit#define NR_syscalls __NR_syscalls
arch/x86_64/kernel/functionlist +1 -0
@@ -932,6 +932,7 @@ *(.text.sys_getitimer) *(.text.sys_getgroups) *(.text.sys_ftruncate) +*(.text.sys_fallocate) *(.text.sysfs_lookup) *(.text.sys_exit_group) *(.text.stub_fork)
include/asm-powerpc/systbl.h +1 -0
@@ -305,3 +305,4 @@ SYSCALL_SPU(faccessat) COMPAT_SYS_SPU(get_robust_list) COMPAT_SYS_SPU(set_robust_list) COMPAT_SYS(move_pages) +SYSCALL(fallocate)
--
Regards,
Amit Arora
Re: [RFC][PATCH] sys_fallocate() system call
I hate to comment at this late stage, especially on something that I think is really a great idea (I did similar more complex, sys_blkalloc with even more arguments time ago --- I'm glad given how complex this thread has become I didn't post them now).
In the past there wasn't that much incentive to get this functionality exposed because of various other issues (mmap + page dirty didn't flush reliably) which are close to being resolve, so I think the timing of this is really great....
Quoted 4 lines · Amit K. Arora
As suggested by you and Russel, I have made this change to the patch. Here is how it looks like now. Please let me know if anyone has concerns about passing arguments this way (breaking each "
loff_t" into two "u32"s).
I really dislike breaking 64-bit args up unless it's necessary. I guess it doesn't really hurt, but it feels needlessly ugly.
include/linux/fs.h extern int dir_notify_enable; · line 271
Quoted 8 lines
include/linux/fs.h +7
-0+ .long sys_fallocate /* 320 */ +/* +* fallocate() modes +*/ +#define FA_ALLOCATE 0x1 +#define FA_DEALLOCATE 0x2 +
given there are the only TWO modes right now, why not leave the arguments as 64-bit sane and simply have two syscalls, one for each?
Interface for the new fallocate() system call
In reply to Amit K. AroraHello,
We need to come up with the best possible layout of arguments for the fallocate() system call. Various architectures have different requirements for how the arguments should look like. Since the mail chain has become huge, here is the summary of various inputs received so far.
Platform: s390
--------------
s390 prefers following layout:
int fallocate(int fd, loff_t offset, loff_t len, int mode)
For details on why and how "int, int, loff_t, loff_t" is a problem on s390, please see Heiko's mail on 16th March. Here is the link:
http://www.mail-archive.com/[email protected]/msg133595.html
Platform: ppc, arm
------------------
ppc (32 bit) has a problem with "int, loff_t, loff_t, int" layout, since this will result in a pad between fd and offset, making seven arguments total - which is not supported by ppc32. It supports only 6 arguments. Thus the desired layout by ppc32 is:
int fallocate(int fd, int mode, loff_t offset, loff_t len)
Even ARM prefers above kind of layout. For details please see the definition of sys_arm_sync_file_range().
Option of loff_t => high u32 + low u32
--------------------------------------
Matthew and Russell have suggested another option of breaking each "loff_t" into two "u32"s. This will result in 6 arguments in total.
Following think that this is a good alternative:
Matthew Wilcox, Russell King, Heiko Carstens
Following do not like this idea:
Chris Wedgwood
What are your thoughts on this ? What layout should we finalize on ? Perhaps, since sync_file_range() system call has similar arguments, we can take hint from the challenges faced on implementing it on various architectures, and decide.
Please suggest. Thanks!
--
Regards,
Amit Arora
Re: Interface for the new fallocate() system call
Quoted 1 line · Amit K. Arora
int
fallocate(int fd, loff_t offset, loff_t len, int mode)
Right now there are only two possible values for mode --- it's not clear what additional values there will be in the future.
How about two syscalls? If we decide later on we need something more complicated we can revisit this and *THEN* add another system call which may end up being a superset of the other two.
I know that sounds somewhat icky but:
* it's fairly simple
* we get nice argument handling on all arches by dropping u32 mode
(don't we?)
* syscalls don't really cost a lot to keep about, they do cost in terms on maintenance though, but in this case i don't see it being all that much of a problem
* IMO badly/over designed syscalls are going to be a bigger problem long term
Given that *NO* single fs in mainline right now can *reliably* use this functionality for a while maybe whatever solution people come up with next should sit in -mm for a while? At least that gives people exposure to it and a chance to make some changes as once it's merged to mainline it's pretty hard to change.
Re: Interface for the new fallocate() system call
In reply to Amit K. AroraHi,
Quoted 7 lines · Amit K. Arora
We need to come up with the best possible layout of arguments for the
fallocate()system call. Various architectures have different requirements for how the arguments should look like. Since the mail chain has become huge, here is the summary of various inputs received so far.
Quoted 5 lines
s390 prefers following layout:
intfallocate(int fd, loff_t offset, loff_t len, int mode)
For details on why and how "int, int,loff_t,loff_t" is a problem on s390, please see Heiko's mail on 16th March. Here is the link:
http://www.mail-archive.com/[email protected]/msg133595.html
Quoting that...
|len -> r6 + second halve on stack
Then, is not this a gcc glitch? (IMO, it should put all of "len" on the stack)
Quoted 10 lines
Platform: ppc, arm
------------------
6 arguments. Thus the desired layout by ppc32 is:
intfallocate(int fd, int mode, loff_t offset, loff_t len)Option of
loff_t=> high u32 + low u32
--------------------------------------
Matthew and Russell have suggested another option of breaking each "loff_t" into two "u32"s. This will result in 6 arguments in total.
Quoted 6 lines
What are your thoughts on this ? What layout should we finalize on ? Perhaps, since
sync_file_range()system call has similar arguments, we can take hint from the challenges faced on implementing it on various architectures, and decide.Please suggest. Thanks!
Does it actually matter? Glibc can have its own argument ordering different from the syscalls, so at least it would be possible to lay out the syscall arguments in the most portable way while retaining nice userspace C code. Hey, glibc might even wrap it up in a struct! (Using a pointer, as suggested in one of the proposals.)
int fallocate(int fd, loff_t offset, loff_t len, int mode)
{
struct fallocate_foobar d = {fd, offset, len, mode};
return _syscall(..., &d);
}Jan
Re: Interface for the new fallocate() system call
In reply to Amit K. AroraQuoted 25 lines · On Thu, 29 Mar 2007 17:21:26 +0530 "Amit K. Arora" <[email protected]>…
Hello,
We need to come up with the best possible layout of arguments for the
fallocate()system call. Various architectures have different requirements for how the arguments should look like. Since the mail chain has become huge, here is the summary of various inputs received so far.Platform: s390
--------------
s390 prefers following layout:int
fallocate(int fd, loff_t offset, loff_t len, int mode)For details on why and how "int, int,
loff_t,loff_t" is a problem on s390, please see Heiko's mail on 16th March. Here is the link:
http://www.mail-archive.com/[email protected]/msg133595.htmlPlatform: ppc, arm
------------------
ppc (32 bit) has a problem with "int,loff_t,loff_t, int" layout, since this will result in a pad between fd and offset, making seven arguments total - which is not supported by ppc32. It supports only 6 arguments. Thus the desired layout by ppc32 is:
Quoted 4 lines
int
fallocate(int fd, int mode, loff_t offset, loff_t len)Even ARM prefers above kind of layout. For details please see the definition of
sys_arm_sync_file_range().
This is a clean-looking option. Can s390 be changed to support seven-arg syscalls?
Quoted 10 lines
Option of
loff_t=> high u32 + low u32
--------------------------------------
Matthew and Russell have suggested another option of breaking each "loff_t" into two "u32"s. This will result in 6 arguments in total.Following think that this is a good alternative:
Matthew Wilcox, Russell King, Heiko CarstensFollowing do not like this idea:
Chris Wedgwood
It's a bit weird-looking, but the six-32-bit-args approach is simple enought to understand and implement. Presumably the glibc wrapper would hide that detail from everyone.
Quoted 6 lines
What are your thoughts on this ? What layout should we finalize on ? Perhaps, since
sync_file_range()system call has similar arguments, we can take hint from the challenges faced on implementing it on various architectures, and decide.
Re: Interface for the new fallocate() system call
In reply to Jan EngelhardtQuoted 45 lines · Jan Engelhardt
Hi,
Quoted 7 lines · Amit K. Arora
We need to come up with the best possible layout of arguments for the
fallocate()system call. Various architectures have different requirements for how the arguments should look like. Since the mail chain has become huge, here is the summary of various inputs received so far.Quoted 5 lines
s390 prefers following layout:
intfallocate(int fd, loff_t offset, loff_t len, int mode)
For details on why and how "int, int,loff_t,loff_t" is a problem on s390, please see Heiko's mail on 16th March. Here is the link:
http://www.mail-archive.com/[email protected]/msg133595.htmlQuoting that...
|len -> r6 + second halve on stackThen, is not this a gcc glitch? (IMO, it should put all of "len" on the stack)
Quoted 10 lines
Platform: ppc, arm
------------------
6 arguments. Thus the desired layout by ppc32 is:
intfallocate(int fd, int mode, loff_t offset, loff_t len)Option of
loff_t=> high u32 + low u32
--------------------------------------
Matthew and Russell have suggested another option of breaking each "loff_t" into two "u32"s. This will result in 6 arguments in total.Quoted 6 lines
What are your thoughts on this ? What layout should we finalize on ? Perhaps, since
sync_file_range()system call has similar arguments, we can take hint from the challenges faced on implementing it on various architectures, and decide.Please suggest. Thanks!
Does it actually matter? Glibc can have its own argument ordering different from the syscalls, so at least it would be possible to lay out the syscall arguments in the most portable way while retaining nice userspace C code. Hey, glibc might even wrap it up in a struct! (Using a pointer, as suggested in one of the proposals.)
Quoted 8 lines
int
fallocate(int fd, loff_t offset, loff_t len, int mode){ struct fallocate_foobar d = {fd, offset, len, mode}; return _syscall(..., &d); }Jan
--
I think it's always better to put only a pointer on the stack as above.
Cheers,
Dick Johnson
Penguin : Linux version 2.6.16.24 on an i686 machine (5592.62 BogoMips). New book: http://www.AbominableFirebug.com/
_
****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
Re: Interface for the new fallocate() system call
Quoted 3 lines · linux-os (Dick Johnson)
I think it's always better to put only a pointer on the stack as above.
I have to disagree, since wrapping it into a struct and copying the struct in kernelspace from userspace requires more code. Pointers only become useful at 3 (rarely) or 4 (yeah, more likely) and 5+ (definitely) arguments, (3) see above about copying, (4) middle thing and (5) tons of arguments like mmap() should be wrapped up... for simplicity of dealing with it later.
Jan
Re: Interface for the new fallocate() system call
Quoted 3 lines · Jan Engelhardt
I have to disagree, since wrapping it into a struct and copying the struct in kernelspace from userspace requires more code.
Not just more code, but more security issues too.
Passing system call arguments by value means that there are no subtle security issues - the value you use is the value you got. But once you pass-by-reference, you have to make damn sure that you do the proper user space accesses and verify the pointer correctly.
User-space (aka "user-supplied") pointers are just more dangerous. We obviously can't avoid them, but they need much more care than just a random value directly passed in a register.
Linus
Re: Interface for the new fallocate() system call
In reply to Jan EngelhardtQuoted 16 lines · Jan Engelhardt
Hi,
Quoted 7 lines · Amit K. Arora
We need to come up with the best possible layout of arguments for the
fallocate()system call. Various architectures have different requirements for how the arguments should look like. Since the mail chain has become huge, here is the summary of various inputs received so far.Quoted 5 lines
s390 prefers following layout:
intfallocate(int fd, loff_t offset, loff_t len, int mode)
For details on why and how "int, int,loff_t,loff_t" is a problem on s390, please see Heiko's mail on 16th March. Here is the link:
http://www.mail-archive.com/[email protected]/msg133595.html
Quoted 5 lines
Quoting that...
|len -> r6 + second halve on stackThen, is not this a gcc glitch? (IMO, it should put all of "len" on the stack)
It _does_ put all of "len" on the stack. That is what I tried to explain in the section that follows what you quoted.
Re: Interface for the new fallocate() system call
In reply to Andrew MortonQuoted 17 lines · Andrew Morton
Quoted 17 lines
Platform: s390
--------------
s390 prefers following layout:int
fallocate(int fd, loff_t offset, loff_t len, int mode)For details on why and how "int, int,
loff_t,loff_t" is a problem on s390, please see Heiko's mail on 16th March. Here is the link:
http://www.mail-archive.com/[email protected]/msg133595.htmlPlatform: ppc, arm
------------------
ppc (32 bit) has a problem with "int,loff_t,loff_t, int" layout, since this will result in a pad between fd and offset, making seven arguments total - which is not supported by ppc32. It supports only 6 arguments. Thus the desired layout by ppc32 is:
Quoted 7 lines
Quoted 4 lines
int
fallocate(int fd, int mode, loff_t offset, loff_t len)Even ARM prefers above kind of layout. For details please see the definition of
sys_arm_sync_file_range().This is a clean-looking option. Can s390 be changed to support seven-arg syscalls?
Wouldn't
int fallocate(loff_t offset, loff_t len, int fd, int mode) work on both s390 and ppc/arm? glibc will certainly wrap it and reorder the arguments as needed, so there is no need to keep fd first.
Jakub
Re: Interface for the new fallocate() system call
In reply to Andrew MortonQuoted 14 lines
Quoted 2 lines
Even ARM prefers above kind of layout. For details please see the definition of
sys_arm_sync_file_range().This is a clean-looking option. Can s390 be changed to support seven-arg syscalls?
Quoted 8 lines
Option of
loff_t=> high u32 + low u32
--------------------------------------
Matthew and Russell have suggested another option of breaking each "loff_t" into two "u32"s. This will result in 6 arguments in total.Following think that this is a good alternative:
Matthew Wilcox, Russell King, Heiko Carstens
Quoted 6 lines
Quoted 2 lines
Following do not like this idea:
Chris WedgwoodIt's a bit weird-looking, but the six-32-bit-args approach is simple enought to understand and implement. Presumably the glibc wrapper would hide that detail from everyone.
s390 can be changed to support seven-arg syscalls. But that would require creating an additional stackframe in *libc to save original register contents and in addition it would make our syscall hotpath slower. That is because we have to take care of an additional register that might contain user space passed contents and needs to be put on the kernel stack. If possible I'd prefer the six-32-bit-args approach.
Re: Interface for the new fallocate() system call
In reply to Jakub JelinekQuoted 23 lines · Jakub Jelinek
Quoted 22 lines · Andrew Morton
Quoted 21 lines
Platform: s390
--------------
s390 prefers following layout:int
fallocate(int fd, loff_t offset, loff_t len, int mode)For details on why and how "int, int,
loff_t,loff_t" is a problem on s390, please see Heiko's mail on 16th March. Here is the link:
http://www.mail-archive.com/[email protected]/msg133595.htmlPlatform: ppc, arm
------------------
ppc (32 bit) has a problem with "int,loff_t,loff_t, int" layout, since this will result in a pad between fd and offset, making seven arguments total - which is not supported by ppc32. It supports only 6 arguments. Thus the desired layout by ppc32 is:int
fallocate(int fd, int mode, loff_t offset, loff_t len)Even ARM prefers above kind of layout. For details please see the definition of
sys_arm_sync_file_range().
Quoted 7 lines
Quoted 2 lines
This is a clean-looking option. Can s390 be changed to support seven-arg syscalls?
Wouldn't
intfallocate(loff_t offset, loff_t len, int fd, int mode)work on both s390 and ppc/arm? glibc will certainly wrap it and reorder the arguments as needed, so there is no need to keep fd first.
That would be fine for s390.
Re: Interface for the new fallocate() system call
In reply to Jakub JelinekQuoted 23 lines · Jakub Jelinek
Quoted 22 lines · Andrew Morton
Quoted 21 lines
Platform: s390
--------------
s390 prefers following layout:int
fallocate(int fd, loff_t offset, loff_t len, int mode)For details on why and how "int, int,
loff_t,loff_t" is a problem on s390, please see Heiko's mail on 16th March. Here is the link:
http://www.mail-archive.com/[email protected]/msg133595.htmlPlatform: ppc, arm
------------------
ppc (32 bit) has a problem with "int,loff_t,loff_t, int" layout, since this will result in a pad between fd and offset, making seven arguments total - which is not supported by ppc32. It supports only 6 arguments. Thus the desired layout by ppc32 is:int
fallocate(int fd, int mode, loff_t offset, loff_t len)Even ARM prefers above kind of layout. For details please see the definition of
sys_arm_sync_file_range().
Quoted 7 lines
Quoted 2 lines
This is a clean-looking option. Can s390 be changed to support seven-arg syscalls?
Wouldn't
intfallocate(loff_t offset, loff_t len, int fd, int mode)work on both s390 and ppc/arm? glibc will certainly wrap it and reorder the arguments as needed, so there is no need to keep fd first.
That would be fine for s390.
Re: Interface for the new fallocate() system call
In reply to Jakub JelinekQuoted 4 lines · Jakub Jelinek
Wouldn't
intfallocate(loff_t offset, loff_t len, int fd, int mode)work on both s390 and ppc/arm? glibc will certainly wrap it and reorder the arguments as needed, so there is no need to keep fd first.
That looks fine to me.
Paul.
Re: Interface for the new fallocate() system call
In reply to Jakub JelinekQuoted 4 lines · Jakub Jelinek
Wouldn't
intfallocate(loff_t offset, loff_t len, int fd, int mode)work on both s390 and ppc/arm? glibc will certainly wrap it and reorder the arguments as needed, so there is no need to keep fd first.
That looks fine to me.
Paul.
Re: Interface for the new fallocate() system call
In reply to Heiko CarstensQuoted 1 line · Heiko Carstens
If possible I'd prefer the six-32-bit-args approach.
It does mean extra unnecessary work for 64-bit platforms, though...
Paul.
Re: Interface for the new fallocate() system call
In reply to Heiko CarstensQuoted 1 line · Heiko Carstens
If possible I'd prefer the six-32-bit-args approach.
It does mean extra unnecessary work for 64-bit platforms, though...
Paul.
Re: Interface for the new fallocate() system call
In reply to Paul MackerrasQuoted 5 lines · Paul Mackerras
Quoted 1 line · Heiko Carstens
If possible I'd prefer the six-32-bit-args approach.
It does mean extra unnecessary work for 64-bit platforms, though...
Wouldn't that work be confined to fallocate()? If I understand Heiko correctly, the alternative would slow s390 down for every syscall, including more performance-critical ones.
Jörn
Signature · 6 lines
tglx1 thinks that joern should get a (TM) for "Thinking Is Hard" -- Thomas Gleixner - To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Interface for the new fallocate() system call
In reply to Paul MackerrasQuoted 5 lines · Paul Mackerras
Quoted 1 line · Heiko Carstens
If possible I'd prefer the six-32-bit-args approach.
It does mean extra unnecessary work for 64-bit platforms, though...
Wouldn't that work be confined to fallocate()? If I understand Heiko correctly, the alternative would slow s390 down for every syscall, including more performance-critical ones.
Jörn
Signature · 2 lines
tglx1 thinks that joern should get a (TM) for "Thinking Is Hard" -- Thomas Gleixner
Re: Interface for the new fallocate() system call
In reply to Jörn EngelQuoted 6 lines · Jörn Engel
Quoted 1 line · Paul Mackerras
It does mean extra unnecessary work for 64-bit platforms, though...
Wouldn't that work be confined to
fallocate()? If I understand Heiko correctly, the alternative would slow s390 down for every syscall, including more performance-critical ones.
That is correct.
Re: Interface for the new fallocate() system call
In reply to Jörn EngelQuoted 6 lines · Jörn Engel
Quoted 1 line · Paul Mackerras
It does mean extra unnecessary work for 64-bit platforms, though...
Wouldn't that work be confined to
fallocate()? If I understand Heiko correctly, the alternative would slow s390 down for every syscall, including more performance-critical ones.
That is correct.
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Interface for the new fallocate() system call
In reply to Jakub JelinekQuoted 4 lines · Jakub Jelinek
Wouldn't
intfallocate(loff_t offset, loff_t len, int fd, int mode)work on both s390 and ppc/arm? glibc will certainly wrap it and reorder the arguments as needed, so there is no need to keep fd first.
This should work on all the platforms. The only concern I can think of here is the convention being followed till now, where all the entities on which the action has to be performed by the kernel (say fd, file/device name, pid etc.) is the first argument of the system call. If we can live with the small exception here, fine.
Or else, we may have to implement the
int fd, int mode, loff_t offset, loff_t len
as the layout of arguments here. I think only s390 will have a problem with this, and we can think of a workaround for it (may be similar to
what ARM did to implement sync_file_range() system call) :
asmlinkage long sys_s390_fallocate(int fd, loff_t offset, loff_t len, int mode)
{
return sys_fallocate(fd, offset, len, mode);
}To me both the approaches look slightly unconventional. But, we need to compromise somewhere to make things work on all the platforms.
Any thoughts on which one of the above should we finalize on ?
Thanks!
--
Regards,
Amit Arora
Re: Interface for the new fallocate() system call
On Thu, Apr 05, 2007 at 04:56:19PM +0530, Amit K. Arora wrote:
Correction below:
Quoted 3 lines
asmlinkage long
sys_s390_fallocate(int fd, loff_t offset, loff_t len, int mode){ return sys_fallocate(fd, offset, len, mode);
return sys_fallocate(fd, mode, offset, len);
Quoted 1 line
}
--
Regards,
Amit Arora
Re: Interface for the new fallocate() system call
In reply to Amit K. AroraQuoted 26 lines · On Thu, 5 Apr 2007 16:56:19 +0530 Amit K. Arora wrote:
Quoted 4 lines · Jakub Jelinek
Wouldn't
intfallocate(loff_t offset, loff_t len, int fd, int mode)work on both s390 and ppc/arm? glibc will certainly wrap it and reorder the arguments as needed, so there is no need to keep fd first.This should work on all the platforms. The only concern I can think of here is the convention being followed till now, where all the entities on which the action has to be performed by the kernel (say fd, file/device name, pid etc.) is the first argument of the system call. If we can live with the small exception here, fine.
Or else, we may have to implement the
int fd, int mode,
loff_toffset,loff_tlenas the layout of arguments here. I think only s390 will have a problem with this, and we can think of a workaround for it (may be similar to
what ARM did to implementsync_file_range()system call) :asmlinkage long
sys_s390_fallocate(int fd, loff_t offset, loff_t len, int mode){ return sys_fallocate(fd, offset, len, mode); }
Quoted 6 lines
To me both the approaches look slightly unconventional. But, we need to compromise somewhere to make things work on all the platforms.
Any thoughts on which one of the above should we finalize on ?
Thanks!
If s390 can work around the calling order that easily, I certainly prefer the more conventional ordering of:
Quoted 1 line
int fd, int mode,
loff_toffset,loff_tlen
---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***
Re: Interface for the new fallocate() system call
In reply to Amit K. AroraQuoted 5 lines · Amit K. Arora
This should work on all the platforms. The only concern I can think of here is the convention being followed till now, where all the entities on which the action has to be performed by the kernel (say fd, file/device name, pid etc.) is the first argument of the system call. If we can live with the small exception here, fine.
Yes, it is much cleaner to have fd first, like every other such syscall.
Quoted 4 lines
Or else, we may have to implement the
int fd, int mode,
loff_toffset,loff_tlen
Quoted 8 lines
as the layout of arguments here. I think only s390 will have a problem with this, and we can think of a workaround for it (may be similar to
what ARM did to implementsync_file_range()system call) :asmlinkage long
sys_s390_fallocate(int fd, loff_t offset, loff_t len, int mode){ return sys_fallocate(fd, offset, len, mode); }
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Re: Interface for the new fallocate() system call
In reply to Jörn EngelQuoted 3 lines · Jörn Engel
Wouldn't that work be confined to
fallocate()? If I understand Heiko correctly, the alternative would slow s390 down for every syscall, including more performance-critical ones.
The alternative that Jakub suggested wouldn't slow s390 down.
Paul.
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Interface for the new fallocate() system call
Quoted 7 lines · Paul Mackerras
Quoted 3 lines · Jörn Engel
Wouldn't that work be confined to
fallocate()? If I understand Heiko correctly, the alternative would slow s390 down for every syscall, including more performance-critical ones.The alternative that Jakub suggested wouldn't slow s390 down.
True. And it appears to be one of the least offensive options we have.
Jörn
Signature · 8 lines
My second remark is that our intellectual powers are rather geared to master static relations and that our powers to visualize processes evolving in time are relatively poorly developed. -- Edsger W. Dijkstra - To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Interface for the new fallocate() system call
In reply to Jakub JelinekQuoted 5 lines · Jakub Jelinek
Wouldn't
intfallocate(loff_t offset, loff_t len, int fd, int mode)work on both s390 and ppc/arm? glibc will certainly wrap it and reorder the arguments as needed, so there is no need to keep fd first.
I think more people are comfirtable with this approach. Since glibc will wrap the system call and export the "conventional" interface (with fd first) to applications, we may not worry about keeping fd first in kernel code. I am personally fine with this approach.
Still, if people have major concerns, we can think of getting rid of the "mode" argument itself. Anyhow we may, in future, need to have a policy based system call (say, for providing the goal block by applications for performance reasons). "mode" can then be made part of it.
Comments ?
--
Regards,
Amit Arora
Re: Interface for the new fallocate() system call
Quoted 7 lines · Amit K. Arora
Quoted 4 lines · Jakub Jelinek
Wouldn't
intfallocate(loff_t offset, loff_t len, int fd, int mode)work on both s390 and ppc/arm? glibc will certainly wrap it and reorder the arguments as needed, so there is no need to keep fd first.I think more people are comfirtable with this approach.
Really? I thought from the last postings that "fd first, wrap on s390" was better.
Quoted 4 lines
Since glibc
will wrap the system call and export the "conventional" interface (with fd first) to applications, we may not worry about keeping fd first in kernel code. I am personally fine with this approach.
It would seem to make more sense to wrap the syscall on those architectures that can't handle the "conventional" interface (fd first).
Quoted 4 lines
Still, if people have major concerns, we can think of getting rid of the "mode" argument itself. Anyhow we may, in future, need to have a policy based system call (say, for providing the goal block by applications for performance reasons). "mode" can then be made part of it.
We need at least mode="unallocate" or a separate funallocate() call to allow allocated-but-unwritten blocks to be unallocated without actually punching out written data.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Re: Interface for the new fallocate() system call
Quoted 12 lines · Andreas Dilger
Quoted 7 lines · Amit K. Arora
Quoted 4 lines · Jakub Jelinek
Wouldn't
intfallocate(loff_t offset, loff_t len, int fd, int mode)work on both s390 and ppc/arm? glibc will certainly wrap it and reorder the arguments as needed, so there is no need to keep fd first.I think more people are comfirtable with this approach.
Really? I thought from the last postings that "fd first, wrap on s390" was better.
Quoted 7 lines
Quoted 4 lines
Since glibc
will wrap the system call and export the "conventional" interface (with fd first) to applications, we may not worry about keeping fd first in kernel code. I am personally fine with this approach.It would seem to make more sense to wrap the syscall on those architectures that can't handle the "conventional" interface (fd first).
Ok.
In this case we may have to consider following things:
1) Obviously, for this glibc will have to call fallocate() syscall with different arguments on s390, than other archs. I think this should be doable and should not be an issue with glibc folks (right?).
2) we also need to see how strace behaves in this case. With little knowledge that I have of strace, I don't think it should depend on argument ordering of a system call on different archs (since it uses ptrace internally and that should take care of it). But, it will be nice if someone can confirm this.
Thanks!
--
Regards,
Amit Arora
Re: Interface for the new fallocate() system call
Quoted 6 lines · Amit K. Arora
Ok.
In this case we may have to consider following things:1) Obviously, for this glibc will have to call
fallocate()syscall with different arguments on s390, than other archs. I think this should be doable and should not be an issue with glibc folks (right?).
glibc can cope with this easily, will just add sysdeps/unix/sysv/linux/s390/fallocate.c or something similar to override the generic Linux implementation.
Quoted 5 lines
2) we also need to see how strace behaves in this case. With little knowledge that I have of strace, I don't think it should depend on argument ordering of a system call on different archs (since it uses ptrace internally and that should take care of it). But, it will be nice if someone can confirm this.
strace would solve this with #ifdef mess, it already does that in many places so guess another few lines don't make it significantly worse.
Jakub
Re: Interface for the new fallocate() system call
Quoted 12 lines · Jakub Jelinek
Quoted 6 lines · Amit K. Arora
Ok.
In this case we may have to consider following things:1) Obviously, for this glibc will have to call
fallocate()syscall with different arguments on s390, than other archs. I think this should be doable and should not be an issue with glibc folks (right?).glibc can cope with this easily, will just add
sysdeps/unix/sysv/linux/s390/fallocate.cor something similar to override the generic Linux implementation.
Quoted 8 lines
Quoted 5 lines
2) we also need to see how strace behaves in this case. With little knowledge that I have of strace, I don't think it should depend on argument ordering of a system call on different archs (since it uses ptrace internally and that should take care of it). But, it will be nice if someone can confirm this.
strace would solve this with #ifdef mess, it already does that in many places so guess another few lines don't make it significantly worse.
I will work on the revised fallocate patchset and will post it soon.
Thanks!
--
Regards,
Amit Arora
cover fallocate system call
Based on the discussion, this new patchset uses following as the interface for fallocate() system call:
asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len)
It seems that only s390 architecture has a problem with such a layout of arguments in fallocate(). Thus for s390, we plan to have a wrapper (say, sys_s390_fallocate()) for the sys_fallocate(), which will get called by glibc when an application issues a fallocate() system call on s390. The s390 arch specific changes will be part of a separate patch (PATCH 2/5). It will be great if some s390 expert can verify the patch, since I have not been able to test it on s390 so far.
It was also noted that minor changes might be required to strace code to take care of "different arguments on s390" issue.
Currently we have two modes FA_ALLOCATE and FA_DEALLOCATE, for preallocation and deallocation of preallocated blocks respectively. More modes can be added, when required.
ToDos:
=====
1> Implementation on other architectures (other than i386, x86_64,
ppc64 and s390(x))
2> A generic file system operation to handle fallocate
(generic_fallocate), for filesystems that do _not_ have the fallocate inode operation implemented.
3> Changes to glibc,
a) to support fallocate() system call
b) so that posix_fallocate() and posix_fallocate64() call fallocate() system call
4> Changes to XFS to implement the fallocate inode operation
Following patches follow:
Patch 1/5 : fallocate() implementation in i86, x86_64 and powerpc Patch 2/5 : fallocate() on s390
Patch 3/5 : ext4: Extent overlap bugfix
Patch 4/5 : ext4: fallocate support in ext4
Patch 5/5 : ext4: write support for preallocated blocks
--
Regards,
Amit Arora
PATCH 1/5 fallocate() implementation in i86, x86_64 and powerpc
This patch implements the fallocate() system call and adds support for i386, x86_64 and powerpc.
NOTE: It is based on 2.6.21 kernel version.
--- arch/i386/kernel/syscall_table.S | 1 arch/powerpc/kernel/sys_ppc32.c | 7 ++++++ arch/x86_64/kernel/functionlist | 1 fs/open.c | 41 +++++++++++++++++++++++++++++++++++++++ include/asm-i386/unistd.h | 3 +- include/asm-powerpc/systbl.h | 1 include/asm-powerpc/unistd.h | 3 +- include/asm-x86_64/unistd.h | 4 ++- include/linux/fs.h | 7 ++++++ include/linux/syscalls.h | 1 10 files changed, 66 insertions(+), 3 deletions(-)
arch/i386/kernel/syscall_table.S +1 -0
@@ -319,3 +319,4 @@ ENTRY(sys_call_table) .long sys_move_pages .long sys_getcpu .long sys_epoll_pwait + .long sys_fallocate /* 320 */
arch/x86_64/kernel/functionlist +1 -0
@@ -931,6 +931,7 @@ *(.text.sys_getitimer) *(.text.sys_getgroups) *(.text.sys_ftruncate) +*(.text.sys_fallocate) *(.text.sysfs_lookup) *(.text.sys_exit_group) *(.text.stub_fork)
fs/open.c +41 -0
47 lines not on this page · raw message
include/asm-i386/unistd.h +2 -1
@@ -325,10 +325,11 @@#define __NR_move_pages 317#define __NR_getcpu 318#define __NR_epoll_pwait 319 +#define __NR_fallocate 320#ifdef __KERNEL__ -#define NR_syscalls 320 +#define NR_syscalls 321#define __ARCH_WANT_IPC_PARSE_VERSION#define __ARCH_WANT_OLD_READDIR
include/asm-powerpc/systbl.h +1 -0
@@ -307,3 +307,4 @@ COMPAT_SYS_SPU(set_robust_list) COMPAT_SYS_SPU(move_pages) SYSCALL_SPU(getcpu) COMPAT_SYS(epoll_pwait) +COMPAT_SYS(fallocate)
include/asm-powerpc/unistd.h +2 -1
@@ -326,10 +326,11 @@#define __NR_move_pages 301#define __NR_getcpu 302#define __NR_epoll_pwait 303 +#define __NR_fallocate 304#ifdef __KERNEL__ -#define __NR_syscalls 304 +#define __NR_syscalls 305#define __NR__exit __NR_exit#define NR_syscalls __NR_syscalls
include/asm-x86_64/unistd.h +3 -1
@@ -619,8 +619,10 @@ __SYSCALL(__NR_sync_file_range, sys_sync __SYSCALL(__NR_vmsplice, sys_vmsplice)#define __NR_move_pages 279 __SYSCALL(__NR_move_pages, sys_move_pages) +#define __NR_fallocate 280 +__SYSCALL(__NR_fallocate, sys_fallocate) -#define __NR_syscall_max __NR_move_pages +#define __NR_syscall_max __NR_fallocate#ifndef __NO_STUBS#define __ARCH_WANT_OLD_READDIR
include/linux/fs.h +7 -0
@@ -264,6 +264,12 @@ extern int dir_notify_enable;#define SYNC_FILE_RANGE_WRITE 2#define SYNC_FILE_RANGE_WAIT_AFTER 4 +/* +* fallocate() modes +*/ +#define FA_ALLOCATE 0x1 +#define FA_DEALLOCATE 0x2 +#ifdef __KERNEL__#include <linux/linkage.h>
@@ -1125,6 +1131,7 @@ struct inode_operations {ssize_t (*listxattr) (struct dentry *,char *,size_t );int (*removexattr) (struct dentry *,const char *);void (*truncate_range)(struct inode *,loff_t ,loff_t ); +long (*fallocate)(struct inode *,int ,loff_t ,loff_t ); };struct seq_file ;
include/linux/syscalls.h +1 -0
@@ -602,6 +602,7 @@ asmlinkage long sys_get_robust_list(intasmlinkage long sys_set_robust_list (struct robust_list_head __user *head,size_t len);asmlinkage long sys_getcpu (unsigned __user *cpu,unsigned __user *node,struct getcpu_cache __user *cache); +asmlinkage long sys_fallocate (int fd,int mode,loff_t offset,loff_t len);int kernel_execve (const char *filename,char *const argv[],char *const envp[]);
arch/powerpc/kernel/sys_ppc32.c +7 -0
@@ -777,6 +777,13 @@ asmlinkage int compat_sys_truncate64(conreturn sys_truncate (path, (high <<32 ) | low); } +asmlinkage long compat_sys_fallocate (int fd,int mode,u32 offhi,u32 offlo, +u32 lenhi,u32 lenlo) +{ +return sys_fallocate (fd, mode, ((loff_t )offhi <<32 ) | offlo, + ((loff_t )lenhi <<32 ) | lenlo); +} + asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,unsigned long low) {
PATCH 2/5 fallocate() on s390
In reply to Amit K. AroraThis patch implements support of fallocate system call on s390(x) platform. A wrapper is added to address the issue which s390 ABI has with "preferred" ordering of arguments in this system call (i.e. int, int, loff_t, loff_t).
I will request s390 experts to please review this code and verify if this patch is correct. Thanks!
--- arch/s390/kernel/compat_wrapper.S | 10 ++++++++++ arch/s390/kernel/sys_s390.c | 10 ++++++++++ arch/s390/kernel/syscalls.S | 1 + include/asm-s390/unistd.h | 3 ++- 4 files changed, 23 insertions(+), 1 deletion(-)
arch/s390/kernel/compat_wrapper.S +10 -0
@@ -1682,3 +1682,13 @@ compat_sys_utimes_wrapper: llgtr %r2,%r2 # char * llgtr %r3,%r3 # struct compat_timeval * jg compat_sys_utimes + + .globl s390_fallocate_wrapper +s390_fallocate_wrapper: + lgfr %r2,%r2 # int + sllg %r3,%r3,32 # get high word of 64bit loff_t + or %r3,%r4 # get low word of 64bit loff_t + sllg %r4,%r5,32 # get high word of 64bit loff_t + or %r4,%r6 # get low word of 64bit loff_t + llgf %r5,164(%r15) # unsigned int + jg s390_fallocate
arch/s390/kernel/sys_s390.c +10 -0
@@ -268,6 +268,16 @@ s390_fadvise64_64(struct fadvise64_64_ar }/* +* This is a wrapper to call sys_fallocate(). Since s390 ABI has a problem +* with the int, int, loff_t, loff_t ordering of arguments, this wrapper +* is required. +*/ +asmlinkage long s390_fallocate (int fd,loff_t offset,loff_t len,int mode) +{ +return sys_fallocate (fd, mode, offset, len); +} + +/* * Do a system call from kernel instead of calling sys_execve so we * end up with proper pt_regs. */
arch/s390/kernel/syscalls.S +1 -0
@@ -322,3 +322,4 @@ NI_SYSCALL /* 310 sys_move_pages * SYSCALL(sys_getcpu,sys_getcpu,sys_getcpu_wrapper) SYSCALL(sys_epoll_pwait,sys_epoll_pwait,compat_sys_epoll_pwait_wrapper) SYSCALL(sys_utimes,sys_utimes,compat_sys_utimes_wrapper) +SYSCALL(s390_fallocate,s390_fallocate,s390_fallocate_wrapper)
include/asm-s390/unistd.h +2 -1
@@ -251,8 +251,9 @@#define __NR_getcpu 311#define __NR_epoll_pwait 312#define __NR_utimes 313 +#define __NR_fallocate 314 -#define NR_syscalls 314 +#define NR_syscalls 315/* * There are some system calls that are not present on 64 bit, some
PATCH 3/5 ext4: Extent overlap bugfix
In reply to Amit K. AroraThis is a fix for an extent-overlap bug. The fallocate() implementation on ext4 depends on this bugfix. Though this fix had been posted earlier, but because it is still not part of mainline code, I have attached it here too.
--- fs/ext4/extents.c | 50 ++++++++++++++++++++++++++++++++++++++-- include/linux/ext4_fs_extents.h | 1 2 files changed, 49 insertions(+), 2 deletions(-)
fs/ext4/extents.c +48 -2
@@ -1129,6 +1129,45 @@ ext4_can_extents_be_merged(struct inode }/* +* ext4_ext_check_overlap: +* check if a portion of the "newext" extent overlaps with an +* existing extent. +* +* If there is an overlap discovered, it updates the length of the newext +* such that there will be no overlap, and then returns 1. +* If there is no overlap found, it returns 0. +*/ +unsigned int ext4_ext_check_overlap (struct inode *inode, +struct ext4_extent *newext, +struct ext4_ext_path *path) +{ +unsigned long b1, b2; +unsigned int depth, len1; + + b1 =le32_to_cpu (newext->ee_block); + len1 =le16_to_cpu (newext->ee_len); + depth =ext_depth (inode); +if (!path[depth].p_ext) + goto out; + b2 =le32_to_cpu (path[depth].p_ext->ee_block); + +/* get the next allocated block if the extent in the path +* is before the requested block(s) */ +if (b2 < b1) { + b2 =ext4_ext_next_allocated_block (path); +if (b2 ==EXT_MAX_BLOCK ) + goto out; + } + +if (b1 + len1 > b2) { + newext->ee_len =cpu_to_le16 (b2 - b1); +return 1 ; + } +out: +return 0 ; +} + +/* * ext4_ext_insert_extent: * tries to merge requsted extent into the existing extent or * inserts requested extent as new one into the tree,
@@ -2032,7 +2071,15 @@ int ext4_ext_get_blocks(handle_t *handle/* allocate new block */ goal =ext4_ext_find_goal (inode, path, iblock); - allocated = max_blocks; + +/* Check if we can really insert (iblock)::(iblock+max_blocks) extent */ + newex.ee_block =cpu_to_le32 (iblock); + newex.ee_len =cpu_to_le16 (max_blocks); + err =ext4_ext_check_overlap (inode, &newex, path); +if (err) + allocated =le16_to_cpu (newex.ee_len); +else + allocated = max_blocks; newblock =ext4_new_blocks (handle, inode, goal, &allocated, &err);if (!newblock) goto out2;
@@ -2040,7 +2087,6 @@ int ext4_ext_get_blocks(handle_t *handle goal, newblock, allocated);/* try to insert new extent into found leaf and return */ - newex.ee_block =cpu_to_le32 (iblock);ext4_ext_store_pblock (&newex, newblock); newex.ee_len =cpu_to_le16 (allocated); err =ext4_ext_insert_extent (handle, inode, path, &newex);
include/linux/ext4_fs_extents.h +1 -0
@@ -190,6 +190,7 @@ ext4_ext_invalidate_cache(struct inode *extern int ext4_extent_tree_init (handle_t *,struct inode *);extern int ext4_ext_calc_credits_for_insert (struct inode *,struct ext4_ext_path *); +extern unsigned int ext4_ext_check_overlap (struct inode *,struct ext4_extent *,struct ext4_ext_path *);extern int ext4_ext_insert_extent (handle_t *,struct inode *,struct ext4_ext_path *,struct ext4_extent *);extern int ext4_ext_walk_space (struct inode *,unsigned long ,unsigned long ,ext_prepare_callback ,void *);extern struct ext4_ext_path *ext4_ext_find_extent (struct inode *,int ,struct ext4_ext_path *);
PATCH 4/5 ext4: fallocate support in ext4
In reply to Amit K. AroraThis patch has the ext4 implemtation of fallocate system call.
--- fs/ext4/extents.c | 201 +++++++++++++++++++++++++++++++--------- fs/ext4/file.c | 1 include/linux/ext4_fs.h | 7 + include/linux/ext4_fs_extents.h | 13 ++ 4 files changed, 179 insertions(+), 43 deletions(-)
fs/ext4/extents.c +158 -43
@@ -283,7 +283,7 @@ static void ext4_ext_show_path(struct in }else if (path->p_ext) {ext_debug (" %d:%d:%llu " ,le32_to_cpu (path->p_ext->ee_block), -le16_to_cpu (path->p_ext->ee_len), +ext4_ext_get_actual_len (path->p_ext),ext_pblock (path->p_ext)); }else ext_debug (" []" );
@@ -306,7 +306,7 @@ static void ext4_ext_show_leaf(struct infor (i =0 ; i <le16_to_cpu (eh->eh_entries); i++, ex++) {ext_debug ("%d:%d:%llu " ,le32_to_cpu (ex->ee_block), -le16_to_cpu (ex->ee_len),ext_pblock (ex)); +ext4_ext_get_actual_len (ex),ext_pblock (ex)); }ext_debug ("\n" ); }
@@ -426,7 +426,7 @@ ext4_ext_binsearch(struct inode *inode,ext_debug (" -> %d:%llu:%d " ,le32_to_cpu (path->p_ext->ee_block),ext_pblock (path->p_ext), -le16_to_cpu (path->p_ext->ee_len)); +ext4_ext_get_actual_len (path->p_ext));#ifdef CHECK_BINSEARCH {
@@ -687,7 +687,7 @@ static int ext4_ext_split(handle_t *handext_debug ("move %d:%llu:%d in new leaf %llu\n" ,le32_to_cpu (path[depth].p_ext->ee_block),ext_pblock (path[depth].p_ext), -le16_to_cpu (path[depth].p_ext->ee_len), +ext4_ext_get_actual_len (path[depth].p_ext), newblock);/*memmove(ex++, path[depth].p_ext++, sizeof(struct ext4_extent));
@@ -1107,7 +1107,19 @@ static int ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, struct ext4_extent *ex2) { - if (le32_to_cpu(ex1->ee_block) + le16_to_cpu(ex1->ee_len) != + unsigned short ext1_ee_len, ext2_ee_len; + +/* +* Make sure that either both extents are uninitialized, or +* both are _not_. +*/ +if (ext4_ext_is_uninitialized (ex1) ^ext4_ext_is_uninitialized (ex2)) +return 0 ; + + ext1_ee_len =ext4_ext_get_actual_len (ex1); + ext2_ee_len =ext4_ext_get_actual_len (ex2); + +if (le32_to_cpu (ex1->ee_block) + ext1_ee_len !=le32_to_cpu (ex2->ee_block))return 0 ;
@@ -1116,14 +1128,14 @@ ext4_can_extents_be_merged(struct inode* as an RO_COMPAT feature, refuse to merge to extents if * this can result in the top bit of ee_len being set. */ -if (le16_to_cpu (ex1->ee_len) +le16_to_cpu (ex2->ee_len) >EXT_MAX_LEN ) +if (ext1_ee_len + ext2_ee_len >EXT_MAX_LEN )return 0 ;#ifdef AGGRESSIVE_TEST if (le16_to_cpu (ex1->ee_len) >=4 )return 0 ;#endif -if (ext_pblock (ex1) +le16_to_cpu (ex1->ee_len) ==ext_pblock (ex2)) +if (ext_pblock (ex1) + ext1_ee_len ==ext_pblock (ex2))return 1 ;return 0 ; }
@@ -1145,7 +1157,7 @@ unsigned int ext4_ext_check_overlap(struunsigned int depth, len1; b1 =le32_to_cpu (newext->ee_block); - len1 =le16_to_cpu (newext->ee_len); + len1 =ext4_ext_get_actual_len (newext); depth =ext_depth (inode);if (!path[depth].p_ext) goto out;
@@ -1181,9 +1193,9 @@ int ext4_ext_insert_extent(handle_t *hanstruct ext4_extent *ex, *fex;struct ext4_extent *nearex;/* nearest extent */ struct ext4_ext_path *npath =NULL ; -int depth, len, err, next; +int depth, len, err, next, uninitialized =0 ; -BUG_ON (newext->ee_len ==0 ); +BUG_ON (ext4_ext_get_actual_len (newext) ==0 ); depth =ext_depth (inode); ex = path[depth].p_ext;BUG_ON (path[depth].p_hdr ==NULL );
@@ -1191,14 +1203,23 @@ int ext4_ext_insert_extent(handle_t *han/* try to insert block into found extent and return */ if (ex &&ext4_can_extents_be_merged (inode, ex, newext)) {ext_debug ("append %d block to %d:%d (from %llu)\n" , -le16_to_cpu (newext->ee_len), +ext4_ext_get_actual_len (newext),le32_to_cpu (ex->ee_block), -le16_to_cpu (ex->ee_len),ext_pblock (ex)); +ext4_ext_get_actual_len (ex),ext_pblock (ex)); err =ext4_ext_get_access (handle, inode, path + depth);if (err)return err; - ex->ee_len =cpu_to_le16 (le16_to_cpu (ex->ee_len) - +le16_to_cpu (newext->ee_len)); + +/* ext4_can_extents_be_merged should have checked that either +* both extents are uninitialized, or both aren't. Thus we +* need to check only one of them here. +*/ +if (ext4_ext_is_uninitialized (ex)) + uninitialized =1 ; + ex->ee_len =cpu_to_le16 (ext4_ext_get_actual_len (ex) + +ext4_ext_get_actual_len (newext)); +if (uninitialized) +ext4_ext_mark_uninitialized (ex); eh = path[depth].p_hdr; nearex = ex; goto merge;
@@ -1254,7 +1275,7 @@ has_space:ext_debug ("first extent in the leaf: %d:%llu:%d\n" ,le32_to_cpu (newext->ee_block),ext_pblock (newext), -le16_to_cpu (newext->ee_len)); +ext4_ext_get_actual_len (newext)); path[depth].p_ext =EXT_FIRST_EXTENT (eh); }else if (le32_to_cpu (newext->ee_block) >le32_to_cpu (nearex->ee_block)) {
@@ -1267,7 +1288,7 @@ has_space:"move %d from 0x%p to 0x%p\n" ,le32_to_cpu (newext->ee_block),ext_pblock (newext), -le16_to_cpu (newext->ee_len), +ext4_ext_get_actual_len (newext), nearex, len, nearex + 1, nearex + 2);memmove (nearex +2 , nearex +1 , len); }
@@ -1280,7 +1301,7 @@ has_space:"move %d from 0x%p to 0x%p\n" ,le32_to_cpu (newext->ee_block),ext_pblock (newext), -le16_to_cpu (newext->ee_len), +ext4_ext_get_actual_len (newext), nearex, len, nearex + 1, nearex + 2);memmove (nearex +1 , nearex, len); path[depth].p_ext = nearex;
@@ -1299,8 +1320,13 @@ merge:if (!ext4_can_extents_be_merged (inode, nearex, nearex +1 ))break ;/* merge with next extent! */ - nearex->ee_len =cpu_to_le16 (le16_to_cpu (nearex->ee_len) - +le16_to_cpu (nearex[1 ].ee_len)); +if (ext4_ext_is_uninitialized (nearex)) + uninitialized =1 ; + nearex->ee_len =cpu_to_le16 (ext4_ext_get_actual_len (nearex) + +ext4_ext_get_actual_len (nearex +1 )); +if (uninitialized) +ext4_ext_mark_uninitialized (nearex); +if (nearex +1 <EXT_LAST_EXTENT (eh)) { len = (EXT_LAST_EXTENT (eh) - nearex -1 ) *sizeof (struct ext4_extent );
@@ -1370,8 +1396,8 @@ int ext4_ext_walk_space(struct inode *in end =le32_to_cpu (ex->ee_block);if (block + num < end) end = block + num; - }else if (block >= -le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len)) { + }else if (block >=le32_to_cpu (ex->ee_block) + +ext4_ext_get_actual_len (ex)) {/* need to allocate space after found extent */ start = block; end = block + num;
@@ -1383,7 +1409,8 @@ int ext4_ext_walk_space(struct inode *in* by found extent */ start = block; - end =le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len); + end =le32_to_cpu (ex->ee_block) + +ext4_ext_get_actual_len (ex);if (block + num < end) end = block + num; exists =1 ;
@@ -1399,7 +1426,7 @@ int ext4_ext_walk_space(struct inode *in cbex.ec_type =EXT4_EXT_CACHE_GAP ; }else { cbex.ec_block =le32_to_cpu (ex->ee_block); - cbex.ec_len =le16_to_cpu (ex->ee_len); + cbex.ec_len =ext4_ext_get_actual_len (ex); cbex.ec_start =ext_pblock (ex); cbex.ec_type =EXT4_EXT_CACHE_EXTENT ; }
@@ -1472,15 +1499,15 @@ ext4_ext_put_gap_in_cache(struct inode *ext_debug ("cache gap(before): %lu [%lu:%lu]" , (unsigned long ) block, (unsigned long )le32_to_cpu (ex->ee_block), - (unsigned long )le16_to_cpu (ex->ee_len)); + (unsigned long )ext4_ext_get_actual_len (ex)); }else if (block >=le32_to_cpu (ex->ee_block) - +le16_to_cpu (ex->ee_len)) { + +ext4_ext_get_actual_len (ex)) { lblock =le32_to_cpu (ex->ee_block) - +le16_to_cpu (ex->ee_len); + +ext4_ext_get_actual_len (ex); len =ext4_ext_next_allocated_block (path);ext_debug ("cache gap(after): [%lu:%lu] %lu" , (unsigned long )le32_to_cpu (ex->ee_block), - (unsigned long )le16_to_cpu (ex->ee_len), + (unsigned long )ext4_ext_get_actual_len (ex), (unsigned long ) block);BUG_ON (len == lblock); len = len - lblock;
@@ -1610,12 +1637,12 @@ static int ext4_remove_blocks(handle_t * unsigned long from, unsigned long to) {struct buffer_head *bh; +unsigned short ee_len =ext4_ext_get_actual_len (ex);int i;#ifdef EXTENTS_STATS {struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb); -unsigned short ee_len =le16_to_cpu (ex->ee_len);spin_lock (&sbi->s_ext_stats_lock); sbi->s_ext_blocks += ee_len; sbi->s_ext_extents++;
@@ -1629,12 +1656,12 @@ static int ext4_remove_blocks(handle_t * }#endif if (from >=le32_to_cpu (ex->ee_block) - && to ==le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len) -1 ) { + && to ==le32_to_cpu (ex->ee_block) + ee_len -1 ) {/* tail removal */ unsigned long num;ext4_fsblk_t start; - num =le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len) - from; - start =ext_pblock (ex) +le16_to_cpu (ex->ee_len) - num; + num =le32_to_cpu (ex->ee_block) + ee_len - from; + start =ext_pblock (ex) + ee_len - num;ext_debug ("free last %lu blocks starting %llu\n" , num, start);for (i =0 ; i < num; i++) { bh =sb_find_get_block (inode->i_sb, start + i);
@@ -1642,12 +1669,12 @@ static int ext4_remove_blocks(handle_t * }ext4_free_blocks (handle, inode, start, num); }else if (from ==le32_to_cpu (ex->ee_block) - && to <=le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len) -1 ) { + && to <=le32_to_cpu (ex->ee_block) + ee_len -1 ) {printk ("strange request: removal %lu-%lu from %u:%u\n" , - from, to,le32_to_cpu (ex->ee_block),le16_to_cpu (ex->ee_len)); + from, to,le32_to_cpu (ex->ee_block), ee_len); }else {printk ("strange request: removal(2) %lu-%lu from %u:%u\n" , - from, to,le32_to_cpu (ex->ee_block),le16_to_cpu (ex->ee_len)); + from, to,le32_to_cpu (ex->ee_block), ee_len); }return 0 ; }
@@ -1661,7 +1688,7 @@ ext4_ext_rm_leaf(handle_t *handle, strucstruct ext4_extent_header *eh;unsigned a, b, block, num;unsigned long ex_ee_block; -unsigned short ex_ee_len; +unsigned short ex_ee_len, uninitialized =0 ;struct ext4_extent *ex;ext_debug ("truncate since %lu in leaf\n" , start);
@@ -1676,7 +1703,9 @@ ext4_ext_rm_leaf(handle_t *handle, struc ex =EXT_LAST_EXTENT (eh); ex_ee_block =le32_to_cpu (ex->ee_block); - ex_ee_len =le16_to_cpu (ex->ee_len); +if (ext4_ext_is_uninitialized (ex)) + uninitialized =1 ; + ex_ee_len =ext4_ext_get_actual_len (ex);while (ex >=EXT_FIRST_EXTENT (eh) && ex_ee_block + ex_ee_len > start) {
@@ -1744,6 +1773,8 @@ ext4_ext_rm_leaf(handle_t *handle, struc ex->ee_block =cpu_to_le32 (block); ex->ee_len =cpu_to_le16 (num); +if (uninitialized) +ext4_ext_mark_uninitialized (ex); err =ext4_ext_dirty (handle, inode, path + depth);if (err)
@@ -1753,7 +1784,7 @@ ext4_ext_rm_leaf(handle_t *handle, struc ext_pblock(ex)); ex--; ex_ee_block =le32_to_cpu (ex->ee_block); - ex_ee_len =le16_to_cpu (ex->ee_len); + ex_ee_len =ext4_ext_get_actual_len (ex); }if (correct_index && eh->eh_entries)
@@ -2029,7 +2060,7 @@ int ext4_ext_get_blocks(handle_t *handleif (ex) {unsigned long ee_block =le32_to_cpu (ex->ee_block);ext4_fsblk_t ee_start =ext_pblock (ex); -unsigned short ee_len =le16_to_cpu (ex->ee_len); +unsigned short ee_len;/* * Allow future support for preallocated extents to be added
@@ -2037,8 +2068,9 @@ int ext4_ext_get_blocks(handle_t *handle* Uninitialized extents are treated as holes, except that * we avoid (fail) allocating new blocks during a write. */ -if (ee_len >EXT_MAX_LEN ) +if (le16_to_cpu (ex->ee_len) >EXT_MAX_LEN ) goto out2; + ee_len =ext4_ext_get_actual_len (ex);/* if found extent covers block, simply return it */ if (iblock >= ee_block && iblock < ee_block + ee_len) { newblock = iblock - ee_block + ee_start;
@@ -2046,8 +2078,11 @@ int ext4_ext_get_blocks(handle_t *handle allocated = ee_len - (iblock - ee_block);ext_debug ("%d fit into %lu:%d -> %llu\n" , (int ) iblock, ee_block, ee_len, newblock); -ext4_ext_put_in_cache (inode, ee_block, ee_len, - ee_start,EXT4_EXT_CACHE_EXTENT ); +/* Do not put uninitialized extent in the cache */ +if (!ext4_ext_is_uninitialized (ex)) +ext4_ext_put_in_cache (inode, ee_block, + ee_len, ee_start, +EXT4_EXT_CACHE_EXTENT ); goto out; } }
@@ -2089,6 +2124,8 @@ int ext4_ext_get_blocks(handle_t *handle/* try to insert new extent into found leaf and return */ ext4_ext_store_pblock (&newex, newblock); newex.ee_len =cpu_to_le16 (allocated); +if (create ==EXT4_CREATE_UNINITIALIZED_EXT )/* Mark uninitialized */ +ext4_ext_mark_uninitialized (&newex); err =ext4_ext_insert_extent (handle, inode, path, &newex);if (err) goto out2;
@@ -2100,8 +2137,10 @@ int ext4_ext_get_blocks(handle_t *handle newblock =ext_pblock (&newex);__set_bit (BH_New, &bh_result->b_state); -ext4_ext_put_in_cache (inode, iblock, allocated, newblock, -EXT4_EXT_CACHE_EXTENT ); +/* Cache only when it is _not_ an uninitialized extent */ +if (create!=EXT4_CREATE_UNINITIALIZED_EXT ) +ext4_ext_put_in_cache (inode, iblock, allocated, newblock, +EXT4_EXT_CACHE_EXTENT ); out:if (allocated > max_blocks) allocated = max_blocks;
@@ -2205,10 +2244,86 @@ int ext4_ext_writepage_trans_blocks(strureturn needed; } +/* +* ext4_fallocate: +* preallocate space for a file +* mode is for future use, e.g. for unallocating preallocated blocks etc. +*/ +int ext4_fallocate (struct inode *inode,int mode,loff_t offset,loff_t len) +{ +handle_t *handle; +ext4_fsblk_t block, max_blocks; +int ret, ret2, nblocks =0 , retries =0 ; +struct buffer_head map_bh; +unsigned int credits, blkbits = inode->i_blkbits; + +/* Currently supporting (pre)allocate mode _only_ */ +if (mode !=FA_ALLOCATE ) +return -EOPNOTSUPP ; + +if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) +return -ENOTTY ; + + block = offset >> blkbits; + max_blocks = (EXT4_BLOCK_ALIGN (len + offset, blkbits) >> blkbits) + - block; +mutex_lock (&EXT4_I (inode)->truncate_mutex); + credits =ext4_ext_calc_credits_for_insert (inode,NULL ); +mutex_unlock (&EXT4_I (inode)->truncate_mutex); + handle=ext4_journal_start (inode, credits + +EXT4_DATA_TRANS_BLOCKS (inode->i_sb)+1 ); +if (IS_ERR (handle)) +return PTR_ERR (handle); +retry: + ret =0 ; +while (ret >=0 && ret < max_blocks) { + block = block + ret; + max_blocks = max_blocks - ret; + ret =ext4_ext_get_blocks (handle, inode, block, + max_blocks, &map_bh, +EXT4_CREATE_UNINITIALIZED_EXT ,0 ); +BUG_ON (!ret); +if (ret >0 &&test_bit (BH_New, &map_bh.b_state) + && ((block + ret) > (i_size_read (inode) << blkbits))) + nblocks = nblocks + ret; + } + +if (ret == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) + goto retry; + +/* Time to update the file size. +* Update only when preallocation was requested beyond the file size. +*/ +if ((offset + len) >i_size_read (inode)) { +if (ret >0 ) { +/* if no error, we assume preallocation succeeded completely */ +mutex_lock (&inode->i_mutex); +i_size_write (inode, offset + len); +EXT4_I (inode)->i_disksize =i_size_read (inode); +mutex_unlock (&inode->i_mutex); + }else if (ret <0 && nblocks) { +/* Handle partial allocation scenario */ +loff_t newsize; +mutex_lock (&inode->i_mutex); + newsize = (nblocks << blkbits) +i_size_read (inode); +i_size_write (inode,EXT4_BLOCK_ALIGN (newsize, blkbits)); +EXT4_I (inode)->i_disksize =i_size_read (inode); +mutex_unlock (&inode->i_mutex); + } + } +ext4_mark_inode_dirty (handle, inode); + ret2 =ext4_journal_stop (handle); +if (ret >0 ) + ret = ret2; + +return ret >0 ?0 : ret; +} +EXPORT_SYMBOL (ext4_mark_inode_dirty);EXPORT_SYMBOL (ext4_ext_invalidate_cache);EXPORT_SYMBOL (ext4_ext_insert_extent);EXPORT_SYMBOL (ext4_ext_walk_space);EXPORT_SYMBOL (ext4_ext_find_goal);EXPORT_SYMBOL (ext4_ext_calc_credits_for_insert); +EXPORT_SYMBOL (ext4_fallocate);
fs/ext4/file.c +1 -0
@@ -135,5 +135,6 @@ const struct inode_operations ext4_file_ .removexattr = generic_removexattr, #endif .permission = ext4_permission, + .fallocate = ext4_fallocate, };
include/linux/ext4_fs.h +7 -0
@@ -102,6 +102,8 @@ EXT4_GOOD_OLD_FIRST_INO : \ (s)->s_first_ino)#endif +#define EXT4_BLOCK_ALIGN (size, blkbits) (((size)+(1 << blkbits)-1) & \ + (~((1 << blkbits)-1)))/* * Macro-instructions used to manage fragments
@@ -225,6 +227,10 @@ struct ext4_new_group_data {__u32 free_blocks_count; }; +/* Following is used by preallocation logic to tell get_blocks() that we +* want uninitialzed extents. +*/ +#define EXT4_CREATE_UNINITIALIZED_EXT 2/* * ioctl commands
@@ -976,6 +982,7 @@ extern int ext4_ext_get_blocks(handle_textern void ext4_ext_truncate (struct inode *,struct page *);extern void ext4_ext_init (struct super_block *);extern void ext4_ext_release (struct super_block *); +extern int ext4_fallocate (struct inode *,int ,loff_t ,loff_t ); static inline int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, unsigned long max_blocks, struct buffer_head *bh,
include/linux/ext4_fs_extents.h +13 -0
@@ -125,6 +125,19 @@ struct ext4_ext_path {#define EXT4_EXT_CACHE_EXTENT 2/* +* Macro-instructions to handle (mark/unmark/check/create) unitialized +* extents. Applications can issue an IOCTL for preallocation, which results +* in assigning unitialized extents to the file. +*/ +#define ext4_ext_mark_uninitialized (ext) ((ext)->ee_len |= \ + cpu_to_le16(0x8000)) +#define ext4_ext_is_uninitialized (ext) ((le16_to_cpu((ext)->ee_len))& \ + 0x8000) +#define ext4_ext_get_actual_len (ext) ((le16_to_cpu((ext)->ee_len))& \ + 0x7FFF) + + +/* * to be called by ext4_ext_walk_space() * negative retcode - error * positive retcode - signal for ext4_ext_walk_space(), see below
PATCH 5/5 ext4: write support for preallocated blocks/extents
In reply to Amit K. AroraThis patch adds write support for preallocated (using fallocate system call) blocks/extents. The preallocated extents in ext4 are marked "uninitialized", hence they need special handling especially while writing to them. This patch takes care of that.
--- fs/ext4/extents.c | 228 +++++++++++++++++++++++++++++++++++----- include/linux/ext4_fs_extents.h | 1 2 files changed, 202 insertions(+), 27 deletions(-)
fs/ext4/extents.c +201 -27
@@ -1141,6 +1141,51 @@ ext4_can_extents_be_merged(struct inode }/* +* ext4_ext_try_to_merge: +* tries to merge the "ex" extent to the next extent in the tree. +* It always tries to merge towards right. If you want to merge towards +* left, pass "ex - 1" as argument instead of "ex". +* Returns 0 if the extents (ex and ex+1) were _not_ merged and returns +* 1 if they got merged. +*/ +int ext4_ext_try_to_merge (struct inode *inode, +struct ext4_ext_path *path, +struct ext4_extent *ex) +{ +struct ext4_extent_header *eh; +unsigned int depth, len; +int merge_done=0 , uninitialized =0 ; + + depth =ext_depth (inode); +BUG_ON (path[depth].p_hdr ==NULL ); + eh = path[depth].p_hdr; + +while (ex <EXT_LAST_EXTENT (eh)) { +if (!ext4_can_extents_be_merged (inode, ex, ex +1 )) +break ; +/* merge with next extent! */ +if (ext4_ext_is_uninitialized (ex)) + uninitialized =1 ; + ex->ee_len =cpu_to_le16 (ext4_ext_get_actual_len (ex) + +ext4_ext_get_actual_len (ex +1 )); +if (uninitialized) +ext4_ext_mark_uninitialized (ex); + +if (ex +1 <EXT_LAST_EXTENT (eh)) { + len = (EXT_LAST_EXTENT (eh) - ex -1 ) + *sizeof (struct ext4_extent ); +memmove (ex +1 , ex +2 , len); + } + eh->eh_entries =cpu_to_le16 (le16_to_cpu (eh->eh_entries)-1 ); + merge_done =1 ; +BUG_ON (eh->eh_entries ==0 ); + } + +return merge_done; +} + + +/* * ext4_ext_check_overlap: * check if a portion of the "newext" extent overlaps with an * existing extent.
@@ -1316,25 +1361,7 @@ has_space: merge:/* try to merge extents to the right */ -while (nearex <EXT_LAST_EXTENT (eh)) { -if (!ext4_can_extents_be_merged (inode, nearex, nearex +1 )) -break ; -/* merge with next extent! */ -if (ext4_ext_is_uninitialized (nearex)) - uninitialized =1 ; - nearex->ee_len =cpu_to_le16 (ext4_ext_get_actual_len (nearex) - +ext4_ext_get_actual_len (nearex +1 )); -if (uninitialized) -ext4_ext_mark_uninitialized (nearex); - -if (nearex +1 <EXT_LAST_EXTENT (eh)) { - len = (EXT_LAST_EXTENT (eh) - nearex -1 ) - *sizeof (struct ext4_extent ); -memmove (nearex +1 , nearex +2 , len); - } - eh->eh_entries =cpu_to_le16 (le16_to_cpu (eh->eh_entries)-1 ); -BUG_ON (eh->eh_entries ==0 ); - } +ext4_ext_try_to_merge (inode, path, nearex);/* try to merge extents to the left */
@@ -1999,15 +2026,149 @@ void ext4_ext_release(struct super_block#endif } +/* +* ext4_ext_convert_to_initialized: +* this function is called by ext4_ext_get_blocks() if someone tries to write +* to an uninitialized extent. It may result in splitting the uninitialized +* extent into multiple extents (upto three). Atleast one initialized extent +* and atmost two uninitialized extents can result. +* There are three possibilities: +* a> No split required: Entire extent should be initialized. +* b> Split into two extents: Only one end of the extent is being written to. +* c> Split into three extents: Somone is writing in middle of the extent. +*/ +int ext4_ext_convert_to_initialized (handle_t *handle,struct inode *inode, +struct ext4_ext_path *path, +ext4_fsblk_t iblock, +unsigned long max_blocks) +{ +struct ext4_extent *ex, *ex1 =NULL , *ex2 =NULL , *ex3 =NULL , newex; +struct ext4_extent_header *eh; +unsigned int allocated, ee_block, ee_len, depth; +ext4_fsblk_t newblock; +int err =0 , ret =0 ; + + depth =ext_depth (inode); + eh = path[depth].p_hdr; + ex = path[depth].p_ext; + ee_block =le32_to_cpu (ex->ee_block); + ee_len =ext4_ext_get_actual_len (ex); + allocated = ee_len - (iblock - ee_block); + newblock = iblock - ee_block +ext_pblock (ex); + ex2 = ex; + +/* ex1: ee_block to iblock - 1 : uninitialized */ +if (iblock > ee_block) { + ex1 = ex; + ex1->ee_len =cpu_to_le16 (iblock - ee_block); +ext4_ext_mark_uninitialized (ex1); + ex2 = &newex; + } +/* for sanity, update the length of the ex2 extent before +* we insert ex3, if ex1 is NULL. This is to avoid temporary +* overlap of blocks. +*/ +if (!ex1 && allocated > max_blocks) + ex2->ee_len =cpu_to_le16 (max_blocks); +/* ex3: to ee_block + ee_len : uninitialised */ +if (allocated > max_blocks) { +unsigned int newdepth; + ex3 = &newex; + ex3->ee_block =cpu_to_le32 (iblock + max_blocks); +ext4_ext_store_pblock (ex3, newblock + max_blocks); + ex3->ee_len =cpu_to_le16 (allocated - max_blocks); +ext4_ext_mark_uninitialized (ex3); + err =ext4_ext_insert_extent (handle, inode, path, ex3); +if (err) + goto out; +/* The depth, and hence eh & ex might change +* as part of the insert above. +*/ + newdepth =ext_depth (inode); +if (newdepth != depth) + { + depth=newdepth; + path =ext4_ext_find_extent (inode, iblock,NULL ); +if (IS_ERR (path)) { + err =PTR_ERR (path); + path =NULL ; + goto out; + } + eh = path[depth].p_hdr; + ex = path[depth].p_ext; +if (ex2 != &newex) + ex2 = ex; + } + allocated = max_blocks; + } +/* If there was a change of depth as part of the +* insertion of ex3 above, we need to update the length +* of the ex1 extent again here +*/ +if (ex1 && ex1 != ex) { + ex1 = ex; + ex1->ee_len =cpu_to_le16 (iblock - ee_block); +ext4_ext_mark_uninitialized (ex1); + ex2 = &newex; + } +/* ex2: iblock to iblock + maxblocks-1 : initialised */ + ex2->ee_block =cpu_to_le32 (iblock); + ex2->ee_start =cpu_to_le32 (newblock); +ext4_ext_store_pblock (ex2, newblock); + ex2->ee_len =cpu_to_le16 (allocated); +if (ex2 != ex) + goto insert; +if ((err =ext4_ext_get_access (handle, inode, path + depth))) + goto out; +/* New (initialized) extent starts from the first block +* in the current extent. i.e., ex2 == ex +* We have to see if it can be merged with the extent +* on the left. +*/ +if (ex2 >EXT_FIRST_EXTENT (eh)) { +/* To merge left, pass "ex2 - 1" to try_to_merge(), +* since it merges towards right _only_. +*/ + ret =ext4_ext_try_to_merge (inode, path, ex2 -1 ); +if (ret) { + err =ext4_ext_correct_indexes (handle, inode, path); +if (err) + goto out; + depth =ext_depth (inode); + ex2--; + } + } +/* Try to Merge towards right. This might be required +* only when the whole extent is being written to. +* i.e. ex2==ex and ex3==NULL. +*/ +if (!ex3) { + ret =ext4_ext_try_to_merge (inode, path, ex2); +if (ret) { + err =ext4_ext_correct_indexes (handle, inode, path); +if (err) + goto out; + } + } +/* Mark modified extent as dirty */ + err =ext4_ext_dirty (handle, inode, path + depth); + goto out; +insert: + err =ext4_ext_insert_extent (handle, inode, path, &newex); +out: +return err ? err : allocated; +} +int ext4_ext_get_blocks (handle_t *handle,struct inode *inode,ext4_fsblk_t iblock,unsigned long max_blocks,struct buffer_head *bh_result,int create,int extend_disksize) {struct ext4_ext_path *path =NULL ; +struct ext4_extent_header *eh;struct ext4_extent newex, *ex;ext4_fsblk_t goal, newblock; -int err =0 , depth; +int err =0 , depth, ret;unsigned long allocated =0 ;__clear_bit (BH_New, &bh_result->b_state);
@@ -2055,6 +2216,7 @@ int ext4_ext_get_blocks(handle_t *handle* this is why assert can't be put in ext4_ext_find_extent() */ BUG_ON (path[depth].p_ext ==NULL && depth !=0 ); + eh = path[depth].p_hdr; ex = path[depth].p_ext;if (ex) {
@@ -2063,13 +2225,9 @@ int ext4_ext_get_blocks(handle_t *handleunsigned short ee_len;/* -* Allow future support for preallocated extents to be added -* as an RO_COMPAT feature: * Uninitialized extents are treated as holes, except that -* we avoid (fail) allocating new blocks during a write. +* we split out initialized portions during a write. */ -if (le16_to_cpu (ex->ee_len) >EXT_MAX_LEN ) - goto out2; ee_len =ext4_ext_get_actual_len (ex);/* if found extent covers block, simply return it */ if (iblock >= ee_block && iblock < ee_block + ee_len) {
@@ -2078,12 +2236,27 @@ int ext4_ext_get_blocks(handle_t *handle allocated = ee_len - (iblock - ee_block);ext_debug ("%d fit into %lu:%d -> %llu\n" , (int ) iblock, ee_block, ee_len, newblock); +/* Do not put uninitialized extent in the cache */ -if (!ext4_ext_is_uninitialized (ex)) +if (!ext4_ext_is_uninitialized (ex)) {ext4_ext_put_in_cache (inode, ee_block, ee_len, ee_start,EXT4_EXT_CACHE_EXTENT ); - goto out; + goto out; + } +if (create ==EXT4_CREATE_UNINITIALIZED_EXT ) + goto out; +if (!create) + goto out2; + + ret =ext4_ext_convert_to_initialized (handle, inode, + path, iblock, + max_blocks); +if (ret <=0 ) + goto out2; +else + allocated = ret; + goto outnew; } }
@@ -2135,6 +2308,7 @@ int ext4_ext_get_blocks(handle_t *handle/* previous routine could use block we allocated */ newblock =ext_pblock (&newex); +outnew:__set_bit (BH_New, &bh_result->b_state);/* Cache only when it is _not_ an uninitialized extent */
include/linux/ext4_fs_extents.h +1 -0
@@ -203,6 +203,7 @@ ext4_ext_invalidate_cache(struct inode *extern int ext4_extent_tree_init (handle_t *,struct inode *);extern int ext4_ext_calc_credits_for_insert (struct inode *,struct ext4_ext_path *); +extern int ext4_ext_try_to_merge (struct inode *,struct ext4_ext_path *,struct ext4_extent *);extern unsigned int ext4_ext_check_overlap (struct inode *,struct ext4_extent *,struct ext4_ext_path *);extern int ext4_ext_insert_extent (handle_t *,struct inode *,struct ext4_ext_path *,struct ext4_extent *);extern int ext4_ext_walk_space (struct inode *,unsigned long ,unsigned long ,ext_prepare_callback ,void *);
Re: [PATCH 0/5] fallocate system call
In reply to Amit K. AroraQuoted 5 lines · Amit K. Arora
Based on the discussion, this new patchset uses following as the interface for
fallocate()system call:asmlinkage long
sys_fallocate(int fd, int mode, loff_t offset, loff_t len)
Quoted 7 lines
It seems that only s390 architecture has a problem with such a layout of arguments in
fallocate(). Thus for s390, we plan to have a wrapper (say,sys_s390_fallocate()) for thesys_fallocate(), which will get called by glibc when an application issues afallocate()system call on s390. The s390 arch specific changes will be part of a separate patch (PATCH 2/5). It will be great if some s390 expert can verify the patch, since I have not been able to test it on s390 so far.
After long discussions where at least two possible implementations were suggested that would work on _all_ architectures you chose one which doesn't and causes extra effort.
Quoted 2 lines
It was also noted that minor changes might be required to strace code to take care of "different arguments on s390" issue.
This is not limited to strace...
Besides that the s390 backend looks ok.
Re: [PATCH 0/5] fallocate system call
Quoted 4 lines · Heiko Carstens
After long discussions where at least two possible implementations were suggested that would work on _all_ architectures you chose one which doesn't and causes extra effort.
I believe the long discussion also showed that every possible implementation has drawbacks. To me this one appeared to be the best of many bad choices.
Is this implementation worse than we thought?
Jörn
Signature · 3 lines
The grand essentials of happiness are: something to do, something to love, and something to hope for. -- Allan K. Chalmers
Re: [PATCH 0/5] fallocate system call
Quoted 9 lines · Jörn Engel
Quoted 4 lines · Heiko Carstens
After long discussions where at least two possible implementations were suggested that would work on _all_ architectures you chose one which doesn't and causes extra effort.
I believe the long discussion also showed that every possible implementation has drawbacks. To me this one appeared to be the best of many bad choices.
If one insists to have fd at first argument, what is wrong with having u32 arguments only? It's not that this syscall comes even close to what can be considered performance critical...
Quoted 1 line
Is this implementation worse than we thought?
It adds userspace overhead for one architecture. Every *trace and *libc needs special handling on s390 for this syscall. I would prefer to avoid this.
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/5] fallocate system call
Quoted 2 lines · Heiko Carstens
If one insists to have fd at first argument, what is wrong with having u32 arguments only?
Well, I was one of those who objected as it seems *UGLY* to me.
Quoted 2 lines
It's not that this syscall comes even close to what can be considered performance critical...
Right.
Quoted 3 lines
It adds userspace overhead for one architecture. Every *trace and *libc needs special handling on s390 for this syscall. I would prefer to avoid this.
I'm not that bothered about it. I would prefer it did use clean 64-bit arguments, but given it's a non-critical syscall I'm don't think the aesthetics are worth impossing crud on s390 for.
Re: [PATCH 0/5] fallocate system call
In reply to Amit K. AroraQuoted 4 lines · Amit K. Arora
Based on the discussion, this new patchset uses following as the interface for
fallocate()system call:asmlinkage long
sys_fallocate(int fd, int mode, loff_t offset, loff_t len)
Ok, so now for the hard questions - what are the semantics of FA_ALLOCATE and FA_DEALLOCATE?
For FA_ALLOCATE, it's supposed to change the file size if we allocate past EOF, right? What's the return value supposed to be? Zero for success, error otherwise? Does this update a/m/ctime at all? How persistent is this preallocation? Should it be there "forever" or for the lifetime of the currently open fd that it was preallocated on?
For FA_DEALLOCATE, does it change the filesize at all? Or does it just punch a hole in the file? If it does change file size, what happens when you punch out preallocation beyond EOF? What's the return value supposed to be?
Quoted 3 lines
Currently we have two modes
FA_ALLOCATEandFA_DEALLOCATE, for preallocation and deallocation of preallocated blocks respectively. More modes can be added, when required.
FWIW, we definitely need a FA_PREALLOCATE mode (FA_ALLOCATE but does not change file size) so we can preallocate beyond EOF for apps which use O_APPEND (i.e. changing file size would cause problems for them).
Quoted 4 lines
ToDos:
=====
1> Implementation on other architectures (other than i386,x86_64,
ppc64 and s390(x))
I'll have ia64 soon.
Quoted 8 lines
2> A generic file system operation to handle fallocate
(generic_fallocate), for filesystems that do _not_ have the fallocate inode operation implemented.
3> Changes to glibc,
a) to supportfallocate()system call
b) so thatposix_fallocate()andposix_fallocate64()callfallocate()system call
4> Changes to XFS to implement the fallocate inode operation
And that's what I'm doing now, hence all the questions ;)
BTW, do you have a test program for this, or will I need to write one myself?
Cheers,
Dave.
Signature · 3 lines
Dave Chinner Principal Engineer SGI Australian Software Group
PATCH 1/1 ia64 fallocate syscall
ia64 fallocate syscall support.
--- arch/ia64/kernel/entry.S | 1 + include/asm-ia64/unistd.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
arch/ia64/kernel/entry.S +1 -0
@@ -1612,5 +1612,6 @@ sys_call_table: data8 sys_vmsplice data8 sys_ni_syscall // reserved for move_pages data8 sys_getcpu + data8 sys_fallocate .org sys_call_table + 8*NR_syscalls // guard against failures to increase NR_syscalls
include/asm-ia64/unistd.h +2 -1
@@ -293,11 +293,12 @@#define __NR_vmsplice 1302/* 1303 reserved for move_pages */ #define __NR_getcpu 1304 +#define __NR_fallocate 1305#ifdef __KERNEL__ -#define NR_syscalls 281/* length of syscall table */ +#define NR_syscalls 282/* length of syscall table */ #define __ARCH_WANT_SYS_RT_SIGACTION
PATCH 1/1 XFS ->fallocate() support
In reply to David ChinnerAdd XFS support for ->fallocate() vector.
--- fs/xfs/linux-2.6/xfs_iops.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
fs/xfs/linux-2.6/xfs_iops.c +48 -0
@@ -812,6 +812,53 @@ xfs_vn_removexattr(return namesp->attr_remove (vp, attr, xflags); } +STATIC long +xfs_vn_fallocate ( +struct inode *inode, +int mode, +loff_t offset, +loff_t len) +{ +long error = -EOPNOTSUPP ; +bhv_vnode_t *vp =vn_from_inode (inode); +bhv_desc_t *bdp; +int do_setattr =0 ; +xfs_flock64_t bf; + + bf.l_whence =0 ; + bf.l_start = offset; + bf.l_len = len; + + bdp =bhv_lookup_range (VN_BHV_HEAD (vp),VNODE_POSITION_XFS , +VNODE_POSITION_XFS ); + +switch (mode) { +case FA_ALLOCATE :/* changes file size */ + error =xfs_change_file_space (bdp,XFS_IOC_RESVSP , + &bf,0 ,NULL ,0 ); +if (offset + len >i_size_read (inode)) + do_setattr = offset + len; +break ; +case FA_DEALLOCATE : +/* XXX: changes file size? this just punches a hole */ + error =xfs_change_file_space (bdp,XFS_IOC_UNRESVSP , + &bf,0 ,NULL ,0 ); +break ; +default : +break ; + } + +/* Change file size if needed */ +if (!error && do_setattr) { +bhv_vattr_t va; + + va.va_mask =XFS_AT_SIZE ; + va.va_size = do_setattr; + error =bhv_vop_setattr (vp, &va,0 ,NULL ); + } + +return error; +}struct inode_operations xfs_inode_operations = { .permission = xfs_vn_permission,
@@ -822,6 +869,7 @@ struct inode_operations xfs_inode_operat .getxattr = xfs_vn_getxattr, .listxattr = xfs_vn_listxattr, .removexattr = xfs_vn_removexattr, + .fallocate = xfs_vn_fallocate, };struct inode_operations xfs_dir_inode_operations = {
PATCH 1/1 Add preallocation beyond EOF to fallocate
In reply to David ChinnerAdd new mode to ->fallocate() to allow allocation to occur beyond the current EOF without changing the file size. Implement in XFS ->fallocate() vector.
--- fs/xfs/linux-2.6/xfs_iops.c | 8 +++++--- include/linux/fs.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-)
fs/xfs/linux-2.6/xfs_iops.c +5 -3
@@ -833,11 +833,13 @@ xfs_vn_fallocate( VNODE_POSITION_XFS);switch (mode) { -case FA_ALLOCATE :/* changes file size */ - error =xfs_change_file_space (bdp,XFS_IOC_RESVSP , - &bf,0 ,NULL ,0 ); +case FA_ALLOCATE :/* changes file size */ if (offset + len >i_size_read (inode)) do_setattr = offset + len; +/* FALL THROUGH */ +case FA_PREALLOCATE :/* no filesize change */ + error =xfs_change_file_space (bdp,XFS_IOC_RESVSP , + &bf,0 ,NULL ,0 );break ;case FA_DEALLOCATE :/* XXX: changes file size? this just punches a hole */
include/linux/fs.h +1 -0
@@ -269,6 +269,7 @@ extern int dir_notify_enable;*/ #define FA_ALLOCATE 0x1#define FA_DEALLOCATE 0x2 +#define FA_PREALLOCATE 0x3#ifdef __KERNEL__
Re: [PATCH 0/5] fallocate system call
In reply to David ChinnerQuoted 2 lines · David Chinner
For
FA_ALLOCATE, it's supposed to change the file size if we allocate past EOF, right?
I would argue no. Use truncate for that.
Quoted 1 line
For
FA_DEALLOCATE, does it change the filesize at all?
Same as above.
Quoted 2 lines
Or does
it just punch a hole in the file?
Yes.
Quoted 4 lines
FWIW, we definitely need a
FA_PREALLOCATEmode (FA_ALLOCATEbut does not change file size) so we can preallocate beyond EOF for apps which useO_APPEND(i.e. changing file size would cause problems for them).
FA_ALLOCATE should be able to allocate past-EOF I would argue.
Re: [PATCH 0/5] fallocate system call
Quoted 6 lines · Chris Wedgwood
Quoted 2 lines · David Chinner
For
FA_ALLOCATE, it's supposed to change the file size if we allocate past EOF, right?I would argue no. Use truncate for that.
I'm going from the ext4 implementation because the semantics have not been documented yet.
IIRC, the argument for FA_ALLOCATE changing file size is that posix_fallocate() is supposed to change the file size. I think that having a mode for real preallocation and another for posix_fallocate is a valid thing to do...
Note that the way XFS implements growing the file size after the allocation is via a truncate....
Quoted 8 lines
Quoted 1 line
For
FA_DEALLOCATE, does it change the filesize at all?Same as above.
Quoted 2 lines
Or does
it just punch a hole in the file?Yes.
That's would what I did because otherwise you'd use ftruncate64(). Without documented behaviour or an ext4 implementation, I have to ask what it's supposed to do, though ;)
Cheers,
Dave.
Signature · 3 lines
Dave Chinner Principal Engineer SGI Australian Software Group
Re: [PATCH 0/5] fallocate system call
Quoted 4 lines · David Chinner
On Sun, Apr 29, 2007 at 10:25:59PM -0700, Chris Wedgwood wrote:
IIRC, the argument for
FA_ALLOCATEchanging file size is thatposix_fallocate()is supposed to change the file size.
But it's not posix_fallocate; it's something more generic. glibc can do posix_fallocate using truncate + fallocate.
Quoted 2 lines
Note that the way XFS implements growing the file size after the allocation is via a truncate....
What's wrong with that? That seems very reasonable.
Quoted 3 lines
That's would what I did because otherwise you'd use
ftruncate64(). Without documented behaviour or an ext4 implementation, I have to ask what it's supposed to do, though ;)
How many *real* users are there for ext4? Why does 'what ext4 does' define 'the semantics'?
Surely semantics should be decided either by precedent (if there is an existing relevant userbase) or sensible thought and some debate?
Re: [PATCH 0/5] fallocate system call
In reply to Chris WedgwoodQuoted 6 lines · Chris Wedgwood
Quoted 2 lines · David Chinner
For
FA_ALLOCATE, it's supposed to change the file size if we allocate past EOF, right?I would argue no. Use truncate for that.
The patch I posted for ext4 *does* change the filesize after preallocation, if required (i.e. when preallocation is after EOF). I may have to change that, if we decide on not doing this.
--
Regards,
Amit Arora
Re: [PATCH 0/5] fallocate system call
Quoted 11 lines · Amit K. Arora
Quoted 6 lines · Chris Wedgwood
Quoted 2 lines · David Chinner
For
FA_ALLOCATE, it's supposed to change the file size if we allocate past EOF, right?I would argue no. Use truncate for that.
The patch I posted for ext4 *does* change the filesize after preallocation, if required (i.e. when preallocation is after EOF). I may have to change that, if we decide on not doing this.
I think I'd agree - it may be useful to allow preallocation beyond EOF for some kinds of applications (e.g. PVR preallocating live TV in 10 minute segments or something, but not knowing in advance how long the show will actually be recorded or the final encoded size).
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Re: [PATCH 0/5] fallocate system call
In article <[email protected]> you write:
Quoted 9 lines · Amit K. Arora
Quoted 8 lines · Chris Wedgwood
Quoted 6 lines · David Chinner
Quoted 3 lines
For
FA_ALLOCATE, it's supposed to change the file size if we allocate past EOF, right?I would argue no. Use truncate for that.
Quoted 8 lines
Quoted 3 lines
The patch I posted for ext4 *does* change the filesize after preallocation, if required (i.e. when preallocation is after EOF). I may have to change that, if we decide on not doing this.
I think I'd agree - it may be useful to allow preallocation beyond EOF for some kinds of applications (e.g. PVR preallocating live TV in 10 minute segments or something, but not knowing in advance how long the show will actually be recorded or the final encoded size).
I have an application (diablo dreader) where the header-info database basically consists of ~40.000 files, one for each group (it's more complicated that that, but never mind that now).
If you grow those files randomly by a few hundred bytes every update, the filesystem gets hopelessly fragmented.
I'm using XFS with preallocation turned on, and biosize=18 (which makes it preallocate in blocks of 256KB), and a homebrew patch that leaves the preallocated space on disk preallocated even if the file is closed .. and it helps enormously.
Mike.
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Amit K. AroraQuoted 6 lines · On Thu, 26 Apr 2007 23:33:32 +0530 "Amit K. Arora" <[email protected]>…
This patch implements the
fallocate()system call and adds support for i386,x86_64and powerpc....
+asmlinkage long
sys_fallocate(int fd, int mode, loff_t offset, loff_t len)
Please add a comment over this function which specifies its behaviour. Really it should be enough material from which a full manpage can be written.
If that's all too much, this material should at least be spelled out in the changelog. Because there's no way in which this change can be fully reviewed unless someone (ie: you) tells us what it is setting out to achieve.
If we 100% implement some standard then a URL for what we claim to implement would suffice. Given that we're at least using different types from posix I doubt if such a thing would be sufficient.
And given the complexity and potential variability within the filesystem implementations of this, I'd expect that _something_ additional needs to be said?
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 360
Quoted 7 lines
fs/open.c +7
-0+{ +struct file *file; +struct inode *inode; +long ret = -EINVAL ; + +if (len ==0 || offset <0 ) + goto out;
The posix spec implies that negative len' is permitted - presumably "allocate ahead of offset'". How peculiar.
Quoted 6 lines
fs/open.c +6
-0+ ret = -EBADF ; + file =fget (fd); +if (!file) + goto out; +if (!(file->f_mode &FMODE_WRITE )) + goto out_fput;
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 377
Quoted 10 lines
fs/open.c +10
-0+ + inode = file->f_path.dentry->d_inode; + + ret = -ESPIPE ; +if (S_ISFIFO (inode->i_mode)) + goto out_fput; + + ret = -ENODEV ; +if (!S_ISREG (inode->i_mode)) + goto out_fput;
So we return ENODEV against an S_ISBLK fd, as per the posix spec. That seems a bit silly of them.
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 381
Quoted 3 lines
fs/open.c +3
-0+ ret = -EFBIG ; +if (offset + len > inode->i_sb->s_maxbytes) + goto out_fput;
This code does handle offset+len going negative, but only by accident, I suspect. It happens that s_maxbytes has unsigned type. Perhaps a comment here would settle the reader's mind.
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 386
Quoted 4 lines
fs/open.c +4
-0+if (inode->i_op && inode->i_op->fallocate) + ret = inode->i_op->fallocate (inode, mode, offset, len); +else + ret = -ENOSYS ;
If we _are_ going to support negative len', as posix suggests, I think we should perform the appropriate sanity conversions to offset' and `len' right here, rather than expecting each filesystem to do it.
If we're not going to handle negative `len' then we should check for it.
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 392
Quoted 6 lines
fs/open.c +6
-0+out_fput: +fput (file); +out: +return ret; +} +EXPORT_SYMBOL (sys_fallocate);
I don't believe this needs to be exported to modules?
include/linux/fs.h extern int dir_notify_enable; · line 271
Quoted 5 lines
include/linux/fs.h +5
-0+/* +* fallocate() modes +*/ +#define FA_ALLOCATE 0x1 +#define FA_DEALLOCATE 0x2
Now those aren't in posix. They should be documented, along with their expected semantics.
include/linux/fs.h struct inode_operations { · line 1134
Quoted 8 lines
#ifdef
__KERNEL__#include <
linux/linkage.h>include/linux/fs.h +1
-0@@ -1125,6 +1131,7 @@ struct inode_operations {ssize_t (*listxattr) (struct dentry *,char *,size_t );int (*removexattr) (struct dentry *,const char *);void (*truncate_range)(struct inode *,loff_t ,loff_t ); +long (*fallocate)(struct inode *,int ,loff_t ,loff_t );
I really do think it's better to put the variable names in definitions such as this. Especially when we have two identically-typed variables next to each other like that. Quick: which one is the offset and which is the length?
Re: [PATCH 3/5] ext4: Extent overlap bugfix
In reply to Amit K. AroraQuoted 13 lines · On Thu, 26 Apr 2007 23:41:01 +0530 "Amit K. Arora" <[email protected]>…
fs/ext4/extents.c +13
-0+unsigned int ext4_ext_check_overlap (struct inode *inode, +struct ext4_extent *newext, +struct ext4_ext_path *path) +{ +unsigned long b1, b2; +unsigned int depth, len1; + + b1 =le32_to_cpu (newext->ee_block); + len1 =le16_to_cpu (newext->ee_len); + depth =ext_depth (inode); +if (!path[depth].p_ext) + goto out; + b2 =le32_to_cpu (path[depth].p_ext->ee_block);
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode · line 1162
Quoted 10 lines
fs/ext4/extents.c +10
-0+ +/* get the next allocated block if the extent in the path +* is before the requested block(s) */ +if (b2 < b1) { + b2 =ext4_ext_next_allocated_block (path); +if (b2 ==EXT_MAX_BLOCK ) + goto out; + } + +if (b1 + len1 > b2) {
Are we sure that b1+len cannot wrap through zero here?
Quoted 3 lines
fs/ext4/extents.c +3
-0+ newext->ee_len =cpu_to_le16 (b2 - b1); +return 1 ; + }
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Amit K. Arorafs/ext4/extents.c int ext4_ext_insert_extent(handle_t *han · line 1216
Quoted 8 lines · On Thu, 26 Apr 2007 23:43:32 +0530 "Amit K. Arora" <[email protected]>…
This patch has the ext4 implemtation of fallocate system call.
...
fs/ext4/extents.c +4
-0+/* ext4_can_extents_be_merged should have checked that either +* both extents are uninitialized, or both aren't. Thus we +* need to check only one of them here. +*/
Please always format multiline comments like this:
/*
* ext4_can_extents_be_merged should have checked that either
* both extents are uninitialized, or both aren't. Thus we
* need to check only one of them here.
*/
Quoted 7 lines
...
+/*
+ *ext4_fallocate:
+ * preallocate space for a file
+ * mode is for future use, e.g. for unallocating preallocated blocks etc.
+ */
This description is rather thin. What is the filesystem's actual behaviour here? If the file is using extents then the implementation will do <something>. If the file is using bitmaps then we will do <something else>.
But what? Here is where it should be described.
Quoted 4 lines
fs/ext4/extents.c +4
-0+int ext4_fallocate (struct inode *inode,int mode,loff_t offset,loff_t len) +{ +handle_t *handle; +ext4_fsblk_t block, max_blocks;
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2265
Quoted 10 lines
fs/ext4/extents.c +10
-0+int ret, ret2, nblocks =0 , retries =0 ; +struct buffer_head map_bh; +unsigned int credits, blkbits = inode->i_blkbits; + +/* Currently supporting (pre)allocate mode _only_ */ +if (mode !=FA_ALLOCATE ) +return -EOPNOTSUPP ; + +if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) +return -ENOTTY ;
So we don't implement fallocate on bitmap-based files! Well that's huge news. The changelog would be an appropriate place to communicate this, along with reasons why, or a description of the plan to fix it.
Also, posix says nothing about fallocate() returning ENOTTY.
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2272
Quoted 6 lines
fs/ext4/extents.c +6
-0+ block = offset >> blkbits; + max_blocks = (EXT4_BLOCK_ALIGN (len + offset, blkbits) >> blkbits) + - block; +mutex_lock (&EXT4_I (inode)->truncate_mutex); + credits =ext4_ext_calc_credits_for_insert (inode,NULL ); +mutex_unlock (&EXT4_I (inode)->truncate_mutex);
Now I'm mystified. Given that we're allocating an arbitrary amount of disk space, and that this disk space will require an arbitrary amount of metadata, how can we work out how much journal space we'll be needing without at least looking at `len'?
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2273
Quoted 1 line
fs/ext4/extents.c +1
-0+ handle=ext4_journal_start(inode, credits +
Please always put spaces around "="
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2274
Quoted 1 line
fs/ext4/extents.c +1
-0+ EXT4_DATA_TRANS_BLOCKS(inode->i_sb)+1);
And around "+"
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2285
Quoted 11 lines
fs/ext4/extents.c +11
-0+if (IS_ERR (handle)) +return PTR_ERR (handle); +retry: + ret =0 ; +while (ret >=0 && ret < max_blocks) { + block = block + ret; + max_blocks = max_blocks - ret; + ret =ext4_ext_get_blocks (handle, inode, block, + max_blocks, &map_bh, +EXT4_CREATE_UNINITIALIZED_EXT ,0 ); +BUG_ON (!ret);
BUG_ON is vicious. Is it really justified here? Possibly a WARN_ON and ext4_error() would be safer and more useful here.
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2286
Quoted 1 line
fs/ext4/extents.c +1
-0+ if (ret > 0 && test_bit(BH_New, &map_bh.b_state)
Use buffer_new() here. A separate patch which fixes the three existing
instances of open-coded BH_foo usage would be appreciated.
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2287
Quoted 1 line
fs/ext4/extents.c +1
-0+ && ((block + ret) > (i_size_read(inode) << blkbits)))
Check for wrap though the sign bit and through zero please.
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2296
Quoted 9 lines
fs/ext4/extents.c +9
-0+ nblocks = nblocks + ret; + } + +if (ret == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) + goto retry; + +/* Time to update the file size. +* Update only when preallocation was requested beyond the file size. +*/
Fix comment layout.
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2297
Quoted 1 line
fs/ext4/extents.c +1
-0+if ((offset + len) >i_size_read (inode)) {
Both the lhs and the rhs here are signed. Please review for possible overflows through the sign bit and through zero. Perhaps a comment explaining why it's correct would be appropriate.
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2305
Quoted 8 lines
fs/ext4/extents.c +8
-0+if (ret >0 ) { +/* if no error, we assume preallocation succeeded completely */ +mutex_lock (&inode->i_mutex); +i_size_write (inode, offset + len); +EXT4_I (inode)->i_disksize =i_size_read (inode); +mutex_unlock (&inode->i_mutex); + }else if (ret <0 && nblocks) { +/* Handle partial allocation scenario */
The above two comments should be indented one additional tabstop.
Quoted 40 lines
fs/ext4/extents.c +17
-0+loff_t newsize; +mutex_lock (&inode->i_mutex); + newsize = (nblocks << blkbits) +i_size_read (inode); +i_size_write (inode,EXT4_BLOCK_ALIGN (newsize, blkbits)); +EXT4_I (inode)->i_disksize =i_size_read (inode); +mutex_unlock (&inode->i_mutex); + } + } +ext4_mark_inode_dirty (handle, inode); + ret2 =ext4_journal_stop (handle); +if (ret >0 ) + ret = ret2; + +return ret >0 ?0 : ret; +} +EXPORT_SYMBOL (ext4_mark_inode_dirty);EXPORT_SYMBOL (ext4_ext_invalidate_cache);EXPORT_SYMBOL (ext4_ext_insert_extent);EXPORT_SYMBOL (ext4_ext_walk_space);EXPORT_SYMBOL (ext4_ext_find_goal);EXPORT_SYMBOL (ext4_ext_calc_credits_for_insert); +EXPORT_SYMBOL (ext4_fallocate);Index:
linux-2.6.21/fs/ext4/file.c
===================================================================fs/ext4/file.c +1
-0@@ -135,5 +135,6 @@ const struct inode_operations ext4_file_ .removexattr = generic_removexattr, #endif .permission = ext4_permission, + .fallocate = ext4_fallocate, };Index:
linux-2.6.21/include/linux/ext4_fs.h
===================================================================
include/linux/ext4_fs.h line 106
Quoted 5 lines
include/linux/ext4_fs.h +2
-0@@ -102,6 +102,8 @@ EXT4_GOOD_OLD_FIRST_INO : \ (s)->s_first_ino)#endif +#define EXT4_BLOCK_ALIGN (size, blkbits) (((size)+(1 << blkbits)-1) & \ + (~((1 << blkbits)-1)))
Maybe a comment describing what this does? Probably it's obvious enough.
I think it could use the standard ALIGN macro.
Is blkbits sufficiently parenthesised here? Even if it is, adding the parens would be better practice.
include/linux/ext4_fs.h struct ext4_new_group_data { · line 232
Quoted 9 lines
include/linux/ext4_fs.h +3
-0/* * Macro-instructions used to manage fragments @@ -225,6 +227,10 @@ struct ext4_new_group_data {__u32 free_blocks_count; }; +/* Following is used by preallocation logic to tell get_blocks() that we +* want uninitialzed extents. +*/
Please convert all newly-added multiline comments to the preferred layout.
include/linux/ext4_fs.h extern int ext4_ext_get_blocks(handle_t · line 985
Quoted 9 lines
include/linux/ext4_fs.h +2
-0+#define EXT4_CREATE_UNINITIALIZED_EXT 2/* * ioctl commands @@ -976,6 +982,7 @@ extern int ext4_ext_get_blocks(handle_textern void ext4_ext_truncate (struct inode *,struct page *);extern void ext4_ext_init (struct super_block *);extern void ext4_ext_release (struct super_block *); +extern int ext4_fallocate (struct inode *,int ,loff_t ,loff_t );
argh. And feel free to give these args some useful names.
Quoted 11 lines
include/linux/ext4_fs.h +0
-0static inline int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, unsigned long max_blocks, struct buffer_head *bh,Index:
linux-2.6.21/include/linux/ext4_fs_extents.h
===================================================================include/linux/ext4_fs_extents.h +0
-0@@ -125,6 +125,19 @@ struct ext4_ext_path {#define EXT4_EXT_CACHE_EXTENT 2/*
include/linux/ext4_fs_extents.h struct ext4_ext_path { · line 137
Quoted 10 lines
include/linux/ext4_fs_extents.h +10
-0+* Macro-instructions to handle (mark/unmark/check/create) unitialized +* extents. Applications can issue an IOCTL for preallocation, which results +* in assigning unitialized extents to the file. +*/ +#define ext4_ext_mark_uninitialized (ext) ((ext)->ee_len |= \ + cpu_to_le16(0x8000)) +#define ext4_ext_is_uninitialized (ext) ((le16_to_cpu((ext)->ee_len))& \ + 0x8000) +#define ext4_ext_get_actual_len (ext) ((le16_to_cpu((ext)->ee_len))& \ + 0x7FFF)
inlined C functions are preferred, and I think these could be implemented that way.
Re: [PATCH 5/5] ext4: write support for preallocated blocks/extents
In reply to Amit K. AroraQuoted 7 lines · On Thu, 26 Apr 2007 23:46:23 +0530 "Amit K. Arora" <[email protected]>…
This patch adds write support for preallocated (using fallocate system call) blocks/extents. The preallocated extents in ext4 are marked "uninitialized", hence they need special handling especially while writing to them. This patch takes care of that.
...
Quoted 7 lines
/*
+ *ext4_ext_try_to_merge:
+ * tries to merge the "ex" extent to the next extent in the tree.
+ * It always tries to merge towards right. If you want to merge towards
+ * left, pass "ex - 1" as argument instead of "ex".
+ * Returns 0 if the extents (ex and ex+1) were _not_ merged and returns
+ * 1 if they got merged.
OK.
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode · line 1157
Quoted 8 lines
+ */
fs/ext4/extents.c +7
-0+int ext4_ext_try_to_merge (struct inode *inode, +struct ext4_ext_path *path, +struct ext4_extent *ex) +{ +struct ext4_extent_header *eh; +unsigned int depth, len; +int merge_done=0 , uninitialized =0 ;
space around "=", please.
Many people prefer not to do the multiple-definitions-per-line, btw:
int merge_done = 0; int uninitialized = 0;
reasons:
- If gives you some space for a nice comment
- It makes patches much more readable, and it makes rejects easier to fix
- standardisation.
Quoted 11 lines
fs/ext4/extents.c +11
-0+ depth =ext_depth (inode); +BUG_ON (path[depth].p_hdr ==NULL ); + eh = path[depth].p_hdr; + +while (ex <EXT_LAST_EXTENT (eh)) { +if (!ext4_can_extents_be_merged (inode, ex, ex +1 )) +break ; +/* merge with next extent! */ +if (ext4_ext_is_uninitialized (ex)) + uninitialized =1 ; + ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex)
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode · line 1179
Quoted 10 lines
fs/ext4/extents.c +10
-0+ + ext4_ext_get_actual_len(ex + 1)); +if (uninitialized) +ext4_ext_mark_uninitialized (ex); + +if (ex +1 <EXT_LAST_EXTENT (eh)) { + len = (EXT_LAST_EXTENT (eh) - ex -1 ) + *sizeof (struct ext4_extent ); +memmove (ex +1 , ex +2 , len); + } + eh->eh_entries =cpu_to_le16 (le16_to_cpu (eh->eh_entries)-1 );
Kenrel convention is to put spaces around "-"
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode · line 1181
Quoted 2 lines
fs/ext4/extents.c +2
-0+ merge_done =1 ; +BUG_ON (eh->eh_entries ==0 );
eek, scary BUG_ON. Do we really need to be that severe? Would it be better to warn and run ext4_error() here?
Quoted 5 lines
fs/ext4/extents.c +5
-0+ } + +return merge_done; +} +
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode
Quoted 10 lines
fs/ext4/extents.c +7
-0+ +/* +* ext4_ext_convert_to_initialized: +* this function is called by ext4_ext_get_blocks() if someone tries to write +* to an uninitialized extent. It may result in splitting the uninitialized +* extent into multiple extents (upto three). Atleast one initialized extent +* and atmost two uninitialized extents can result.
There are some typos here
Quoted 4 lines
+ * There are three possibilities:
+ * a> No split required: Entire extent should be initialized. + * b> Split into two extents: Only one end of the extent is being written to. + * c> Split into three extents: Somone is writing in middle of the extent.
and here
Quoted 41 lines
+ */
fs/ext4/extents.c +40
-0+int ext4_ext_convert_to_initialized (handle_t *handle,struct inode *inode, +struct ext4_ext_path *path, +ext4_fsblk_t iblock, +unsigned long max_blocks) +{ +struct ext4_extent *ex, *ex1 =NULL , *ex2 =NULL , *ex3 =NULL , newex; +struct ext4_extent_header *eh; +unsigned int allocated, ee_block, ee_len, depth; +ext4_fsblk_t newblock; +int err =0 , ret =0 ; + + depth =ext_depth (inode); + eh = path[depth].p_hdr; + ex = path[depth].p_ext; + ee_block =le32_to_cpu (ex->ee_block); + ee_len =ext4_ext_get_actual_len (ex); + allocated = ee_len - (iblock - ee_block); + newblock = iblock - ee_block +ext_pblock (ex); + ex2 = ex; + +/* ex1: ee_block to iblock - 1 : uninitialized */ +if (iblock > ee_block) { + ex1 = ex; + ex1->ee_len =cpu_to_le16 (iblock - ee_block); +ext4_ext_mark_uninitialized (ex1); + ex2 = &newex; + } +/* for sanity, update the length of the ex2 extent before +* we insert ex3, if ex1 is NULL. This is to avoid temporary +* overlap of blocks. +*/ +if (!ex1 && allocated > max_blocks) + ex2->ee_len =cpu_to_le16 (max_blocks); +/* ex3: to ee_block + ee_len : uninitialised */ +if (allocated > max_blocks) { +unsigned int newdepth; + ex3 = &newex; + ex3->ee_block =cpu_to_le32 (iblock + max_blocks); +ext4_ext_store_pblock (ex3, newblock + max_blocks); + ex3->ee_len =cpu_to_le16 (allocated - max_blocks);
fs/ext4/extents.c void ext4_ext_release(struct super_block · line 2089
Quoted 10 lines
fs/ext4/extents.c +10
-0+ext4_ext_mark_uninitialized (ex3); + err =ext4_ext_insert_extent (handle, inode, path, ex3); +if (err) + goto out; +/* The depth, and hence eh & ex might change +* as part of the insert above. +*/ + newdepth =ext_depth (inode); +if (newdepth != depth) + {
Use
if (newdepth != depth) {fs/ext4/extents.c void ext4_ext_release(struct super_block · line 2090
Quoted 1 line
fs/ext4/extents.c +1
-0+ depth=newdepth;
spaces
Quoted 22 lines
fs/ext4/extents.c +22
-0+ path =ext4_ext_find_extent (inode, iblock,NULL ); +if (IS_ERR (path)) { + err =PTR_ERR (path); + path =NULL ; + goto out; + } + eh = path[depth].p_hdr; + ex = path[depth].p_ext; +if (ex2 != &newex) + ex2 = ex; + } + allocated = max_blocks; + } +/* If there was a change of depth as part of the +* insertion of ex3 above, we need to update the length +* of the ex1 extent again here +*/ +if (ex1 && ex1 != ex) { + ex1 = ex; + ex1->ee_len =cpu_to_le16 (iblock - ee_block); +ext4_ext_mark_uninitialized (ex1); + ex2 = &newex;
fs/ext4/extents.c void ext4_ext_release(struct super_block · line 2122
Quoted 10 lines
fs/ext4/extents.c +10
-0+ } +/* ex2: iblock to iblock + maxblocks-1 : initialised */ + ex2->ee_block =cpu_to_le32 (iblock); + ex2->ee_start =cpu_to_le32 (newblock); +ext4_ext_store_pblock (ex2, newblock); + ex2->ee_len =cpu_to_le16 (allocated); +if (ex2 != ex) + goto insert; +if ((err =ext4_ext_get_access (handle, inode, path + depth))) + goto out;
The preferred style is
err = ext4_ext_get_access(handle, inode, path + depth); if (err) goto out;
Quoted 28 lines
fs/ext4/extents.c +28
-0+/* New (initialized) extent starts from the first block +* in the current extent. i.e., ex2 == ex +* We have to see if it can be merged with the extent +* on the left. +*/ +if (ex2 >EXT_FIRST_EXTENT (eh)) { +/* To merge left, pass "ex2 - 1" to try_to_merge(), +* since it merges towards right _only_. +*/ + ret =ext4_ext_try_to_merge (inode, path, ex2 -1 ); +if (ret) { + err =ext4_ext_correct_indexes (handle, inode, path); +if (err) + goto out; + depth =ext_depth (inode); + ex2--; + } + } +/* Try to Merge towards right. This might be required +* only when the whole extent is being written to. +* i.e. ex2==ex and ex3==NULL. +*/ +if (!ex3) { + ret =ext4_ext_try_to_merge (inode, path, ex2); +if (ret) { + err =ext4_ext_correct_indexes (handle, inode, path); +if (err) + goto out;
fs/ext4/extents.c void ext4_ext_release(struct super_block · line 2160
Quoted 10 lines
fs/ext4/extents.c +10
-0+ } + } +/* Mark modified extent as dirty */ + err =ext4_ext_dirty (handle, inode, path + depth); + goto out; +insert: + err =ext4_ext_insert_extent (handle, inode, path, &newex); +out: +return err ? err : allocated; +}
Sigh. I hope you guys know how all this works, because the extent code is a mystery to me. Is the on-disk layout and the allocation strategy described anywhere?
Quoted 1 line
+extern int
ext4_ext_try_to_merge(struct inode *, struct ext4_ext_path *, struct ext4_extent *);
Again, I do think that sticking the identifiers in there helps readability. Although it is not as important in a boring old declaration as it is in, say, inode_operations, etc.
Please try to keep the code looking nice in an 80-column display.
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Andrew MortonQuoted 5 lines · Andrew Morton
Quoted 3 lines · On Thu, 26 Apr 2007 23:33:32 +0530 "Amit K. Arora" <[email protected]>…
This patch implements the
fallocate()system call and adds support for i386,x86_64and powerpc.
Quoted 7 lines
Quoted 3 lines
...
+asmlinkage long
sys_fallocate(int fd, int mode, loff_t offset, loff_t len)Please add a comment over this function which specifies its behaviour. Really it should be enough material from which a full manpage can be written.
This looks like it will have the same problem on s390 as sys_sync_file_range. Maybe the prototype should be:
asmlinkage long sys_fallocate(loff_t offset, loff_t len, int fd, int mode)
Paul.
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Andrew MortonQuoted 6 lines · On Thu, 3 May 2007 21:29:55 -0700 Andrew Morton <[email protected]>…
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 381
Quoted 3 lines
fs/open.c +3
-0+ ret = -EFBIG ; +if (offset + len > inode->i_sb->s_maxbytes) + goto out_fput;This code does handle offset+len going negative, but only by accident, I suspect.
But it doesn't handle offset+len wrapping through zero.
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Andrew MortonQuoted 5 lines · Andrew Morton
Quoted 3 lines · On Thu, 26 Apr 2007 23:33:32 +0530 "Amit K. Arora" <[email protected]>…
This patch implements the
fallocate()system call and adds support for i386,x86_64and powerpc.
Quoted 11 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 360
Quoted 8 lines
...
fs/open.c +7
-0+{ +struct file *file; +struct inode *inode; +long ret = -EINVAL ; + +if (len ==0 || offset <0 ) + goto out;The posix spec implies that negative
len' is permitted - presumably "allocate ahead ofoffset'". How peculiar.
I just checked the man page for posix_fallocate() and it says:
EINVAL offset or len was less than zero.
We should probably follow this lead.
Quoted 7 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 377
Quoted 4 lines
fs/open.c +4
-0+ + ret = -ENODEV ; +if (!S_ISREG (inode->i_mode)) + goto out_fput;So we return ENODEV against an
S_ISBLKfd, as per the posix spec. That seems a bit silly of them.
Hmmmm - I thought that the intention of sys_fallocate() was to be generic enough to eventually allow preallocation on directories. If that is the case, then this check will prevent that....
Cheers,
Dave.
Signature · 3 lines
Dave Chinner Principal Engineer SGI Australian Software Group
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
Quoted 18 lines · On Fri, 4 May 2007 16:07:31 +1000 David Chinner <[email protected]> wrote:
Quoted 5 lines · Andrew Morton
Quoted 3 lines · On Thu, 26 Apr 2007 23:33:32 +0530 "Amit K. Arora" <[email protected]>…
This patch implements the
fallocate()system call and adds support for i386,x86_64and powerpc.Quoted 11 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 360
Quoted 8 lines
...
fs/open.c +7
-0+{ +struct file *file; +struct inode *inode; +long ret = -EINVAL ; + +if (len ==0 || offset <0 ) + goto out;The posix spec implies that negative
len' is permitted - presumably "allocate ahead ofoffset'". How peculiar.
Quoted 5 lines
I just checked the man page for
posix_fallocate()and it says:EINVAL offset or len was less than zero.
We should probably follow this lead.
Yes, I think so. I'm suspecting that
http://www.opengroup.org/onlinepubs/009695399/functions/posix_fallocate.html
is just buggy. Or I can't read.
I mean, if we're going to support negative len' then is the byte at offset' inside or outside the segment? Head spins.
However it would be neat if someone could test $OTHER_OS and, perhaps more importantly, the present glibc emulation (which I assume your manpage is referring to, so this would be a manpage test ;)).
Quoted 11 lines
Quoted 7 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 377
Quoted 4 lines
fs/open.c +4
-0+ + ret = -ENODEV ; +if (!S_ISREG (inode->i_mode)) + goto out_fput;So we return ENODEV against an
S_ISBLKfd, as per the posix spec. That seems a bit silly of them.Hmmmm - I thought that the intention of
sys_fallocate()was to be generic enough to eventually allow preallocation on directories. If that is the case, then this check will prevent that....
The above opengroup page only permits S_ISREG. Preallocating directories sounds quite useful to me, although it's something which would be pretty hard to emulate if the FS doesn't support it. And there's a decent case to be made for emulating it - run-anywhere reasons. Does glibc emulation support directories? Quite unlikely.
But yes, sounds like a desirable thing. Would XFS support it easily if the above check was relaxed?
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
Quoted 6 lines · Andrew Morton
Quoted 6 lines
Quoted 2 lines
The posix spec implies that negative
len' is permitted - presumably "allocate ahead ofoffset'". How peculiar.I just checked the man page for
posix_fallocate()and it says:EINVAL offset or len was less than zero.
That describes the current glibc implementation.
Quoted 6 lines
Quoted 1 line
We should probably follow this lead.
Yes, I think so. I'm suspecting that
http://www.opengroup.org/onlinepubs/009695399/functions/posix_fallocate.html
is just buggy. Or I can't read.
Quoted 6 lines
I mean, if we're going to support negative
len' then is the byte atoffset' inside or outside the segment? Head spins.However it would be neat if someone could test $OTHER_OS and, perhaps more importantly, the present glibc emulation (which I assume your manpage is referring to, so this would be a manpage test ;)).
intposix_fallocate (int fd, __off_t offset, __off_t len) {
struct stat64 st;
struct statfs f;
/* `off_t' is a signed type. Therefore we can determine whether
OFFSET + LEN is too large if it is a negative value. */
if (offset < 0 || len < 0)
return EINVAL;
if (offset + len < 0)
return EFBIG;/* First thing we have to make sure is that this is really a regular
file. */
if (__fxstat64 (_STAT_VER, fd, &st) != 0)
return EBADF;
if (S_ISFIFO (st.st_mode))
return ESPIPE;
if (! S_ISREG (st.st_mode))
return ENODEV; if (len == 0)
{
if (st.st_size < offset)
{
int ret = __ftruncate (fd, offset); if (ret != 0)
ret = errno;
return ret;
}
return 0;
}...
is what glibc does ATM. Seems we violate the case where len == 0, as EINVAL in that case is "shall fail". But reading the standard to imply negative len is ok is too much guessing, there is no word what it means when len is negative and
"required storage for regular file data starting at offset and continuing for len bytes" doesn't make sense for negative size.
And given the general
"Implementations may support additional errors not included in this list, may generate errors included in this list under circumstances other than those described here, or may contain extensions or limitations that prevent some errors from occurring."
I believe returning EINVAL for len < 0 is not a POSIX violation.
That doesn't mean the standard shouldn't be clarified, whether by saying EINVAL must be returned for non-positive len or saying that using negative len has undefined or implementation defined behavior.
Quoted 5 lines
The above opengroup page only permits
S_ISREG. Preallocating directories sounds quite useful to me, although it's something which would be pretty hard to emulate if the FS doesn't support it. And there's a decent case to be made for emulating it - run-anywhere reasons. Does glibc emulation support directories? Quite unlikely.
No, see above.
Jakub
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Andrew MortonQuoted 23 lines · Andrew Morton
Quoted 22 lines · On Fri, 4 May 2007 16:07:31 +1000 David Chinner <[email protected]> wrote:
Quoted 5 lines · Andrew Morton
Quoted 3 lines · On Thu, 26 Apr 2007 23:33:32 +0530 "Amit K. Arora" <[email protected]>…
This patch implements the
fallocate()system call and adds support for i386,x86_64and powerpc.Quoted 11 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 360
Quoted 8 lines
...
fs/open.c +7
-0+{ +struct file *file; +struct inode *inode; +long ret = -EINVAL ; + +if (len ==0 || offset <0 ) + goto out;The posix spec implies that negative
len' is permitted - presumably "allocate ahead ofoffset'". How peculiar.I just checked the man page for
posix_fallocate()and it says:EINVAL offset or len was less than zero.
Quoted 8 lines
Quoted 1 line
We should probably follow this lead.
Yes, I think so. I'm suspecting that
http://www.opengroup.org/onlinepubs/009695399/functions/posix_fallocate.html
is just buggy. Or I can't read.I mean, if we're going to support negative
len' then is the byte atoffset' inside or outside the segment? Head spins.
I don't think we should care. If we provide a syscall with the semantics of "allocate from offset to offset+len" then glibc's implementation can turn negative length into two separate fallocate syscalls....
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 377
Quoted 3 lines
fs/open.c +3
-0+ ret = -ENODEV ; +if (!S_ISREG (inode->i_mode)) + goto out_fput;So we return ENODEV against an
S_ISBLKfd, as per the posix spec. That seems a bit silly of them.Hmmmm - I thought that the intention of
sys_fallocate()was to be generic enough to eventually allow preallocation on directories. If that is the case, then this check will prevent that....
Quoted 8 lines
The above opengroup page only permits
S_ISREG. Preallocating directories sounds quite useful to me, although it's something which would be pretty hard to emulate if the FS doesn't support it. And there's a decent case to be made for emulating it - run-anywhere reasons. Does glibc emulation support directories? Quite unlikely.But yes, sounds like a desirable thing. Would XFS support it easily if the above check was relaxed?
No - right now empty blocks are pruned from the directory immediately so I don't think we really have a concept of empty blocks in the btree structure. dir2 is bloody complex, so adding preallocation is probably not going to be simple to do.
It's not high on my list to add, either, because we can typically avoid the worst case directory fragmentation by using larger directory block sizes (e.g. 16k instead of the default 4k on a 4k block size fs).
IIRC directory preallocation has been talked about more for ext3/4....
Cheers,
Dave.
Signature · 3 lines
Dave Chinner Principal Engineer SGI Australian Software Group
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Andrew MortonAndrew,
Thanks for the review comments!
Quoted 18 lines · Andrew Morton
Quoted 6 lines · On Thu, 26 Apr 2007 23:33:32 +0530 "Amit K. Arora" <[email protected]>…
This patch implements the
fallocate()system call and adds support for i386,x86_64and powerpc....
+asmlinkage long
sys_fallocate(int fd, int mode, loff_t offset, loff_t len)Please add a comment over this function which specifies its behaviour. Really it should be enough material from which a full manpage can be written.
If that's all too much, this material should at least be spelled out in the changelog. Because there's no way in which this change can be fully reviewed unless someone (ie: you) tells us what it is setting out to achieve.
Quoted 7 lines
If we 100% implement some standard then a URL for what we claim to implement would suffice. Given that we're at least using different types from posix I doubt if such a thing would be sufficient.
And given the complexity and potential variability within the filesystem implementations of this, I'd expect that _something_ additional needs to be said?
Ok. I will add a detailed comment here.
Quoted 11 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 360
Quoted 8 lines
fs/open.c +7
-0+{ +struct file *file; +struct inode *inode; +long ret = -EINVAL ; + +if (len ==0 || offset <0 ) + goto out;The posix spec implies that negative
len' is permitted - presumably "allocate ahead ofoffset'". How peculiar.
I think we should go ahead with current glibc implementation (which Jakub poited at) of not allowing a negative 'len', since posix also doesn't explicitly say anything about allowing negative 'len'.
Quoted 12 lines
Quoted 12 lines
fs/open.c +11
-0+ ret = -EBADF ; + file =fget (fd); +if (!file) + goto out; +if (!(file->f_mode &FMODE_WRITE )) + goto out_fput; + + inode = file->f_path.dentry->d_inode; + + ret = -ESPIPE ; +if (S_ISFIFO (inode->i_mode))
Quoted 8 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 377
Quoted 5 lines
fs/open.c +5
-0+ goto out_fput; + + ret = -ENODEV ; +if (!S_ISREG (inode->i_mode)) + goto out_fput;So we return ENODEV against an
S_ISBLKfd, as per the posix spec. That seems a bit silly of them.
True.
Quoted 7 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 381
Quoted 3 lines
fs/open.c +3
-0+ ret = -EFBIG ; +if (offset + len > inode->i_sb->s_maxbytes) + goto out_fput;This code does handle offset+len going negative, but only by accident, I suspect. It happens that
s_maxbyteshas unsigned type. Perhaps a comment here would settle the reader's mind.
Ok. I will add a check here for wrap though zero.
Quoted 10 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 386
Quoted 4 lines
fs/open.c +4
-0+if (inode->i_op && inode->i_op->fallocate) + ret = inode->i_op->fallocate (inode, mode, offset, len); +else + ret = -ENOSYS ;If we _are_ going to support negative
len', as posix suggests, I think we should perform the appropriate sanity conversions tooffset' and `len' right here, rather than expecting each filesystem to do it.If we're not going to handle negative `len' then we should check for it.
Will add a check for negative 'len' and return -EINVAL. This will be done where currently we check for negative offset (i.e. at the start of the function).
Quoted 8 lines
fs/open.c asmlinkage long sys_ftruncate64(unsigned · line 392
Quoted 6 lines
fs/open.c +6
-0+out_fput: +fput (file); +out: +return ret; +} +EXPORT_SYMBOL (sys_fallocate);I don't believe this needs to be exported to modules?
Ok. Will remove it.
Quoted 8 lines
include/linux/fs.h extern int dir_notify_enable; · line 271
Quoted 5 lines
include/linux/fs.h +5
-0+/* +* fallocate() modes +*/ +#define FA_ALLOCATE 0x1 +#define FA_DEALLOCATE 0x2Now those aren't in posix. They should be documented, along with their expected semantics.
Will add a comment describing the role of these modes.
Quoted 13 lines
include/linux/fs.h struct inode_operations { · line 1134
Quoted 8 lines
#ifdef
__KERNEL__#include <
linux/linkage.h>include/linux/fs.h +1
-0@@ -1125,6 +1131,7 @@ struct inode_operations {ssize_t (*listxattr) (struct dentry *,char *,size_t );int (*removexattr) (struct dentry *,const char *);void (*truncate_range)(struct inode *,loff_t ,loff_t ); +long (*fallocate)(struct inode *,int ,loff_t ,loff_t );I really do think it's better to put the variable names in definitions such as this. Especially when we have two identically-typed variables next to each other like that. Quick: which one is the offset and which is the length?
Ok. Will add the variable names here.
--
Regards,
Amit Arora
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Andrew MortonQuoted 8 lines · Andrew Morton
The above opengroup page only permits
S_ISREG. Preallocating directories sounds quite useful to me, although it's something which would be pretty hard to emulate if the FS doesn't support it. And there's a decent case to be made for emulating it - run-anywhere reasons. Does glibc emulation support directories? Quite unlikely.But yes, sounds like a desirable thing. Would XFS support it easily if the above check was relaxed?
I think we may relax the check here and let the individual file system decide if they support preallocation for directories or not. What do you think ?
One thing to be thought in this case is the error code which should be returned by the file system implementation, incase it doesn't support preallocation for directories. Should it be -ENODEV (to match with what posix says) , or something else (which might make more sense in this case) ?
--
Regards,
Amit Arora
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Andrew MortonQuoted 11 lines · Andrew Morton
Quoted 4 lines · On Thu, 26 Apr 2007 23:43:32 +0530 "Amit K. Arora" <[email protected]>…
+ *
ext4_fallocate:
+ * preallocate space for a file
+ * mode is for future use, e.g. for unallocating preallocated blocks etc.
+ */This description is rather thin. What is the filesystem's actual behaviour here? If the file is using extents then the implementation will do <something>. If the file is using bitmaps then we will do <something else>.
But what? Here is where it should be described.
My understanding is that glibc will handle zero-filling of files for filesystems that do not support fallocate().
Quoted 19 lines
Quoted 4 lines
fs/ext4/extents.c +4
-0+int ext4_fallocate (struct inode *inode,int mode,loff_t offset,loff_t len) +{ +handle_t *handle; +ext4_fsblk_t block, max_blocks;fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2265
Quoted 10 lines
fs/ext4/extents.c +10
-0+int ret, ret2, nblocks =0 , retries =0 ; +struct buffer_head map_bh; +unsigned int credits, blkbits = inode->i_blkbits; + +/* Currently supporting (pre)allocate mode _only_ */ +if (mode !=FA_ALLOCATE ) +return -EOPNOTSUPP ; + +if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) +return -ENOTTY ;So we don't implement fallocate on bitmap-based files! Well that's huge news. The changelog would be an appropriate place to communicate this, along with reasons why, or a description of the plan to fix it.
Quoted 1 line
Also, posix says nothing about
fallocate()returning ENOTTY.
I _think_ this is to convince glibc to do the zero-filling in userspace, but I'm not up on the API specifics.
Quoted 11 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2272
Quoted 6 lines
fs/ext4/extents.c +6
-0+ block = offset >> blkbits; + max_blocks = (EXT4_BLOCK_ALIGN (len + offset, blkbits) >> blkbits) + - block; +mutex_lock (&EXT4_I (inode)->truncate_mutex); + credits =ext4_ext_calc_credits_for_insert (inode,NULL ); +mutex_unlock (&EXT4_I (inode)->truncate_mutex);Now I'm mystified. Given that we're allocating an arbitrary amount of disk space, and that this disk space will require an arbitrary amount of metadata, how can we work out how much journal space we'll be needing without at least looking at `len'?
Good question.
The uninitialized extent can cover up to 128MB with a single entry. If @path isn't specified, then ext4_ext_calc_credits_for_insert() function returns the maximum number of extents needed to insert a leaf, including splitting all of the index blocks. That would allow up to 43GB (340 extents/block * 128MB) to be preallocated, but it still needs to take the size of the preallocation into account (adding 3 blocks per 43GB - a leaf block, a bitmap block and a group descriptor).
Also, since @path is not being given then truncate_mutex is not needed.
Quoted 7 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2285
Quoted 4 lines
fs/ext4/extents.c +4
-0+ ret =ext4_ext_get_blocks (handle, inode, block, + max_blocks, &map_bh, +EXT4_CREATE_UNINITIALIZED_EXT ,0 ); +BUG_ON (!ret);
BUG_ONis vicious. Is it really justified here? Possibly aWARN_ONandext4_error()would be safer and more useful here.
Ouch, not very friendly error handling.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Re: [PATCH 3/5] ext4: Extent overlap bugfix
In reply to Andrew MortonQuoted 19 lines · Andrew Morton
Quoted 17 lines · On Thu, 26 Apr 2007 23:41:01 +0530 "Amit K. Arora" <[email protected]>…
fs/ext4/extents.c +17
-0+unsigned int ext4_ext_check_overlap (struct inode *inode, +struct ext4_extent *newext, +struct ext4_ext_path *path) +{ +unsigned long b1, b2; +unsigned int depth, len1; + + b1 =le32_to_cpu (newext->ee_block); + len1 =le16_to_cpu (newext->ee_len); + depth =ext_depth (inode); +if (!path[depth].p_ext) + goto out; + b2 =le32_to_cpu (path[depth].p_ext->ee_block); + +/* get the next allocated block if the extent in the path +* is before the requested block(s) */ +if (b2 < b1) {
Quoted 8 lines
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode · line 1162
Quoted 6 lines
fs/ext4/extents.c +6
-0+ b2 =ext4_ext_next_allocated_block (path); +if (b2 ==EXT_MAX_BLOCK ) + goto out; + } + +if (b1 + len1 > b2) {Are we sure that b1+len cannot wrap through zero here?
No. Will add a check here for this. Thanks!
Quoted 3 lines
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode · line 1165
Quoted 3 lines
fs/ext4/extents.c +3
-0+ newext->ee_len =cpu_to_le16 (b2 - b1); +return 1 ; + }
--
Regards,
Amit Arora
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Andrew MortonQuoted 13 lines · Andrew Morton
fs/ext4/extents.c int ext4_ext_insert_extent(handle_t *han · line 1216
Quoted 8 lines · On Thu, 26 Apr 2007 23:43:32 +0530 "Amit K. Arora" <[email protected]>…
This patch has the ext4 implemtation of fallocate system call.
...
fs/ext4/extents.c +4
-0+/* ext4_can_extents_be_merged should have checked that either +* both extents are uninitialized, or both aren't. Thus we +* need to check only one of them here. +*/ Please always format multiline comments like this:
Quoted 5 lines
/*
*ext4_can_extents_be_mergedshould have checked that either
* both extents are uninitialized, or both aren't. Thus we
* need to check only one of them here.
*/
Ok.
Quoted 8 lines
Quoted 7 lines
...
+/*
+ *ext4_fallocate:
+ * preallocate space for a file
+ * mode is for future use, e.g. for unallocating preallocated blocks etc.
+ */
Quoted 5 lines
This description is rather thin. What is the filesystem's actual behaviour here? If the file is using extents then the implementation will do <something>. If the file is using bitmaps then we will do <something else>.
But what? Here is where it should be described.
Ok. Will expand the description.
Quoted 10 lines
Quoted 10 lines
fs/ext4/extents.c +10
-0+int ext4_fallocate (struct inode *inode,int mode,loff_t offset,loff_t len) +{ +handle_t *handle; +ext4_fsblk_t block, max_blocks; +int ret, ret2, nblocks =0 , retries =0 ; +struct buffer_head map_bh; +unsigned int credits, blkbits = inode->i_blkbits; + +/* Currently supporting (pre)allocate mode _only_ */ +if (mode !=FA_ALLOCATE )
Quoted 8 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2265
Quoted 4 lines
fs/ext4/extents.c +4
-0+return -EOPNOTSUPP ; + +if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) +return -ENOTTY ;So we don't implement fallocate on bitmap-based files! Well that's huge news. The changelog would be an appropriate place to communicate this, along with reasons why, or a description of the plan to fix it.
Ok. Will add this in the function description as well.
Quoted 1 line
Also, posix says nothing about
fallocate()returning ENOTTY.
Right. I don't seem to find any suitable error from posix description. Can you please suggest an error code which might make more sense here ? Will -ENOTSUPP be ok ? Since we want to say here that we don't support non-extent files.
Quoted 11 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2272
Quoted 6 lines
fs/ext4/extents.c +6
-0+ block = offset >> blkbits; + max_blocks = (EXT4_BLOCK_ALIGN (len + offset, blkbits) >> blkbits) + - block; +mutex_lock (&EXT4_I (inode)->truncate_mutex); + credits =ext4_ext_calc_credits_for_insert (inode,NULL ); +mutex_unlock (&EXT4_I (inode)->truncate_mutex);Now I'm mystified. Given that we're allocating an arbitrary amount of disk space, and that this disk space will require an arbitrary amount of metadata, how can we work out how much journal space we'll be needing without at least looking at `len'?
You are right to say that the credits can not be fixed here. But, 'len' will not directly tell us how many extents might need to be inserted and how many block groups (if any - think about the "segment range" already being allocated case) the allocation request might touch.
One solution I have thought is to check the buffer credits after a call to ext4_ext_get_blocks (in the while loop) and do a journal_extend, if the credits are falling short. Incase journal_extend fails, we call journal_restart. This will automatically take care of how much journal space we might need for any value of "len".
Quoted 3 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2273
Quoted 1 line
fs/ext4/extents.c +1
-0+ handle=ext4_journal_start(inode, credits +Please always put spaces around "="A
Ok.
Quoted 4 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2274
Quoted 2 lines
fs/ext4/extents.c +1
-0+ EXT4_DATA_TRANS_BLOCKS(inode->i_sb)+1);And around "+"
Ok.
Quoted 15 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2285
Quoted 12 lines
fs/ext4/extents.c +11
-0+if (IS_ERR (handle)) +return PTR_ERR (handle); +retry: + ret =0 ; +while (ret >=0 && ret < max_blocks) { + block = block + ret; + max_blocks = max_blocks - ret; + ret =ext4_ext_get_blocks (handle, inode, block, + max_blocks, &map_bh, +EXT4_CREATE_UNINITIALIZED_EXT ,0 ); +BUG_ON (!ret);
BUG_ONis vicious. Is it really justified here? Possibly aWARN_ONandext4_error()would be safer and more useful here.
Ok. Will do that.
Quoted 5 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2286
Quoted 2 lines
fs/ext4/extents.c +1
-0+ if (ret > 0 && test_bit(BH_New, &map_bh.b_state)Use
buffer_new()here. A separate patch which fixes the three existing
instances of open-codedBH_foousage would be appreciated.
Ok.
Quoted 4 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2287
Quoted 2 lines
fs/ext4/extents.c +1
-0+ && ((block + ret) > (i_size_read(inode) << blkbits)))Check for wrap though the sign bit and through zero please.
Ok.
Quoted 12 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2296
Quoted 10 lines
fs/ext4/extents.c +9
-0+ nblocks = nblocks + ret; + } + +if (ret == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) + goto retry; + +/* Time to update the file size. +* Update only when preallocation was requested beyond the file size. +*/ Fix comment layout.
Ok.
Quoted 6 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2297
Quoted 2 lines
fs/ext4/extents.c +1
-0+if ((offset + len) >i_size_read (inode)) {Both the lhs and the rhs here are signed. Please review for possible overflows through the sign bit and through zero. Perhaps a comment explaining why it's correct would be appropriate.
Ok.
Quoted 12 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2305
Quoted 10 lines
fs/ext4/extents.c +8
-0+if (ret >0 ) { +/* if no error, we assume preallocation succeeded completely */ +mutex_lock (&inode->i_mutex); +i_size_write (inode, offset + len); +EXT4_I (inode)->i_disksize =i_size_read (inode); +mutex_unlock (&inode->i_mutex); + }else if (ret <0 && nblocks) { +/* Handle partial allocation scenario */ The above two comments should be indented one additional tabstop.
Ok.
Quoted 49 lines
Quoted 41 lines
fs/ext4/extents.c +17
-0+loff_t newsize; +mutex_lock (&inode->i_mutex); + newsize = (nblocks << blkbits) +i_size_read (inode); +i_size_write (inode,EXT4_BLOCK_ALIGN (newsize, blkbits)); +EXT4_I (inode)->i_disksize =i_size_read (inode); +mutex_unlock (&inode->i_mutex); + } + } +ext4_mark_inode_dirty (handle, inode); + ret2 =ext4_journal_stop (handle); +if (ret >0 ) + ret = ret2; + +return ret >0 ?0 : ret; +} +EXPORT_SYMBOL (ext4_mark_inode_dirty);EXPORT_SYMBOL (ext4_ext_invalidate_cache);EXPORT_SYMBOL (ext4_ext_insert_extent);EXPORT_SYMBOL (ext4_ext_walk_space);EXPORT_SYMBOL (ext4_ext_find_goal);EXPORT_SYMBOL (ext4_ext_calc_credits_for_insert); +EXPORT_SYMBOL (ext4_fallocate);Index:
linux-2.6.21/fs/ext4/file.c
===================================================================fs/ext4/file.c +1
-0@@ -135,5 +135,6 @@ const struct inode_operations ext4_file_ .removexattr = generic_removexattr, #endif .permission = ext4_permission, + .fallocate = ext4_fallocate, };Index:
linux-2.6.21/include/linux/ext4_fs.h
===================================================================include/linux/ext4_fs.h line 106
Quoted 5 lines
include/linux/ext4_fs.h +2
-0@@ -102,6 +102,8 @@ EXT4_GOOD_OLD_FIRST_INO : \ (s)->s_first_ino)#endif +#define EXT4_BLOCK_ALIGN (size, blkbits) (((size)+(1 << blkbits)-1) & \ + (~((1 << blkbits)-1)))Maybe a comment describing what this does? Probably it's obvious enough.
Quoted 4 lines
I think it could use the standard ALIGN macro.
Is blkbits sufficiently parenthesised here? Even if it is, adding the parens would be better practice.
I agree. Will change it.
Quoted 7 lines
Quoted 7 lines
include/linux/ext4_fs.h +0
-0/* * Macro-instructions used to manage fragments @@ -225,6 +227,10 @@ struct ext4_new_group_data {__u32 free_blocks_count; };
Quoted 5 lines
include/linux/ext4_fs.h struct ext4_new_group_data { · line 232
Quoted 3 lines
include/linux/ext4_fs.h +3
-0+/* Following is used by preallocation logic to tell get_blocks() that we +* want uninitialzed extents. +*/ Please convert all newly-added multiline comments to the preferred layout.
Ok.
Quoted 12 lines
include/linux/ext4_fs.h extern int ext4_ext_get_blocks(handle_t · line 985
Quoted 10 lines
include/linux/ext4_fs.h +2
-0+#define EXT4_CREATE_UNINITIALIZED_EXT 2/* * ioctl commands @@ -976,6 +982,7 @@ extern int ext4_ext_get_blocks(handle_textern void ext4_ext_truncate (struct inode *,struct page *);extern void ext4_ext_init (struct super_block *);extern void ext4_ext_release (struct super_block *); +extern int ext4_fallocate (struct inode *,int ,loff_t ,loff_t );argh. And feel free to give these args some useful names.
Ok.
Quoted 11 lines
Quoted 11 lines
include/linux/ext4_fs.h +0
-0static inline int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, unsigned long max_blocks, struct buffer_head *bh,Index:
linux-2.6.21/include/linux/ext4_fs_extents.h
===================================================================include/linux/ext4_fs_extents.h +0
-0@@ -125,6 +125,19 @@ struct ext4_ext_path {#define EXT4_EXT_CACHE_EXTENT 2
Quoted 14 lines
include/linux/ext4_fs_extents.h struct ext4_ext_path { · line 137
Quoted 11 lines
include/linux/ext4_fs_extents.h +10
-0/* +* Macro-instructions to handle (mark/unmark/check/create) unitialized +* extents. Applications can issue an IOCTL for preallocation, which results +* in assigning unitialized extents to the file. +*/ +#define ext4_ext_mark_uninitialized (ext) ((ext)->ee_len |= \ + cpu_to_le16(0x8000)) +#define ext4_ext_is_uninitialized (ext) ((le16_to_cpu((ext)->ee_len))& \ + 0x8000) +#define ext4_ext_get_actual_len (ext) ((le16_to_cpu((ext)->ee_len))& \ + 0x7FFF)inlined C functions are preferred, and I think these could be implemented that way.
Ok. Will convert them to inline functions.
Thanks!
--
Regards,
Amit Arora
Re: [PATCH 5/5] ext4: write support for preallocated blocks/extents
In reply to Andrew MortonQuoted 12 lines · Andrew Morton
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode · line 1157
Quoted 8 lines · On Thu, 26 Apr 2007 23:46:23 +0530 "Amit K. Arora" <[email protected]>…
+ */
fs/ext4/extents.c +7
-0+int ext4_ext_try_to_merge (struct inode *inode, +struct ext4_ext_path *path, +struct ext4_extent *ex) +{ +struct ext4_extent_header *eh; +unsigned int depth, len; +int merge_done=0 , uninitialized =0 ;space around "=", please.
Quoted 4 lines
Many people prefer not to do the multiple-definitions-per-line, btw:
int merge_done = 0; int uninitialized = 0;
Ok. Will make the change.
Quoted 24 lines
reasons:
- If gives you some space for a nice comment
- It makes patches much more readable, and it makes rejects easier to fix
- standardisation.
Quoted 15 lines
fs/ext4/extents.c +15
-0+ depth =ext_depth (inode); +BUG_ON (path[depth].p_hdr ==NULL ); + eh = path[depth].p_hdr; + +while (ex <EXT_LAST_EXTENT (eh)) { +if (!ext4_can_extents_be_merged (inode, ex, ex +1 )) +break ; +/* merge with next extent! */ +if (ext4_ext_is_uninitialized (ex)) + uninitialized =1 ; + ex->ee_len =cpu_to_le16 (ext4_ext_get_actual_len (ex) + +ext4_ext_get_actual_len (ex +1 )); +if (uninitialized) +ext4_ext_mark_uninitialized (ex); +
Quoted 8 lines
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode · line 1179
Quoted 6 lines
fs/ext4/extents.c +6
-0+if (ex +1 <EXT_LAST_EXTENT (eh)) { + len = (EXT_LAST_EXTENT (eh) - ex -1 ) + *sizeof (struct ext4_extent ); +memmove (ex +1 , ex +2 , len); + } + eh->eh_entries =cpu_to_le16 (le16_to_cpu (eh->eh_entries)-1 );Kenrel convention is to put spaces around "-"
Will fix this.
Quoted 6 lines
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode · line 1181
Quoted 3 lines
fs/ext4/extents.c +2
-0+ merge_done =1 ; +BUG_ON (eh->eh_entries ==0 );eek, scary
BUG_ON. Do we really need to be that severe? Would it be better to warn and runext4_error()here?
Ok.
Quoted 19 lines
Quoted 6 lines
fs/ext4/extents.c +5
-0+ } + +return merge_done; +} +fs/ext4/extents.c ext4_can_extents_be_merged(struct inode
Quoted 10 lines
fs/ext4/extents.c +7
-0+ +/* +* ext4_ext_convert_to_initialized: +* this function is called by ext4_ext_get_blocks() if someone tries to write +* to an uninitialized extent. It may result in splitting the uninitialized +* extent into multiple extents (upto three). Atleast one initialized extent +* and atmost two uninitialized extents can result. There are some typos here
Quoted 7 lines
Quoted 4 lines
+ * There are three possibilities:
+ * a> No split required: Entire extent should be initialized. + * b> Split into two extents: Only one end of the extent is being written to. + * c> Split into three extents: Somone is writing in middle of the extent.and here
Ok. Will fix them.
Quoted 54 lines
Quoted 41 lines
+ */
fs/ext4/extents.c +40
-0+int ext4_ext_convert_to_initialized (handle_t *handle,struct inode *inode, +struct ext4_ext_path *path, +ext4_fsblk_t iblock, +unsigned long max_blocks) +{ +struct ext4_extent *ex, *ex1 =NULL , *ex2 =NULL , *ex3 =NULL , newex; +struct ext4_extent_header *eh; +unsigned int allocated, ee_block, ee_len, depth; +ext4_fsblk_t newblock; +int err =0 , ret =0 ; + + depth =ext_depth (inode); + eh = path[depth].p_hdr; + ex = path[depth].p_ext; + ee_block =le32_to_cpu (ex->ee_block); + ee_len =ext4_ext_get_actual_len (ex); + allocated = ee_len - (iblock - ee_block); + newblock = iblock - ee_block +ext_pblock (ex); + ex2 = ex; + +/* ex1: ee_block to iblock - 1 : uninitialized */ +if (iblock > ee_block) { + ex1 = ex; + ex1->ee_len =cpu_to_le16 (iblock - ee_block); +ext4_ext_mark_uninitialized (ex1); + ex2 = &newex; + } +/* for sanity, update the length of the ex2 extent before +* we insert ex3, if ex1 is NULL. This is to avoid temporary +* overlap of blocks. +*/ +if (!ex1 && allocated > max_blocks) + ex2->ee_len =cpu_to_le16 (max_blocks); +/* ex3: to ee_block + ee_len : uninitialised */ +if (allocated > max_blocks) { +unsigned int newdepth; + ex3 = &newex; + ex3->ee_block =cpu_to_le32 (iblock + max_blocks); +ext4_ext_store_pblock (ex3, newblock + max_blocks); + ex3->ee_len =cpu_to_le16 (allocated - max_blocks);fs/ext4/extents.c void ext4_ext_release(struct super_block · line 2089
Quoted 10 lines
fs/ext4/extents.c +10
-0+ext4_ext_mark_uninitialized (ex3); + err =ext4_ext_insert_extent (handle, inode, path, ex3); +if (err) + goto out; +/* The depth, and hence eh & ex might change +* as part of the insert above. +*/ + newdepth =ext_depth (inode); +if (newdepth != depth) + {Use
Quoted 1 line
if (newdepth != depth) {Ok.
Quoted 4 lines
fs/ext4/extents.c void ext4_ext_release(struct super_block · line 2090
Quoted 2 lines
fs/ext4/extents.c +1
-0+ depth=newdepth;spaces
Ok.
Quoted 36 lines
Quoted 23 lines
fs/ext4/extents.c +22
-0+ path =ext4_ext_find_extent (inode, iblock,NULL ); +if (IS_ERR (path)) { + err =PTR_ERR (path); + path =NULL ; + goto out; + } + eh = path[depth].p_hdr; + ex = path[depth].p_ext; +if (ex2 != &newex) + ex2 = ex; + } + allocated = max_blocks; + } +/* If there was a change of depth as part of the +* insertion of ex3 above, we need to update the length +* of the ex1 extent again here +*/ +if (ex1 && ex1 != ex) { + ex1 = ex; + ex1->ee_len =cpu_to_le16 (iblock - ee_block); +ext4_ext_mark_uninitialized (ex1); + ex2 = &newex;fs/ext4/extents.c void ext4_ext_release(struct super_block · line 2122
Quoted 10 lines
fs/ext4/extents.c +10
-0+ } +/* ex2: iblock to iblock + maxblocks-1 : initialised */ + ex2->ee_block =cpu_to_le32 (iblock); + ex2->ee_start =cpu_to_le32 (newblock); +ext4_ext_store_pblock (ex2, newblock); + ex2->ee_len =cpu_to_le16 (allocated); +if (ex2 != ex) + goto insert; +if ((err =ext4_ext_get_access (handle, inode, path + depth))) + goto out;The preferred style is
Quoted 3 lines
err = ext4_ext_get_access(handle, inode, path + depth); if (err) goto out;
Right. Will change it.
Quoted 43 lines
Quoted 28 lines
fs/ext4/extents.c +28
-0+/* New (initialized) extent starts from the first block +* in the current extent. i.e., ex2 == ex +* We have to see if it can be merged with the extent +* on the left. +*/ +if (ex2 >EXT_FIRST_EXTENT (eh)) { +/* To merge left, pass "ex2 - 1" to try_to_merge(), +* since it merges towards right _only_. +*/ + ret =ext4_ext_try_to_merge (inode, path, ex2 -1 ); +if (ret) { + err =ext4_ext_correct_indexes (handle, inode, path); +if (err) + goto out; + depth =ext_depth (inode); + ex2--; + } + } +/* Try to Merge towards right. This might be required +* only when the whole extent is being written to. +* i.e. ex2==ex and ex3==NULL. +*/ +if (!ex3) { + ret =ext4_ext_try_to_merge (inode, path, ex2); +if (ret) { + err =ext4_ext_correct_indexes (handle, inode, path); +if (err) + goto out;fs/ext4/extents.c void ext4_ext_release(struct super_block · line 2160
Quoted 10 lines
fs/ext4/extents.c +10
-0+ } + } +/* Mark modified extent as dirty */ + err =ext4_ext_dirty (handle, inode, path + depth); + goto out; +insert: + err =ext4_ext_insert_extent (handle, inode, path, &newex); +out: +return err ? err : allocated; +}Sigh. I hope you guys know how all this works, because the extent code is a mystery to me. Is the on-disk layout and the allocation strategy described anywhere?
Quoted 7 lines
Quoted 1 line
+extern int
ext4_ext_try_to_merge(struct inode *, struct ext4_ext_path *, struct ext4_extent *);Again, I do think that sticking the identifiers in there helps readability. Although it is not as important in a boring old declaration as it is in, say,
inode_operations, etc.Please try to keep the code looking nice in an 80-column display.
Ok. Will make the required changes.
Thanks again for your comments!
--
Regards,
Amit Arora
Re: [PATCH 5/5] ext4: write support for preallocated blocks/extents
In reply to Amit K. Arorafs/ext4/extents.c ext4_can_extents_be_merged(struct inode · line 1154
Quoted 12 lines · Amit K. Arora
/*
+ *ext4_ext_try_to_merge:
+ * tries to merge the "ex" extent to the next extent in the tree.
+ * It always tries to merge towards right. If you want to merge towards
+ * left, pass "ex - 1" as argument instead of "ex".
+ * Returns 0 if the extents (ex and ex+1) were _not_ merged and returns
+ * 1 if they got merged.
+ */fs/ext4/extents.c +4
-0+int ext4_ext_try_to_merge (struct inode *inode, +struct ext4_ext_path *path, +struct ext4_extent *ex) +{
Please either use proper kerneldoc format or drop
"ext4_ext_try_to_merge" from the comment.
Re: [PATCH 5/5] ext4: write support for preallocated blocks/extents
Quoted 16 lines · Pekka Enberg
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode · line 1154
Quoted 12 lines · Amit K. Arora
/*
+ *ext4_ext_try_to_merge:
+ * tries to merge the "ex" extent to the next extent in the tree.
+ * It always tries to merge towards right. If you want to merge towards
+ * left, pass "ex - 1" as argument instead of "ex".
+ * Returns 0 if the extents (ex and ex+1) were _not_ merged and returns
+ * 1 if they got merged.
+ */fs/ext4/extents.c +4
-0+int ext4_ext_try_to_merge (struct inode *inode, +struct ext4_ext_path *path, +struct ext4_extent *ex) +{Please either use proper kerneldoc format or drop
"ext4_ext_try_to_merge" from the comment.
Ok, Thanks.
--
Regards,
Amit Arora
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Jakub JelinekQuoted 6 lines · Jakub Jelinek
is what glibc does ATM. Seems we violate the case where len == 0, as EINVAL in that case is "shall fail". But reading the standard to imply negative len is ok is too much guessing, there is no word what it means when len is negative and
"required storage for regular file data starting at offset and continuing for len bytes" doesn't make sense for negative size.
This wording has already been cleaned up. The current draft for the next revision reads:
[EINVAL] The len argument is less than or equal to zero, or the offset
argument is less than zero, or the underlying file system does not support this operation.
I still don't like it since len==0 shouldn't create an error (it's inconsistent) but len<0 is already outlawed.
Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Amit K. AroraQuoted 22 lines · Amit K. Arora
Quoted 12 lines · Andrew Morton
Quoted 10 lines · On Thu, 26 Apr 2007 23:43:32 +0530 "Amit K. Arora" <[email protected]>…
fs/ext4/extents.c +10
-0+int ext4_fallocate (struct inode *inode,int mode,loff_t offset,loff_t len) +{ +handle_t *handle; +ext4_fsblk_t block, max_blocks; +int ret, ret2, nblocks =0 , retries =0 ; +struct buffer_head map_bh; +unsigned int credits, blkbits = inode->i_blkbits; + +/* Currently supporting (pre)allocate mode _only_ */ +if (mode !=FA_ALLOCATE )Quoted 8 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2265
Quoted 4 lines
fs/ext4/extents.c +4
-0+return -EOPNOTSUPP ; + +if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) +return -ENOTTY ;So we don't implement fallocate on bitmap-based files! Well that's huge news. The changelog would be an appropriate place to communicate this, along with reasons why, or a description of the plan to fix it.
Quoted 8 lines
Ok. Will add this in the function description as well.
Quoted 1 line
Also, posix says nothing about
fallocate()returning ENOTTY.Right. I don't seem to find any suitable error from posix description. Can you please suggest an error code which might make more sense here ? Will
-ENOTSUPPbe ok ? Since we want to say here that we don't support non-extent files.
Isn't the idea that libc will interpret -ENOTTY, or whatever is returned here, and fall back to the current library code to do preallocation? This way, the caller of fallocate() will never see this return code, so it won't violate posix.
Signature · 2 lines
David Kleikamp IBM Linux Technology Center
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Andreas DilgerQuoted 14 lines · On Mon, 7 May 2007 05:37:54 -0600 Andreas Dilger <[email protected]> wrote:
Quoted 11 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2272
Quoted 6 lines
fs/ext4/extents.c +6
-0+ block = offset >> blkbits; + max_blocks = (EXT4_BLOCK_ALIGN (len + offset, blkbits) >> blkbits) + - block; +mutex_lock (&EXT4_I (inode)->truncate_mutex); + credits =ext4_ext_calc_credits_for_insert (inode,NULL ); +mutex_unlock (&EXT4_I (inode)->truncate_mutex);Now I'm mystified. Given that we're allocating an arbitrary amount of disk space, and that this disk space will require an arbitrary amount of metadata, how can we work out how much journal space we'll be needing without at least looking at `len'?
Good question.
Quoted 7 lines
The uninitialized extent can cover up to 128MB with a single entry. If @path isn't specified, then
ext4_ext_calc_credits_for_insert()function returns the maximum number of extents needed to insert a leaf, including splitting all of the index blocks. That would allow up to 43GB (340 extents/block * 128MB) to be preallocated, but it still needs to take the size of the preallocation into account (adding 3 blocks per 43GB - a leaf block, a bitmap block and a group descriptor).
I think the use of ext4_journal_extend() (as Amit has proposed) will help here, but it is not sufficient.
Because under some circumstances, a journal_extend() failure could mean that we fail to allocate all the required disk space. If it is infrequent enough, that is acceptable when the caller is using fallocate() for performance reasons.
But it is very much not acceptable if the caller is using fallocate() for space-reservation reasons. If you used fallocate to reserve 1GB of disk and fallocate() "succeeded" and you later get ENOSPC then you'd have a right to get a bit upset.
So I think the ext3/4 fallocate() implementation will need to be implemented as a loop:
while (len) {
journal_start();
len -= do_fallocate(len, ...);
journal_stop();
}Now the interesting question is: what do we do if we get halfway through this loop and then run out of space? We could leave the disk all filled up and then return failure to the caller, but that's pretty poor behaviour, IMO.
Does the proposed implementation handle quotas correctly, btw? Has that been tested?
Final point: it's fairly disappointing that the present implementation is ext4-only, and extent-only. I do think we should be aiming at an ext4 bitmap-based implementation and an ext3 implementation.
Re: [PATCH 4/5] ext4: fallocate support in ext4
Quoted 3 lines · Andrew Morton
Final point: it's fairly disappointing that the present implementation is ext4-only, and extent-only. I do think we should be aiming at an ext4 bitmap-based implementation and an ext3 implementation.
Actually, this is a non-issue. The reason that it is handled for extent-only is that this is the only way to allocate space in the filesystem without doing the explicit zeroing. For other filesystems (including ext3 and ext4 with block-mapped files) the filesystem should return an error (e.g. -EOPNOTSUPP) and glibc will do manual zero-filling of the file in userspace.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Re: [PATCH 4/5] ext4: fallocate support in ext4
Quoted 10 lines · On Mon, 7 May 2007 15:21:04 -0700 Andreas Dilger <[email protected]> wrote:
Quoted 3 lines · Andrew Morton
Final point: it's fairly disappointing that the present implementation is ext4-only, and extent-only. I do think we should be aiming at an ext4 bitmap-based implementation and an ext3 implementation.
Actually, this is a non-issue. The reason that it is handled for extent-only is that this is the only way to allocate space in the filesystem without doing the explicit zeroing. For other filesystems (including ext3 and ext4 with block-mapped files) the filesystem should return an error (e.g.
-EOPNOTSUPP) and glibc will do manual zero-filling of the file in userspace.
hrm, spose so.
It can be a bit suboptimal from the layout POV. The reservations code will largely save us here, but kernel support might make it a bit better.
Totally blowing pagecache could be a problem. Fixable in userspace by using sync_file_range()+fadvise() or O_DIRECT, but I bet it doesn't.
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Andreas DilgerQuoted 8 lines · Andreas Dilger
Quoted 3 lines · Andrew Morton
Final point: it's fairly disappointing that the present implementation is ext4-only, and extent-only. I do think we should be aiming at an ext4 bitmap-based implementation and an ext3 implementation.
Actually, this is a non-issue. The reason that it is handled for extent-only is that this is the only way to allocate space in the filesystem without doing the explicit zeroing. For other filesystems (including ext3 and
Precisely /how/ do you avoid the zeroing issue, for extents?
If I posix_fallocate() 20GB on ext4, it damn well better be zeroed, otherwise the implementation is broken.
Jeff
Theodore Tso
maintainerRe: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Andrew MortonQuoted 8 lines · Andrew Morton
Quoted 5 lines
Actually, this is a non-issue. The reason that it is handled for extent-only is that this is the only way to allocate space in the filesystem without doing the explicit zeroing. For other filesystems (including ext3 and ext4 with block-mapped files) the filesystem should return an error (e.g.
-EOPNOTSUPP) and glibc will do manual zero-filling of the file in userspace.It can be a bit suboptimal from the layout POV. The reservations code will largely save us here, but kernel support might make it a bit better.
Actually, the reservations code won't matter, since glibc will fall back to its current behavior, which is it will do the preallocation by explicitly writing zeros to the file. This wlil result in the same layout as if we had done the persistent preallocation, but of course it will mean the posix_fallocate() could potentially take a long time if you're a PVR and you're reserving a gig or two for a two hour movie at high quality. That seems suboptimal, granted, and ideally the application should be warned about this before it calls posix_fallocate(). On the other hand, it's what happens today, all the time, so applications won't be too badly surprised.
If we think applications programmers badly need to know in advance if posix_fallocate() will be fast or slow, probably the right thing is to define a new fpathconf() configuration option so they can query to see whether a particular file will support a fast posix_fallocate(). I'm not 100% convinced such complexity is really needed, but I'm willing to be convinced.... what do folks think?
- Ted
Re: [PATCH 4/5] ext4: fallocate support in ext4
Quoted 7 lines · On Mon, 7 May 2007 19:14:42 -0400 Theodore Tso <[email protected]> wrote:
Quoted 6 lines · Andrew Morton
Quoted 5 lines
Actually, this is a non-issue. The reason that it is handled for extent-only is that this is the only way to allocate space in the filesystem without doing the explicit zeroing. For other filesystems (including ext3 and ext4 with block-mapped files) the filesystem should return an error (e.g.
-EOPNOTSUPP) and glibc will do manual zero-filling of the file in userspace.
Quoted 6 lines
Quoted 2 lines
It can be a bit suboptimal from the layout POV. The reservations code will largely save us here, but kernel support might make it a bit better.
Actually, the reservations code won't matter, since glibc will fall back to its current behavior, which is it will do the preallocation by explicitly writing zeros to the file.
No! Reservations code is *critical* here. Without reservations, we get disastrously-bad layout if two processes were running a large fallocate() at the same time. (This is an SMP-only problem, btw: on UP the timeslice lengths save us).
My point is that even though reservations save us, we could do even-better in-kernel.
But then, a smart application would bypass the glibc() fallocate() implementation and would tune the reservation window size and would use direct-IO or sync_file_range()+fadvise(FADV_DONTNEED).
Quoted 8 lines
This wlil result in the same
layout as if we had done the persistent preallocation, but of course it will mean theposix_fallocate()could potentially take a long time if you're a PVR and you're reserving a gig or two for a two hour movie at high quality. That seems suboptimal, granted, and ideally the application should be warned about this before it callsposix_fallocate(). On the other hand, it's what happens today, all the time, so applications won't be too badly surprised.
A PVR implementor would take all this over and would do it themselves, for sure.
Quoted 7 lines
If we think applications programmers badly need to know in advance if
posix_fallocate()will be fast or slow, probably the right thing is to define a newfpathconf()configuration option so they can query to see whether a particular file will support a fastposix_fallocate(). I'm not 100% convinced such complexity is really needed, but I'm willing to be convinced.... what do folks think?
An application could do sys_fallocate(one-byte) to work out whether it's supported in-kernel, I guess.
Theodore Tso
maintainerRe: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Jeff GarzikQuoted 11 lines · Jeff Garzik
Quoted 9 lines · Andreas Dilger
Quoted 3 lines · Andrew Morton
Final point: it's fairly disappointing that the present implementation is ext4-only, and extent-only. I do think we should be aiming at an ext4 bitmap-based implementation and an ext3 implementation.
Actually, this is a non-issue. The reason that it is handled for extent-only
is that this is the only way to allocate space in the filesystem without doing the explicit zeroing. For other filesystems (including ext3 and
Quoted 4 lines
Precisely /how/ do you avoid the zeroing issue, for extents?
If I
posix_fallocate()20GB on ext4, it damn well better be zeroed, otherwise the implementation is broken.
There is a bit in the extent structure which indicates that the extent has not been initialized. When reading from a block where the extent is marked as unitialized, ext4 returns zero's, to avoid returning the uninitalized contents of the disk, which might contain someone else's love letters, p0rn, or other information which we shouldn't leak out. When writing to an extent which is uninitalized, we may potentially have to split the extent into three extents in the worst case.
My understanding is that XFS uses a similar implementation; it's a pretty obvious and standard way to implement allocated-but-not-initialized extents.
We thought about supporting persistent preallocation for inodes using indirect blocks, but it would require stealing a bit from each entry in the indirect block, reducing the maximum size of the filesystem by two (i.e., 2**31 blocks). It was decided it wasn't worth the complexity, given the tradeoffs.
- Ted
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Andrew MortonQuoted 38 lines · Andrew Morton
Quoted 14 lines · On Mon, 7 May 2007 05:37:54 -0600 Andreas Dilger <[email protected]> wrote:
Quoted 11 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2272
Quoted 6 lines
fs/ext4/extents.c +6
-0+ block = offset >> blkbits; + max_blocks = (EXT4_BLOCK_ALIGN (len + offset, blkbits) >> blkbits) + - block; +mutex_lock (&EXT4_I (inode)->truncate_mutex); + credits =ext4_ext_calc_credits_for_insert (inode,NULL ); +mutex_unlock (&EXT4_I (inode)->truncate_mutex);Now I'm mystified. Given that we're allocating an arbitrary amount of disk space, and that this disk space will require an arbitrary amount of metadata, how can we work out how much journal space we'll be needing without at least looking at `len'?
Good question.
Quoted 7 lines
The uninitialized extent can cover up to 128MB with a single entry. If @path isn't specified, then
ext4_ext_calc_credits_for_insert()function returns the maximum number of extents needed to insert a leaf, including splitting all of the index blocks. That would allow up to 43GB (340 extents/block * 128MB) to be preallocated, but it still needs to take the size of the preallocation into account (adding 3 blocks per 43GB - a leaf block, a bitmap block and a group descriptor).I think the use of
ext4_journal_extend()(as Amit has proposed) will help here, but it is not sufficient.Because under some circumstances, a
journal_extend()failure could mean that we fail to allocate all the required disk space. If it is infrequent enough, that is acceptable when the caller is usingfallocate()for performance reasons.But it is very much not acceptable if the caller is using
fallocate()for space-reservation reasons. If you used fallocate to reserve 1GB of disk andfallocate()"succeeded" and you later get ENOSPC then you'd have a right to get a bit upset.
Quoted 10 lines
So I think the ext3/4
fallocate()implementation will need to be implemented as a loop:while (len) { journal_start(); len -= do_fallocate(len, ...); journal_stop(); }
I agree. There is already a loop in Amit's current's patch to call ext4_ext_get_blocks() thoug. Question is how much credit should ext4 to ask for in each journal_start()?
Quoted 7 lines
fs/ext4/extents.c +7
-0+/* +* ext4_fallocate: +* preallocate space for a file +* mode is for future use, e.g. for unallocating preallocated blocks etc. +*/ +int ext4_fallocate (struct inode *inode,int mode,loff_t offset,loff_t len) +{
....
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2272
Quoted 3 lines
fs/ext4/extents.c +3
-0+mutex_lock (&EXT4_I (inode)->truncate_mutex); + credits =ext4_ext_calc_credits_for_insert (inode,NULL ); +mutex_unlock (&EXT4_I (inode)->truncate_mutex);
I think the calculation is based on the assumption that there is only a single extent to be inserted, which is the ideal case. But in some cases we may end up allocating several chunk of blocks(extents) for this single preallocation request when fs is fragmented (or part of preallocation request is already fulfilled)
I think we should move this calculation inside the loop as well,and we really do not need to grab the lock to calculate the credit if the @path is always NULL, all the function does is mathmatics.
I can't think of any good way to estimate the total credits needed for this whole preallocation request. Looked at ext4_get_block(), which is used for DIO code to deal with large amount of block allocation. The credit reservation is quite weak there too. The DIO_CREDIT is only (EXT4_RESERVE_TRANS_BLOCKS + 32)
Quoted 21 lines
fs/ext4/extents.c +21
-0+ handle=ext4_journal_start (inode, credits + +EXT4_DATA_TRANS_BLOCKS (inode->i_sb)+1 ); +if (IS_ERR (handle)) +return PTR_ERR (handle); +retry: + ret =0 ; +while (ret >=0 && ret < max_blocks) { + block = block + ret; + max_blocks = max_blocks - ret; + ret =ext4_ext_get_blocks (handle, inode, block, + max_blocks, &map_bh, +EXT4_CREATE_UNINITIALIZED_EXT ,0 ); +BUG_ON (!ret); +if (ret >0 &&test_bit (BH_New, &map_bh.b_state) + && ((block + ret) > (i_size_read (inode) << blkbits))) + nblocks = nblocks + ret; + } + +if (ret == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) + goto retry; +
Quoted 5 lines
Now the interesting question is: what do we do if we get halfway through this loop and then run out of space? We could leave the disk all filled up and then return failure to the caller, but that's pretty poor behaviour, IMO.
The current code handles earlier ENOSPC by three times retries. After that if we still run out of space, then it's propably right to notify the caller there isn't much space left.
We could extend the block reservation window size before the while loop so we could get a lower chance to get more fragmented.
Quoted 4 lines
Does the proposed implementation handle quotas correctly, btw? Has that been tested?
I think so. The ext4_ext_get_blocks() will end up calling ext4_new_blocks() to do the real block allocation, quota is being handled there, therefor is tested already.
Mingming
Re: [PATCH 4/5] ext4: fallocate support in ext4
Quoted 24 lines · On Mon, 07 May 2007 17:00:24 -0700 Mingming Cao <[email protected]> wrote:
Quoted 15 lines
fs/ext4/extents.c +15
-0+while (ret >=0 && ret < max_blocks) { + block = block + ret; + max_blocks = max_blocks - ret; + ret =ext4_ext_get_blocks (handle, inode, block, + max_blocks, &map_bh, +EXT4_CREATE_UNINITIALIZED_EXT ,0 ); +BUG_ON (!ret); +if (ret >0 &&test_bit (BH_New, &map_bh.b_state) + && ((block + ret) > (i_size_read (inode) << blkbits))) + nblocks = nblocks + ret; + } + +if (ret == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) + goto retry; +Quoted 5 lines
Now the interesting question is: what do we do if we get halfway through this loop and then run out of space? We could leave the disk all filled up and then return failure to the caller, but that's pretty poor behaviour, IMO.
The current code handles earlier ENOSPC by three times retries. After that if we still run out of space, then it's propably right to notify the caller there isn't much space left.
Quoted 2 lines
We could extend the block reservation window size before the while loop so we could get a lower chance to get more fragmented.
yes, but my point is that the proposed behaviour is really quite bad.
We will attempt to allocate the disk space and then we will return failure, having consumed all the disk space and having partially and uselessly populated an unknown amount of the file.
Userspace could presumably repair the mess in most situations by truncating the file back again. The kernel cannot do that because there might be live data in amongst there.
So we'd need to either keep track of which blocks were newly-allocated and then free them all again on the error path (doesn't work right across commit+crash+recovery) or we could later use the space-reservation scheme which delayed allocation will need to introduce.
Or we could decide to live with the above IMO-crappy behaviour.
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Andrew MortonQuoted 17 lines · Andrew Morton
Quoted 7 lines · On Mon, 7 May 2007 19:14:42 -0400 Theodore Tso <[email protected]> wrote:
Quoted 6 lines · Andrew Morton
Quoted 5 lines
Actually, this is a non-issue. The reason that it is handled for extent-only is that this is the only way to allocate space in the filesystem without doing the explicit zeroing. For other filesystems (including ext3 and ext4 with block-mapped files) the filesystem should return an error (e.g.
-EOPNOTSUPP) and glibc will do manual zero-filling of the file in userspace.Quoted 6 lines
Quoted 2 lines
It can be a bit suboptimal from the layout POV. The reservations code will largely save us here, but kernel support might make it a bit better.
Actually, the reservations code won't matter, since glibc will fall back to its current behavior, which is it will do the preallocation by explicitly writing zeros to the file.
Quoted 8 lines
No! Reservations code is *critical* here. Without reservations, we get disastrously-bad layout if two processes were running a large
fallocate()at the same time. (This is an SMP-only problem, btw: on UP the timeslice lengths save us).My point is that even though reservations save us, we could do even-better in-kernel.
In this case, since the number of blocks to preallocate (eg. N=10GB) is clear, we could improve the current reservation code, to allow callers explicitly ask for a new window that have the minimum N free blocks for the blocks-to-preallocated(rather than just have at least 1 free blocks).
Before the ext4_fallocate() is called, the right reservation window size is set with the flag to indicating "please spend time if needed to find a window covers at least N free blocks".
So for ex4 block mapped files, later when glibc is doing allocation and zeroing, the ext4 block-mapped allocator will knows to reserve the right amount of free blocks before allocating and zeroing 10GB space.
I am not sure whether this worth the effort though.
Quoted 27 lines
But then, a smart application would bypass the
glibc()fallocate()implementation and would tune the reservation window size and would use direct-IO or sync_file_range()+fadvise(FADV_DONTNEED).Quoted 8 lines
This wlil result in the same
layout as if we had done the persistent preallocation, but of course it will mean theposix_fallocate()could potentially take a long time if you're a PVR and you're reserving a gig or two for a two hour movie at high quality. That seems suboptimal, granted, and ideally the application should be warned about this before it callsposix_fallocate(). On the other hand, it's what happens today, all the time, so applications won't be too badly surprised.A PVR implementor would take all this over and would do it themselves, for sure.
Quoted 7 lines
If we think applications programmers badly need to know in advance if
posix_fallocate()will be fast or slow, probably the right thing is to define a newfpathconf()configuration option so they can query to see whether a particular file will support a fastposix_fallocate(). I'm not 100% convinced such complexity is really needed, but I'm willing to be convinced.... what do folks think?An application could do
sys_fallocate(one-byte)to work out whether it's supported in-kernel, I guess.
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Andrew MortonQuoted 27 lines · Andrew Morton
Quoted 24 lines · On Mon, 07 May 2007 17:00:24 -0700 Mingming Cao <[email protected]> wrote:
Quoted 15 lines
fs/ext4/extents.c +15
-0+while (ret >=0 && ret < max_blocks) { + block = block + ret; + max_blocks = max_blocks - ret; + ret =ext4_ext_get_blocks (handle, inode, block, + max_blocks, &map_bh, +EXT4_CREATE_UNINITIALIZED_EXT ,0 ); +BUG_ON (!ret); +if (ret >0 &&test_bit (BH_New, &map_bh.b_state) + && ((block + ret) > (i_size_read (inode) << blkbits))) + nblocks = nblocks + ret; + } + +if (ret == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) + goto retry; +Quoted 5 lines
Now the interesting question is: what do we do if we get halfway through this loop and then run out of space? We could leave the disk all filled up and then return failure to the caller, but that's pretty poor behaviour, IMO.
The current code handles earlier ENOSPC by three times retries. After that if we still run out of space, then it's propably right to notify the caller there isn't much space left.
Quoted 5 lines
Quoted 2 lines
We could extend the block reservation window size before the while loop so we could get a lower chance to get more fragmented.
yes, but my point is that the proposed behaviour is really quite bad.
I agree your point, that's why I mention it only helped the fragmentation issue but not the ENOSPC case.
Quoted 4 lines
We will attempt to allocate the disk space and then we will return failure, having consumed all the disk space and having partially and uselessly populated an unknown amount of the file.
Not totally useless I think. If only half of the space is preallocated because run out of space, the application can decide whether it's good enough to start to use this preallocated space or wait for the fs to have more free space.
Quoted 10 lines
Userspace could presumably repair the mess in most situations by truncating the file back again. The kernel cannot do that because there might be live data in amongst there.
So we'd need to either keep track of which blocks were newly-allocated and then free them all again on the error path (doesn't work right across commit+crash+recovery) or we could later use the space-reservation scheme which delayed allocation will need to introduce.
Or we could decide to live with the above IMO-crappy behaviour.
In fact Amit and I had raised this issue before, whether it's okay to do allow partial preallocation. At that moment the feedback is it's no much different than the current zero-out-preallocation behavior: people might preallocating half-way then later deal with ENOSPC.
We could check the total number of fs free blocks account before preallocation happens, if there isn't enough space left, there is no need to bother preallocating.
If there is enough free space, we could make a reservation window that have at least N free blocks and mark it not stealable by other files. So later we will not run into the ENOSPC error.
The fs free blocks account is just a estimate though.
Mingming
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Jeff GarzikQuoted 9 lines · Jeff Garzik
Quoted 3 lines · Andreas Dilger
Actually, this is a non-issue. The reason that it is handled for extent-only is that this is the only way to allocate space in the filesystem without doing the explicit zeroing.
Precisely /how/ do you avoid the zeroing issue, for extents?
If I
posix_fallocate()20GB on ext4, it damn well better be zeroed, otherwise the implementation is broken.
In ext4 (as in XFS) there is a flag stored in the extent that tells if the extent is initialized or not. Reads from uninitialized extents will return zero-filled data, and writes that don't span the whole extent will cause the uninitialized extent to be split into a regular extent and one or two uninitialized extents (depending where the write is).
My comment was just that the extent doesn't have to be explicitly zero filled on the disk, by virtue of the fact that the uninitialized flag will cause reads to return zero.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Re: [PATCH 4/5] ext4: fallocate support in ext4
Quoted 3 lines · Andreas Dilger
My comment was just that the extent doesn't have to be explicitly zero filled on the disk, by virtue of the fact that the uninitialized flag will cause reads to return zero.
Agreed, thanks for the clarification.
Jeff
Theodore Tso
maintainerRe: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Mingming CaoQuoted 3 lines · Mingming Cao
We could check the total number of fs free blocks account before preallocation happens, if there isn't enough space left, there is no need to bother preallocating.
Checking against the fs free blocks is a good idea, since it will prevent the obvious error case where someone tries to preallocate 10GB when there is only 2GB left. But it won't help if there are multiple processes trying to allocate blocks the same time. On the other hand, that case is probably relatively rare, and in that case, the filesystem was probably going to be left completely full in any case.
Quoted 3 lines · Andrew Morton
Userspace could presumably repair the mess in most situations by truncating the file back again. The kernel cannot do that because there might be live data in amongst there.
Actually, the kernel could do it, in that could simply release all unitialized extents back to the system. The problem is distinguishing between the unitialized extents that had just been newly added, versus the ones that had there from before. (On the other hand, if the filesystem was completely full, releasing unitialized blocks wouldn't be the worse thing in the world to do, although releasing previously fallocated blocks probably does violate the princple of least surprise, even if it's what the user would have wanted.)
Quoted 3 lines · Mingming Cao
If there is enough free space, we could make a reservation window that have at least N free blocks and mark it not stealable by other files. So later we will not run into the ENOSPC error.
Could you really use a single reservation window? When the filesystem is almost full, the free extents are likely going to be scattered all over the disk. The general principle of grabbing all of the extents and keeping them in an in-memory data structure, and only adding them to the extent tree would work, though; I'm just not sure we could do it using the existing reservation window code, since it only supports a single reservation window per file, yes?
- Ted
Re: [PATCH 0/5] fallocate system call
In reply to Miquel van SmoorenburgQuoted 23 lines · Miquel van Smoorenburg
In article <[email protected]> you write:
Quoted 9 lines · Amit K. Arora
Quoted 8 lines · Chris Wedgwood
Quoted 6 lines · David Chinner
Quoted 3 lines
For
FA_ALLOCATE, it's supposed to change the file size if we allocate past EOF, right?I would argue no. Use truncate for that.
Quoted 8 lines
Quoted 3 lines
The patch I posted for ext4 *does* change the filesize after preallocation, if required (i.e. when preallocation is after EOF). I may have to change that, if we decide on not doing this.
I think I'd agree - it may be useful to allow preallocation beyond EOF for some kinds of applications (e.g. PVR preallocating live TV in 10 minute segments or something, but not knowing in advance how long the show will actually be recorded or the final encoded size).
I have an application (diablo dreader) where the header-info database basically consists of ~40.000 files, one for each group (it's more complicated that that, but never mind that now).
Quoted 7 lines
If you grow those files randomly by a few hundred bytes every update, the filesystem gets hopelessly fragmented.
I'm using XFS with preallocation turned on, and biosize=18 (which makes it preallocate in blocks of 256KB), and a homebrew patch that leaves the preallocated space on disk preallocated even if the file is closed .. and it helps enormously.
XFS always has speculative preallocation turned on - this is different to explicit preallocation which we are talking about here ;)
FWIW, the reason you need your homebrew patch is that specualtive allocation does not set the PREALLOC bit on the inode, and so when you close the file the speculative prealloc gets truncated away. If you use a real preallocation (XFS_IOC_RESVSP64) or the upcoming fallocate() syscall, XFS also sets the PREALLOC bit in the inode so it doesn't get truncated away on file close.
If you don't want to use XFS_IOC_RESVSP64, you could just use XFS_IOC_FSSETXATTR to set the prealloc bit on the files you care about so you don't need a hack in XFS to prevent truncation of speculative allocation on file close.....
Cheers,
Dave.
Signature · 3 lines
Dave Chinner Principal Engineer SGI Australian Software Group
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Dave KleikampQuoted 32 lines · Dave Kleikamp
Quoted 22 lines · Amit K. Arora
Quoted 12 lines · Andrew Morton
Quoted 10 lines · On Thu, 26 Apr 2007 23:43:32 +0530 "Amit K. Arora" <[email protected]>…
fs/ext4/extents.c +10
-0+int ext4_fallocate (struct inode *inode,int mode,loff_t offset,loff_t len) +{ +handle_t *handle; +ext4_fsblk_t block, max_blocks; +int ret, ret2, nblocks =0 , retries =0 ; +struct buffer_head map_bh; +unsigned int credits, blkbits = inode->i_blkbits; + +/* Currently supporting (pre)allocate mode _only_ */ +if (mode !=FA_ALLOCATE )Quoted 8 lines
fs/ext4/extents.c int ext4_ext_writepage_trans_blocks(stru · line 2265
Quoted 4 lines
fs/ext4/extents.c +4
-0+return -EOPNOTSUPP ; + +if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) +return -ENOTTY ;So we don't implement fallocate on bitmap-based files! Well that's huge news. The changelog would be an appropriate place to communicate this, along with reasons why, or a description of the plan to fix it.
Quoted 8 lines
Ok. Will add this in the function description as well.
Quoted 1 line
Also, posix says nothing about
fallocate()returning ENOTTY.Right. I don't seem to find any suitable error from posix description. Can you please suggest an error code which might make more sense here ? Will
-ENOTSUPPbe ok ? Since we want to say here that we don't support non-extent files.
Quoted 4 lines
Isn't the idea that libc will interpret
-ENOTTY, or whatever is returned here, and fall back to the current library code to do preallocation? This way, the caller offallocate()will never see this return code, so it won't violate posix.
You are right.
But, we still need to "standardize" (and limit) the error codes which we should return from kernel when we want to fall back on the library implementation. The posix_fallocate() library function will have to look for a set of errors from fallocate() system call, upon receiving which it will do preallocation from user level; or else, it will return success/error-code returned by the system call to the user.
I think we can make it fall back to library implementation of fallocate, whenever posix_fallocate() receives any of the following errors from fallocate() system call:
1. ENOSYS
2. EOPNOTSUPP
3. ENOTTY (?)
Now the question is - should we limit the set of errors for this purpose to just 1 & 2 above ? In that case I will need to change the error being returned here to -EOPNOTSUPP (from current -ENOTTY).
--
Regards,
Amit Arora
Re: [PATCH 4/5] ext4: fallocate support in ext4
Quoted 35 lines · Amit K. Arora
Quoted 16 lines · Dave Kleikamp
Quoted 6 lines · Amit K. Arora
Quoted 3 lines · Andrew Morton
So we don't implement fallocate on bitmap-based files! Well that's huge news. The changelog would be an appropriate place to communicate this, along with reasons why, or a description of the plan to fix it.
Quoted 8 lines
Ok. Will add this in the function description as well.
Quoted 1 line
Also, posix says nothing about
fallocate()returning ENOTTY.Right. I don't seem to find any suitable error from posix description. Can you please suggest an error code which might make more sense here ? Will
-ENOTSUPPbe ok ? Since we want to say here that we don't support non-extent files.Quoted 4 lines
Isn't the idea that libc will interpret
-ENOTTY, or whatever is returned here, and fall back to the current library code to do preallocation? This way, the caller offallocate()will never see this return code, so it won't violate posix.You are right.
But, we still need to "standardize" (and limit) the error codes which we should return from kernel when we want to fall back on the library implementation. The
posix_fallocate()library function will have to look for a set of errors fromfallocate()system call, upon receiving which it will do preallocation from user level; or else, it will return success/error-code returned by the system call to the user.I think we can make it fall back to library implementation of fallocate, whenever
posix_fallocate()receives any of the following errors fromfallocate()system call:
Quoted 7 lines
1. ENOSYS
2. EOPNOTSUPP
3. ENOTTY (?)Now the question is - should we limit the set of errors for this purpose to just 1 & 2 above ? In that case I will need to change the error being returned here to
-EOPNOTSUPP(from current-ENOTTY).
If you want my opinion, -EOPNOTSUPP is better than -ENOTTY.
Shaggy
Signature · 2 lines
David Kleikamp IBM Linux Technology Center
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Theodore TsoQuoted 5 lines · Theodore Tso
Quoted 3 lines · Andrew Morton
Userspace could presumably repair the mess in most situations by truncating the file back again. The kernel cannot do that because there might be live data in amongst there.
Quoted 8 lines
Actually, the kernel could do it, in that could simply release all unitialized extents back to the system. The problem is distinguishing between the unitialized extents that had just been newly added, versus the ones that had there from before. (On the other hand, if the filesystem was completely full, releasing unitialized blocks wouldn't be the worse thing in the world to do, although releasing previously fallocated blocks probably does violate the princple of least surprise, even if it's what the user would have wanted.)
I tend to agree with this. Having fallocate() fill up the filesystem is exactly what the caller asked. Doing a write() hit ENOSPC doesn't trucate off the whole write either, nor does "dd" delete the whole file when the filesystem is full.
Even checking the statfs() space before doing the fallocate() may be counter intuitive, since it will return ENOSPC but the filesystem will not actually be full. Some applications (e.g. database) may WANT to fill the filesystem and then get the actual file size back to avoid trusting statfs() because of metadata overhead (e.g. indirect blocks).
One of the design goals for sys_fallocate() was to allow FA_DELALLOC to deallocate unwritten extents in a safe manner.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Re: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Theodore TsoQuoted 8 lines · Theodore Tso
Quoted 3 lines · Mingming Cao
We could check the total number of fs free blocks account before preallocation happens, if there isn't enough space left, there is no need to bother preallocating.
Checking against the fs free blocks is a good idea, since it will prevent the obvious error case where someone tries to preallocate 10GB when there is only 2GB left.
Think it again, this check is useful when preallocate blocks at EOF. It's not much useful is preallocating a range with holes. In that case 2GB space might be enough if the application tries to preallocate a 10GB.
Quoted 6 lines
But it won't help if there are multiple
processes trying to allocate blocks the same time. On the other hand, that case is probably relatively rare, and in that case, the filesystem was probably going to be left completely full in any case.On Mon, May 07, 2007 at 05:15:41PM -0700, Andrew Morton wrote:
Quoted 8 lines
Quoted 3 lines
Userspace could presumably repair the mess in most situations by truncating the file back again. The kernel cannot do that because there might be live data in amongst there.
Actually, the kernel could do it, in that could simply release all unitialized extents back to the system. The problem is distinguishing between the unitialized extents that had just been newly added, versus the ones that had there from before.
True, the new uninitialized extents can be merged to the near old uninitialized extents, there is no way to distinguish the just added unintialized extents from the merged one.
Quoted 11 lines
(On the other hand, if the
filesystem was completely full, releasing unitialized blocks wouldn't be the worse thing in the world to do, although releasing previously fallocated blocks probably does violate the princple of least surprise, even if it's what the user would have wanted.)Quoted 3 lines · Mingming Cao
If there is enough free space, we could make a reservation window that have at least N free blocks and mark it not stealable by other files. So later we will not run into the ENOSPC error.
Quoted 8 lines
Could you really use a single reservation window? When the filesystem is almost full, the free extents are likely going to be scattered all over the disk. The general principle of grabbing all of the extents and keeping them in an in-memory data structure, and only adding them to the extent tree would work, though; I'm just not sure we could do it using the existing reservation window code, since it only supports a single reservation window per file, yes?
You are right. One reservation window per file and there is limit to the maximum window size). So yeah this way it's not going to prevent ENOSPC for sure:(
Mingming
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Paul MackerrasQuoted 11 lines · Paul Mackerras
Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Thu, 26 Apr 2007 23:33:32 +0530 "Amit K. Arora" <[email protected]>…
This patch implements the
fallocate()system call and adds support for i386,x86_64and powerpc....
+asmlinkage long
sys_fallocate(int fd, int mode, loff_t offset, loff_t len)
Quoted 8 lines
Quoted 3 lines
Please add a comment over this function which specifies its behaviour. Really it should be enough material from which a full manpage can be written.
This looks like it will have the same problem on s390 as
sys_sync_file_range. Maybe the prototype should be:asmlinkage long
sys_fallocate(loff_t offset, loff_t len, int fd, int mode)
Yes, but the trouble is that there was a contrary viewpoint preferring that fd first be maintained as a convention like other syscalls (see the following posts)
http://marc.info/?l=linux-fsdevel&m=117585330016809&w=2 (Andreas)
http://marc.info/?l=linux-fsdevel&m=117690157917378&w=2 (Andreas)
http://marc.info/?l=linux-fsdevel&m=117578821827323&w=2 (Randy)
So we are kind of deadlocked, aren't we ?
The debates on the proposed solution for s390
http://marc.info/?l=linux-fsdevel&m=117760995610639&w=2
http://marc.info/?l=linux-fsdevel&m=117708124913098&w=2
http://marc.info/?l=linux-fsdevel&m=117767607229807&w=2
Are there any better ideas ?
Regards
Suparna
Quoted 6 lines
Paul.
-
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Suparna Bhattacharya ([email protected]) Linux Technology Center IBM Software Lab, India
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
Quoted 8 lines · Suparna Bhattacharya
Quoted 4 lines
This looks like it will have the same problem on s390 as
sys_sync_file_range. Maybe the prototype should be:asmlinkage long
sys_fallocate(loff_t offset, loff_t len, int fd, int mode)Yes, but the trouble is that there was a contrary viewpoint preferring that fd first be maintained as a convention like other syscalls (see the following posts)
Of course the interface used by an application program would have the fd first. Glibc can do the translation.
Paul.
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
Quoted 5 lines · Paul Mackerras
Quoted 3 lines · Suparna Bhattacharya
Quoted 3 lines
This looks like it will have the same problem on s390 as
sys_sync_file_range. Maybe the prototype should be:
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
asmlinkage long
sys_fallocate(loff_t offset, loff_t len, int fd, int mode)Yes, but the trouble is that there was a contrary viewpoint preferring that fd first be maintained as a convention like other syscalls (see the following posts)
Of course the interface used by an application program would have the fd first. Glibc can do the translation.
I think that was understood.
Regards
Suparna
Quoted 2 lines
Paul.
Signature · 3 lines
Suparna Bhattacharya ([email protected]) Linux Technology Center IBM Software Lab, India
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
Quoted 4 lines · Suparna Bhattacharya
Quoted 2 lines
Of course the interface used by an application program would have the fd first. Glibc can do the translation.
I think that was understood.
OK, then what does it matter what the glibc/kernel interface is, as long as it works?
It's only a minor point; the order of arguments can vary between architectures if necessary, but it's nicer if they don't have to. 32-bit powerpc will need to have the two int arguments adjacent in order to avoid using more than 6 argument registers at the user/kernel boundary, and s390 will need to avoid having a 64-bit argument last (if I understand it correctly).
Paul.
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
Quoted 10 lines · Paul Mackerras
Quoted 4 lines · Suparna Bhattacharya
Quoted 2 lines
Of course the interface used by an application program would have the fd first. Glibc can do the translation.
I think that was understood.
OK, then what does it matter what the glibc/kernel interface is, as long as it works?
Quoted 6 lines
It's only a minor point; the order of arguments can vary between architectures if necessary, but it's nicer if they don't have to. 32-bit powerpc will need to have the two int arguments adjacent in order to avoid using more than 6 argument registers at the user/kernel boundary, and s390 will need to avoid having a 64-bit argument last (if I understand it correctly).
Ah, almost but not quite the point. But I admit it is hard to understand.. The trouble started with the futex call which has been the first system call with 6 arguments. s390 supported only 5 arguments up to that point (%r2 - %r6). For futex we added a wrapper to the glibc that loaded the 6th argument to %r7. In entry.S we set up things so that %r7 gets stored to the kernel stack where normal C code expects the first overflow argument. This enabled us to use the standard futex system call with 6 arguments.
fallocate now has an additional problem: the last argument is a 64 bit integers AND registers %r2-%r5 are already used. In this case the 64 bit number would have to be split into the high part in %r6 and the low part on the stack so that the glibc wrapper can load the low part to %r7. But the C compiler will skip %r6 and store the 64 bit number on the stack.
If the order of the arguments if modified so that %r6 is assigned to a 32-bit argument, then the entry.S magic with %r7 would work.
Signature · 2 lines
blue skies, Martin
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Paul MackerrasQuoted 10 lines · Paul Mackerras
Quoted 4 lines · Suparna Bhattacharya
Quoted 2 lines
Of course the interface used by an application program would have the fd first. Glibc can do the translation.
I think that was understood.
OK, then what does it matter what the glibc/kernel interface is, as long as it works?
Quoted 6 lines
It's only a minor point; the order of arguments can vary between architectures if necessary, but it's nicer if they don't have to. 32-bit powerpc will need to have the two int arguments adjacent in order to avoid using more than 6 argument registers at the user/kernel boundary, and s390 will need to avoid having a 64-bit argument last (if I understand it correctly).
You are right to say that. But, it may not be _that_ a minor point, especially for the arch which is getting affected. It has other implications like what Heiko noticed in his post below:
http://lkml.org/lkml/2007/4/27/377
- implications like modifying glibc and *trace utilities for a particular
arch.
--
Regards,
Amit Arora
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Amit K. AroraI have the updated patches ready which take care of Andrew's comments. Will run some tests and post them soon.
But, before submitting these patches, I think it will be better to finalize on certain things which might be worth some discussion here:
1) Should the file size change when preallocation is done beyond EOF ?
- Andreas and Chris Wedgwood are in favor of not changing the file size in this case. I also tend to agree with them. Does anyone has an argument in favor of changing the filesize ?
If not, I will remove the code which changes the filesize, before I resubmit the concerned ext4 patch.
2) For FA_UNALLOCATE mode, should the file system allow unallocation of normal (non-preallocated) blocks (blocks allocated via regular write/truncate operations) also (i.e. work as punch()) ?
- Though FA_UNALLOCATE mode is yet to be implemented on ext4, still we need to finalize on the convention here as a general guideline to all the filesystems that implement fallocate.
3) If above is true, the file size will need to be changed for "unallocation" when block holding the EOF gets unallocated.
- If we do not "unallocate" normal (non-preallocated) blocks and we do not change the file size on preallocation, then this is a non-issue.
4) Should we update mtime & ctime on a successfull allocation/ unallocation ?
- David Chinner raised this question in following post:
http://lkml.org/lkml/2007/4/29/407
I think it makes sense to update the [mc]time for a successfull preallocation/unallocation. Does anyone feel otherwise ? It will be interesting to know how XFS behaves currently. Does XFS update [mc]time for preallocation ?
--
Regards,
Amit Arora
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
Quoted 6 lines · Amit K. Arora
2) For
FA_UNALLOCATEmode, should the file system allow unallocation of normal (non-preallocated) blocks (blocks allocated via regular write/truncate operations) also (i.e. work aspunch()) ?
- ThoughFA_UNALLOCATEmode is yet to be implemented on ext4, still we need to finalize on the convention here as a general guideline to all the filesystems that implement fallocate.
I would only allow this on FA_ALLOCATE extents. That means it won't be possible to do this for filesystems that don't understand unwritten extents unless there are blocks allocated beyond EOF.
Quoted 5 lines
3) If above is true, the file size will need to be changed for "unallocation" when block holding the EOF gets unallocated.
- If we do not "unallocate" normal (non-preallocated) blocks and we do not change the file size on preallocation, then this is a non-issue.
Not necessarily. That will just make the file sparse. If FA_ALLOCATE does not change the file size, why should FA_UNALLOCATE.
Quoted 2 lines
4) Should we update mtime & ctime on a successfull allocation/ unallocation ?
I would say yes. If glibc does the fallback fallocate via write() the mtime/ctime will be updated, so it makes sense to be consistent for both methods. Also, it just makes sense from the "this file was modified" point of view.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Amit K. AroraQuoted 6 lines · Amit K. Arora
I have the updated patches ready which take care of Andrew's comments. Will run some tests and post them soon.
But, before submitting these patches, I think it will be better to finalize on certain things which might be worth some discussion here:
Quoted 7 lines
1) Should the file size change when preallocation is done beyond EOF ?
- Andreas and Chris Wedgwood are in favor of not changing the file size in this case. I also tend to agree with them. Does anyone has an argument in favor of changing the filesize ?
If not, I will remove the code which changes the filesize, before I resubmit the concerned ext4 patch.
If we chose not to update the file size beyong EOF, then for filesystem without fallocate() support (ext2,3 currently), posix_fallocate() will follow the hard way(zero-out) to do preallocation. Then we will get different behavior on filesystems w/o fallocate() support. It make sense to be consistent, IMO.
My point of view, preallocation is just a efficient way to allocating blocks for files without zero-out, other than this, the new behavior should be consistent with the old way: file size update,mtime/ctime, ENOSPC etc.
Mingming
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
In reply to Amit K. AroraQuoted 6 lines · Amit K. Arora
I have the updated patches ready which take care of Andrew's comments. Will run some tests and post them soon.
But, before submitting these patches, I think it will be better to finalize on certain things which might be worth some discussion here:
Quoted 6 lines
1) Should the file size change when preallocation is done beyond EOF ?
- Andreas and Chris Wedgwood are in favor of not changing the file size in this case. I also tend to agree with them. Does anyone has an argument in favor of changing the filesize ?
If not, I will remove the code which changes the filesize, before I resubmit the concerned ext4 patch.
I think there needs to be both. If we don't have a mechanism to atomically change the file size with the preallocation, then applications that use stat() to work out if they need to preallocate more space will end up racing.
Quoted 3 lines
2) For
FA_UNALLOCATEmode, should the file system allow unallocation of normal (non-preallocated) blocks (blocks allocated via regular write/truncate operations) also (i.e. work aspunch()) ?
Yes. That is the current XFS implementation for XFS_IOC_UNRESVSP, and what i did for FA_UNALLOCATE as well.
Quoted 6 lines
- Though
FA_UNALLOCATEmode is yet to be implemented on ext4, still we need to finalize on the convention here as a general guideline to all the filesystems that implement fallocate.3) If above is true, the file size will need to be changed for "unallocation" when block holding the EOF gets unallocated.
No - we punch a hole. If you want the filesize to change, then you use ftruncate() to remove the blocks at EOF and change the file size atomically.
Quoted 8 lines
4) Should we update mtime & ctime on a successfull allocation/ unallocation ?
- David Chinner raised this question in following post:
http://lkml.org/lkml/2007/4/29/407
I think it makes sense to update the [mc]time for a successfull preallocation/unallocation. Does anyone feel otherwise ? It will be interesting to know how XFS behaves currently. Does XFS update [mc]time for preallocation ?
No, XFS does *not* update a/m/ctime on prealloc/punch unless the file size changes. If the filesize changes, it behaves exactly the same way that ftruncate() behaves.
Cheers,
Dave.
Signature · 3 lines
Dave Chinner Principal Engineer SGI Australian Software Group
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
Quoted 14 lines · David Chinner
Quoted 6 lines · Amit K. Arora
I have the updated patches ready which take care of Andrew's comments. Will run some tests and post them soon.
But, before submitting these patches, I think it will be better to finalize on certain things which might be worth some discussion here:
Quoted 6 lines
1) Should the file size change when preallocation is done beyond EOF ?
- Andreas and Chris Wedgwood are in favor of not changing the file size in this case. I also tend to agree with them. Does anyone has an argument in favor of changing the filesize ?
If not, I will remove the code which changes the filesize, before I resubmit the concerned ext4 patch.
Quoted 4 lines
I think there needs to be both. If we don't have a mechanism to atomically change the file size with the preallocation, then applications that use
stat()to work out if they need to preallocate more space will end up racing.
By "both" above, do you mean we should give user the flexibility if it wants the filesize changed or not ? It can be done by having *two* modes for preallocation in the system call - say FA_PREALLOCATE and FA_ALLOCATE. If we use FA_PREALLOCATE mode, fallocate() will allocate blocks, but will not change the filesize and [cm]time. If FA_ALLOCATE mode is used, fallocate() will change the filesize if required (i.e. when allocation is beyond EOF) and also update [cm]time. This way, the application can decide what it wants.
This will be helpfull for the partial allocation scenario also. Think of the case when we do not change the filesize in fallocate() and expect applications/posix_fallocate() to do ftruncate() after fallocate() for this. Now if fallocate() results in a partial allocation with -ENOSPC error returned, applications/posix_fallocate() will not know for what length ftruncate() has to be called. :(
Hence it may be a good idea to give user the flexibility if it wants to atomically change the file size with preallocation or not. But, with more flexibility there comes inconsistency in behavior, which is worth considering.
Quoted 7 lines
Quoted 4 lines
2) For
FA_UNALLOCATEmode, should the file system allow unallocation of normal (non-preallocated) blocks (blocks allocated via regular write/truncate operations) also (i.e. work aspunch()) ?Yes. That is the current XFS implementation for
XFS_IOC_UNRESVSP, and what i did forFA_UNALLOCATEas well.
Ok. But, some people may not expect/like this. I think, we can keep it on the backburner for a while, till other issues are sorted out.
Quoted 10 lines
Quoted 6 lines
- Though
FA_UNALLOCATEmode is yet to be implemented on ext4, still we need to finalize on the convention here as a general guideline to all the filesystems that implement fallocate.3) If above is true, the file size will need to be changed for "unallocation" when block holding the EOF gets unallocated.
No - we punch a hole. If you want the filesize to change, then you use
ftruncate()to remove the blocks at EOF and change the file size atomically.
Ok.
Quoted 10 lines
Quoted 9 lines
4) Should we update mtime & ctime on a successfull allocation/ unallocation ?
- David Chinner raised this question in following post:
http://lkml.org/lkml/2007/4/29/407
I think it makes sense to update the [mc]time for a successfull preallocation/unallocation. Does anyone feel otherwise ? It will be interesting to know how XFS behaves currently. Does XFS update [mc]time for preallocation ?
Quoted 3 lines
No, XFS does *not* update a/m/ctime on prealloc/punch unless the file size changes. If the filesize changes, it behaves exactly the same way that
ftruncate()behaves.
Having additional mode (of FA_PREALLOCATE) might help here too. Please see above.
--
Regards,
Amit Arora
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
Quoted 20 lines · Amit K. Arora
Quoted 14 lines · David Chinner
Quoted 6 lines · Amit K. Arora
I have the updated patches ready which take care of Andrew's comments. Will run some tests and post them soon.
But, before submitting these patches, I think it will be better to finalize on certain things which might be worth some discussion here:
Quoted 6 lines
1) Should the file size change when preallocation is done beyond EOF ?
- Andreas and Chris Wedgwood are in favor of not changing the file size in this case. I also tend to agree with them. Does anyone has an argument in favor of changing the filesize ? If not, I will remove the code which changes the filesize, before I resubmit the concerned ext4 patch.Quoted 4 lines
I think there needs to be both. If we don't have a mechanism to atomically change the file size with the preallocation, then applications that use
stat()to work out if they need to preallocate more space will end up racing.
Quoted 8 lines
By "both" above, do you mean we should give user the flexibility if it wants the filesize changed or not ? It can be done by having *two* modes for preallocation in the system call - say
FA_PREALLOCATEandFA_ALLOCATE. If we useFA_PREALLOCATEmode,fallocate()will allocate blocks, but will not change the filesize and [cm]time. IfFA_ALLOCATEmode is used,fallocate()will change the filesize if required (i.e. when allocation is beyond EOF) and also update [cm]time. This way, the application can decide what it wants.
Yes, that's right.
Quoted 6 lines
This will be helpfull for the partial allocation scenario also. Think of the case when we do not change the filesize in
fallocate()and expect applications/posix_fallocate() to doftruncate()afterfallocate()for this. Now iffallocate()results in a partial allocation with-ENOSPCerror returned, applications/posix_fallocate() will not know for what lengthftruncate()has to be called. :(
Well, posix_fallocate() either gets all the space or it fails. If you truncate to extend the file size after an ENOSPC, then that is a buggy implementation.
The same could be said for any application, or even the fallocate() call itself if it changes the filesize without having completely preallocated the space asked....
Quoted 4 lines
Hence it may be a good idea to give user the flexibility if it wants to atomically change the file size with preallocation or not. But, with more flexibility there comes inconsistency in behavior, which is worth considering.
We've got different modes to specify different behaviour. That's what the mode field was put there for in the first place - the interface is *designed* to support different preallocation behaviours....
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
2) For
FA_UNALLOCATEmode, should the file system allow unallocation of normal (non-preallocated) blocks (blocks allocated via regular write/truncate operations) also (i.e. work aspunch()) ?Yes. That is the current XFS implementation for
XFS_IOC_UNRESVSP, and what i did forFA_UNALLOCATEas well.Ok. But, some people may not expect/like this. I think, we can keep it on the backburner for a while, till other issues are sorted out.
How can it be a "backburner" issue when it defines the implementation? I've already implemented some thing in XFS that sort of does what I think that the interface is supposed to do, but I need that interface to be nailed down before proceeding any further.
All I'm really interested in right now is that the fallocate _interface_ can be used as a *complete replacement* for the pre-existing XFS-specific ioctls that are already used by applications. What ext4 can or can't do right now is irrelevant to this discussion - the interface definition needs to take priority over implementation....
Cheers,
Dave,
Signature · 3 lines
Dave Chinner Principal Engineer SGI Australian Software Group
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
Quoted 73 lines · David Chinner
Quoted 20 lines · Amit K. Arora
Quoted 14 lines · David Chinner
Quoted 6 lines · Amit K. Arora
I have the updated patches ready which take care of Andrew's comments. Will run some tests and post them soon.
But, before submitting these patches, I think it will be better to finalize on certain things which might be worth some discussion here:
Quoted 6 lines
1) Should the file size change when preallocation is done beyond EOF ?
- Andreas and Chris Wedgwood are in favor of not changing the file size in this case. I also tend to agree with them. Does anyone has an argument in favor of changing the filesize ? If not, I will remove the code which changes the filesize, before I resubmit the concerned ext4 patch.Quoted 4 lines
I think there needs to be both. If we don't have a mechanism to atomically change the file size with the preallocation, then applications that use
stat()to work out if they need to preallocate more space will end up racing.Quoted 8 lines
By "both" above, do you mean we should give user the flexibility if it wants the filesize changed or not ? It can be done by having *two* modes for preallocation in the system call - say
FA_PREALLOCATEandFA_ALLOCATE. If we useFA_PREALLOCATEmode,fallocate()will allocate blocks, but will not change the filesize and [cm]time. IfFA_ALLOCATEmode is used,fallocate()will change the filesize if required (i.e. when allocation is beyond EOF) and also update [cm]time. This way, the application can decide what it wants.Yes, that's right.
Quoted 6 lines
This will be helpfull for the partial allocation scenario also. Think of the case when we do not change the filesize in
fallocate()and expect applications/posix_fallocate() to doftruncate()afterfallocate()for this. Now iffallocate()results in a partial allocation with-ENOSPCerror returned, applications/posix_fallocate() will not know for what lengthftruncate()has to be called. :(Well,
posix_fallocate()either gets all the space or it fails. If you truncate to extend the file size after an ENOSPC, then that is a buggy implementation.The same could be said for any application, or even the
fallocate()call itself if it changes the filesize without having completely preallocated the space asked....Quoted 4 lines
Hence it may be a good idea to give user the flexibility if it wants to atomically change the file size with preallocation or not. But, with more flexibility there comes inconsistency in behavior, which is worth considering.
We've got different modes to specify different behaviour. That's what the mode field was put there for in the first place - the interface is *designed* to support different preallocation behaviours....
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
2) For
FA_UNALLOCATEmode, should the file system allow unallocation of normal (non-preallocated) blocks (blocks allocated via regular write/truncate operations) also (i.e. work aspunch()) ?Yes. That is the current XFS implementation for
XFS_IOC_UNRESVSP, and what i did forFA_UNALLOCATEas well.Ok. But, some people may not expect/like this. I think, we can keep it on the backburner for a while, till other issues are sorted out.
How can it be a "backburner" issue when it defines the implementation? I've already implemented some thing in XFS that sort of does what I think that the interface is supposed to do, but I need that interface to be nailed down before proceeding any further.
Quoted 6 lines
All I'm really interested in right now is that the fallocate _interface_ can be used as a *complete replacement* for the pre-existing XFS-specific ioctls that are already used by applications. What ext4 can or can't do right now is irrelevant to this discussion - the interface definition needs to take priority over implementation....
Would you like to write up an interface definition description (likely man page) and post it for review, possibly with a mention of apps using it today ?
One reason for introducing the mode parameter was to allow the interface to evolve incrementally as more options / semantic questions are proposed, so that we don't have to make all the decisions right now.
So it would be good to start with a *minimal* definition, even just one mode. The rest could follow as subsequent patches, each being reviewed and debated separately. Otherwise this discussion can drag on for a long time.
Regards
Suparna
Quoted 12 lines
Cheers,
Dave,
Signature · 7 lines
Dave Chinner Principal Engineer SGI Australian Software Group - To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Suparna Bhattacharya ([email protected]) Linux Technology Center IBM Software Lab, India
Re: [PATCH 1/5] fallocate() implementation in i86, x86_64 and powerpc
Quoted 11 lines · Suparna Bhattacharya
Quoted 6 lines · David Chinner
All I'm really interested in right now is that the fallocate _interface_ can be used as a *complete replacement* for the pre-existing XFS-specific ioctls that are already used by applications. What ext4 can or can't do right now is irrelevant to this discussion - the interface definition needs to take priority over implementation....
Would you like to write up an interface definition description (likely man page) and post it for review, possibly with a mention of apps using it today ?
Yeah, I started doing that yesterday as i figured it was the only way to cut the discussion short....
Quoted 6 lines
One reason for introducing the mode parameter was to allow the interface to evolve incrementally as more options / semantic questions are proposed, so that we don't have to make all the decisions right now.
So it would be good to start with a *minimal* definition, even just one mode. The rest could follow as subsequent patches, each being reviewed and debated separately. Otherwise this discussion can drag on for a long time.
Minimal definition to replace what applicaitons use on XFS and to support poasix_fallocate are the thre that have been mentioned so far (FA_ALLOCATE, FA_PREALLOCATE, FA_DEALLOCATE). I'll document them all in a man page...
Cheers,
Dave.
Signature · 3 lines
Dave Chinner Principal Engineer SGI Australian Software Group
cover fallocate system call
In reply to Amit K. AroraThis is the new set of patches which take care of the review comments received from the community (mainly from Andrew).
Description:
-----------fallocate() is a new system call being proposed here which will allow applications to preallocate space to any file(s) in a file system. Each file system implementation that wants to use this feature will need to support an inode operation called fallocate.
Applications can use this feature to avoid fragmentation to certain level and thus get faster access speed. With preallocation, applications also get a guarantee of space for particular file(s) - even if later the the system becomes full.
Currently, glibc provides an interface called posix_fallocate() which can be used for similar cause. Though this has the advantage of working on all file systems, but it is quite slow (since it writes zeroes to each block that has to be preallocated). Without a doubt, file systems can do this more efficiently within the kernel, by implementing the proposed fallocate() system call. It is expected that posix_fallocate() will be modified to call this new system call first and incase the kernel/filesystem does not implement it, it should fall back to the current implementation of writing zeroes to the new blocks.
Interface:
---------
The proposed system call's layout is:
asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len)
fd: The descriptor of the open file.
mode*: This specifies the behavior of the system call. Currently the
system call supports two modes - FA_ALLOCATE and FA_DEALLOCATE.
FA_ALLOCATE: Applications can use this mode to preallocate blocks to
a given file (specified by fd). This mode changes the file size if the preallocation is done beyond the EOF. It also updates the ctime/mtime in the inode of the corresponding file, marking a successfull allocation.
FA_DEALLOCATE: This mode can be used by applications to deallocate the
previously preallocated blocks. This also may change the file size and the ctime/mtime.
* New modes might get added in future. One such new mode which is already under discussion is FA_PREALLOCATE, which when used will preallocate space but will not change the filesize and [cm]time. Since the semantics of this new mode is not clear and agreed upon yet, this patchset does not implement it currently.
offset: This is the offset in bytes, from where the preallocation should
start.
len: This is the number of bytes requested for preallocation (from
offset).
sys_fallocate() on s390:
-----------------------
There is a problem with s390 ABI to implement sys_fallocate() with the proposed order of arguments. Martin Schwidefsky has suggested a patch to solve this problem which makes use of a wrapper in the kernel. This will require special handling of this system call on s390 in glibc as well. But, this seems to be the best solution so far.
Known Problem:
-------------
mmapped writes into uninitialized extents is a known problem with the current ext4 patches. Like XFS, ext4 may need to implement ->page_mkwrite() to solve this. See:
http://lkml.org/lkml/2007/5/8/583
Since there is a talk of ->fault() replacing ->page_mkwrite() and also with a generic block_page_mkwrite() implementation already posted, we can implement this later some time. See:
http://lkml.org/lkml/2007/3/7/161
http://lkml.org/lkml/2007/3/18/198
ToDos:
-----
1> Implementation on other architectures (other than i386, x86_64, ppc64 and s390(x)). David Chinner has already posted a patch for ia64. 2> A generic file system operation to handle fallocate (generic_fallocate), for filesystems that do _not_ have the fallocate inode operation implemented.
3> Changes to glibc,
a) to support fallocate() system call
b) to make posix_fallocate() and posix_fallocate64() call fallocate()
Changelog:
---------
Each post will have an individual changelog for the particular patch. Following posts with patches follow:
Patch 1/5 : fallocate() implementation on i86, x86_64 and powerpc Patch 2/5 : fallocate() on s390
Patch 3/5 : ext4: Extent overlap bugfix
Patch 4/5 : ext4: fallocate support in ext4
Patch 5/5 : ext4: write support for preallocated blocks
--
Regards,
Amit Arora
Jan Kara
reviewerRe: [PATCH 4/5] ext4: fallocate support in ext4
In reply to Andrew MortonQuoted 4 lines
On Mon, 7 May 2007 05:37:54 -0600
Does the proposed implementation handle quotas correctly, btw? Has that been tested?
It seems to handle quotas fine - the block allocation itself does not
differ from the usual case, just the extents in the tree are marked as uninitialized...
The only question is whether DQUOT_PREALLOC_BLOCK() shouldn't be
called instead of DQUOT_ALLOC_BLOCK(). Then fallocate() won't be able to allocate anything after the softlimit has been reached which makes some sence but probably current behavior is kind-of less surprising.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SuSE CR Labs
PATCH 1/5 fallocate() implementation on i86, x86_64 and powerpc
In reply to a message not in the archiveThis patch implements sys_fallocate() and adds support on i386, x86_64 and powerpc platforms.
Changelog:
---------
Following changes were made to the previous version:
1) Added description before sys_fallocate() definition.
2) Return EINVAL for len<=0 (With new draft that Ulrich pointed to, posix_fallocate should return EINVAL for len <= 0.
3) Return EOPNOTSUPP if mode is not one of FA_ALLOCATE or FA_DEALLOCATE
4) Do not return ENODEV for dirs (let individual file systems decide if they want to support preallocation to directories or not.
5) Check for wrap through zero.
6) Update c/mtime if fallocate() succeeds.
7) Added mode descriptions in fs.h
8) Added variable names to function definition (fallocate inode op)
Here is the new patch:
--- arch/i386/kernel/syscall_table.S | 1 arch/powerpc/kernel/sys_ppc32.c | 7 +++ arch/x86_64/kernel/functionlist | 1 fs/open.c | 89 +++++++++++++++++++++++++++++++++++++++ include/asm-i386/unistd.h | 3 - include/asm-powerpc/systbl.h | 1 include/asm-powerpc/unistd.h | 3 - include/asm-x86_64/unistd.h | 4 + include/linux/fs.h | 13 +++++ include/linux/syscalls.h | 1 10 files changed, 120 insertions(+), 3 deletions(-)
arch/i386/kernel/syscall_table.S +1 -0
@@ -319,3 +319,4 @@ ENTRY(sys_call_table) .long sys_move_pages .long sys_getcpu .long sys_epoll_pwait + .long sys_fallocate /* 320 */
arch/x86_64/kernel/functionlist +1 -0
@@ -931,6 +931,7 @@ *(.text.sys_getitimer) *(.text.sys_getgroups) *(.text.sys_ftruncate) +*(.text.sys_fallocate) *(.text.sysfs_lookup) *(.text.sys_exit_group) *(.text.stub_fork)
fs/open.c +89 -0
95 lines not on this page · raw message
include/asm-i386/unistd.h +2 -1
@@ -325,10 +325,11 @@#define __NR_move_pages 317#define __NR_getcpu 318#define __NR_epoll_pwait 319 +#define __NR_fallocate 320#ifdef __KERNEL__ -#define NR_syscalls 320 +#define NR_syscalls 321#define __ARCH_WANT_IPC_PARSE_VERSION#define __ARCH_WANT_OLD_READDIR
include/asm-powerpc/systbl.h +1 -0
@@ -307,3 +307,4 @@ COMPAT_SYS_SPU(set_robust_list) COMPAT_SYS_SPU(move_pages) SYSCALL_SPU(getcpu) COMPAT_SYS(epoll_pwait) +COMPAT_SYS(fallocate)
include/asm-powerpc/unistd.h +2 -1
@@ -326,10 +326,11 @@#define __NR_move_pages 301#define __NR_getcpu 302#define __NR_epoll_pwait 303 +#define __NR_fallocate 304#ifdef __KERNEL__ -#define __NR_syscalls 304 +#define __NR_syscalls 305#define __NR__exit __NR_exit#define NR_syscalls __NR_syscalls
include/asm-x86_64/unistd.h +3 -1
@@ -619,8 +619,10 @@ __SYSCALL(__NR_sync_file_range, sys_sync __SYSCALL(__NR_vmsplice, sys_vmsplice)#define __NR_move_pages 279 __SYSCALL(__NR_move_pages, sys_move_pages) +#define __NR_fallocate 280 +__SYSCALL(__NR_fallocate, sys_fallocate) -#define __NR_syscall_max __NR_move_pages +#define __NR_syscall_max __NR_fallocate#ifndef __NO_STUBS#define __ARCH_WANT_OLD_READDIR
include/linux/fs.h +13 -0
@@ -264,6 +264,17 @@ extern int dir_notify_enable;#define SYNC_FILE_RANGE_WRITE 2#define SYNC_FILE_RANGE_WAIT_AFTER 4 +/* +* sys_fallocate modes +* Currently sys_fallocate supports two modes: +* FA_ALLOCATE : This is the preallocate mode, using which an application/user +* may request (pre)allocation of blocks. +* FA_DEALLOCATE: This is the deallocate mode, which can be used to free +* the preallocated blocks. +*/ +#define FA_ALLOCATE 0x1 +#define FA_DEALLOCATE 0x2 +#ifdef __KERNEL__#include <linux/linkage.h>
@@ -1125,6 +1136,8 @@ struct inode_operations {ssize_t (*listxattr) (struct dentry *,char *,size_t );int (*removexattr) (struct dentry *,const char *);void (*truncate_range)(struct inode *,loff_t ,loff_t ); +long (*fallocate)(struct inode *inode,int mode,loff_t offset, +loff_t len); };struct seq_file ;
include/linux/syscalls.h +1 -0
@@ -602,6 +602,7 @@ asmlinkage long sys_get_robust_list(intasmlinkage long sys_set_robust_list (struct robust_list_head __user *head,size_t len);asmlinkage long sys_getcpu (unsigned __user *cpu,unsigned __user *node,struct getcpu_cache __user *cache); +asmlinkage long sys_fallocate (int fd,int mode,loff_t offset,loff_t len);int kernel_execve (const char *filename,char *const argv[],char *const envp[]);
arch/powerpc/kernel/sys_ppc32.c +7 -0
@@ -777,6 +777,13 @@ asmlinkage int compat_sys_truncate64(conreturn sys_truncate (path, (high <<32 ) | low); } +asmlinkage long compat_sys_fallocate (int fd,int mode,u32 offhi,u32 offlo, +u32 lenhi,u32 lenlo) +{ +return sys_fallocate (fd, mode, ((loff_t )offhi <<32 ) | offlo, + ((loff_t )lenhi <<32 ) | lenlo); +} + asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,unsigned long low) {
PATCH 2/5 fallocate() on s390
In reply to a message not in the archiveThis is the patch suggested by Martin Schwidefsky. Here are the comments and patch from him.
-------------
From: Martin Schwidefsky <[email protected]>
This patch implements support of fallocate system call on s390(x) platform. A wrapper is added to address the issue which s390 ABI has with the arguments of this system call.
---
arch/s390/kernel/compat_wrapper.S | 10 ++++++++++ arch/s390/kernel/sys_s390.c | 29 +++++++++++++++++++++++++++++ arch/s390/kernel/syscalls.S | 1 + include/asm-s390/unistd.h | 3 ++- 4 files changed, 42 insertions(+), 1 deletion(-)
arch/s390/kernel/compat_wrapper.S +10 -0
@@ -1682,3 +1682,13 @@ compat_sys_utimes_wrapper: llgtr %r2,%r2 # char * llgtr %r3,%r3 # struct compat_timeval * jg compat_sys_utimes + + .globl sys_fallocate_wrapper +sys_fallocate_wrapper: + lgfr %r2,%r2 # int + lgfr %r3,%r3 # int + sllg %r4,%r4,32 # get high word of 64bit loff_t + lr %r4,%r5 # get low word of 64bit loff_t + sllg %r5,%r6,32 # get high word of 64bit loff_t + l %r5,164(%r15) # get low word of 64bit loff_t + jg sys_fallocate
arch/s390/kernel/syscalls.S +1 -0
@@ -322,3 +322,4 @@ NI_SYSCALL /* 310 sys_move_pages * SYSCALL(sys_getcpu,sys_getcpu,sys_getcpu_wrapper) SYSCALL(sys_epoll_pwait,sys_epoll_pwait,compat_sys_epoll_pwait_wrapper) SYSCALL(sys_utimes,sys_utimes,compat_sys_utimes_wrapper) +SYSCALL(s390_fallocate,sys_fallocate,sys_fallocate_wrapper)
arch/s390/kernel/sys_s390.c +29 -0
@@ -286,3 +286,32 @@ int kernel_execve(const char *filename, "d" (__arg3) : "memory"); return __svcres; } + +#ifndef CONFIG_64BIT +/* +* This is a wrapper to call sys_fallocate(). For 31 bit s390 the last +* 64 bit argument "len" is split into the upper and lower 32 bits. The +* system call wrapper in the user space loads the value to %r6/%r7. +* The code in entry.S keeps the values in %r2 - %r6 where they are and +* stores %r7 to 96(%r15). But the standard C linkage requires that +* the whole 64 bit value for len is stored on the stack and doesn't +* use %r6 at all. So s390_fallocate has to convert the arguments from +* %r2: fd, %r3: mode, %r4/%r5: offset, %r6/96(%r15)-99(%r15): len +* to +* %r2: fd, %r3: mode, %r4/%r5: offset, 96(%r15)-103(%r15): len +*/ +asmlinkage long s390_fallocate (int fd,int mode,loff_t offset, +u32 len_high,u32 len_low) +{ +union { +u64 len; +struct { +u32 high; +u32 low; + }; + } cv; + cv.high = len_high; + cv.low = len_low; +return sys_fallocate (fd, mode, offset, cv.len); +} +#endif
include/asm-s390/unistd.h +2 -1
@@ -251,8 +251,9 @@#define __NR_getcpu 311#define __NR_epoll_pwait 312#define __NR_utimes 313 +#define __NR_fallocate 314 -#define NR_syscalls 314 +#define NR_syscalls 315/* * There are some system calls that are not present on 64 bit, some
PATCH 3/5 ext4: Extent overlap bugfix
In reply to a message not in the archiveThis patch adds a check for overlap of extents and cuts short the new extent to be inserted, if there is a chance of overlap.
Changelog:
---------
As suggested by Andrew, a check for wrap though zero has been added.
Here is the new patch:
--- fs/ext4/extents.c | 60 ++++++++++++++++++++++++++++++++++++++-- include/linux/ext4_fs_extents.h | 1 2 files changed, 59 insertions(+), 2 deletions(-)
fs/ext4/extents.c +58 -2
@@ -1129,6 +1129,55 @@ ext4_can_extents_be_merged(struct inode }/* +* check if a portion of the "newext" extent overlaps with an +* existing extent. +* +* If there is an overlap discovered, it updates the length of the newext +* such that there will be no overlap, and then returns 1. +* If there is no overlap found, it returns 0. +*/ +unsigned int ext4_ext_check_overlap (struct inode *inode, +struct ext4_extent *newext, +struct ext4_ext_path *path) +{ +unsigned long b1, b2; +unsigned int depth, len1; +unsigned int ret =0 ; + + b1 =le32_to_cpu (newext->ee_block); + len1 =le16_to_cpu (newext->ee_len); + depth =ext_depth (inode); +if (!path[depth].p_ext) + goto out; + b2 =le32_to_cpu (path[depth].p_ext->ee_block); + +/* +* get the next allocated block if the extent in the path +* is before the requested block(s) +*/ +if (b2 < b1) { + b2 =ext4_ext_next_allocated_block (path); +if (b2 ==EXT_MAX_BLOCK ) + goto out; + } + +/* check for wrap through zero */ +if (b1 + len1 < b1) { + len1 =EXT_MAX_BLOCK - b1; + newext->ee_len =cpu_to_le16 (len1); + ret =1 ; + } + +/* check for overlap */ +if (b1 + len1 > b2) { + newext->ee_len =cpu_to_le16 (b2 - b1); + ret =1 ; + } +out: +return ret; +} + +/* * ext4_ext_insert_extent: * tries to merge requsted extent into the existing extent or * inserts requested extent as new one into the tree,
@@ -2032,7 +2081,15 @@ int ext4_ext_get_blocks(handle_t *handle/* allocate new block */ goal =ext4_ext_find_goal (inode, path, iblock); - allocated = max_blocks; + +/* Check if we can really insert (iblock)::(iblock+max_blocks) extent */ + newex.ee_block =cpu_to_le32 (iblock); + newex.ee_len =cpu_to_le16 (max_blocks); + err =ext4_ext_check_overlap (inode, &newex, path); +if (err) + allocated =le16_to_cpu (newex.ee_len); +else + allocated = max_blocks; newblock =ext4_new_blocks (handle, inode, goal, &allocated, &err);if (!newblock) goto out2;
@@ -2040,7 +2097,6 @@ int ext4_ext_get_blocks(handle_t *handle goal, newblock, allocated);/* try to insert new extent into found leaf and return */ - newex.ee_block =cpu_to_le32 (iblock);ext4_ext_store_pblock (&newex, newblock); newex.ee_len =cpu_to_le16 (allocated); err =ext4_ext_insert_extent (handle, inode, path, &newex);
include/linux/ext4_fs_extents.h +1 -0
@@ -190,6 +190,7 @@ ext4_ext_invalidate_cache(struct inode *extern int ext4_extent_tree_init (handle_t *,struct inode *);extern int ext4_ext_calc_credits_for_insert (struct inode *,struct ext4_ext_path *); +extern unsigned int ext4_ext_check_overlap (struct inode *,struct ext4_extent *,struct ext4_ext_path *);extern int ext4_ext_insert_extent (handle_t *,struct inode *,struct ext4_ext_path *,struct ext4_extent *);extern int ext4_ext_walk_space (struct inode *,unsigned long ,unsigned long ,ext_prepare_callback ,void *);extern struct ext4_ext_path *ext4_ext_find_extent (struct inode *,int ,struct ext4_ext_path *);