]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_aio_throttle.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2018 Red Hat, Inc.
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
18 #include "include/rados/librados_fwd.hpp"
20 #include "common/ceph_mutex.h"
21 #include "services/svc_rados.h"
26 // a throttle for aio operations that enforces a maximum window on outstanding
27 // bytes. only supports a single waiter, so all public functions must be called
28 // from the same thread
29 class AioThrottle
: public Aio
{
31 const uint64_t window
;
32 uint64_t pending_size
= 0;
34 bool is_available() const { return pending_size
<= window
; }
35 bool has_completion() const { return !completed
.empty(); }
36 bool is_drained() const { return pending
.empty(); }
38 struct Pending
: AioResultEntry
{
39 AioThrottle
*parent
= nullptr;
41 librados::AioCompletion
*completion
= nullptr;
43 OwningList
<Pending
> pending
;
44 AioResultList completed
;
46 enum class Wait
{ None
, Available
, Completion
, Drained
};
47 Wait waiter
= Wait::None
;
49 bool waiter_ready() const;
51 ceph::mutex mutex
= ceph::make_mutex("AioThrottle");
52 ceph::condition_variable cond
;
57 static void aio_cb(void *cb
, void *arg
);
60 AioThrottle(uint64_t window
) : window(window
) {}
62 virtual ~AioThrottle() {
63 // must drain before destructing
64 ceph_assert(pending
.empty());
65 ceph_assert(completed
.empty());
68 AioResultList
submit(RGWSI_RADOS::Obj
& obj
,
69 librados::ObjectReadOperation
*op
,
70 uint64_t cost
, uint64_t id
) override
;
72 AioResultList
submit(RGWSI_RADOS::Obj
& obj
,
73 librados::ObjectWriteOperation
*op
,
74 uint64_t cost
, uint64_t id
) override
;
76 AioResultList
poll() override
;
78 AioResultList
wait() override
;
80 AioResultList
drain() override
;