mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] ceph: add compression_hint mount option
@ 2026-12-01  2:40 Daolong Zhang
  2026-12-02 13:24 ` Alex Markuze
  0 siblings, 1 reply; 2+ messages in thread
From: Daolong Zhang @ 2026-12-01  2:40 UTC (permalink / raw)
  To: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko
  Cc: ceph-devel, Jonathan Corbet, Shuah Khan, linux-doc, linux-kernel,
	Daolong Zhang

Add support for the compression_hint=<none|compressible|incompressible>
mount option to the CephFS kernel client, matching the existing RBD
compression_hint option.

When set to 'compressible' or 'incompressible', CephFS attaches a
CEPH_OSD_OP_SETALLOCHINT operation with
CEPH_OSD_ALLOC_HINT_FLAG_COMPRESSIBLE or
CEPH_OSD_ALLOC_HINT_FLAG_INCOMPRESSIBLE (and zero expected object/write
sizes) to data writes across page writeback, uninline, direct I/O
(including AIO retries), and sync writes.

For normal writes without an active truncate sequence (truncate_seq == 0
or the initial (1, -1ULL) pair), SETALLOCHINT is placed before WRITE
(and after any leading guard operation such as ASSERT_VER/CREATE in
fscrypt RMW sync writes or CMPXATTR in uninline writes). When a write
carries an active truncate sequence, SETALLOCHINT is placed after the
WRITE operation(s) instead so that SETALLOCHINT cannot create an absent
object (or clear a whiteout) before WRITE evaluates its truncate
sequence and truncate boundary. On classic OSDs, PGTransaction still
lowers set_alloc_hint before buffer writes, so the hint continues to
apply on the first write.

When set to 'none' (the default), no CEPH_OSD_OP_SETALLOCHINT operation
is sent. The option is also displayed in /proc/mounts and can be updated
on remount while preserving the existing hint when omitted.

Link: https://tracker.ceph.com/issues/81140
Signed-off-by: Daolong Zhang <dlzhangak@isoftstone.com>
---
Changes since v2:
- Preserve missing-object behavior for WRITE's truncate handling by placing
  SETALLOCHINT after WRITE(s) whenever a write carries an active truncate
  sequence, instead of creating an absent object before WRITE runs.
- Snapshot ci->i_truncate_seq and ci->i_truncate_size once before building
  direct and sync write requests so hint placement matches the encoded
  truncate fields.
- Rebase onto latest ceph-client/testing (3f90412e989c).

Changes since v1:
- Preserve existing compression_hint across remount when the option is
  omitted, while allowing compression_hint=none to clear it explicitly.
- Rebase onto latest ceph-client/testing.

 Documentation/filesystems/ceph.rst |  13 ++++
 fs/ceph/addr.c                     | 106 ++++++++++++++++++++++-------
 fs/ceph/file.c                     |  81 ++++++++++++++++------
 fs/ceph/super.c                    |  51 ++++++++++++++
 fs/ceph/super.h                    |  11 +++
 5 files changed, 218 insertions(+), 44 deletions(-)

diff --git a/Documentation/filesystems/ceph.rst b/Documentation/filesystems/ceph.rst
index ee2ca0c0c654..0cfedc8645ee 100644
--- a/Documentation/filesystems/ceph.rst
+++ b/Documentation/filesystems/ceph.rst
@@ -214,6 +214,19 @@ Mount Options
 	  of them. If an inode contains any stale file locks, read/write on the
 	  inode is not allowed until applications release all stale file locks.
 
+  compression_hint=<none|compressible|incompressible>
+	Hint to the underlying OSD object store backend (e.g. BlueStore)
+	whether written data is compressible or incompressible. The default
+	is "none".
+
+	* none: do not send compression hints.
+
+	* compressible: hint that the data is compressible, enabling
+	  compression when the OSD compression mode is set to passive.
+
+	* incompressible: hint that the data is incompressible, disabling
+	  compression when the OSD compression mode is set to aggressive.
+
 More Information
 ================
 
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index de3431f28ba9..21525e8558b0 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -1050,6 +1050,9 @@ static int write_folio_nounlock(struct folio *folio,
 	struct ceph_osd_request *req;
 	bool caching = ceph_is_cache_enabled(inode);
 	struct page *bounce_page = NULL;
+	u32 alloc_hint_flags = READ_ONCE(fsc->mount_options->alloc_hint_flags);
+	bool trailing_hint;
+	unsigned int op_idx;
 
 	doutc(cl, "%llx.%llx folio %p idx %lu\n", ceph_vinop(inode), folio,
 	      folio->index);
@@ -1110,8 +1113,15 @@ static int write_folio_nounlock(struct folio *folio,
 	    CONGESTION_ON_THRESH(fsc->mount_options->congestion_kb))
 		fsc->write_congested = true;
 
+	trailing_hint = alloc_hint_flags &&
+			ceph_has_truncate_seq(ceph_wbc.truncate_seq,
+					      ceph_wbc.truncate_size);
+	op_idx = (alloc_hint_flags && !trailing_hint) ? 1 : 0;
+
 	req = ceph_osdc_new_request(osdc, &ci->i_layout, ceph_vino(inode),
-				    page_off, &wlen, 0, 1, CEPH_OSD_OP_WRITE,
+				    page_off, &wlen, op_idx,
+				    alloc_hint_flags ? 2 : 1,
+				    CEPH_OSD_OP_WRITE,
 				    CEPH_OSD_FLAG_WRITE, snapc,
 				    ceph_wbc.truncate_seq,
 				    ceph_wbc.truncate_size, true);
@@ -1123,6 +1133,10 @@ static int write_folio_nounlock(struct folio *folio,
 		return PTR_ERR(req);
 	}
 
+	if (alloc_hint_flags)
+		osd_req_op_alloc_hint_init(req, trailing_hint ? 1 : 0, 0, 0,
+					   alloc_hint_flags);
+
 	if (wlen < len)
 		len = wlen;
 
@@ -1149,7 +1163,7 @@ static int write_folio_nounlock(struct folio *folio,
 	/* it may be a short write due to an object boundary */
 	WARN_ON_ONCE(start + len > folio_size(folio));
 	page = bounce_page ? bounce_page : &folio->page;
-	osd_req_op_extent_osd_data_pages(req, 0, &page, wlen, start, false,
+	osd_req_op_extent_osd_data_pages(req, op_idx, &page, wlen, start, false,
 					 false);
 	doutc(cl, "%llx.%llx %llu~%llu (%llu bytes, %sencrypted)\n",
 	      ceph_vinop(inode), page_off, len, wlen,
@@ -1234,6 +1248,8 @@ static void writepages_finish(struct ceph_osd_request *req)
 	struct ceph_fs_client *fsc = ceph_inode_to_fs_client(inode);
 	struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(inode->i_sb);
 	unsigned int len = 0;
+	unsigned int first_write_op = 0;
+	unsigned int end_write_op = req->r_num_ops;
 	bool remove_page;
 
 	doutc(cl, "%llx.%llx rc %d\n", ceph_vinop(inode), rc);
@@ -1255,8 +1271,16 @@ static void writepages_finish(struct ceph_osd_request *req)
 	remove_page = !(ceph_caps_issued(ci) &
 			(CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO));
 
+	if (req->r_num_ops > 1) {
+		if (req->r_ops[0].op == CEPH_OSD_OP_SETALLOCHINT)
+			first_write_op = 1;
+		else if (req->r_ops[req->r_num_ops - 1].op ==
+			 CEPH_OSD_OP_SETALLOCHINT)
+			end_write_op = req->r_num_ops - 1;
+	}
+
 	/* clean all pages */
-	for (i = 0; i < req->r_num_ops; i++) {
+	for (i = first_write_op; i < end_write_op; i++) {
 		if (req->r_ops[i].op != CEPH_OSD_OP_WRITE) {
 			pr_warn_client(cl,
 				"%llx.%llx incorrect op %d req %p index %d tid %llu\n",
@@ -1320,7 +1344,7 @@ static void writepages_finish(struct ceph_osd_request *req)
 
 	ceph_put_wrbuffer_cap_refs(ci, total_pages, snapc);
 
-	osd_data = osd_req_op_extent_osd_data(req, 0);
+	osd_data = osd_req_op_extent_osd_data(req, first_write_op);
 	if (osd_data->pages_from_pool)
 		mempool_free(osd_data->pages, ceph_wb_pagevec_pool);
 	else
@@ -1622,10 +1646,14 @@ bool is_folio_index_contiguous(const struct ceph_writeback_ctl *ceph_wbc,
 }
 
 static inline
-bool is_num_ops_too_big(struct ceph_writeback_ctl *ceph_wbc)
+bool is_num_ops_too_big(struct ceph_fs_client *fsc,
+			struct ceph_writeback_ctl *ceph_wbc)
 {
-	return ceph_wbc->num_ops >=
-		(ceph_wbc->from_pool ?  CEPH_OSD_SLAB_OPS : CEPH_OSD_MAX_OPS);
+	unsigned int extra_ops =
+		READ_ONCE(fsc->mount_options->alloc_hint_flags) ? 1 : 0;
+
+	return ceph_wbc->num_ops + extra_ops >=
+		(ceph_wbc->from_pool ? CEPH_OSD_SLAB_OPS : CEPH_OSD_MAX_OPS);
 }
 
 static inline
@@ -1731,7 +1759,7 @@ void ceph_process_folio_batch(struct address_space *mapping,
 		 */
 		if (ceph_wbc->locked_pages &&
 		    !is_folio_index_contiguous(ceph_wbc, folio) &&
-		    is_num_ops_too_big(ceph_wbc)) {
+		    is_num_ops_too_big(fsc, ceph_wbc)) {
 			folio_unlock(folio);
 			break;
 		}
@@ -1831,6 +1859,9 @@ int ceph_submit_write(struct address_space *mapping,
 	struct ceph_osd_request *req = NULL;
 	struct folio *folio = NULL;
 	bool caching = ceph_is_cache_enabled(inode);
+	u32 alloc_hint_flags;
+	bool trailing_hint;
+	unsigned int first_op, last_write_op, hint_ops, write_ops;
 	u64 offset, start, end, last_len = 0;
 	u64 len;
 	unsigned int i, align;
@@ -1839,19 +1870,29 @@ int ceph_submit_write(struct address_space *mapping,
 	folio = ceph_fscrypt_pagecache_folio(page_folio(ceph_wbc->pages[0]));
 	ceph_folio_write_range(folio, &offset, &end);
 	len = ceph_wbc->wsize;
+	alloc_hint_flags = READ_ONCE(fsc->mount_options->alloc_hint_flags);
+	hint_ops = alloc_hint_flags ? 1 : 0;
+	trailing_hint = alloc_hint_flags &&
+			ceph_has_truncate_seq(ceph_wbc->truncate_seq,
+					      ceph_wbc->truncate_size);
+	first_op = (alloc_hint_flags && !trailing_hint) ? 1 : 0;
+	write_ops = min_t(unsigned int, ceph_wbc->num_ops,
+			  CEPH_OSD_MAX_OPS - hint_ops);
 
 	req = ceph_osdc_new_request(&fsc->client->osdc,
 				    &ci->i_layout, vino,
-				    offset, &len, 0, ceph_wbc->num_ops,
+				    offset, &len, first_op,
+				    write_ops + hint_ops,
 				    CEPH_OSD_OP_WRITE, CEPH_OSD_FLAG_WRITE,
 				    ceph_wbc->snapc, ceph_wbc->truncate_seq,
 				    ceph_wbc->truncate_size, false);
 	if (IS_ERR(req)) {
+		write_ops = min_t(unsigned int, ceph_wbc->num_ops,
+				  CEPH_OSD_SLAB_OPS - hint_ops);
 		req = ceph_osdc_new_request(&fsc->client->osdc,
 					    &ci->i_layout, vino,
-					    offset, &len, 0,
-					    min(ceph_wbc->num_ops,
-						CEPH_OSD_SLAB_OPS),
+					    offset, &len, first_op,
+					    write_ops + hint_ops,
 					    CEPH_OSD_OP_WRITE,
 					    CEPH_OSD_FLAG_WRITE,
 					    ceph_wbc->snapc,
@@ -1861,6 +1902,12 @@ int ceph_submit_write(struct address_space *mapping,
 		BUG_ON(IS_ERR(req));
 	}
 
+	if (alloc_hint_flags)
+		osd_req_op_alloc_hint_init(req,
+					   trailing_hint ? req->r_num_ops - 1 : 0,
+					   0, 0, alloc_hint_flags);
+	last_write_op = first_op + write_ops - 1;
+
 	folio = ceph_fscrypt_pagecache_folio(
 			page_folio(ceph_wbc->pages[ceph_wbc->locked_pages - 1]));
 	ceph_folio_write_range(folio, &start, &end);
@@ -1903,7 +1950,7 @@ int ceph_submit_write(struct address_space *mapping,
 	/* Format the osd request message and submit the write */
 	len = 0;
 	ceph_wbc->data_pages = ceph_wbc->pages;
-	ceph_wbc->op_idx = 0;
+	ceph_wbc->op_idx = first_op;
 	align = offset_in_page(offset);
 	for (i = 0; i < ceph_wbc->locked_pages; i++) {
 		u64 cur_offset;
@@ -1917,7 +1964,7 @@ int ceph_submit_write(struct address_space *mapping,
 		 */
 		if (offset + len != cur_offset) {
 			/* If it's full, stop here */
-			if (ceph_wbc->op_idx + 1 == req->r_num_ops)
+			if (ceph_wbc->op_idx == last_write_op)
 				break;
 
 			/* Kick off an fscache write with what we have so far. */
@@ -1985,12 +2032,12 @@ int ceph_submit_write(struct address_space *mapping,
 					 align, ceph_wbc->from_pool, false);
 	osd_req_op_extent_update(req, ceph_wbc->op_idx, len);
 
-	BUG_ON(ceph_wbc->op_idx + 1 != req->r_num_ops);
+	BUG_ON(ceph_wbc->op_idx != last_write_op);
 
 	ceph_wbc->from_pool = false;
 	if (i < ceph_wbc->locked_pages) {
-		BUG_ON(ceph_wbc->num_ops <= req->r_num_ops);
-		ceph_wbc->num_ops -= req->r_num_ops;
+		BUG_ON(ceph_wbc->num_ops <= write_ops);
+		ceph_wbc->num_ops -= write_ops;
 		ceph_wbc->locked_pages -= i;
 
 		/* allocate new pages array for next request */
@@ -2001,7 +2048,7 @@ int ceph_submit_write(struct address_space *mapping,
 		memset(ceph_wbc->data_pages + i, 0,
 			ceph_wbc->locked_pages * sizeof(*ceph_wbc->pages));
 	} else {
-		BUG_ON(ceph_wbc->num_ops != req->r_num_ops);
+		BUG_ON(ceph_wbc->num_ops != write_ops);
 		/* request message now owns the pages array */
 		ceph_wbc->pages = NULL;
 	}
@@ -3031,6 +3078,8 @@ int ceph_uninline_data(struct file *file)
 	struct ceph_snap_context *snapc = NULL;
 	u64 inline_version = CEPH_INLINE_NONE;
 	struct page *pages[1];
+	u32 alloc_hint_flags;
+	unsigned int write_op;
 	int err = 0;
 	u64 len;
 
@@ -3102,18 +3151,23 @@ int ceph_uninline_data(struct file *file)
 	if (err < 0)
 		goto out_unlock;
 
+	alloc_hint_flags = READ_ONCE(fsc->mount_options->alloc_hint_flags);
+	write_op = alloc_hint_flags ? 2 : 1;
+
 	req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
-				    ceph_vino(inode), 0, &len, 1, 3,
-				    CEPH_OSD_OP_WRITE, CEPH_OSD_FLAG_WRITE,
-				    snapc, ci->i_truncate_seq,
-				    ci->i_truncate_size, false);
+				    ceph_vino(inode), 0, &len, write_op,
+				    write_op + 2, CEPH_OSD_OP_WRITE,
+				    CEPH_OSD_FLAG_WRITE, snapc,
+				    ci->i_truncate_seq, ci->i_truncate_size,
+				    false);
 	if (IS_ERR(req)) {
 		err = PTR_ERR(req);
 		goto out_unlock;
 	}
 
 	pages[0] = folio_page(folio, 0);
-	osd_req_op_extent_osd_data_pages(req, 1, pages, len, 0, false, false);
+	osd_req_op_extent_osd_data_pages(req, write_op, pages, len, 0,
+					 false, false);
 
 	{
 		__le64 xattr_buf = cpu_to_le64(inline_version);
@@ -3126,11 +3180,15 @@ int ceph_uninline_data(struct file *file)
 			goto out_put_req;
 	}
 
+	if (alloc_hint_flags)
+		osd_req_op_alloc_hint_init(req, 1, 0, 0, alloc_hint_flags);
+
 	{
 		char xattr_buf[32];
 		int xattr_len = snprintf(xattr_buf, sizeof(xattr_buf),
 					 "%llu", inline_version);
-		err = osd_req_op_xattr_init(req, 2, CEPH_OSD_OP_SETXATTR,
+		err = osd_req_op_xattr_init(req, write_op + 1,
+					    CEPH_OSD_OP_SETXATTR,
 					    "inline_version",
 					    xattr_buf, xattr_len, 0, 0);
 		if (err)
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index 6d56a9b2447e..fe56da2b3a0b 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -1369,8 +1369,11 @@ static void ceph_aio_complete_req(struct ceph_osd_request *req)
 	int rc = req->r_result;
 	struct inode *inode = req->r_inode;
 	struct ceph_aio_request *aio_req = req->r_priv;
-	struct ceph_osd_data *osd_data = osd_req_op_extent_osd_data(req, 0);
-	struct ceph_osd_req_op *op = &req->r_ops[0];
+	unsigned int op_idx = (req->r_num_ops > 1 &&
+			       req->r_ops[0].op == CEPH_OSD_OP_SETALLOCHINT) ?
+			      1 : 0;
+	struct ceph_osd_data *osd_data = osd_req_op_extent_osd_data(req, op_idx);
+	struct ceph_osd_req_op *op = &req->r_ops[op_idx];
 	struct ceph_client_metric *metric = &ceph_sb_to_mdsc(inode->i_sb)->metric;
 	unsigned int len = osd_data->bvec_pos.iter.bi_size;
 	bool sparse = (op->op == CEPH_OSD_OP_SPARSE_READ);
@@ -1467,6 +1470,7 @@ static void ceph_aio_retry_work(struct work_struct *work)
 	struct ceph_inode_info *ci = ceph_inode(inode);
 	struct ceph_snap_context *snapc;
 	struct ceph_osd_request *req;
+	unsigned int i, op_idx;
 	int ret;
 
 	spin_lock(&ci->i_ceph_lock);
@@ -1482,8 +1486,8 @@ static void ceph_aio_retry_work(struct work_struct *work)
 	}
 	spin_unlock(&ci->i_ceph_lock);
 
-	req = ceph_osdc_alloc_request(orig_req->r_osdc, snapc, 1,
-			false, GFP_NOFS);
+	req = ceph_osdc_alloc_request(orig_req->r_osdc, snapc,
+				      orig_req->r_num_ops, false, GFP_NOFS);
 	if (!req) {
 		ret = -ENOMEM;
 		req = orig_req;
@@ -1494,10 +1498,13 @@ static void ceph_aio_retry_work(struct work_struct *work)
 	ceph_oloc_copy(&req->r_base_oloc, &orig_req->r_base_oloc);
 	ceph_oid_copy(&req->r_base_oid, &orig_req->r_base_oid);
 
-	req->r_ops[0] = orig_req->r_ops[0];
+	for (i = 0; i < orig_req->r_num_ops; i++)
+		req->r_ops[i] = orig_req->r_ops[i];
 
+	op_idx = (orig_req->r_num_ops > 1 &&
+		  orig_req->r_ops[0].op == CEPH_OSD_OP_SETALLOCHINT) ? 1 : 0;
 	req->r_mtime = aio_req->mtime;
-	req->r_data_offset = req->r_ops[0].extent.offset;
+	req->r_data_offset = req->r_ops[op_idx].extent.offset;
 
 	ret = ceph_osdc_alloc_messages(req, GFP_NOFS);
 	if (ret) {
@@ -1579,6 +1586,14 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter,
 		struct ceph_osd_req_op *op;
 		int readop = sparse ? CEPH_OSD_OP_SPARSE_READ : CEPH_OSD_OP_READ;
 		int extent_cnt;
+		u32 truncate_seq = READ_ONCE(ci->i_truncate_seq);
+		u64 truncate_size = READ_ONCE(ci->i_truncate_size);
+		u32 alloc_hint_flags = write ?
+			READ_ONCE(fsc->mount_options->alloc_hint_flags) : 0;
+		bool trailing_hint = alloc_hint_flags &&
+			ceph_has_truncate_seq(truncate_seq, truncate_size);
+		unsigned int op_idx = (alloc_hint_flags && !trailing_hint) ?
+				      1 : 0;
 
 		if (write)
 			size = min_t(u64, size, fsc->mount_options->wsize);
@@ -1587,19 +1602,22 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter,
 
 		vino = ceph_vino(inode);
 		req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
-					    vino, pos, &size, 0,
-					    1,
+					    vino, pos, &size, op_idx,
+					    alloc_hint_flags ? 2 : 1,
 					    write ? CEPH_OSD_OP_WRITE : readop,
 					    flags, snapc,
-					    ci->i_truncate_seq,
-					    ci->i_truncate_size,
+					    truncate_seq, truncate_size,
 					    false);
 		if (IS_ERR(req)) {
 			ret = PTR_ERR(req);
 			break;
 		}
 
-		op = &req->r_ops[0];
+		if (alloc_hint_flags)
+			osd_req_op_alloc_hint_init(req, trailing_hint ? 1 : 0,
+						   0, 0, alloc_hint_flags);
+
+		op = &req->r_ops[op_idx];
 		if (!write && sparse) {
 			extent_cnt = __ceph_sparse_read_ext_count(inode, size);
 			ret = ceph_alloc_sparse_ext_map(op, extent_cnt);
@@ -1616,9 +1634,10 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter,
 			break;
 		}
 		if (len != size)
-			osd_req_op_extent_update(req, 0, len);
+			osd_req_op_extent_update(req, op_idx, len);
 
-		osd_req_op_extent_osd_data_bvecs(req, 0, bvecs, num_bvecs, len);
+		osd_req_op_extent_osd_data_bvecs(req, op_idx, bvecs, num_bvecs,
+						 len);
 
 		/*
 		 * To simplify error handling, allow AIO when IO within i_size
@@ -1811,6 +1830,11 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos,
 		bool first, last;
 		struct iov_iter saved_iter = *from;
 		size_t off;
+		u32 truncate_seq;
+		u64 truncate_size;
+		u32 alloc_hint_flags;
+		bool trailing_hint;
+		unsigned int write_op, num_ops;
 
 		ceph_fscrypt_adjust_off_and_len(inode, &write_pos, &write_len);
 
@@ -2065,13 +2089,23 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos,
 			}
 		}
 
+		truncate_seq = READ_ONCE(ci->i_truncate_seq);
+		truncate_size = READ_ONCE(ci->i_truncate_size);
+		alloc_hint_flags =
+			READ_ONCE(fsc->mount_options->alloc_hint_flags);
+		trailing_hint = alloc_hint_flags &&
+			ceph_has_truncate_seq(truncate_seq, truncate_size);
+		write_op = (rmw ? 1 : 0) +
+			(alloc_hint_flags && !trailing_hint ? 1 : 0);
+		num_ops = (rmw ? 1 : 0) + (alloc_hint_flags ? 2 : 1);
+
 		req = ceph_osdc_new_request(osdc, &ci->i_layout,
-					    ceph_vino(inode), write_pos, &write_len,
-					    rmw ? 1 : 0, rmw ? 2 : 1,
+					    ceph_vino(inode), write_pos,
+					    &write_len, write_op, num_ops,
 					    CEPH_OSD_OP_WRITE,
 					    CEPH_OSD_FLAG_WRITE,
-					    snapc, ci->i_truncate_seq,
-					    ci->i_truncate_size, false);
+					    snapc, truncate_seq, truncate_size,
+					    false);
 		if (IS_ERR(req)) {
 			ret = PTR_ERR(req);
 			ceph_release_page_vector(pages, num_pages);
@@ -2079,9 +2113,10 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos,
 		}
 
 		doutc(cl, "write op %lld~%llu\n", write_pos, write_len);
-		osd_req_op_extent_osd_data_pages(req, rmw ? 1 : 0, pages, write_len,
-						 offset_in_page(write_pos), false,
-						 true);
+		osd_req_op_extent_osd_data_pages(req, write_op, pages,
+						 write_len,
+						 offset_in_page(write_pos),
+						 false, true);
 		req->r_inode = inode;
 		req->r_mtime = mtime;
 
@@ -2102,6 +2137,12 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos,
 			}
 		}
 
+		if (alloc_hint_flags)
+			osd_req_op_alloc_hint_init(req,
+						   trailing_hint ? num_ops - 1 :
+								   (rmw ? 1 : 0),
+						   0, 0, alloc_hint_flags);
+
 		ceph_osdc_start_request(osdc, req);
 		ret = ceph_osdc_wait_request(osdc, req);
 
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 2639c14cb757..1d6400b5fb30 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -162,6 +162,7 @@ enum {
 	Opt_snapdirname,
 	Opt_mds_namespace,
 	Opt_recover_session,
+	Opt_compression_hint,
 	Opt_source,
 	Opt_mon_addr,
 	Opt_test_dummy_encryption,
@@ -195,12 +196,27 @@ static const struct constant_table ceph_param_recover[] = {
 	{}
 };
 
+enum ceph_compression_hint {
+	Opt_compression_hint_none,
+	Opt_compression_hint_compressible,
+	Opt_compression_hint_incompressible,
+};
+
+static const struct constant_table ceph_param_compression_hint[] = {
+	{ "none",		Opt_compression_hint_none },
+	{ "compressible",	Opt_compression_hint_compressible },
+	{ "incompressible",	Opt_compression_hint_incompressible },
+	{}
+};
+
 static const struct fs_parameter_spec ceph_mount_parameters[] = {
 	fsparam_flag_no ("acl",				Opt_acl),
 	fsparam_flag_no ("asyncreaddir",		Opt_asyncreaddir),
 	fsparam_s32	("caps_max",			Opt_caps_max),
 	fsparam_u32	("caps_wanted_delay_max",	Opt_caps_wanted_delay_max),
 	fsparam_u32	("caps_wanted_delay_min",	Opt_caps_wanted_delay_min),
+	fsparam_enum	("compression_hint",		Opt_compression_hint,
+			 ceph_param_compression_hint),
 	fsparam_u32	("write_congestion_kb",		Opt_congestion_kb),
 	fsparam_flag_no ("copyfrom",			Opt_copyfrom),
 	fsparam_flag_no ("dcache",			Opt_dcache),
@@ -235,6 +251,7 @@ static const struct fs_parameter_spec ceph_mount_parameters[] = {
 struct ceph_parse_opts_ctx {
 	struct ceph_options		*copts;
 	struct ceph_mount_options	*opts;
+	bool				compression_hint_set;
 };
 
 /*
@@ -455,6 +472,30 @@ static int ceph_parse_mount_param(struct fs_context *fc,
 		else
 			BUG();
 		break;
+	case Opt_compression_hint:
+		switch (result.uint_32) {
+		case Opt_compression_hint_none:
+			fsopt->alloc_hint_flags &=
+				~(CEPH_OSD_ALLOC_HINT_FLAG_COMPRESSIBLE |
+				  CEPH_OSD_ALLOC_HINT_FLAG_INCOMPRESSIBLE);
+			break;
+		case Opt_compression_hint_compressible:
+			fsopt->alloc_hint_flags |=
+				CEPH_OSD_ALLOC_HINT_FLAG_COMPRESSIBLE;
+			fsopt->alloc_hint_flags &=
+				~CEPH_OSD_ALLOC_HINT_FLAG_INCOMPRESSIBLE;
+			break;
+		case Opt_compression_hint_incompressible:
+			fsopt->alloc_hint_flags |=
+				CEPH_OSD_ALLOC_HINT_FLAG_INCOMPRESSIBLE;
+			fsopt->alloc_hint_flags &=
+				~CEPH_OSD_ALLOC_HINT_FLAG_COMPRESSIBLE;
+			break;
+		default:
+			BUG();
+		}
+		pctx->compression_hint_set = true;
+		break;
 	case Opt_source:
 		if (fc->source)
 			return invalfc(fc, "Multiple sources specified");
@@ -714,6 +755,7 @@ static int ceph_show_options(struct seq_file *m, struct dentry *root)
 {
 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(root->d_sb);
 	struct ceph_mount_options *fsopt = fsc->mount_options;
+	u32 alloc_hint_flags = READ_ONCE(fsopt->alloc_hint_flags);
 	size_t pos;
 	int ret;
 
@@ -767,6 +809,11 @@ static int ceph_show_options(struct seq_file *m, struct dentry *root)
 	if (fsopt->flags & CEPH_MOUNT_OPT_CLEANRECOVER)
 		seq_show_option(m, "recover_session", "clean");
 
+	if (alloc_hint_flags & CEPH_OSD_ALLOC_HINT_FLAG_COMPRESSIBLE)
+		seq_show_option(m, "compression_hint", "compressible");
+	else if (alloc_hint_flags & CEPH_OSD_ALLOC_HINT_FLAG_INCOMPRESSIBLE)
+		seq_show_option(m, "compression_hint", "incompressible");
+
 	if (!(fsopt->flags & CEPH_MOUNT_OPT_ASYNC_DIROPS))
 		seq_puts(m, ",wsync");
 	if (fsopt->flags & CEPH_MOUNT_OPT_NOPAGECACHE)
@@ -1457,6 +1504,10 @@ static int ceph_reconfigure_fc(struct fs_context *fc)
 	else
 		ceph_clear_mount_opt(fsc, LAZYIO);
 
+	if (pctx->compression_hint_set)
+		WRITE_ONCE(fsc->mount_options->alloc_hint_flags,
+			   fsopt->alloc_hint_flags);
+
 	if (strcmp_null(fsc->mount_options->mon_addr, fsopt->mon_addr)) {
 		kfree(fsc->mount_options->mon_addr);
 		fsc->mount_options->mon_addr = fsopt->mon_addr;
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 978dd7be1778..f8c31a507433 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -91,6 +91,7 @@ struct ceph_mount_options {
 	int caps_max;
 	unsigned int max_readdir;       /* max readdir result (entries) */
 	unsigned int max_readdir_bytes; /* max readdir result (bytes) */
+	u32 alloc_hint_flags;           /* CEPH_OSD_ALLOC_HINT_FLAG_* */
 
 	bool new_dev_syntax;
 
@@ -107,6 +108,16 @@ struct ceph_mount_options {
 	struct fscrypt_dummy_policy dummy_enc_policy;
 };
 
+/*
+ * Return true if the truncate sequence/size pair represents an active
+ * truncate that OSD WRITE will evaluate against the object's state
+ * (matching PrimaryLogPG's munging of (1, -1ULL) to (0, 0)).
+ */
+static inline bool ceph_has_truncate_seq(u32 truncate_seq, u64 truncate_size)
+{
+	return truncate_seq && !(truncate_seq == 1 && truncate_size == -1ULL);
+}
+
 #define CEPH_NAMESPACE_WILDCARD		"*"
 
 static inline bool ceph_namespace_match(const char *pattern,
-- 
2.48.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] ceph: add compression_hint mount option
  2026-12-01  2:40 [PATCH v3] ceph: add compression_hint mount option Daolong Zhang
@ 2026-12-02 13:24 ` Alex Markuze
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Markuze @ 2026-12-02 13:24 UTC (permalink / raw)
  To: Daolong Zhang
  Cc: Ilya Dryomov, Viacheslav Dubeyko, ceph-devel, Jonathan Corbet,
	Shuah Khan, linux-doc, linux-kernel

Hi Daolong,

With a compression hint, ceph_osdc_new_request() allocates two ops for a
direct write but initializes only WRITE before allocating the messages. If
a message allocation fails, cleanup releases both slots before the hint
slot is initialized. A slot reused from a sparse read can still contain
its already-freed extent pointer, so this can double-free it. Please make
all op slots safe to release before a constructor failure, for both hint
positions.

The initial (1, -1ULL) truncate pair also puts the hint before WRITE. In
the experimental Crimson/BlueStore implementation at Ceph commit
6d531bf08b7c, a first direct write to a new file can then abort the OSD:
the hint creates the object, and WRITE queues a truncate to -1ULL, which
BlueStore rejects. The classic OSD normalizes this sentinel. Please
preserve the initial no-truncate semantics for Crimson as well, without
reintroducing the missing-object problem for real truncates.

Thanks,
Alex

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02 13:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01  2:40 [PATCH v3] ceph: add compression_hint mount option Daolong Zhang
2026-12-02 13:24 ` Alex Markuze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®