Skip to contentSkip to conversation

libceph: increase the max extents check for sparse read

PATCH Superseded [email protected] 3 participants 5 messages Nov 6, 2023 Ceph common code (libceph)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libceph: increase the max extents check for sparse read

From: Xiubo Li <[email protected]>

There is no any limit for the extent array size and it's possible that we will hit 4096 limit just after a lot of random writes to a file and then read with a large size. In this case the messager will fail by reseting the connection and keeps resending the inflight IOs infinitely.

Just increase the limit to a larger number and then warn it to let user know that allocating memory could fail with this.

URL: https://tracker.ceph.com/issues/62081

---

V2:
- Increase the MAX_EXTENTS instead of removing it.
- Do not return an errno when hit the limit.

 net/ceph/osd_client.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
net/ceph/osd_client.c +7 -8
index c03d48bd3aff..050dc39065fb 100644
@@ -5850,7 +5850,7 @@ static inline void convert_extent_map(struct ceph_sparse_read *sr)
 }
 #endif
 
-#define MAX_EXTENTS 4096
+#define MAX_EXTENTS (16*1024*1024)
 
 static int osd_sparse_read(struct ceph_connection *con,
 			   struct ceph_msg_data_cursor *cursor,
@@ -5883,14 +5883,13 @@ static int osd_sparse_read(struct ceph_connection *con,
 		if (count > 0) {
 			if (!sr->sr_extent || count > sr->sr_ext_len) {
 				/*
-				 * Apply a hard cap to the number of extents.
-				 * If we have more, assume something is wrong.
+				 * Warn if hits a hard cap to the number of extents.
+				 * Too many extents could make the following
+				 * kmalloc_array() fail.
 				 */
-				if (count > MAX_EXTENTS) {
-					dout("%s: OSD returned 0x%x extents in a single reply!\n",
-					     __func__, count);
-					return -EREMOTEIO;
-				}
+				if (count > MAX_EXTENTS)
+					pr_warn_ratelimited("%s: OSD returned 0x%x extents in a single reply!\n",
+							    __func__, count);
 
 				/* no extent array provided, or too short */
 				kfree(sr->sr_extent);
Signature · 1 line
2.39.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 47 lines · On Mon, 2023-11-06 at 09:03 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

There is no any limit for the extent array size and it's possible that we will hit 4096 limit just after a lot of random writes to a file and then read with a large size. In this case the messager will fail by reseting the connection and keeps resending the inflight IOs infinitely.

Just increase the limit to a larger number and then warn it to let user know that allocating memory could fail with this.

URL: https://tracker.ceph.com/issues/62081

---

V2:
- Increase the MAX_EXTENTS instead of removing it.
- Do not return an errno when hit the limit.

 net/ceph/osd_client.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
net/ceph/osd_client.c +4 -4
index c03d48bd3aff..050dc39065fb 100644
@@ -5850,7 +5850,7 @@ static inline void convert_extent_map(struct ceph_sparse_read *sr)
 }
 #endif
 
-#define MAX_EXTENTS 4096
+#define MAX_EXTENTS (16*1024*1024)
 
 static int osd_sparse_read(struct ceph_connection *con,
 			   struct ceph_msg_data_cursor *cursor,
@@ -5883,14 +5883,13 @@ static int osd_sparse_read(struct ceph_connection *con,
 		if (count > 0) {
 			if (!sr->sr_extent || count > sr->sr_ext_len) {
 				/*
-				 * Apply a hard cap to the number of extents.
-				 * If we have more, assume something is wrong.
+				 * Warn if hits a hard cap to the number of extents.
+				 * Too many extents could make the following
+				 * kmalloc_array() fail.
 				 */
-				if (count > MAX_EXTENTS) {

net/ceph/osd_client.c static int osd_sparse_read(struct ceph_connection *con, · line 5895

Quoted 10 lines
net/ceph/osd_client.c +3 -4
-					dout("%s: OSD returned 0x%x extents in a single reply!\n",
-					     __func__, count);
-					return -EREMOTEIO;
-				}
+				if (count > MAX_EXTENTS)
+					pr_warn_ratelimited("%s: OSD returned 0x%x extents in a single reply!\n",
+							    __func__, count);
 
 				/* no extent array provided, or too short */
 				kfree(sr->sr_extent);

Looks reasonable.

maintainer
#2 lore raw
In reply to [email protected]
Quoted 29 lines · On Mon, Nov 6, 2023 at 2:05 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

There is no any limit for the extent array size and it's possible that we will hit 4096 limit just after a lot of random writes to a file and then read with a large size. In this case the messager will fail by reseting the connection and keeps resending the inflight IOs infinitely.

Just increase the limit to a larger number and then warn it to let user know that allocating memory could fail with this.

URL: https://tracker.ceph.com/issues/62081

---

V2:
- Increase the MAX_EXTENTS instead of removing it.
- Do not return an errno when hit the limit.

 net/ceph/osd_client.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
net/ceph/osd_client.c +0 -0
index c03d48bd3aff..050dc39065fb 100644

net/ceph/osd_client.c static inline void convert_extent_map(struct ceph_sparse_read *sr) · line 5853

Quoted 5 lines
net/ceph/osd_client.c +1 -1
@@ -5850,7 +5850,7 @@ static inline void convert_extent_map(struct ceph_sparse_read *sr)
 }
 #endif
 
-#define MAX_EXTENTS 4096
+#define MAX_EXTENTS (16*1024*1024)

I don't think this is a sensible limit -- see my other reply.

Thanks,

Ilya

author
#3 lore raw
Quoted 32 lines · Ilya Dryomov
Quoted 31 lines · On Mon, Nov 6, 2023 at 2:05 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

There is no any limit for the extent array size and it's possible that we will hit 4096 limit just after a lot of random writes to a file and then read with a large size. In this case the messager will fail by reseting the connection and keeps resending the inflight IOs infinitely.

Just increase the limit to a larger number and then warn it to let user know that allocating memory could fail with this.

URL: https://tracker.ceph.com/issues/62081

---

V2:
- Increase the MAX_EXTENTS instead of removing it.
- Do not return an errno when hit the limit.

  net/ceph/osd_client.c | 15 +++++++--------
  1 file changed, 7 insertions(+), 8 deletions(-)
net/ceph/osd_client.c +0 -0
index c03d48bd3aff..050dc39065fb 100644
@@ -5850,7 +5850,7 @@ static inline void convert_extent_map(struct ceph_sparse_read *sr)
  }
  #endif
 
Quoted 3 lines

net/ceph/osd_client.c static inline void convert_extent_map(struct ceph_sparse_read *sr) · line 5853

Quoted 2 lines
net/ceph/osd_client.c +1 -1
-#define MAX_EXTENTS 4096
+#define MAX_EXTENTS (16*1024*1024)

I don't think this is a sensible limit -- see my other reply.

Ilya,

As I mentioned in that thread, the sparse read could be enabled in non-fscrypt case. If so the "64M (CEPH_MSG_MAX_DATA_LEN) / 4K = 16384" still won't be enough.

Thanks

- Xiubo

Quoted 4 lines

Thanks,

Ilya

maintainer
#4 lore raw
Quoted 39 lines · Xiubo Li
Quoted 32 lines · Ilya Dryomov
Quoted 31 lines · On Mon, Nov 6, 2023 at 2:05 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

There is no any limit for the extent array size and it's possible that we will hit 4096 limit just after a lot of random writes to a file and then read with a large size. In this case the messager will fail by reseting the connection and keeps resending the inflight IOs infinitely.

Just increase the limit to a larger number and then warn it to let user know that allocating memory could fail with this.

URL: https://tracker.ceph.com/issues/62081

---

V2:
- Increase the MAX_EXTENTS instead of removing it.
- Do not return an errno when hit the limit.

  net/ceph/osd_client.c | 15 +++++++--------
  1 file changed, 7 insertions(+), 8 deletions(-)
net/ceph/osd_client.c +0 -0
index c03d48bd3aff..050dc39065fb 100644
@@ -5850,7 +5850,7 @@ static inline void convert_extent_map(struct ceph_sparse_read *sr)
  }
  #endif
 
Quoted 3 lines

net/ceph/osd_client.c static inline void convert_extent_map(struct ceph_sparse_read *sr) · line 5853

Quoted 2 lines
net/ceph/osd_client.c +1 -1
-#define MAX_EXTENTS 4096
+#define MAX_EXTENTS (16*1024*1024)

I don't think this is a sensible limit -- see my other reply.

Quoted 5 lines

Ilya,

As I mentioned in that thread, the sparse read could be enabled in non-fscrypt case. If so the "64M (CEPH_MSG_MAX_DATA_LEN) / 4K = 16384" still won't be enough.

I have just replied in the other thread. Let's continue this discussion there ;)

Thanks,

Ilya