In fscrypt case and for a smaller read length we can predict the max count of the extent map. And for small read length use cases this could save some memories. [ idryomov: squash into a single patch to avoid build break, drop redundant variable in ceph_alloc_sparse_ext_map() ]
Unified · Split
| @@ -357,6 +357,7 @@ static void ceph_netfs_issue_read(struct netfs_io_subrequest *subreq) · 356 unmodified lines | ||
| 357 | 357 | u64 len = subreq->len; |
| 358 | 358 | bool sparse = IS_ENCRYPTED(inode) || ceph_test_mount_opt(fsc, SPARSEREAD); |
| 359 | 359 | u64 off = subreq->start; |
| 360 | + int extent_cnt; | |
| 360 | 361 | |
| 361 | 362 | if (ceph_inode_is_shutdown(inode)) { |
| 362 | 363 | err = -EIO; |
| @@ -379,7 +380,8 @@ static void ceph_netfs_issue_read(struct netfs_io_subrequest *subreq) · 16 unmodified lines | ||
| 379 | 380 | } |
| 380 | 381 | |
| 381 | 382 | if (sparse) { |
| 382 | − err = ceph_alloc_sparse_ext_map(&req->r_ops[0]); | |
| 383 | + extent_cnt = __ceph_sparse_read_ext_count(inode, len); | |
| 384 | + err = ceph_alloc_sparse_ext_map(&req->r_ops[0], extent_cnt); | |
| 383 | 385 | if (err) |
| 384 | 386 | goto out; |
| 385 | 387 | } |
| @@ -1028,6 +1028,7 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, · 1027 unmodified lines | ||
| 1028 | 1028 | struct ceph_osd_req_op *op; |
| 1029 | 1029 | u64 read_off = off; |
| 1030 | 1030 | u64 read_len = len; |
| 1031 | + int extent_cnt; | |
| 1031 | 1032 | |
| 1032 | 1033 | /* determine new offset/length if encrypted */ |
| 1033 | 1034 | ceph_fscrypt_adjust_off_and_len(inode, &read_off, &read_len); |
| @@ -1067,7 +1068,8 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, · 33 unmodified lines | ||
| 1067 | 1068 | |
| 1068 | 1069 | op = &req->r_ops[0]; |
| 1069 | 1070 | if (sparse) { |
| 1070 | − ret = ceph_alloc_sparse_ext_map(op); | |
| 1071 | + extent_cnt = __ceph_sparse_read_ext_count(inode, read_len); | |
| 1072 | + ret = ceph_alloc_sparse_ext_map(op, extent_cnt); | |
| 1071 | 1073 | if (ret) { |
| 1072 | 1074 | ceph_osdc_put_request(req); |
| 1073 | 1075 | break; |
| @@ -1464,6 +1466,7 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter, · 390 unmodified lines | ||
| 1464 | 1466 | ssize_t len; |
| 1465 | 1467 | struct ceph_osd_req_op *op; |
| 1466 | 1468 | int readop = sparse ? CEPH_OSD_OP_SPARSE_READ : CEPH_OSD_OP_READ; |
| 1469 | + int extent_cnt; | |
| 1467 | 1470 | |
| 1468 | 1471 | if (write) |
| 1469 | 1472 | size = min_t(u64, size, fsc->mount_options->wsize); |
| @@ -1527,7 +1530,8 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter, · 57 unmodified lines | ||
| 1527 | 1530 | osd_req_op_extent_osd_data_bvecs(req, 0, bvecs, num_pages, len); |
| 1528 | 1531 | op = &req->r_ops[0]; |
| 1529 | 1532 | if (sparse) { |
| 1530 | − ret = ceph_alloc_sparse_ext_map(op); | |
| 1533 | + extent_cnt = __ceph_sparse_read_ext_count(inode, size); | |
| 1534 | + ret = ceph_alloc_sparse_ext_map(op, extent_cnt); | |
| 1531 | 1535 | if (ret) { |
| 1532 | 1536 | ceph_osdc_put_request(req); |
| 1533 | 1537 | break; |
| @@ -3,6 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | #define _FS_CEPH_SUPER_H |
| 4 | 4 | |
| 5 | 5 | #include <linux/ceph/ceph_debug.h> |
| 6 | +#include <linux/ceph/osd_client.h> | |
| 6 | 7 | |
| 7 | 8 | #include <asm/unaligned.h> |
| 8 | 9 | #include <linux/backing-dev.h> |
| @@ -1407,6 +1408,19 @@ static inline void __ceph_update_quota(struct ceph_inode_info *ci, · 1398 unmodified lines | ||
| 1407 | 1408 | ceph_adjust_quota_realms_count(&ci->netfs.inode, has_quota); |
| 1408 | 1409 | } |
| 1409 | 1410 | |
| 1411 | +static inline int __ceph_sparse_read_ext_count(struct inode *inode, u64 len) | |
| 1412 | +{ | |
| 1413 | + int cnt = 0; | |
| 1414 | + | |
| 1415 | + if (IS_ENCRYPTED(inode)) { | |
| 1416 | + cnt = len >> CEPH_FSCRYPT_BLOCK_SHIFT; | |
| 1417 | + if (cnt > CEPH_SPARSE_EXT_ARRAY_INITIAL) | |
| 1418 | + cnt = 0; | |
| 1419 | + } | |
| 1420 | + | |
| 1421 | + return cnt; | |
| 1422 | +} | |
| 1423 | + | |
| 1410 | 1424 | extern void ceph_handle_quota(struct ceph_mds_client *mdsc, |
| 1411 | 1425 | struct ceph_mds_session *session, |
| 1412 | 1426 | struct ceph_msg *msg); |
| @@ -572,9 +572,12 @@ int __ceph_alloc_sparse_ext_map(struct ceph_osd_req_op *op, int cnt); · 571 unmodified lines | ||
| 572 | 572 | */ |
| 573 | 573 | #define CEPH_SPARSE_EXT_ARRAY_INITIAL 16 |
| 574 | 574 | |
| 575 | −static inline int ceph_alloc_sparse_ext_map(struct ceph_osd_req_op *op) | |
| 575 | +static inline int ceph_alloc_sparse_ext_map(struct ceph_osd_req_op *op, int cnt) | |
| 576 | 576 | { |
| 577 | − return __ceph_alloc_sparse_ext_map(op, CEPH_SPARSE_EXT_ARRAY_INITIAL); | |
| 577 | + if (!cnt) | |
| 578 | + cnt = CEPH_SPARSE_EXT_ARRAY_INITIAL; | |
| 579 | + | |
| 580 | + return __ceph_alloc_sparse_ext_map(op, cnt); | |
| 578 | 581 | } |
| 579 | 582 | |
| 580 | 583 | extern void ceph_osdc_get_request(struct ceph_osd_request *req); |