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
357 u64 len = subreq->len;357 u64 len = subreq->len;
358 bool sparse = IS_ENCRYPTED(inode) || ceph_test_mount_opt(fsc, SPARSEREAD);358 bool sparse = IS_ENCRYPTED(inode) || ceph_test_mount_opt(fsc, SPARSEREAD);
359 u64 off = subreq->start;359 u64 off = subreq->start;
360 int extent_cnt;
360 361
361 if (ceph_inode_is_shutdown(inode)) {362 if (ceph_inode_is_shutdown(inode)) {
362 err = -EIO;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 if (sparse) {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 if (err)385 if (err)
384 goto out;386 goto out;
385 }387 }
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
1028 struct ceph_osd_req_op *op;1028 struct ceph_osd_req_op *op;
1029 u64 read_off = off;1029 u64 read_off = off;
1030 u64 read_len = len;1030 u64 read_len = len;
1031 int extent_cnt;
1031 1032
1032 /* determine new offset/length if encrypted */1033 /* determine new offset/length if encrypted */
1033 ceph_fscrypt_adjust_off_and_len(inode, &read_off, &read_len);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 op = &req->r_ops[0];1069 op = &req->r_ops[0];
1069 if (sparse) {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 if (ret) {1073 if (ret) {
1072 ceph_osdc_put_request(req);1074 ceph_osdc_put_request(req);
1073 break;1075 break;
@@ -1464,6 +1466,7 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter, · 390 unmodified lines
1464 ssize_t len;1466 ssize_t len;
1465 struct ceph_osd_req_op *op;1467 struct ceph_osd_req_op *op;
1466 int readop = sparse ? CEPH_OSD_OP_SPARSE_READ : CEPH_OSD_OP_READ;1468 int readop = sparse ? CEPH_OSD_OP_SPARSE_READ : CEPH_OSD_OP_READ;
1469 int extent_cnt;
1467 1470
1468 if (write)1471 if (write)
1469 size = min_t(u64, size, fsc->mount_options->wsize);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 osd_req_op_extent_osd_data_bvecs(req, 0, bvecs, num_pages, len);1530 osd_req_op_extent_osd_data_bvecs(req, 0, bvecs, num_pages, len);
1528 op = &req->r_ops[0];1531 op = &req->r_ops[0];
1529 if (sparse) {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 if (ret) {1535 if (ret) {
1532 ceph_osdc_put_request(req);1536 ceph_osdc_put_request(req);
1533 break;1537 break;
fs/ceph/super.h+14−0
@@ -3,6 +3,7 @@ · 2 unmodified lines
3#define _FS_CEPH_SUPER_H3#define _FS_CEPH_SUPER_H
4 4
5#include <linux/ceph/ceph_debug.h>5#include <linux/ceph/ceph_debug.h>
6#include <linux/ceph/osd_client.h>
6 7
7#include <asm/unaligned.h>8#include <asm/unaligned.h>
8#include <linux/backing-dev.h>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 ceph_adjust_quota_realms_count(&ci->netfs.inode, has_quota);1408 ceph_adjust_quota_realms_count(&ci->netfs.inode, has_quota);
1408}1409}
1409 1410
1411static 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
1410extern void ceph_handle_quota(struct ceph_mds_client *mdsc,1424extern void ceph_handle_quota(struct ceph_mds_client *mdsc,
1411 struct ceph_mds_session *session,1425 struct ceph_mds_session *session,
1412 struct ceph_msg *msg);1426 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
572 */572 */
573#define CEPH_SPARSE_EXT_ARRAY_INITIAL 16573#define CEPH_SPARSE_EXT_ARRAY_INITIAL 16
574 574
575static inline int ceph_alloc_sparse_ext_map(struct ceph_osd_req_op *op)575static 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
580extern void ceph_osdc_get_request(struct ceph_osd_request *req);583extern 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