mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 21:21:41 +00:00
6f94cbc29a
Currently the io_rsrc_node assignment in io_kiocb is an array of two pointers, as two nodes may be assigned to a request - one file node, and one buffer node. However, the buffer node can co-exist with the provided buffers, as currently it's not supported to use both provided and registered buffers at the same time. This crucially brings struct io_kiocb down to 4 cache lines again, as before it spilled into the 5th cacheline. Signed-off-by: Jens Axboe <axboe@kernel.dk>
137 lines
3.6 KiB
C
137 lines
3.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef IOU_RSRC_H
|
|
#define IOU_RSRC_H
|
|
|
|
#define IO_NODE_ALLOC_CACHE_MAX 32
|
|
|
|
#define IO_RSRC_TAG_TABLE_SHIFT (PAGE_SHIFT - 3)
|
|
#define IO_RSRC_TAG_TABLE_MAX (1U << IO_RSRC_TAG_TABLE_SHIFT)
|
|
#define IO_RSRC_TAG_TABLE_MASK (IO_RSRC_TAG_TABLE_MAX - 1)
|
|
|
|
enum {
|
|
IORING_RSRC_FILE = 0,
|
|
IORING_RSRC_BUFFER = 1,
|
|
|
|
IORING_RSRC_TYPE_MASK = 0x3UL,
|
|
};
|
|
|
|
struct io_rsrc_node {
|
|
unsigned long ctx_ptr;
|
|
int refs;
|
|
|
|
u64 tag;
|
|
union {
|
|
unsigned long file_ptr;
|
|
struct io_mapped_ubuf *buf;
|
|
};
|
|
};
|
|
|
|
struct io_mapped_ubuf {
|
|
u64 ubuf;
|
|
unsigned int len;
|
|
unsigned int nr_bvecs;
|
|
unsigned int folio_shift;
|
|
refcount_t refs;
|
|
unsigned long acct_pages;
|
|
struct bio_vec bvec[] __counted_by(nr_bvecs);
|
|
};
|
|
|
|
struct io_imu_folio_data {
|
|
/* Head folio can be partially included in the fixed buf */
|
|
unsigned int nr_pages_head;
|
|
/* For non-head/tail folios, has to be fully included */
|
|
unsigned int nr_pages_mid;
|
|
unsigned int folio_shift;
|
|
};
|
|
|
|
struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx, int type);
|
|
void io_free_rsrc_node(struct io_rsrc_node *node);
|
|
void io_rsrc_data_free(struct io_rsrc_data *data);
|
|
int io_rsrc_data_alloc(struct io_rsrc_data *data, unsigned nr);
|
|
|
|
int io_import_fixed(int ddir, struct iov_iter *iter,
|
|
struct io_mapped_ubuf *imu,
|
|
u64 buf_addr, size_t len);
|
|
|
|
int io_register_clone_buffers(struct io_ring_ctx *ctx, void __user *arg);
|
|
int io_sqe_buffers_unregister(struct io_ring_ctx *ctx);
|
|
int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
|
|
unsigned int nr_args, u64 __user *tags);
|
|
int io_sqe_files_unregister(struct io_ring_ctx *ctx);
|
|
int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
|
|
unsigned nr_args, u64 __user *tags);
|
|
|
|
int io_register_files_update(struct io_ring_ctx *ctx, void __user *arg,
|
|
unsigned nr_args);
|
|
int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
|
|
unsigned size, unsigned type);
|
|
int io_register_rsrc(struct io_ring_ctx *ctx, void __user *arg,
|
|
unsigned int size, unsigned int type);
|
|
|
|
static inline struct io_rsrc_node *io_rsrc_node_lookup(struct io_rsrc_data *data,
|
|
int index)
|
|
{
|
|
if (index < data->nr)
|
|
return data->nodes[array_index_nospec(index, data->nr)];
|
|
return NULL;
|
|
}
|
|
|
|
static inline void io_put_rsrc_node(struct io_rsrc_node *node)
|
|
{
|
|
if (node && !--node->refs)
|
|
io_free_rsrc_node(node);
|
|
}
|
|
|
|
static inline bool io_reset_rsrc_node(struct io_rsrc_data *data, int index)
|
|
{
|
|
struct io_rsrc_node *node = data->nodes[index];
|
|
|
|
if (!node)
|
|
return false;
|
|
io_put_rsrc_node(node);
|
|
data->nodes[index] = NULL;
|
|
return true;
|
|
}
|
|
|
|
static inline void io_req_put_rsrc_nodes(struct io_kiocb *req)
|
|
{
|
|
if (req->file_node) {
|
|
io_put_rsrc_node(req->file_node);
|
|
req->file_node = NULL;
|
|
}
|
|
if (req->flags & REQ_F_BUF_NODE) {
|
|
io_put_rsrc_node(req->buf_node);
|
|
req->buf_node = NULL;
|
|
}
|
|
}
|
|
|
|
static inline struct io_ring_ctx *io_rsrc_node_ctx(struct io_rsrc_node *node)
|
|
{
|
|
return (struct io_ring_ctx *) (node->ctx_ptr & ~IORING_RSRC_TYPE_MASK);
|
|
}
|
|
|
|
static inline int io_rsrc_node_type(struct io_rsrc_node *node)
|
|
{
|
|
return node->ctx_ptr & IORING_RSRC_TYPE_MASK;
|
|
}
|
|
|
|
static inline void io_req_assign_rsrc_node(struct io_rsrc_node **dst_node,
|
|
struct io_rsrc_node *node)
|
|
{
|
|
node->refs++;
|
|
*dst_node = node;
|
|
}
|
|
|
|
int io_files_update(struct io_kiocb *req, unsigned int issue_flags);
|
|
int io_files_update_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
|
|
|
|
int __io_account_mem(struct user_struct *user, unsigned long nr_pages);
|
|
|
|
static inline void __io_unaccount_mem(struct user_struct *user,
|
|
unsigned long nr_pages)
|
|
{
|
|
atomic_long_sub(nr_pages, &user->locked_vm);
|
|
}
|
|
|
|
#endif
|