Skip to content

Commit 22d2cfd

Browse files
committed
libceph: move away from global osd_req_flags
osd_req_flags is overly general and doesn't suit its only user (read_from_replica option) well: - applying osd_req_flags in account_request() affects all OSD requests, including linger (i.e. watch and notify). However, linger requests should always go to the primary even though some of them are reads (e.g. notify has side effects but it is a read because it doesn't result in mutation on the OSDs). - calls to class methods that are reads are allowed to go to the replica, but most such calls issued for "rbd map" and/or exclusive lock transitions are requested to be resent to the primary via EAGAIN, doubling the latency. Get rid of global osd_req_flags and set read_from_replica flag only on specific OSD requests instead. Fixes: 8ad44d5 ("libceph: read_from_replica option") Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Reviewed-by: Jeff Layton <jlayton@kernel.org>
1 parent b3a9e3b commit 22d2cfd

4 files changed

Lines changed: 13 additions & 16 deletions

File tree

‎drivers/block/rbd.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,8 +1451,10 @@ static void rbd_osd_req_callback(struct ceph_osd_request *osd_req)
14511451
static void rbd_osd_format_read(struct ceph_osd_request *osd_req)
14521452
{
14531453
struct rbd_obj_request *obj_request = osd_req->r_priv;
1454+
struct rbd_device *rbd_dev = obj_request->img_request->rbd_dev;
1455+
struct ceph_options *opt = rbd_dev->rbd_client->client->options;
14541456

1455-
osd_req->r_flags = CEPH_OSD_FLAG_READ;
1457+
osd_req->r_flags = CEPH_OSD_FLAG_READ | opt->read_from_replica;
14561458
osd_req->r_snapid = obj_request->img_request->snap_id;
14571459
}
14581460

‎include/linux/ceph/libceph.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ struct ceph_options {
5252
unsigned long osd_idle_ttl; /* jiffies */
5353
unsigned long osd_keepalive_timeout; /* jiffies */
5454
unsigned long osd_request_timeout; /* jiffies */
55-
56-
u32 osd_req_flags; /* CEPH_OSD_FLAG_*, applied to each OSD request */
55+
u32 read_from_replica; /* CEPH_OSD_FLAG_BALANCE/LOCALIZE_READS */
5756

5857
/*
5958
* any type that can't be simply compared or doesn't need
@@ -76,6 +75,7 @@ struct ceph_options {
7675
#define CEPH_OSD_KEEPALIVE_DEFAULT msecs_to_jiffies(5 * 1000)
7776
#define CEPH_OSD_IDLE_TTL_DEFAULT msecs_to_jiffies(60 * 1000)
7877
#define CEPH_OSD_REQUEST_TIMEOUT_DEFAULT 0 /* no timeout */
78+
#define CEPH_READ_FROM_REPLICA_DEFAULT 0 /* read from primary */
7979

8080
#define CEPH_MONC_HUNT_INTERVAL msecs_to_jiffies(3 * 1000)
8181
#define CEPH_MONC_PING_INTERVAL msecs_to_jiffies(10 * 1000)

‎net/ceph/ceph_common.c‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ struct ceph_options *ceph_alloc_options(void)
332332
opt->mount_timeout = CEPH_MOUNT_TIMEOUT_DEFAULT;
333333
opt->osd_idle_ttl = CEPH_OSD_IDLE_TTL_DEFAULT;
334334
opt->osd_request_timeout = CEPH_OSD_REQUEST_TIMEOUT_DEFAULT;
335+
opt->read_from_replica = CEPH_READ_FROM_REPLICA_DEFAULT;
335336
return opt;
336337
}
337338
EXPORT_SYMBOL(ceph_alloc_options);
@@ -490,16 +491,13 @@ int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
490491
case Opt_read_from_replica:
491492
switch (result.uint_32) {
492493
case Opt_read_from_replica_no:
493-
opt->osd_req_flags &= ~(CEPH_OSD_FLAG_BALANCE_READS |
494-
CEPH_OSD_FLAG_LOCALIZE_READS);
494+
opt->read_from_replica = 0;
495495
break;
496496
case Opt_read_from_replica_balance:
497-
opt->osd_req_flags |= CEPH_OSD_FLAG_BALANCE_READS;
498-
opt->osd_req_flags &= ~CEPH_OSD_FLAG_LOCALIZE_READS;
497+
opt->read_from_replica = CEPH_OSD_FLAG_BALANCE_READS;
499498
break;
500499
case Opt_read_from_replica_localize:
501-
opt->osd_req_flags |= CEPH_OSD_FLAG_LOCALIZE_READS;
502-
opt->osd_req_flags &= ~CEPH_OSD_FLAG_BALANCE_READS;
500+
opt->read_from_replica = CEPH_OSD_FLAG_LOCALIZE_READS;
503501
break;
504502
default:
505503
BUG();
@@ -613,9 +611,9 @@ int ceph_print_client_options(struct seq_file *m, struct ceph_client *client,
613611
}
614612
seq_putc(m, ',');
615613
}
616-
if (opt->osd_req_flags & CEPH_OSD_FLAG_BALANCE_READS) {
614+
if (opt->read_from_replica == CEPH_OSD_FLAG_BALANCE_READS) {
617615
seq_puts(m, "read_from_replica=balance,");
618-
} else if (opt->osd_req_flags & CEPH_OSD_FLAG_LOCALIZE_READS) {
616+
} else if (opt->read_from_replica == CEPH_OSD_FLAG_LOCALIZE_READS) {
619617
seq_puts(m, "read_from_replica=localize,");
620618
}
621619

‎net/ceph/osd_client.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,10 +1117,10 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
11171117
truncate_size, truncate_seq);
11181118
}
11191119

1120-
req->r_flags = flags;
11211120
req->r_base_oloc.pool = layout->pool_id;
11221121
req->r_base_oloc.pool_ns = ceph_try_get_string(layout->pool_ns);
11231122
ceph_oid_printf(&req->r_base_oid, "%llx.%08llx", vino.ino, objnum);
1123+
req->r_flags = flags | osdc->client->options->read_from_replica;
11241124

11251125
req->r_snapid = vino.snap;
11261126
if (flags & CEPH_OSD_FLAG_WRITE)
@@ -2431,14 +2431,11 @@ static void __submit_request(struct ceph_osd_request *req, bool wrlocked)
24312431

24322432
static void account_request(struct ceph_osd_request *req)
24332433
{
2434-
struct ceph_osd_client *osdc = req->r_osdc;
2435-
24362434
WARN_ON(req->r_flags & (CEPH_OSD_FLAG_ACK | CEPH_OSD_FLAG_ONDISK));
24372435
WARN_ON(!(req->r_flags & (CEPH_OSD_FLAG_READ | CEPH_OSD_FLAG_WRITE)));
24382436

24392437
req->r_flags |= CEPH_OSD_FLAG_ONDISK;
2440-
req->r_flags |= osdc->client->options->osd_req_flags;
2441-
atomic_inc(&osdc->num_requests);
2438+
atomic_inc(&req->r_osdc->num_requests);
24422439

24432440
req->r_start_stamp = jiffies;
24442441
req->r_start_latency = ktime_get();

0 commit comments

Comments
 (0)