History

ceph: try to allocate a smaller extent map for sparse read

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() ]

Xiubo Li committed 3 years ago

Commit aaefabc1 parent b79e4a04 files · +28 −5Browse files

Unified · Split

4 files
  1. fs/ceph/addr.c +3 −1
  2. fs/ceph/file.c +6 −2
  3. fs/ceph/super.h +14 −0
  4. include/linux/ceph/osd_client.h +5 −2
fs/ceph/addr.c+3−1
@@ -357,6 +357,7 @@ static void ceph_netfs_issue_read(struct netfs_io_subrequest *subreq) · 356 unmodified lines
357357 u64 len = subreq->len;
358358 bool sparse = IS_ENCRYPTED(inode) || ceph_test_mount_opt(fsc, SPARSEREAD);
359359 u64 off = subreq->start;
360+ int extent_cnt;
360361
361362 if (ceph_inode_is_shutdown(inode)) {
362363 err = -EIO;
@@ -379,7 +380,8 @@ static void ceph_netfs_issue_read(struct netfs_io_subrequest *subreq) · 16 unmodified lines
379380 }
380381
381382 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);
383385 if (err)
384386 goto out;
385387 }
fs/ceph/file.c+6−2
@@ -1028,6 +1028,7 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, · 1027 unmodified lines
10281028 struct ceph_osd_req_op *op;
10291029 u64 read_off = off;
10301030 u64 read_len = len;
1031+ int extent_cnt;
10311032
10321033 /* determine new offset/length if encrypted */
10331034 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
10671068
10681069 op = &req->r_ops[0];
10691070 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);
10711073 if (ret) {
10721074 ceph_osdc_put_request(req);
10731075 break;
@@ -1464,6 +1466,7 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter, · 390 unmodified lines
14641466 ssize_t len;
14651467 struct ceph_osd_req_op *op;
14661468 int readop = sparse ? CEPH_OSD_OP_SPARSE_READ : CEPH_OSD_OP_READ;
1469+ int extent_cnt;
14671470
14681471 if (write)
14691472 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
15271530 osd_req_op_extent_osd_data_bvecs(req, 0, bvecs, num_pages, len);
15281531 op = &req->r_ops[0];
15291532 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);
15311535 if (ret) {
15321536 ceph_osdc_put_request(req);
15331537 break;
fs/ceph/super.h+14−0
@@ -3,6 +3,7 @@ · 2 unmodified lines
33 #define _FS_CEPH_SUPER_H
44
55 #include <linux/ceph/ceph_debug.h>
6+#include <linux/ceph/osd_client.h>
67
78 #include <asm/unaligned.h>
89 #include <linux/backing-dev.h>
@@ -1407,6 +1408,19 @@ static inline void __ceph_update_quota(struct ceph_inode_info *ci, · 1398 unmodified lines
14071408 ceph_adjust_quota_realms_count(&ci->netfs.inode, has_quota);
14081409 }
14091410
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+
14101424 extern void ceph_handle_quota(struct ceph_mds_client *mdsc,
14111425 struct ceph_mds_session *session,
14121426 struct ceph_msg *msg);
include/linux/ceph/osd_client.h+5−2
@@ -572,9 +572,12 @@ int __ceph_alloc_sparse_ext_map(struct ceph_osd_req_op *op, int cnt); · 571 unmodified lines
572572 */
573573 #define CEPH_SPARSE_EXT_ARRAY_INITIAL 16
574574
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)
576576 {
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);
578581 }
579582
580583 extern void ceph_osdc_get_request(struct ceph_osd_request *req);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t