From 9fb0582dd63f336d843bf04ed70e415e1752a67f Mon Sep 17 00:00:00 2001 From: subhamkrai Date: Tue, 28 Apr 2026 17:33:23 +0530 Subject: [PATCH] pool: add stripe_unit with erasure-code-profile set this commit adds flag stripe_unit for the command ceph osd erasure-code-profile set [flags]. This key increase perfomance for ec pool. The default value is 4kib/4096 bytes. Signed-off-by: subhamkrai --- Documentation/CRDs/specification.md | 13 +++ .../charts/rook-ceph/templates/resources.yaml | 105 ++++++++++++++++++ deploy/examples/crds.yaml | 105 ++++++++++++++++++ pkg/apis/ceph.rook.io/v1/types.go | 6 + .../ceph.rook.io/v1/zz_generated.deepcopy.go | 7 +- .../ceph/client/erasure-code-profile.go | 7 ++ .../ceph/client/erasure-code-profile_test.go | 10 ++ 7 files changed, 252 insertions(+), 1 deletion(-) diff --git a/Documentation/CRDs/specification.md b/Documentation/CRDs/specification.md index 73b047744..a81bd6f6d 100644 --- a/Documentation/CRDs/specification.md +++ b/Documentation/CRDs/specification.md @@ -7169,6 +7169,19 @@ string If absent, defaults to the plugin specified in osd_pool_default_erasure_code_profile.

+ + +stripeUnit
+ +k8s.io/apimachinery/pkg/api/resource.Quantity + + + +(Optional) +

Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). +Value must be a multiple of 4096 (4Ki).

+ +

