Skip to content

Commit aaefabc

Browse files
lxbszidryomov
authored andcommitted
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() ] Signed-off-by: Xiubo Li <xiubli@redhat.com> Reviewed-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent b79e4a0 commit aaefabc

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

fs/ceph/addr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ static void ceph_netfs_issue_read(struct netfs_io_subrequest *subreq)
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)
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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos,
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,
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,
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,
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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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,
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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,12 @@ int __ceph_alloc_sparse_ext_map(struct ceph_osd_req_op *op, int cnt);
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);

0 commit comments

Comments
 (0)