Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: Don't save/copy bvec array anymore

Now that drivers have been converted to the bvec_iter primitives, they
shouldn't be modifying the biovec anymore and thus saving it is
unnecessary - code that was previously making a backup of the bvec array
can now just save bio->bi_iter.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>

+13 -41
+13 -41
fs/bio.c
··· 967 967 EXPORT_SYMBOL(bio_copy_data); 968 968 969 969 struct bio_map_data { 970 - struct bio_vec *iovecs; 971 - struct sg_iovec *sgvecs; 972 970 int nr_sgvecs; 973 971 int is_our_pages; 972 + struct sg_iovec sgvecs[]; 974 973 }; 975 974 976 975 static void bio_set_map_data(struct bio_map_data *bmd, struct bio *bio, 977 976 struct sg_iovec *iov, int iov_count, 978 977 int is_our_pages) 979 978 { 980 - memcpy(bmd->iovecs, bio->bi_io_vec, sizeof(struct bio_vec) * bio->bi_vcnt); 981 979 memcpy(bmd->sgvecs, iov, sizeof(struct sg_iovec) * iov_count); 982 980 bmd->nr_sgvecs = iov_count; 983 981 bmd->is_our_pages = is_our_pages; 984 982 bio->bi_private = bmd; 985 983 } 986 984 987 - static void bio_free_map_data(struct bio_map_data *bmd) 988 - { 989 - kfree(bmd->iovecs); 990 - kfree(bmd->sgvecs); 991 - kfree(bmd); 992 - } 993 - 994 985 static struct bio_map_data *bio_alloc_map_data(int nr_segs, 995 986 unsigned int iov_count, 996 987 gfp_t gfp_mask) 997 988 { 998 - struct bio_map_data *bmd; 999 - 1000 989 if (iov_count > UIO_MAXIOV) 1001 990 return NULL; 1002 991 1003 - bmd = kmalloc(sizeof(*bmd), gfp_mask); 1004 - if (!bmd) 1005 - return NULL; 1006 - 1007 - bmd->iovecs = kmalloc(sizeof(struct bio_vec) * nr_segs, gfp_mask); 1008 - if (!bmd->iovecs) { 1009 - kfree(bmd); 1010 - return NULL; 1011 - } 1012 - 1013 - bmd->sgvecs = kmalloc(sizeof(struct sg_iovec) * iov_count, gfp_mask); 1014 - if (bmd->sgvecs) 1015 - return bmd; 1016 - 1017 - kfree(bmd->iovecs); 1018 - kfree(bmd); 1019 - return NULL; 992 + return kmalloc(sizeof(struct bio_map_data) + 993 + sizeof(struct sg_iovec) * iov_count, gfp_mask); 1020 994 } 1021 995 1022 - static int __bio_copy_iov(struct bio *bio, struct bio_vec *iovecs, 1023 - struct sg_iovec *iov, int iov_count, 996 + static int __bio_copy_iov(struct bio *bio, struct sg_iovec *iov, int iov_count, 1024 997 int to_user, int from_user, int do_free_page) 1025 998 { 1026 999 int ret = 0, i; ··· 1003 1030 1004 1031 bio_for_each_segment_all(bvec, bio, i) { 1005 1032 char *bv_addr = page_address(bvec->bv_page); 1006 - unsigned int bv_len = iovecs[i].bv_len; 1033 + unsigned int bv_len = bvec->bv_len; 1007 1034 1008 1035 while (bv_len && iov_idx < iov_count) { 1009 1036 unsigned int bytes; ··· 1063 1090 * don't copy into a random user address space, just free. 1064 1091 */ 1065 1092 if (current->mm) 1066 - ret = __bio_copy_iov(bio, bmd->iovecs, bmd->sgvecs, 1067 - bmd->nr_sgvecs, bio_data_dir(bio) == READ, 1093 + ret = __bio_copy_iov(bio, bmd->sgvecs, bmd->nr_sgvecs, 1094 + bio_data_dir(bio) == READ, 1068 1095 0, bmd->is_our_pages); 1069 1096 else if (bmd->is_our_pages) 1070 1097 bio_for_each_segment_all(bvec, bio, i) 1071 1098 __free_page(bvec->bv_page); 1072 1099 } 1073 - bio_free_map_data(bmd); 1100 + kfree(bmd); 1074 1101 bio_put(bio); 1075 1102 return ret; 1076 1103 } ··· 1184 1211 */ 1185 1212 if ((!write_to_vm && (!map_data || !map_data->null_mapped)) || 1186 1213 (map_data && map_data->from_user)) { 1187 - ret = __bio_copy_iov(bio, bio->bi_io_vec, iov, iov_count, 0, 1, 0); 1214 + ret = __bio_copy_iov(bio, iov, iov_count, 0, 1, 0); 1188 1215 if (ret) 1189 1216 goto cleanup; 1190 1217 } ··· 1198 1225 1199 1226 bio_put(bio); 1200 1227 out_bmd: 1201 - bio_free_map_data(bmd); 1228 + kfree(bmd); 1202 1229 return ERR_PTR(ret); 1203 1230 } 1204 1231 ··· 1515 1542 1516 1543 bio_for_each_segment_all(bvec, bio, i) { 1517 1544 char *addr = page_address(bvec->bv_page); 1518 - int len = bmd->iovecs[i].bv_len; 1519 1545 1520 1546 if (read) 1521 - memcpy(p, addr, len); 1547 + memcpy(p, addr, bvec->bv_len); 1522 1548 1523 1549 __free_page(bvec->bv_page); 1524 - p += len; 1550 + p += bvec->bv_len; 1525 1551 } 1526 1552 1527 - bio_free_map_data(bmd); 1553 + kfree(bmd); 1528 1554 bio_put(bio); 1529 1555 } 1530 1556