ExternalSpec diff --git a/deploy/charts/rook-ceph/templates/resources.yaml b/deploy/charts/rook-ceph/templates/resources.yaml index 591d6c601..7b26dc830 100644 --- a/deploy/charts/rook-ceph/templates/resources.yaml +++ b/deploy/charts/rook-ceph/templates/resources.yaml @@ -475,6 +475,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks @@ -7762,6 +7777,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks @@ -7957,6 +7987,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks @@ -12886,6 +12931,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks @@ -14528,6 +14588,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks @@ -15546,6 +15621,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks @@ -15736,6 +15826,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks diff --git a/deploy/examples/crds.yaml b/deploy/examples/crds.yaml index c99ea3cac..a0a88a43f 100644 --- a/deploy/examples/crds.yaml +++ b/deploy/examples/crds.yaml @@ -477,6 +477,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks @@ -7757,6 +7772,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks @@ -7952,6 +7982,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks @@ -12875,6 +12920,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks @@ -14517,6 +14577,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks @@ -15532,6 +15607,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks @@ -15722,6 +15812,21 @@ spec: as dataChunks so be aware that the larger the number of data chunks, the higher the cost of recovery. minimum: 0 type: integer + stripeUnit: + anyOf: + - type: integer + - type: string + description: |- + Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + Value must be a multiple of 4096 (4Ki). + enum: + - 4Ki + - 16Ki + - 64Ki + - 256Ki + - 1Mi + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true required: - codingChunks - dataChunks diff --git a/pkg/apis/ceph.rook.io/v1/types.go b/pkg/apis/ceph.rook.io/v1/types.go index f5da4f988..25e0c3f65 100755 --- a/pkg/apis/ceph.rook.io/v1/types.go +++ b/pkg/apis/ceph.rook.io/v1/types.go @@ -1371,6 +1371,12 @@ type ErasureCodedSpec struct { // +kubebuilder:validation:Enum=isa;jerasure // +optional Algorithm string `json:"algorithm,omitempty"` + + // Erasure code stripe size in bytes. Ceph default is 4096 bytes (4 KiB). + // Value must be a multiple of 4096 (4Ki). + // +kubebuilder:validation:Enum={"4Ki","16Ki","64Ki","256Ki","1Mi"} + // +optional + StripeUnit *resource.Quantity `json:"stripeUnit,omitempty"` } // +genclient diff --git a/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go b/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go index 0ea8068ef..21defae88 100644 --- a/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go +++ b/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go @@ -2690,6 +2690,11 @@ func (in *EndpointAddress) DeepCopy() *EndpointAddress { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ErasureCodedSpec) DeepCopyInto(out *ErasureCodedSpec) { *out = *in + if in.StripeUnit != nil { + in, out := &in.StripeUnit, &out.StripeUnit + x := (*in).DeepCopy() + *out = &x + } return } @@ -4907,7 +4912,7 @@ func (in *PoolSpec) DeepCopyInto(out *PoolSpec) { **out = **in } in.Replicated.DeepCopyInto(&out.Replicated) - out.ErasureCoded = in.ErasureCoded + in.ErasureCoded.DeepCopyInto(&out.ErasureCoded) if in.Parameters != nil { in, out := &in.Parameters, &out.Parameters *out = make(map[string]string, len(*in)) diff --git a/pkg/daemon/ceph/client/erasure-code-profile.go b/pkg/daemon/ceph/client/erasure-code-profile.go index 115e65c22..b6f2cb130 100644 --- a/pkg/daemon/ceph/client/erasure-code-profile.go +++ b/pkg/daemon/ceph/client/erasure-code-profile.go @@ -92,6 +92,13 @@ func CreateErasureCodeProfile(context *clusterd.Context, clusterInfo *ClusterInf if pool.DeviceClass != "" { profilePairs = append(profilePairs, fmt.Sprintf("crush-device-class=%s", pool.DeviceClass)) } + if pool.ErasureCoded.StripeUnit != nil && !pool.ErasureCoded.StripeUnit.IsZero() { + stripeBytes, ok := pool.ErasureCoded.StripeUnit.AsInt64() + if !ok { + return errors.Errorf("erasure-coded stripeUnit %q cannot be represented as a byte stripe for Ceph", pool.ErasureCoded.StripeUnit.String()) + } + profilePairs = append(profilePairs, fmt.Sprintf("stripe_unit=%d", stripeBytes)) + } args := []string{"osd", "erasure-code-profile", "set", profileName, "--force"} args = append(args, profilePairs...) diff --git a/pkg/daemon/ceph/client/erasure-code-profile_test.go b/pkg/daemon/ceph/client/erasure-code-profile_test.go index 26603113b..4b50a64c4 100644 --- a/pkg/daemon/ceph/client/erasure-code-profile_test.go +++ b/pkg/daemon/ceph/client/erasure-code-profile_test.go @@ -23,6 +23,7 @@ import ( cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" exectest "github.com/rook/rook/pkg/util/exec/test" "github.com/stretchr/testify/assert" + "k8s.io/apimachinery/pkg/api/resource" "github.com/rook/rook/pkg/clusterd" ) @@ -40,6 +41,7 @@ func TestCreateProfileWithDeviceClass(t *testing.T) { } func testCreateProfile(t *testing.T, failureDomain, crushRoot, deviceClass string) { + stripeUnit := resource.MustParse("4Ki") spec := cephv1.PoolSpec{ FailureDomain: failureDomain, CrushRoot: crushRoot, @@ -47,6 +49,7 @@ func testCreateProfile(t *testing.T, failureDomain, crushRoot, deviceClass strin ErasureCoded: cephv1.ErasureCodedSpec{ DataChunks: 2, CodingChunks: 3, + StripeUnit: &stripeUnit, }, } @@ -77,6 +80,13 @@ func testCreateProfile(t *testing.T, failureDomain, crushRoot, deviceClass strin } if deviceClass != "" { assert.Equal(t, fmt.Sprintf("crush-device-class=%s", deviceClass), args[nextArg]) + nextArg++ + } + if spec.ErasureCoded.StripeUnit != nil && !spec.ErasureCoded.StripeUnit.IsZero() { + stripeBytes, ok := spec.ErasureCoded.StripeUnit.AsInt64() + assert.True(t, ok) + assert.Equal(t, fmt.Sprintf("stripe_unit=%d", stripeBytes), args[nextArg]) + assert.Equal(t, stripeBytes, int64(4096), "Validate the resource conversion to bytes") } return "", nil }