RFC: iomap-based swapfile activation
Subsystems (5)
cover RFC: iomap-based swapfile activation
V2 of iomap-based swapfile support.
Changes from V1: additional validations for file extents, based on a patch from Darrick Wong.
Aleksei Besogonov (2):
fs: Add iomap_swap_activate
xfs: add support for iomap-based swapfile activation
fs/iomap.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_aops.c | 8 ++++ include/linux/iomap.h | 5 +++ mm/swapfile.c | 1 + 4 files changed, 120 insertions(+)
Signature · 1 line
2.14.1
PATCH 1/2 fs: Add iomap_swap_activate
This commit adds an alternative to generic_swapfile_activate function based on iomap family. The major driver for this is swap file support on XFS, currently it doesn't work on files with holes due to deficiencies in the old bmap() interface that is used by generic_swapfile_activate.
--- fs/iomap.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/iomap.h | 5 +++ mm/swapfile.c | 1 + 3 files changed, 112 insertions(+)
fs/iomap.c +106 -0
@@ -94,6 +94,7 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,return written ? written : ret; } +EXPORT_SYMBOL_GPL (iomap_apply);static void iomap_write_failed (struct inode *inode,loff_t pos,unsigned len)
@@ -1089,3 +1090,108 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,return ret; }EXPORT_SYMBOL_GPL (iomap_dio_rw); + +struct iomap_swap_walker_context +{ +struct swap_info_struct *sis; +unsigned int page_no; +unsigned int nr_extents; +sector_t *span; +}; + +static loff_t iomap_swap_map (struct inode *inode,loff_t pos,loff_t length, +void *data,struct iomap *iomap) +{ +struct iomap_swap_walker_context *ctx = data; +unsigned int blocks_per_page =PAGE_SIZE >> inode->i_blkbits; +u64 num_pages; +u64 aligned_address; +sector_t disk_pos; +loff_t eff_length; +loff_t ret; + +/* Validate the extent */ + +/* Only one bdev per swap file. */ +if (iomap->bdev != ctx->sis->bdev) + goto err; +/* Only real or unwritten extents. */ +if (iomap->type !=IOMAP_MAPPED && iomap->type !=IOMAP_UNWRITTEN ) + goto err; +/* No uncommitted metadata or shared blocks or inline data. */ +if (iomap->flags & (IOMAP_F_DIRTY |IOMAP_F_SHARED |IOMAP_F_DATA_INLINE )) + goto err; + +/* +* Swap extents need to be PAGE_SIZE aligned on the disk +*/ + aligned_address =ALIGN (iomap->addr,PAGE_SIZE ); + eff_length = length - (aligned_address - iomap->addr); +BUG_ON (eff_length > length); + disk_pos = aligned_address >> inode->i_blkbits; + +if (eff_length <0 ) +return length;/* Continue probing */ + + num_pages = eff_length /PAGE_SIZE ; + +/* Can't add blocks less than 1 page */ +if (num_pages ==0 ) +return length;/* Continue probing */ + + ret =add_swap_extent (ctx->sis, ctx->page_no, num_pages, disk_pos); +if (ret <0 ) +return ret; + + ctx->nr_extents += ret; + ctx->page_no += num_pages; + (*ctx->span) += num_pages * blocks_per_page; + +return length;/* continue probing */ +err: +pr_err ("swapon: swapfile has holes\n" ); +return -EINVAL ; +} + +int iomap_swap_activate (struct swap_info_struct *sis,struct file *file, +sector_t *span,const struct iomap_ops *ops) +{ +struct iomap_swap_walker_context ctx = { + .sis = sis, + .page_no =0 , + .nr_extents =0 , + .span = span + }; + +struct inode * inode =file_inode (file); +loff_t len =i_size_read (inode); +loff_t pos =0 ; +loff_t ret = -EINVAL ; + + + ret =filemap_write_and_wait (inode->i_mapping); +if (ret) +return ret; + +while (len >0 ) { + ret =iomap_apply (inode, pos, len,IOMAP_REPORT , ops, + &ctx, iomap_swap_map); +if (ret <=0 ) +break ; + + pos += ret; + len -= ret; + } + +if (ret <0 ) { +pr_err ("Failed to activate the swap file\n" ); +return -EINVAL ; + } + + sis->max = ctx.page_no ==0 ?1 : ctx.page_no; + sis->pages = ctx.page_no; + sis->highest_bit = ctx.page_no; + +return ctx.nr_extents; +} +EXPORT_SYMBOL_GPL (iomap_swap_activate);
include/linux/iomap.h +5 -0
@@ -10,6 +10,8 @@ struct iov_iter;struct kiocb ;struct vm_area_struct ;struct vm_fault ; +struct file ; +struct swap_info_struct ;/* * Types of block ranges for iomap mappings:
@@ -106,4 +108,7 @@ typedef int (iomap_dio_end_io_t)(struct kiocb *iocb, ssize_t ret,ssize_t iomap_dio_rw (struct kiocb *iocb,struct iov_iter *iter,const struct iomap_ops *ops,iomap_dio_end_io_t end_io); +int iomap_swap_activate (struct swap_info_struct *sis,struct file *file, +sector_t *span,const struct iomap_ops *ops); +#endif /* LINUX_IOMAP_H */
mm/swapfile.c +1 -0
@@ -2381,6 +2381,7 @@ add_swap_extent(struct swap_info_struct *sis, unsigned long start_page,list_add_tail (&new_se->list, &sis->first_swap_extent.list);return 1 ; } +EXPORT_SYMBOL_GPL (add_swap_extent);/* * A `swap extent' is a simple thing which maps a contiguous range of pages
Signature · 1 line
2.14.1
kbuild test robot
build botRe: [PATCH 1/2] fs: Add iomap_swap_activate
Thank you for the patch! Yet something to improve:
Hi Aleksei,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v4.17-rc3 next-20180501]
[cannot apply to dgc-xfs/for-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Aleksei-Besogonov/fs-Add-iomap_swap_activate/20180502-034017
config: x86_64-randconfig-x009-201817 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 All errors (new ones prefixed by >>):
fs/iomap.c: In function 'iomap_swap_map':
>> fs/iomap.c:1142:8: error: implicit declaration of function 'add_swap_extent'; did you mean '__swap_count'? [-Werror=implicit-function-declaration]
ret = add_swap_extent(ctx->sis, ctx->page_no, num_pages, disk_pos);
^~~~~~~~~~~~~~~
__swap_countcc1: some warnings being treated as errors
vim +1142 fs/iomap.c
1101
1102 static loff_t iomap_swap_map(struct inode *inode, loff_t pos, loff_t length,
1103 void *data, struct iomap *iomap)
1104 {
1105 struct iomap_swap_walker_context *ctx = data;
1106 unsigned int blocks_per_page = PAGE_SIZE >> inode->i_blkbits;
1107 u64 num_pages;
1108 u64 aligned_address;
1109 sector_t disk_pos;
1110 loff_t eff_length;
1111 loff_t ret;
1112
1113 /* Validate the extent */
1114
1115 /* Only one bdev per swap file. */
1116 if (iomap->bdev != ctx->sis->bdev)
1117 goto err;
1118 /* Only real or unwritten extents. */
1119 if (iomap->type != IOMAP_MAPPED && iomap->type != IOMAP_UNWRITTEN)
1120 goto err;
1121 /* No uncommitted metadata or shared blocks or inline data. */
1122 if (iomap->flags & (IOMAP_F_DIRTY | IOMAP_F_SHARED | IOMAP_F_DATA_INLINE))
1123 goto err;
1124
1125 /*
1126 * Swap extents need to be PAGE_SIZE aligned on the disk
1127 */
1128 aligned_address = ALIGN(iomap->addr, PAGE_SIZE);
1129 eff_length = length - (aligned_address - iomap->addr);
1130 BUG_ON(eff_length > length);
1131 disk_pos = aligned_address >> inode->i_blkbits;
1132
1133 if (eff_length < 0)
1134 return length; /* Continue probing */
1135
1136 num_pages = eff_length / PAGE_SIZE;
1137
1138 /* Can't add blocks less than 1 page */
1139 if (num_pages == 0)
1140 return length; /* Continue probing */
1141
> 1142 ret = add_swap_extent(ctx->sis, ctx->page_no, num_pages, disk_pos);
1143 if (ret < 0)
1144 return ret;
1145
1146 ctx->nr_extents += ret;
1147 ctx->page_no += num_pages;
1148 (*ctx->span) += num_pages * blocks_per_page;
1149
1150 return length; /* continue probing */
1151 err:
1152 pr_err("swapon: swapfile has holes\n");
1153 return -EINVAL;
1154 }
1155
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [PATCH 1/2] fs: Add iomap_swap_activate
In reply to Aleksei BesogonovThank you for the patch! Yet something to improve:
Hi Aleksei,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v4.17-rc3 next-20180501]
[cannot apply to dgc-xfs/for-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Aleksei-Besogonov/fs-Add-iomap_swap_activate/20180502-034017
config: i386-randconfig-a1-201817 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4 reproduce:
# save the attached .config to linux build tree
make ARCH=i386 All errors (new ones prefixed by >>):
fs/iomap.c: In function 'iomap_swap_map':
>> fs/iomap.c:1142:2: error: implicit declaration of function 'add_swap_extent' [-Werror=implicit-function-declaration]
ret = add_swap_extent(ctx->sis, ctx->page_no, num_pages, disk_pos);
^cc1: some warnings being treated as errors
vim +/add_swap_extent +1142 fs/iomap.c
1101
1102 static loff_t iomap_swap_map(struct inode *inode, loff_t pos, loff_t length,
1103 void *data, struct iomap *iomap)
1104 {
1105 struct iomap_swap_walker_context *ctx = data;
1106 unsigned int blocks_per_page = PAGE_SIZE >> inode->i_blkbits;
1107 u64 num_pages;
1108 u64 aligned_address;
1109 sector_t disk_pos;
1110 loff_t eff_length;
1111 loff_t ret;
1112
1113 /* Validate the extent */
1114
1115 /* Only one bdev per swap file. */
1116 if (iomap->bdev != ctx->sis->bdev)
1117 goto err;
1118 /* Only real or unwritten extents. */
1119 if (iomap->type != IOMAP_MAPPED && iomap->type != IOMAP_UNWRITTEN)
1120 goto err;
1121 /* No uncommitted metadata or shared blocks or inline data. */
1122 if (iomap->flags & (IOMAP_F_DIRTY | IOMAP_F_SHARED | IOMAP_F_DATA_INLINE))
1123 goto err;
1124
1125 /*
1126 * Swap extents need to be PAGE_SIZE aligned on the disk
1127 */
1128 aligned_address = ALIGN(iomap->addr, PAGE_SIZE);
1129 eff_length = length - (aligned_address - iomap->addr);
1130 BUG_ON(eff_length > length);
1131 disk_pos = aligned_address >> inode->i_blkbits;
1132
1133 if (eff_length < 0)
1134 return length; /* Continue probing */
1135
1136 num_pages = eff_length / PAGE_SIZE;
1137
1138 /* Can't add blocks less than 1 page */
1139 if (num_pages == 0)
1140 return length; /* Continue probing */
1141
> 1142 ret = add_swap_extent(ctx->sis, ctx->page_no, num_pages, disk_pos);
1143 if (ret < 0)
1144 return ret;
1145
1146 ctx->nr_extents += ret;
1147 ctx->page_no += num_pages;
1148 (*ctx->span) += num_pages * blocks_per_page;
1149
1150 return length; /* continue probing */
1151 err:
1152 pr_err("swapon: swapfile has holes\n");
1153 return -EINVAL;
1154 }
1155
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH 2/2 xfs: add support for iomap-based swapfile activation
In reply to Aleksei BesogonovUse iomap-based swapfile activation instead of the default generic_swapfile_activate bmap-based infrastructure.
--- fs/xfs/xfs_aops.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/xfs/xfs_aops.c +8 -0
@@ -1491,6 +1491,13 @@ xfs_vm_set_page_dirty(return newly_dirty; } +static int xfs_swap_activate (struct swap_info_struct *sis,struct file *swap_file, +sector_t *span) +{ + sis->bdev =xfs_find_bdev_for_inode (file_inode (swap_file)); +return iomap_swap_activate (sis, swap_file, span, &xfs_iomap_ops); +} +const struct address_space_operations xfs_address_space_operations = { .readpage = xfs_vm_readpage, .readpages = xfs_vm_readpages,
@@ -1504,4 +1511,5 @@ const struct address_space_operations xfs_address_space_operations = { .migratepage = buffer_migrate_page, .is_partially_uptodate = block_is_partially_uptodate, .error_remove_page = generic_error_remove_page, + .swap_activate = xfs_swap_activate, };
Signature · 1 line
2.14.1
Quoted 4 lines · Aleksei Besogonov
V2 of iomap-based swapfile support.
Changes from V1: additional validations for file extents, based on a patch from Darrick Wong.
Aleksei -
As Darrick pointed out earlier and as you acknowledge here, Darrick already has a patchset for this in the works, started a couple days before your first submission.
Generally we don't race to re-implement someone else's patch. If you were unsure whether Darrick planned to send a V2, it would have been good to ask.
Although I think Darrick does plan to resubmit his patches based on the feedback provided so far, I'll go ahead & point out a couple things in your series for future reference:
1) You need a Signed-off-by: line which essentially states that this is your own work, and that you may submit it for inclusion.
2) If you were building on someone else's patch with their blessing, you'd probably preceed your Signed-off-by: with theirs (but this is a bit unusual)
3) There's no reason to export iomap_apply for modules; no module uses it
I'll admit that I didn't look a lot more in depth. ;)
At this point it's probably best to help this along by reviewing & testing Darrick's (forthcoming?) V2 patchset.
It's not that we don't appreciate the help - it's great that you're motivated to get this done - it's just that someone else already started the work, and the normal process there is to review/comment on the first submitter's patches, unless they have clearly abandoned the work. This keeps the development process and the mailing list more organized than if several people submit competing patchsets in parallel.
Thanks,
-Eric
Quoted 10 lines
Aleksei Besogonov (2):
fs: Addiomap_swap_activate
xfs: add support for iomap-based swapfile activationfs/iomap.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_aops.c | 8 ++++ include/linux/iomap.h | 5 +++ mm/swapfile.c | 1 + 4 files changed, 120 insertions(+)