2011-10-31 20:19:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009-2011 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Author: Mikulas Patocka <mpatocka@redhat.com>
|
|
|
|
*
|
|
|
|
* This file is released under the GPL.
|
|
|
|
*/
|
|
|
|
|
2018-03-15 20:02:31 +00:00
|
|
|
#include <linux/dm-bufio.h>
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
#include <linux/device-mapper.h>
|
|
|
|
#include <linux/dm-io.h>
|
|
|
|
#include <linux/slab.h>
|
2017-02-02 19:43:54 +00:00
|
|
|
#include <linux/sched/mm.h>
|
2015-01-06 13:44:15 +00:00
|
|
|
#include <linux/jiffies.h>
|
2011-10-31 20:19:09 +00:00
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/shrinker.h>
|
2011-11-01 07:30:49 +00:00
|
|
|
#include <linux/module.h>
|
2014-10-06 12:48:51 +00:00
|
|
|
#include <linux/rbtree.h>
|
2015-11-24 00:20:06 +00:00
|
|
|
#include <linux/stacktrace.h>
|
2022-07-25 22:26:48 +00:00
|
|
|
#include <linux/jump_label.h>
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
#define DM_MSG_PREFIX "bufio"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Memory management policy:
|
|
|
|
* Limit the number of buffers to DM_BUFIO_MEMORY_PERCENT of main memory
|
|
|
|
* or DM_BUFIO_VMALLOC_PERCENT of vmalloc memory (whichever is lower).
|
|
|
|
* Always allocate at least DM_BUFIO_MIN_BUFFERS buffers.
|
|
|
|
* Start background writeback when there are DM_BUFIO_WRITEBACK_PERCENT
|
|
|
|
* dirty buffers.
|
|
|
|
*/
|
|
|
|
#define DM_BUFIO_MIN_BUFFERS 8
|
|
|
|
|
|
|
|
#define DM_BUFIO_MEMORY_PERCENT 2
|
|
|
|
#define DM_BUFIO_VMALLOC_PERCENT 25
|
2019-09-12 08:44:47 +00:00
|
|
|
#define DM_BUFIO_WRITEBACK_RATIO 3
|
2019-09-12 16:07:23 +00:00
|
|
|
#define DM_BUFIO_LOW_WATERMARK_RATIO 16
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check buffer ages in this interval (seconds)
|
|
|
|
*/
|
2014-10-09 10:10:25 +00:00
|
|
|
#define DM_BUFIO_WORK_TIMER_SECS 30
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free buffers when they are older than this (seconds)
|
|
|
|
*/
|
2014-10-09 10:10:25 +00:00
|
|
|
#define DM_BUFIO_DEFAULT_AGE_SECS 300
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
/*
|
2014-10-09 10:10:25 +00:00
|
|
|
* The nr of bytes of cached data to keep around.
|
2011-10-31 20:19:09 +00:00
|
|
|
*/
|
2014-10-09 10:10:25 +00:00
|
|
|
#define DM_BUFIO_DEFAULT_RETAIN_BYTES (256 * 1024)
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2017-04-30 21:31:22 +00:00
|
|
|
/*
|
|
|
|
* Align buffer writes to this boundary.
|
|
|
|
* Tests show that SSDs have the highest IOPS when using 4k writes.
|
|
|
|
*/
|
|
|
|
#define DM_BUFIO_WRITE_ALIGN 4096
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
/*
|
|
|
|
* dm_buffer->list_mode
|
|
|
|
*/
|
|
|
|
#define LIST_CLEAN 0
|
|
|
|
#define LIST_DIRTY 1
|
|
|
|
#define LIST_SIZE 2
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Linking of buffers:
|
2018-10-30 07:35:54 +00:00
|
|
|
* All buffers are linked to buffer_tree with their node field.
|
2011-10-31 20:19:09 +00:00
|
|
|
*
|
|
|
|
* Clean buffers that are not being written (B_WRITING not set)
|
|
|
|
* are linked to lru[LIST_CLEAN] with their lru_list field.
|
|
|
|
*
|
|
|
|
* Dirty and clean buffers that are being written are linked to
|
|
|
|
* lru[LIST_DIRTY] with their lru_list field. When the write
|
|
|
|
* finishes, the buffer cannot be relinked immediately (because we
|
|
|
|
* are in an interrupt context and relinking requires process
|
|
|
|
* context), so some clean-not-writing buffers can be held on
|
|
|
|
* dirty_lru too. They are later added to lru in the process
|
|
|
|
* context.
|
|
|
|
*/
|
|
|
|
struct dm_bufio_client {
|
|
|
|
struct mutex lock;
|
2022-07-22 09:38:22 +00:00
|
|
|
spinlock_t spinlock;
|
|
|
|
unsigned long spinlock_flags;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
struct list_head lru[LIST_SIZE];
|
|
|
|
unsigned long n_buffers[LIST_SIZE];
|
|
|
|
|
|
|
|
struct block_device *bdev;
|
|
|
|
unsigned block_size;
|
2018-03-26 18:29:46 +00:00
|
|
|
s8 sectors_per_block_bits;
|
2011-10-31 20:19:09 +00:00
|
|
|
void (*alloc_callback)(struct dm_buffer *);
|
|
|
|
void (*write_callback)(struct dm_buffer *);
|
2022-07-22 09:38:22 +00:00
|
|
|
bool no_sleep;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2018-03-26 18:29:45 +00:00
|
|
|
struct kmem_cache *slab_buffer;
|
2018-03-26 18:29:42 +00:00
|
|
|
struct kmem_cache *slab_cache;
|
2011-10-31 20:19:09 +00:00
|
|
|
struct dm_io_client *dm_io;
|
|
|
|
|
|
|
|
struct list_head reserved_buffers;
|
|
|
|
unsigned need_reserved_buffers;
|
|
|
|
|
2014-01-14 00:13:05 +00:00
|
|
|
unsigned minimum_buffers;
|
|
|
|
|
2014-10-06 12:48:51 +00:00
|
|
|
struct rb_root buffer_tree;
|
2011-10-31 20:19:09 +00:00
|
|
|
wait_queue_head_t free_buffer_wait;
|
|
|
|
|
2017-01-04 19:23:52 +00:00
|
|
|
sector_t start;
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
int async_write_error;
|
|
|
|
|
|
|
|
struct list_head client_list;
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
struct shrinker shrinker;
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
struct work_struct shrink_work;
|
|
|
|
atomic_long_t need_shrink;
|
2011-10-31 20:19:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Buffer state bits.
|
|
|
|
*/
|
|
|
|
#define B_READING 0
|
|
|
|
#define B_WRITING 1
|
|
|
|
#define B_DIRTY 2
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Describes how the block was allocated:
|
|
|
|
* kmem_cache_alloc(), __get_free_pages() or vmalloc().
|
|
|
|
* See the comment at alloc_buffer_data.
|
|
|
|
*/
|
|
|
|
enum data_mode {
|
|
|
|
DATA_MODE_SLAB = 0,
|
|
|
|
DATA_MODE_GET_FREE_PAGES = 1,
|
|
|
|
DATA_MODE_VMALLOC = 2,
|
|
|
|
DATA_MODE_LIMIT = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dm_buffer {
|
2014-10-06 12:48:51 +00:00
|
|
|
struct rb_node node;
|
2011-10-31 20:19:09 +00:00
|
|
|
struct list_head lru_list;
|
2019-09-12 08:44:46 +00:00
|
|
|
struct list_head global_list;
|
2011-10-31 20:19:09 +00:00
|
|
|
sector_t block;
|
|
|
|
void *data;
|
2018-03-26 18:29:44 +00:00
|
|
|
unsigned char data_mode; /* DATA_MODE_* */
|
2011-10-31 20:19:09 +00:00
|
|
|
unsigned char list_mode; /* LIST_* */
|
2017-06-03 07:38:06 +00:00
|
|
|
blk_status_t read_error;
|
|
|
|
blk_status_t write_error;
|
2019-09-12 16:07:23 +00:00
|
|
|
unsigned accessed;
|
2018-03-26 18:29:44 +00:00
|
|
|
unsigned hold_count;
|
2011-10-31 20:19:09 +00:00
|
|
|
unsigned long state;
|
|
|
|
unsigned long last_accessed;
|
2017-04-30 21:31:22 +00:00
|
|
|
unsigned dirty_start;
|
|
|
|
unsigned dirty_end;
|
|
|
|
unsigned write_start;
|
|
|
|
unsigned write_end;
|
2011-10-31 20:19:09 +00:00
|
|
|
struct dm_bufio_client *c;
|
2013-07-10 22:41:18 +00:00
|
|
|
struct list_head write_list;
|
2018-03-26 18:29:47 +00:00
|
|
|
void (*end_io)(struct dm_buffer *, blk_status_t);
|
2015-11-24 00:20:06 +00:00
|
|
|
#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
|
|
|
|
#define MAX_STACK 10
|
2019-04-25 09:45:07 +00:00
|
|
|
unsigned int stack_len;
|
2015-11-24 00:20:06 +00:00
|
|
|
unsigned long stack_entries[MAX_STACK];
|
|
|
|
#endif
|
2011-10-31 20:19:09 +00:00
|
|
|
};
|
|
|
|
|
2022-07-25 22:26:48 +00:00
|
|
|
static DEFINE_STATIC_KEY_FALSE(no_sleep_enabled);
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#define dm_bufio_in_request() (!!current->bio_list)
|
|
|
|
|
|
|
|
static void dm_bufio_lock(struct dm_bufio_client *c)
|
|
|
|
{
|
2022-07-25 22:26:48 +00:00
|
|
|
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
|
2022-07-22 09:38:22 +00:00
|
|
|
spin_lock_irqsave_nested(&c->spinlock, c->spinlock_flags, dm_bufio_in_request());
|
|
|
|
else
|
|
|
|
mutex_lock_nested(&c->lock, dm_bufio_in_request());
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dm_bufio_trylock(struct dm_bufio_client *c)
|
|
|
|
{
|
2022-07-25 22:26:48 +00:00
|
|
|
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
|
2022-07-22 09:38:22 +00:00
|
|
|
return spin_trylock_irqsave(&c->spinlock, c->spinlock_flags);
|
|
|
|
else
|
|
|
|
return mutex_trylock(&c->lock);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dm_bufio_unlock(struct dm_bufio_client *c)
|
|
|
|
{
|
2022-07-25 22:26:48 +00:00
|
|
|
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
|
2022-07-22 09:38:22 +00:00
|
|
|
spin_unlock_irqrestore(&c->spinlock, c->spinlock_flags);
|
|
|
|
else
|
|
|
|
mutex_unlock(&c->lock);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default cache size: available memory divided by the ratio.
|
|
|
|
*/
|
|
|
|
static unsigned long dm_bufio_default_cache_size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Total cache size set by the user.
|
|
|
|
*/
|
|
|
|
static unsigned long dm_bufio_cache_size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A copy of dm_bufio_cache_size because dm_bufio_cache_size can change
|
|
|
|
* at any time. If it disagrees, the user has changed cache size.
|
|
|
|
*/
|
|
|
|
static unsigned long dm_bufio_cache_size_latch;
|
|
|
|
|
2019-09-12 08:44:46 +00:00
|
|
|
static DEFINE_SPINLOCK(global_spinlock);
|
|
|
|
|
|
|
|
static LIST_HEAD(global_queue);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2019-09-12 16:07:23 +00:00
|
|
|
static unsigned long global_num = 0;
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
/*
|
|
|
|
* Buffers are freed after this timeout
|
|
|
|
*/
|
|
|
|
static unsigned dm_bufio_max_age = DM_BUFIO_DEFAULT_AGE_SECS;
|
2017-04-30 21:32:28 +00:00
|
|
|
static unsigned long dm_bufio_retain_bytes = DM_BUFIO_DEFAULT_RETAIN_BYTES;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
static unsigned long dm_bufio_peak_allocated;
|
|
|
|
static unsigned long dm_bufio_allocated_kmem_cache;
|
|
|
|
static unsigned long dm_bufio_allocated_get_free_pages;
|
|
|
|
static unsigned long dm_bufio_allocated_vmalloc;
|
|
|
|
static unsigned long dm_bufio_current_allocated;
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The current number of clients.
|
|
|
|
*/
|
|
|
|
static int dm_bufio_client_count;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The list of all clients.
|
|
|
|
*/
|
|
|
|
static LIST_HEAD(dm_bufio_all_clients);
|
|
|
|
|
|
|
|
/*
|
2019-09-12 08:44:47 +00:00
|
|
|
* This mutex protects dm_bufio_cache_size_latch and dm_bufio_client_count
|
2011-10-31 20:19:09 +00:00
|
|
|
*/
|
|
|
|
static DEFINE_MUTEX(dm_bufio_clients_lock);
|
|
|
|
|
2019-09-12 16:07:23 +00:00
|
|
|
static struct workqueue_struct *dm_bufio_wq;
|
|
|
|
static struct delayed_work dm_bufio_cleanup_old_work;
|
|
|
|
static struct work_struct dm_bufio_replacement_work;
|
|
|
|
|
|
|
|
|
2015-11-24 00:20:06 +00:00
|
|
|
#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
|
|
|
|
static void buffer_record_stack(struct dm_buffer *b)
|
|
|
|
{
|
2019-04-25 09:45:07 +00:00
|
|
|
b->stack_len = stack_trace_save(b->stack_entries, MAX_STACK, 2);
|
2015-11-24 00:20:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-06 12:48:51 +00:00
|
|
|
/*----------------------------------------------------------------
|
|
|
|
* A red/black tree acts as an index for all the buffers.
|
|
|
|
*--------------------------------------------------------------*/
|
|
|
|
static struct dm_buffer *__find(struct dm_bufio_client *c, sector_t block)
|
|
|
|
{
|
|
|
|
struct rb_node *n = c->buffer_tree.rb_node;
|
|
|
|
struct dm_buffer *b;
|
|
|
|
|
|
|
|
while (n) {
|
|
|
|
b = container_of(n, struct dm_buffer, node);
|
|
|
|
|
|
|
|
if (b->block == block)
|
|
|
|
return b;
|
|
|
|
|
2020-06-02 13:34:39 +00:00
|
|
|
n = block < b->block ? n->rb_left : n->rb_right;
|
2014-10-06 12:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-06-02 13:34:40 +00:00
|
|
|
static struct dm_buffer *__find_next(struct dm_bufio_client *c, sector_t block)
|
|
|
|
{
|
|
|
|
struct rb_node *n = c->buffer_tree.rb_node;
|
|
|
|
struct dm_buffer *b;
|
|
|
|
struct dm_buffer *best = NULL;
|
|
|
|
|
|
|
|
while (n) {
|
|
|
|
b = container_of(n, struct dm_buffer, node);
|
|
|
|
|
|
|
|
if (b->block == block)
|
|
|
|
return b;
|
|
|
|
|
|
|
|
if (block <= b->block) {
|
|
|
|
n = n->rb_left;
|
|
|
|
best = b;
|
|
|
|
} else {
|
|
|
|
n = n->rb_right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
2014-10-06 12:48:51 +00:00
|
|
|
static void __insert(struct dm_bufio_client *c, struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
struct rb_node **new = &c->buffer_tree.rb_node, *parent = NULL;
|
|
|
|
struct dm_buffer *found;
|
|
|
|
|
|
|
|
while (*new) {
|
|
|
|
found = container_of(*new, struct dm_buffer, node);
|
|
|
|
|
|
|
|
if (found->block == b->block) {
|
|
|
|
BUG_ON(found != b);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = *new;
|
2020-06-02 13:34:39 +00:00
|
|
|
new = b->block < found->block ?
|
|
|
|
&found->node.rb_left : &found->node.rb_right;
|
2014-10-06 12:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rb_link_node(&b->node, parent, new);
|
|
|
|
rb_insert_color(&b->node, &c->buffer_tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __remove(struct dm_bufio_client *c, struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
rb_erase(&b->node, &c->buffer_tree);
|
|
|
|
}
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
|
2019-09-12 08:44:45 +00:00
|
|
|
static void adjust_total_allocated(struct dm_buffer *b, bool unlink)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
2019-09-12 08:44:45 +00:00
|
|
|
unsigned char data_mode;
|
|
|
|
long diff;
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
static unsigned long * const class_ptr[DATA_MODE_LIMIT] = {
|
|
|
|
&dm_bufio_allocated_kmem_cache,
|
|
|
|
&dm_bufio_allocated_get_free_pages,
|
|
|
|
&dm_bufio_allocated_vmalloc,
|
|
|
|
};
|
|
|
|
|
2019-09-12 08:44:45 +00:00
|
|
|
data_mode = b->data_mode;
|
|
|
|
diff = (long)b->c->block_size;
|
|
|
|
if (unlink)
|
|
|
|
diff = -diff;
|
|
|
|
|
2019-09-12 08:44:46 +00:00
|
|
|
spin_lock(&global_spinlock);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
*class_ptr[data_mode] += diff;
|
|
|
|
|
|
|
|
dm_bufio_current_allocated += diff;
|
|
|
|
|
|
|
|
if (dm_bufio_current_allocated > dm_bufio_peak_allocated)
|
|
|
|
dm_bufio_peak_allocated = dm_bufio_current_allocated;
|
|
|
|
|
2019-09-12 16:07:23 +00:00
|
|
|
b->accessed = 1;
|
|
|
|
|
2019-09-12 08:44:46 +00:00
|
|
|
if (!unlink) {
|
|
|
|
list_add(&b->global_list, &global_queue);
|
2019-09-12 16:07:23 +00:00
|
|
|
global_num++;
|
|
|
|
if (dm_bufio_current_allocated > dm_bufio_cache_size)
|
|
|
|
queue_work(dm_bufio_wq, &dm_bufio_replacement_work);
|
2019-09-12 08:44:46 +00:00
|
|
|
} else {
|
|
|
|
list_del(&b->global_list);
|
2019-09-12 16:07:23 +00:00
|
|
|
global_num--;
|
2019-09-12 08:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&global_spinlock);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change the number of clients and recalculate per-client limit.
|
|
|
|
*/
|
|
|
|
static void __cache_size_refresh(void)
|
|
|
|
{
|
|
|
|
BUG_ON(!mutex_is_locked(&dm_bufio_clients_lock));
|
|
|
|
BUG_ON(dm_bufio_client_count < 0);
|
|
|
|
|
locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()
Please do not apply this to mainline directly, instead please re-run the
coccinelle script shown below and apply its output.
For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
preference to ACCESS_ONCE(), and new code is expected to use one of the
former. So far, there's been no reason to change most existing uses of
ACCESS_ONCE(), as these aren't harmful, and changing them results in
churn.
However, for some features, the read/write distinction is critical to
correct operation. To distinguish these cases, separate read/write
accessors must be used. This patch migrates (most) remaining
ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following
coccinelle script:
----
// Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and
// WRITE_ONCE()
// $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch
virtual patch
@ depends on patch @
expression E1, E2;
@@
- ACCESS_ONCE(E1) = E2
+ WRITE_ONCE(E1, E2)
@ depends on patch @
expression E;
@@
- ACCESS_ONCE(E)
+ READ_ONCE(E)
----
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: davem@davemloft.net
Cc: linux-arch@vger.kernel.org
Cc: mpe@ellerman.id.au
Cc: shuah@kernel.org
Cc: snitzer@redhat.com
Cc: thor.thayer@linux.intel.com
Cc: tj@kernel.org
Cc: viro@zeniv.linux.org.uk
Cc: will.deacon@arm.com
Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-10-23 21:07:29 +00:00
|
|
|
dm_bufio_cache_size_latch = READ_ONCE(dm_bufio_cache_size);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use default if set to 0 and report the actual cache size used.
|
|
|
|
*/
|
|
|
|
if (!dm_bufio_cache_size_latch) {
|
|
|
|
(void)cmpxchg(&dm_bufio_cache_size, 0,
|
|
|
|
dm_bufio_default_cache_size);
|
|
|
|
dm_bufio_cache_size_latch = dm_bufio_default_cache_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocating buffer data.
|
|
|
|
*
|
|
|
|
* Small buffers are allocated with kmem_cache, to use space optimally.
|
|
|
|
*
|
|
|
|
* For large buffers, we choose between get_free_pages and vmalloc.
|
|
|
|
* Each has advantages and disadvantages.
|
|
|
|
*
|
|
|
|
* __get_free_pages can randomly fail if the memory is fragmented.
|
|
|
|
* __vmalloc won't randomly fail, but vmalloc space is limited (it may be
|
|
|
|
* as low as 128M) so using it for caching is not appropriate.
|
|
|
|
*
|
|
|
|
* If the allocation may fail we use __get_free_pages. Memory fragmentation
|
|
|
|
* won't have a fatal effect here, but it just causes flushes of some other
|
|
|
|
* buffers and more I/O will be performed. Don't use __get_free_pages if it
|
|
|
|
* always fails (i.e. order >= MAX_ORDER).
|
|
|
|
*
|
|
|
|
* If the allocation shouldn't fail we use __vmalloc. This is only for the
|
|
|
|
* initial reserve allocation, so there's no risk of wasting all vmalloc
|
|
|
|
* space.
|
|
|
|
*/
|
|
|
|
static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask,
|
2018-03-26 18:29:44 +00:00
|
|
|
unsigned char *data_mode)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
2018-03-26 18:29:42 +00:00
|
|
|
if (unlikely(c->slab_cache != NULL)) {
|
2011-10-31 20:19:09 +00:00
|
|
|
*data_mode = DATA_MODE_SLAB;
|
2018-03-26 18:29:42 +00:00
|
|
|
return kmem_cache_alloc(c->slab_cache, gfp_mask);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 18:29:46 +00:00
|
|
|
if (c->block_size <= KMALLOC_MAX_SIZE &&
|
2011-10-31 20:19:09 +00:00
|
|
|
gfp_mask & __GFP_NORETRY) {
|
|
|
|
*data_mode = DATA_MODE_GET_FREE_PAGES;
|
|
|
|
return (void *)__get_free_pages(gfp_mask,
|
2018-03-26 18:29:46 +00:00
|
|
|
c->sectors_per_block_bits - (PAGE_SHIFT - SECTOR_SHIFT));
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*data_mode = DATA_MODE_VMALLOC;
|
2013-05-10 13:37:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* __vmalloc allocates the data pages and auxiliary structures with
|
|
|
|
* gfp_flags that were specified, but pagetables are always allocated
|
|
|
|
* with GFP_KERNEL, no matter what was specified as gfp_mask.
|
|
|
|
*
|
|
|
|
* Consequently, we must set per-process flag PF_MEMALLOC_NOIO so that
|
|
|
|
* all allocations done by this process (including pagetables) are done
|
|
|
|
* as if GFP_NOIO was specified.
|
|
|
|
*/
|
2018-02-22 15:56:16 +00:00
|
|
|
if (gfp_mask & __GFP_NORETRY) {
|
|
|
|
unsigned noio_flag = memalloc_noio_save();
|
2020-06-02 04:51:40 +00:00
|
|
|
void *ptr = __vmalloc(c->block_size, gfp_mask);
|
2013-05-10 13:37:15 +00:00
|
|
|
|
|
|
|
memalloc_noio_restore(noio_flag);
|
2018-02-22 15:56:16 +00:00
|
|
|
return ptr;
|
|
|
|
}
|
2013-05-10 13:37:15 +00:00
|
|
|
|
2020-06-02 04:51:40 +00:00
|
|
|
return __vmalloc(c->block_size, gfp_mask);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free buffer's data.
|
|
|
|
*/
|
|
|
|
static void free_buffer_data(struct dm_bufio_client *c,
|
2018-03-26 18:29:44 +00:00
|
|
|
void *data, unsigned char data_mode)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
|
|
|
switch (data_mode) {
|
|
|
|
case DATA_MODE_SLAB:
|
2018-03-26 18:29:42 +00:00
|
|
|
kmem_cache_free(c->slab_cache, data);
|
2011-10-31 20:19:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_MODE_GET_FREE_PAGES:
|
2018-03-26 18:29:46 +00:00
|
|
|
free_pages((unsigned long)data,
|
|
|
|
c->sectors_per_block_bits - (PAGE_SHIFT - SECTOR_SHIFT));
|
2011-10-31 20:19:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_MODE_VMALLOC:
|
|
|
|
vfree(data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DMCRIT("dm_bufio_free_buffer_data: bad data mode: %d",
|
|
|
|
data_mode);
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate buffer and its data.
|
|
|
|
*/
|
|
|
|
static struct dm_buffer *alloc_buffer(struct dm_bufio_client *c, gfp_t gfp_mask)
|
|
|
|
{
|
2018-03-26 18:29:45 +00:00
|
|
|
struct dm_buffer *b = kmem_cache_alloc(c->slab_buffer, gfp_mask);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
if (!b)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
b->c = c;
|
|
|
|
|
|
|
|
b->data = alloc_buffer_data(c, gfp_mask, &b->data_mode);
|
|
|
|
if (!b->data) {
|
2018-03-26 18:29:45 +00:00
|
|
|
kmem_cache_free(c->slab_buffer, b);
|
2011-10-31 20:19:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-24 00:20:06 +00:00
|
|
|
#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
|
2019-04-25 09:45:07 +00:00
|
|
|
b->stack_len = 0;
|
2015-11-24 00:20:06 +00:00
|
|
|
#endif
|
2011-10-31 20:19:09 +00:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free buffer and its data.
|
|
|
|
*/
|
|
|
|
static void free_buffer(struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
struct dm_bufio_client *c = b->c;
|
|
|
|
|
|
|
|
free_buffer_data(c, b->data, b->data_mode);
|
2018-03-26 18:29:45 +00:00
|
|
|
kmem_cache_free(c->slab_buffer, b);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-10-30 07:35:54 +00:00
|
|
|
* Link buffer to the buffer tree and clean or dirty queue.
|
2011-10-31 20:19:09 +00:00
|
|
|
*/
|
|
|
|
static void __link_buffer(struct dm_buffer *b, sector_t block, int dirty)
|
|
|
|
{
|
|
|
|
struct dm_bufio_client *c = b->c;
|
|
|
|
|
|
|
|
c->n_buffers[dirty]++;
|
|
|
|
b->block = block;
|
|
|
|
b->list_mode = dirty;
|
|
|
|
list_add(&b->lru_list, &c->lru[dirty]);
|
2014-10-06 12:48:51 +00:00
|
|
|
__insert(b->c, b);
|
2011-10-31 20:19:09 +00:00
|
|
|
b->last_accessed = jiffies;
|
2019-09-12 08:44:44 +00:00
|
|
|
|
2019-09-12 08:44:45 +00:00
|
|
|
adjust_total_allocated(b, false);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-10-30 07:35:54 +00:00
|
|
|
* Unlink buffer from the buffer tree and dirty or clean queue.
|
2011-10-31 20:19:09 +00:00
|
|
|
*/
|
|
|
|
static void __unlink_buffer(struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
struct dm_bufio_client *c = b->c;
|
|
|
|
|
|
|
|
BUG_ON(!c->n_buffers[b->list_mode]);
|
|
|
|
|
|
|
|
c->n_buffers[b->list_mode]--;
|
2014-10-06 12:48:51 +00:00
|
|
|
__remove(b->c, b);
|
2011-10-31 20:19:09 +00:00
|
|
|
list_del(&b->lru_list);
|
2019-09-12 08:44:44 +00:00
|
|
|
|
2019-09-12 08:44:45 +00:00
|
|
|
adjust_total_allocated(b, true);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Place the buffer to the head of dirty or clean LRU queue.
|
|
|
|
*/
|
|
|
|
static void __relink_lru(struct dm_buffer *b, int dirty)
|
|
|
|
{
|
|
|
|
struct dm_bufio_client *c = b->c;
|
|
|
|
|
2019-09-12 16:07:23 +00:00
|
|
|
b->accessed = 1;
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
BUG_ON(!c->n_buffers[b->list_mode]);
|
|
|
|
|
|
|
|
c->n_buffers[b->list_mode]--;
|
|
|
|
c->n_buffers[dirty]++;
|
|
|
|
b->list_mode = dirty;
|
2012-10-12 15:59:44 +00:00
|
|
|
list_move(&b->lru_list, &c->lru[dirty]);
|
2014-09-30 08:32:46 +00:00
|
|
|
b->last_accessed = jiffies;
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------
|
|
|
|
* Submit I/O on the buffer.
|
|
|
|
*
|
|
|
|
* Bio interface is faster but it has some problems:
|
|
|
|
* the vector list is limited (increasing this limit increases
|
|
|
|
* memory-consumption per buffer, so it is not viable);
|
|
|
|
*
|
|
|
|
* the memory must be direct-mapped, not vmalloced;
|
|
|
|
*
|
|
|
|
* If the buffer is small enough (up to DM_BUFIO_INLINE_VECS pages) and
|
|
|
|
* it is not vmalloced, try using the bio interface.
|
|
|
|
*
|
|
|
|
* If the buffer is big, if it is vmalloced or if the underlying device
|
|
|
|
* rejects the bio because it is too large, use dm-io layer to do the I/O.
|
|
|
|
* The dm-io layer splits the I/O into multiple requests, avoiding the above
|
|
|
|
* shortcomings.
|
|
|
|
*--------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dm-io completion routine. It just calls b->bio.bi_end_io, pretending
|
|
|
|
* that the request was handled directly with bio interface.
|
|
|
|
*/
|
|
|
|
static void dmio_complete(unsigned long error, void *context)
|
|
|
|
{
|
|
|
|
struct dm_buffer *b = context;
|
|
|
|
|
2018-03-26 18:29:47 +00:00
|
|
|
b->end_io(b, unlikely(error != 0) ? BLK_STS_IOERR : 0);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
2017-01-04 19:23:52 +00:00
|
|
|
static void use_dmio(struct dm_buffer *b, int rw, sector_t sector,
|
2018-03-26 18:29:47 +00:00
|
|
|
unsigned n_sectors, unsigned offset)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct dm_io_request io_req = {
|
2016-06-05 19:32:04 +00:00
|
|
|
.bi_op = rw,
|
|
|
|
.bi_op_flags = 0,
|
2011-10-31 20:19:09 +00:00
|
|
|
.notify.fn = dmio_complete,
|
|
|
|
.notify.context = b,
|
|
|
|
.client = b->c->dm_io,
|
|
|
|
};
|
|
|
|
struct dm_io_region region = {
|
|
|
|
.bdev = b->c->bdev,
|
2017-01-04 19:23:52 +00:00
|
|
|
.sector = sector,
|
|
|
|
.count = n_sectors,
|
2011-10-31 20:19:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (b->data_mode != DATA_MODE_VMALLOC) {
|
|
|
|
io_req.mem.type = DM_IO_KMEM;
|
2017-04-30 21:31:22 +00:00
|
|
|
io_req.mem.ptr.addr = (char *)b->data + offset;
|
2011-10-31 20:19:09 +00:00
|
|
|
} else {
|
|
|
|
io_req.mem.type = DM_IO_VMA;
|
2017-04-30 21:31:22 +00:00
|
|
|
io_req.mem.ptr.vma = (char *)b->data + offset;
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r = dm_io(&io_req, 1, ®ion, NULL);
|
2018-03-26 18:29:47 +00:00
|
|
|
if (unlikely(r))
|
|
|
|
b->end_io(b, errno_to_blk_status(r));
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 18:29:47 +00:00
|
|
|
static void bio_complete(struct bio *bio)
|
2014-11-26 01:45:15 +00:00
|
|
|
{
|
2018-03-26 18:29:47 +00:00
|
|
|
struct dm_buffer *b = bio->bi_private;
|
2017-06-03 07:38:06 +00:00
|
|
|
blk_status_t status = bio->bi_status;
|
2022-04-06 06:12:27 +00:00
|
|
|
bio_uninit(bio);
|
|
|
|
kfree(bio);
|
2018-03-26 18:29:47 +00:00
|
|
|
b->end_io(b, status);
|
2014-11-26 01:45:15 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 18:29:47 +00:00
|
|
|
static void use_bio(struct dm_buffer *b, int rw, sector_t sector,
|
|
|
|
unsigned n_sectors, unsigned offset)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
2018-03-26 18:29:47 +00:00
|
|
|
struct bio *bio;
|
2011-10-31 20:19:09 +00:00
|
|
|
char *ptr;
|
2018-03-26 18:29:47 +00:00
|
|
|
unsigned vec_size, len;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2018-03-26 18:29:47 +00:00
|
|
|
vec_size = b->c->block_size >> PAGE_SHIFT;
|
|
|
|
if (unlikely(b->c->sectors_per_block_bits < PAGE_SHIFT - SECTOR_SHIFT))
|
|
|
|
vec_size += 2;
|
|
|
|
|
2022-04-06 06:12:27 +00:00
|
|
|
bio = bio_kmalloc(vec_size, GFP_NOWAIT | __GFP_NORETRY | __GFP_NOWARN);
|
2018-03-26 18:29:47 +00:00
|
|
|
if (!bio) {
|
|
|
|
dmio:
|
|
|
|
use_dmio(b, rw, sector, n_sectors, offset);
|
|
|
|
return;
|
|
|
|
}
|
2022-04-06 06:12:27 +00:00
|
|
|
bio_init(bio, b->c->bdev, bio->bi_inline_vecs, vec_size, rw);
|
2018-03-26 18:29:47 +00:00
|
|
|
bio->bi_iter.bi_sector = sector;
|
|
|
|
bio->bi_end_io = bio_complete;
|
|
|
|
bio->bi_private = b;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2017-04-30 21:31:22 +00:00
|
|
|
ptr = (char *)b->data + offset;
|
2017-01-04 19:23:52 +00:00
|
|
|
len = n_sectors << SECTOR_SHIFT;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
do {
|
2017-04-30 21:31:22 +00:00
|
|
|
unsigned this_step = min((unsigned)(PAGE_SIZE - offset_in_page(ptr)), len);
|
2018-03-26 18:29:47 +00:00
|
|
|
if (!bio_add_page(bio, virt_to_page(ptr), this_step,
|
2016-01-02 17:45:27 +00:00
|
|
|
offset_in_page(ptr))) {
|
2018-03-26 18:29:47 +00:00
|
|
|
bio_put(bio);
|
|
|
|
goto dmio;
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 21:31:22 +00:00
|
|
|
len -= this_step;
|
|
|
|
ptr += this_step;
|
2011-10-31 20:19:09 +00:00
|
|
|
} while (len > 0);
|
|
|
|
|
2018-03-26 18:29:47 +00:00
|
|
|
submit_bio(bio);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 20:59:25 +00:00
|
|
|
static inline sector_t block_to_sector(struct dm_bufio_client *c, sector_t block)
|
|
|
|
{
|
|
|
|
sector_t sector;
|
|
|
|
|
|
|
|
if (likely(c->sectors_per_block_bits >= 0))
|
|
|
|
sector = block << c->sectors_per_block_bits;
|
|
|
|
else
|
|
|
|
sector = block * (c->block_size >> SECTOR_SHIFT);
|
|
|
|
sector += c->start;
|
|
|
|
|
|
|
|
return sector;
|
|
|
|
}
|
|
|
|
|
2018-03-26 18:29:47 +00:00
|
|
|
static void submit_io(struct dm_buffer *b, int rw, void (*end_io)(struct dm_buffer *, blk_status_t))
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
2017-01-04 19:23:52 +00:00
|
|
|
unsigned n_sectors;
|
|
|
|
sector_t sector;
|
2017-04-30 21:31:22 +00:00
|
|
|
unsigned offset, end;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2018-03-26 18:29:47 +00:00
|
|
|
b->end_io = end_io;
|
|
|
|
|
2020-02-07 20:59:25 +00:00
|
|
|
sector = block_to_sector(b->c, b->block);
|
2017-04-30 21:31:22 +00:00
|
|
|
|
2017-12-02 05:33:39 +00:00
|
|
|
if (rw != REQ_OP_WRITE) {
|
2018-03-26 18:29:46 +00:00
|
|
|
n_sectors = b->c->block_size >> SECTOR_SHIFT;
|
2017-04-30 21:31:22 +00:00
|
|
|
offset = 0;
|
|
|
|
} else {
|
|
|
|
if (b->c->write_callback)
|
|
|
|
b->c->write_callback(b);
|
|
|
|
offset = b->write_start;
|
|
|
|
end = b->write_end;
|
|
|
|
offset &= -DM_BUFIO_WRITE_ALIGN;
|
|
|
|
end += DM_BUFIO_WRITE_ALIGN - 1;
|
|
|
|
end &= -DM_BUFIO_WRITE_ALIGN;
|
|
|
|
if (unlikely(end > b->c->block_size))
|
|
|
|
end = b->c->block_size;
|
|
|
|
|
|
|
|
sector += offset >> SECTOR_SHIFT;
|
|
|
|
n_sectors = (end - offset) >> SECTOR_SHIFT;
|
|
|
|
}
|
2017-01-04 19:23:52 +00:00
|
|
|
|
2018-03-26 18:29:47 +00:00
|
|
|
if (b->data_mode != DATA_MODE_VMALLOC)
|
|
|
|
use_bio(b, rw, sector, n_sectors, offset);
|
2011-10-31 20:19:09 +00:00
|
|
|
else
|
2018-03-26 18:29:47 +00:00
|
|
|
use_dmio(b, rw, sector, n_sectors, offset);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------
|
|
|
|
* Writing dirty buffers
|
|
|
|
*--------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The endio routine for write.
|
|
|
|
*
|
|
|
|
* Set the error, clear B_WRITING bit and wake anyone who was waiting on
|
|
|
|
* it.
|
|
|
|
*/
|
2018-03-26 18:29:47 +00:00
|
|
|
static void write_endio(struct dm_buffer *b, blk_status_t status)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
2018-03-26 18:29:47 +00:00
|
|
|
b->write_error = status;
|
|
|
|
if (unlikely(status)) {
|
2011-10-31 20:19:09 +00:00
|
|
|
struct dm_bufio_client *c = b->c;
|
2017-06-03 07:38:06 +00:00
|
|
|
|
|
|
|
(void)cmpxchg(&c->async_write_error, 0,
|
2018-03-26 18:29:47 +00:00
|
|
|
blk_status_to_errno(status));
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BUG_ON(!test_bit(B_WRITING, &b->state));
|
|
|
|
|
2014-03-17 17:06:10 +00:00
|
|
|
smp_mb__before_atomic();
|
2011-10-31 20:19:09 +00:00
|
|
|
clear_bit(B_WRITING, &b->state);
|
2014-03-17 17:06:10 +00:00
|
|
|
smp_mb__after_atomic();
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
wake_up_bit(&b->state, B_WRITING);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initiate a write on a dirty buffer, but don't wait for it.
|
|
|
|
*
|
|
|
|
* - If the buffer is not dirty, exit.
|
|
|
|
* - If there some previous write going on, wait for it to finish (we can't
|
|
|
|
* have two writes on the same buffer simultaneously).
|
|
|
|
* - Submit our write and don't wait on it. We set B_WRITING indicating
|
|
|
|
* that there is a write in progress.
|
|
|
|
*/
|
2013-07-10 22:41:18 +00:00
|
|
|
static void __write_dirty_buffer(struct dm_buffer *b,
|
|
|
|
struct list_head *write_list)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
|
|
|
if (!test_bit(B_DIRTY, &b->state))
|
|
|
|
return;
|
|
|
|
|
|
|
|
clear_bit(B_DIRTY, &b->state);
|
sched: Remove proliferation of wait_on_bit() action functions
The current "wait_on_bit" interface requires an 'action'
function to be provided which does the actual waiting.
There are over 20 such functions, many of them identical.
Most cases can be satisfied by one of just two functions, one
which uses io_schedule() and one which just uses schedule().
So:
Rename wait_on_bit and wait_on_bit_lock to
wait_on_bit_action and wait_on_bit_lock_action
to make it explicit that they need an action function.
Introduce new wait_on_bit{,_lock} and wait_on_bit{,_lock}_io
which are *not* given an action function but implicitly use
a standard one.
The decision to error-out if a signal is pending is now made
based on the 'mode' argument rather than being encoded in the action
function.
All instances of the old wait_on_bit and wait_on_bit_lock which
can use the new version have been changed accordingly and their
action functions have been discarded.
wait_on_bit{_lock} does not return any specific error code in the
event of a signal so the caller must check for non-zero and
interpolate their own error code as appropriate.
The wait_on_bit() call in __fscache_wait_on_invalidate() was
ambiguous as it specified TASK_UNINTERRUPTIBLE but used
fscache_wait_bit_interruptible as an action function.
David Howells confirms this should be uniformly
"uninterruptible"
The main remaining user of wait_on_bit{,_lock}_action is NFS
which needs to use a freezer-aware schedule() call.
A comment in fs/gfs2/glock.c notes that having multiple 'action'
functions is useful as they display differently in the 'wchan'
field of 'ps'. (and /proc/$PID/wchan).
As the new bit_wait{,_io} functions are tagged "__sched", they
will not show up at all, but something higher in the stack. So
the distinction will still be visible, only with different
function names (gds2_glock_wait versus gfs2_glock_dq_wait in the
gfs2/glock.c case).
Since first version of this patch (against 3.15) two new action
functions appeared, on in NFS and one in CIFS. CIFS also now
uses an action function that makes the same freezer aware
schedule call as NFS.
Signed-off-by: NeilBrown <neilb@suse.de>
Acked-by: David Howells <dhowells@redhat.com> (fscache, keys)
Acked-by: Steven Whitehouse <swhiteho@redhat.com> (gfs2)
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Steve French <sfrench@samba.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20140707051603.28027.72349.stgit@notabene.brown
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2014-07-07 05:16:04 +00:00
|
|
|
wait_on_bit_lock_io(&b->state, B_WRITING, TASK_UNINTERRUPTIBLE);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2017-04-30 21:31:22 +00:00
|
|
|
b->write_start = b->dirty_start;
|
|
|
|
b->write_end = b->dirty_end;
|
|
|
|
|
2013-07-10 22:41:18 +00:00
|
|
|
if (!write_list)
|
2017-12-02 05:33:39 +00:00
|
|
|
submit_io(b, REQ_OP_WRITE, write_endio);
|
2013-07-10 22:41:18 +00:00
|
|
|
else
|
|
|
|
list_add_tail(&b->write_list, write_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __flush_write_list(struct list_head *write_list)
|
|
|
|
{
|
|
|
|
struct blk_plug plug;
|
|
|
|
blk_start_plug(&plug);
|
|
|
|
while (!list_empty(write_list)) {
|
|
|
|
struct dm_buffer *b =
|
|
|
|
list_entry(write_list->next, struct dm_buffer, write_list);
|
|
|
|
list_del(&b->write_list);
|
2017-12-02 05:33:39 +00:00
|
|
|
submit_io(b, REQ_OP_WRITE, write_endio);
|
2016-09-13 08:45:20 +00:00
|
|
|
cond_resched();
|
2013-07-10 22:41:18 +00:00
|
|
|
}
|
|
|
|
blk_finish_plug(&plug);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait until any activity on the buffer finishes. Possibly write the
|
|
|
|
* buffer if it is dirty. When this function finishes, there is no I/O
|
|
|
|
* running on the buffer and the buffer is not dirty.
|
|
|
|
*/
|
|
|
|
static void __make_buffer_clean(struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
BUG_ON(b->hold_count);
|
|
|
|
|
|
|
|
if (!b->state) /* fast case */
|
|
|
|
return;
|
|
|
|
|
sched: Remove proliferation of wait_on_bit() action functions
The current "wait_on_bit" interface requires an 'action'
function to be provided which does the actual waiting.
There are over 20 such functions, many of them identical.
Most cases can be satisfied by one of just two functions, one
which uses io_schedule() and one which just uses schedule().
So:
Rename wait_on_bit and wait_on_bit_lock to
wait_on_bit_action and wait_on_bit_lock_action
to make it explicit that they need an action function.
Introduce new wait_on_bit{,_lock} and wait_on_bit{,_lock}_io
which are *not* given an action function but implicitly use
a standard one.
The decision to error-out if a signal is pending is now made
based on the 'mode' argument rather than being encoded in the action
function.
All instances of the old wait_on_bit and wait_on_bit_lock which
can use the new version have been changed accordingly and their
action functions have been discarded.
wait_on_bit{_lock} does not return any specific error code in the
event of a signal so the caller must check for non-zero and
interpolate their own error code as appropriate.
The wait_on_bit() call in __fscache_wait_on_invalidate() was
ambiguous as it specified TASK_UNINTERRUPTIBLE but used
fscache_wait_bit_interruptible as an action function.
David Howells confirms this should be uniformly
"uninterruptible"
The main remaining user of wait_on_bit{,_lock}_action is NFS
which needs to use a freezer-aware schedule() call.
A comment in fs/gfs2/glock.c notes that having multiple 'action'
functions is useful as they display differently in the 'wchan'
field of 'ps'. (and /proc/$PID/wchan).
As the new bit_wait{,_io} functions are tagged "__sched", they
will not show up at all, but something higher in the stack. So
the distinction will still be visible, only with different
function names (gds2_glock_wait versus gfs2_glock_dq_wait in the
gfs2/glock.c case).
Since first version of this patch (against 3.15) two new action
functions appeared, on in NFS and one in CIFS. CIFS also now
uses an action function that makes the same freezer aware
schedule call as NFS.
Signed-off-by: NeilBrown <neilb@suse.de>
Acked-by: David Howells <dhowells@redhat.com> (fscache, keys)
Acked-by: Steven Whitehouse <swhiteho@redhat.com> (gfs2)
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Steve French <sfrench@samba.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20140707051603.28027.72349.stgit@notabene.brown
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2014-07-07 05:16:04 +00:00
|
|
|
wait_on_bit_io(&b->state, B_READING, TASK_UNINTERRUPTIBLE);
|
2013-07-10 22:41:18 +00:00
|
|
|
__write_dirty_buffer(b, NULL);
|
sched: Remove proliferation of wait_on_bit() action functions
The current "wait_on_bit" interface requires an 'action'
function to be provided which does the actual waiting.
There are over 20 such functions, many of them identical.
Most cases can be satisfied by one of just two functions, one
which uses io_schedule() and one which just uses schedule().
So:
Rename wait_on_bit and wait_on_bit_lock to
wait_on_bit_action and wait_on_bit_lock_action
to make it explicit that they need an action function.
Introduce new wait_on_bit{,_lock} and wait_on_bit{,_lock}_io
which are *not* given an action function but implicitly use
a standard one.
The decision to error-out if a signal is pending is now made
based on the 'mode' argument rather than being encoded in the action
function.
All instances of the old wait_on_bit and wait_on_bit_lock which
can use the new version have been changed accordingly and their
action functions have been discarded.
wait_on_bit{_lock} does not return any specific error code in the
event of a signal so the caller must check for non-zero and
interpolate their own error code as appropriate.
The wait_on_bit() call in __fscache_wait_on_invalidate() was
ambiguous as it specified TASK_UNINTERRUPTIBLE but used
fscache_wait_bit_interruptible as an action function.
David Howells confirms this should be uniformly
"uninterruptible"
The main remaining user of wait_on_bit{,_lock}_action is NFS
which needs to use a freezer-aware schedule() call.
A comment in fs/gfs2/glock.c notes that having multiple 'action'
functions is useful as they display differently in the 'wchan'
field of 'ps'. (and /proc/$PID/wchan).
As the new bit_wait{,_io} functions are tagged "__sched", they
will not show up at all, but something higher in the stack. So
the distinction will still be visible, only with different
function names (gds2_glock_wait versus gfs2_glock_dq_wait in the
gfs2/glock.c case).
Since first version of this patch (against 3.15) two new action
functions appeared, on in NFS and one in CIFS. CIFS also now
uses an action function that makes the same freezer aware
schedule call as NFS.
Signed-off-by: NeilBrown <neilb@suse.de>
Acked-by: David Howells <dhowells@redhat.com> (fscache, keys)
Acked-by: Steven Whitehouse <swhiteho@redhat.com> (gfs2)
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Steve French <sfrench@samba.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20140707051603.28027.72349.stgit@notabene.brown
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2014-07-07 05:16:04 +00:00
|
|
|
wait_on_bit_io(&b->state, B_WRITING, TASK_UNINTERRUPTIBLE);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find some buffer that is not held by anybody, clean it, unlink it and
|
|
|
|
* return it.
|
|
|
|
*/
|
|
|
|
static struct dm_buffer *__get_unclaimed_buffer(struct dm_bufio_client *c)
|
|
|
|
{
|
|
|
|
struct dm_buffer *b;
|
|
|
|
|
|
|
|
list_for_each_entry_reverse(b, &c->lru[LIST_CLEAN], lru_list) {
|
|
|
|
BUG_ON(test_bit(B_WRITING, &b->state));
|
|
|
|
BUG_ON(test_bit(B_DIRTY, &b->state));
|
|
|
|
|
|
|
|
if (!b->hold_count) {
|
|
|
|
__make_buffer_clean(b);
|
|
|
|
__unlink_buffer(b);
|
|
|
|
return b;
|
|
|
|
}
|
2016-09-13 08:45:20 +00:00
|
|
|
cond_resched();
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry_reverse(b, &c->lru[LIST_DIRTY], lru_list) {
|
|
|
|
BUG_ON(test_bit(B_READING, &b->state));
|
|
|
|
|
|
|
|
if (!b->hold_count) {
|
|
|
|
__make_buffer_clean(b);
|
|
|
|
__unlink_buffer(b);
|
|
|
|
return b;
|
|
|
|
}
|
2016-09-13 08:45:20 +00:00
|
|
|
cond_resched();
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait until some other threads free some buffer or release hold count on
|
|
|
|
* some buffer.
|
|
|
|
*
|
|
|
|
* This function is entered with c->lock held, drops it and regains it
|
|
|
|
* before exiting.
|
|
|
|
*/
|
|
|
|
static void __wait_for_free_buffer(struct dm_bufio_client *c)
|
|
|
|
{
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
|
|
|
add_wait_queue(&c->free_buffer_wait, &wait);
|
sched/core: Remove set_task_state()
This is a nasty interface and setting the state of a foreign task must
not be done. As of the following commit:
be628be0956 ("bcache: Make gc wakeup sane, remove set_task_state()")
... everyone in the kernel calls set_task_state() with current, allowing
the helper to be removed.
However, as the comment indicates, it is still around for those archs
where computing current is more expensive than using a pointer, at least
in theory. An important arch that is affected is arm64, however this has
been addressed now [1] and performance is up to par making no difference
with either calls.
Of all the callers, if any, it's the locking bits that would care most
about this -- ie: we end up passing a tsk pointer to a lot of the lock
slowpath, and setting ->state on that. The following numbers are based
on two tests: a custom ad-hoc microbenchmark that just measures
latencies (for ~65 million calls) between get_task_state() vs
get_current_state().
Secondly for a higher overview, an unlink microbenchmark was used,
which pounds on a single file with open, close,unlink combos with
increasing thread counts (up to 4x ncpus). While the workload is quite
unrealistic, it does contend a lot on the inode mutex or now rwsem.
[1] https://lkml.kernel.org/r/1483468021-8237-1-git-send-email-mark.rutland@arm.com
== 1. x86-64 ==
Avg runtime set_task_state(): 601 msecs
Avg runtime set_current_state(): 552 msecs
vanilla dirty
Hmean unlink1-processes-2 36089.26 ( 0.00%) 38977.33 ( 8.00%)
Hmean unlink1-processes-5 28555.01 ( 0.00%) 29832.55 ( 4.28%)
Hmean unlink1-processes-8 37323.75 ( 0.00%) 44974.57 ( 20.50%)
Hmean unlink1-processes-12 43571.88 ( 0.00%) 44283.01 ( 1.63%)
Hmean unlink1-processes-21 34431.52 ( 0.00%) 38284.45 ( 11.19%)
Hmean unlink1-processes-30 34813.26 ( 0.00%) 37975.17 ( 9.08%)
Hmean unlink1-processes-48 37048.90 ( 0.00%) 39862.78 ( 7.59%)
Hmean unlink1-processes-79 35630.01 ( 0.00%) 36855.30 ( 3.44%)
Hmean unlink1-processes-110 36115.85 ( 0.00%) 39843.91 ( 10.32%)
Hmean unlink1-processes-141 32546.96 ( 0.00%) 35418.52 ( 8.82%)
Hmean unlink1-processes-172 34674.79 ( 0.00%) 36899.21 ( 6.42%)
Hmean unlink1-processes-203 37303.11 ( 0.00%) 36393.04 ( -2.44%)
Hmean unlink1-processes-224 35712.13 ( 0.00%) 36685.96 ( 2.73%)
== 2. ppc64le ==
Avg runtime set_task_state(): 938 msecs
Avg runtime set_current_state: 940 msecs
vanilla dirty
Hmean unlink1-processes-2 19269.19 ( 0.00%) 30704.50 ( 59.35%)
Hmean unlink1-processes-5 20106.15 ( 0.00%) 21804.15 ( 8.45%)
Hmean unlink1-processes-8 17496.97 ( 0.00%) 17243.28 ( -1.45%)
Hmean unlink1-processes-12 14224.15 ( 0.00%) 17240.21 ( 21.20%)
Hmean unlink1-processes-21 14155.66 ( 0.00%) 15681.23 ( 10.78%)
Hmean unlink1-processes-30 14450.70 ( 0.00%) 15995.83 ( 10.69%)
Hmean unlink1-processes-48 16945.57 ( 0.00%) 16370.42 ( -3.39%)
Hmean unlink1-processes-79 15788.39 ( 0.00%) 14639.27 ( -7.28%)
Hmean unlink1-processes-110 14268.48 ( 0.00%) 14377.40 ( 0.76%)
Hmean unlink1-processes-141 14023.65 ( 0.00%) 16271.69 ( 16.03%)
Hmean unlink1-processes-172 13417.62 ( 0.00%) 16067.55 ( 19.75%)
Hmean unlink1-processes-203 15293.08 ( 0.00%) 15440.40 ( 0.96%)
Hmean unlink1-processes-234 13719.32 ( 0.00%) 16190.74 ( 18.01%)
Hmean unlink1-processes-265 16400.97 ( 0.00%) 16115.22 ( -1.74%)
Hmean unlink1-processes-296 14388.60 ( 0.00%) 16216.13 ( 12.70%)
Hmean unlink1-processes-320 15771.85 ( 0.00%) 15905.96 ( 0.85%)
x86-64 (known to be fast for get_current()/this_cpu_read_stable() caching)
and ppc64 (with paca) show similar improvements in the unlink microbenches.
The small delta for ppc64 (2ms), does not represent the gains on the unlink
runs. In the case of x86, there was a decent amount of variation in the
latency runs, but always within a 20 to 50ms increase), ppc was more constant.
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: dave@stgolabs.net
Cc: mark.rutland@arm.com
Link: http://lkml.kernel.org/r/1483479794-14013-5-git-send-email-dave@stgolabs.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-01-03 21:43:14 +00:00
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
2011-10-31 20:19:09 +00:00
|
|
|
dm_bufio_unlock(c);
|
|
|
|
|
|
|
|
io_schedule();
|
|
|
|
|
|
|
|
remove_wait_queue(&c->free_buffer_wait, &wait);
|
|
|
|
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
}
|
|
|
|
|
2012-03-28 17:41:29 +00:00
|
|
|
enum new_flag {
|
|
|
|
NF_FRESH = 0,
|
|
|
|
NF_READ = 1,
|
|
|
|
NF_GET = 2,
|
|
|
|
NF_PREFETCH = 3
|
|
|
|
};
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
/*
|
|
|
|
* Allocate a new buffer. If the allocation is not possible, wait until
|
|
|
|
* some other thread frees a buffer.
|
|
|
|
*
|
|
|
|
* May drop the lock and regain it.
|
|
|
|
*/
|
2012-03-28 17:41:29 +00:00
|
|
|
static struct dm_buffer *__alloc_buffer_wait_no_callback(struct dm_bufio_client *c, enum new_flag nf)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
|
|
|
struct dm_buffer *b;
|
2016-11-23 22:04:00 +00:00
|
|
|
bool tried_noio_alloc = false;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* dm-bufio is resistant to allocation failures (it just keeps
|
|
|
|
* one buffer reserved in cases all the allocations fail).
|
|
|
|
* So set flags to not try too hard:
|
2016-11-17 19:24:20 +00:00
|
|
|
* GFP_NOWAIT: don't wait; if we need to sleep we'll release our
|
|
|
|
* mutex and wait ourselves.
|
2011-10-31 20:19:09 +00:00
|
|
|
* __GFP_NORETRY: don't retry and rather return failure
|
|
|
|
* __GFP_NOMEMALLOC: don't use emergency reserves
|
|
|
|
* __GFP_NOWARN: don't print a warning in case of failure
|
|
|
|
*
|
|
|
|
* For debugging, if we set the cache size to 1, no new buffers will
|
|
|
|
* be allocated.
|
|
|
|
*/
|
|
|
|
while (1) {
|
|
|
|
if (dm_bufio_cache_size_latch != 1) {
|
2016-11-17 19:24:20 +00:00
|
|
|
b = alloc_buffer(c, GFP_NOWAIT | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN);
|
2011-10-31 20:19:09 +00:00
|
|
|
if (b)
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2012-03-28 17:41:29 +00:00
|
|
|
if (nf == NF_PREFETCH)
|
|
|
|
return NULL;
|
|
|
|
|
2016-11-23 22:04:00 +00:00
|
|
|
if (dm_bufio_cache_size_latch != 1 && !tried_noio_alloc) {
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
b = alloc_buffer(c, GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN);
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
if (b)
|
|
|
|
return b;
|
|
|
|
tried_noio_alloc = true;
|
|
|
|
}
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
if (!list_empty(&c->reserved_buffers)) {
|
|
|
|
b = list_entry(c->reserved_buffers.next,
|
|
|
|
struct dm_buffer, lru_list);
|
|
|
|
list_del(&b->lru_list);
|
|
|
|
c->need_reserved_buffers++;
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
b = __get_unclaimed_buffer(c);
|
|
|
|
if (b)
|
|
|
|
return b;
|
|
|
|
|
|
|
|
__wait_for_free_buffer(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-28 17:41:29 +00:00
|
|
|
static struct dm_buffer *__alloc_buffer_wait(struct dm_bufio_client *c, enum new_flag nf)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
2012-03-28 17:41:29 +00:00
|
|
|
struct dm_buffer *b = __alloc_buffer_wait_no_callback(c, nf);
|
|
|
|
|
|
|
|
if (!b)
|
|
|
|
return NULL;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
if (c->alloc_callback)
|
|
|
|
c->alloc_callback(b);
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free a buffer and wake other threads waiting for free buffers.
|
|
|
|
*/
|
|
|
|
static void __free_buffer_wake(struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
struct dm_bufio_client *c = b->c;
|
|
|
|
|
|
|
|
if (!c->need_reserved_buffers)
|
|
|
|
free_buffer(b);
|
|
|
|
else {
|
|
|
|
list_add(&b->lru_list, &c->reserved_buffers);
|
|
|
|
c->need_reserved_buffers--;
|
|
|
|
}
|
|
|
|
|
|
|
|
wake_up(&c->free_buffer_wait);
|
|
|
|
}
|
|
|
|
|
2013-07-10 22:41:18 +00:00
|
|
|
static void __write_dirty_buffers_async(struct dm_bufio_client *c, int no_wait,
|
|
|
|
struct list_head *write_list)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
|
|
|
struct dm_buffer *b, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe_reverse(b, tmp, &c->lru[LIST_DIRTY], lru_list) {
|
|
|
|
BUG_ON(test_bit(B_READING, &b->state));
|
|
|
|
|
|
|
|
if (!test_bit(B_DIRTY, &b->state) &&
|
|
|
|
!test_bit(B_WRITING, &b->state)) {
|
|
|
|
__relink_lru(b, LIST_CLEAN);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (no_wait && test_bit(B_WRITING, &b->state))
|
|
|
|
return;
|
|
|
|
|
2013-07-10 22:41:18 +00:00
|
|
|
__write_dirty_buffer(b, write_list);
|
2016-09-13 08:45:20 +00:00
|
|
|
cond_resched();
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if we're over watermark.
|
|
|
|
* If we are over threshold_buffers, start freeing buffers.
|
|
|
|
* If we're over "limit_buffers", block until we get under the limit.
|
|
|
|
*/
|
2013-07-10 22:41:18 +00:00
|
|
|
static void __check_watermark(struct dm_bufio_client *c,
|
|
|
|
struct list_head *write_list)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
2019-09-12 08:44:47 +00:00
|
|
|
if (c->n_buffers[LIST_DIRTY] > c->n_buffers[LIST_CLEAN] * DM_BUFIO_WRITEBACK_RATIO)
|
2013-07-10 22:41:18 +00:00
|
|
|
__write_dirty_buffers_async(c, 1, write_list);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------
|
|
|
|
* Getting a buffer
|
|
|
|
*--------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static struct dm_buffer *__bufio_new(struct dm_bufio_client *c, sector_t block,
|
2013-07-10 22:41:18 +00:00
|
|
|
enum new_flag nf, int *need_submit,
|
|
|
|
struct list_head *write_list)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
|
|
|
struct dm_buffer *b, *new_b = NULL;
|
|
|
|
|
|
|
|
*need_submit = 0;
|
|
|
|
|
|
|
|
b = __find(c, block);
|
2012-03-28 17:41:29 +00:00
|
|
|
if (b)
|
|
|
|
goto found_buffer;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
if (nf == NF_GET)
|
|
|
|
return NULL;
|
|
|
|
|
2012-03-28 17:41:29 +00:00
|
|
|
new_b = __alloc_buffer_wait(c, nf);
|
|
|
|
if (!new_b)
|
|
|
|
return NULL;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We've had a period where the mutex was unlocked, so need to
|
2018-10-30 07:35:54 +00:00
|
|
|
* recheck the buffer tree.
|
2011-10-31 20:19:09 +00:00
|
|
|
*/
|
|
|
|
b = __find(c, block);
|
|
|
|
if (b) {
|
|
|
|
__free_buffer_wake(new_b);
|
2012-03-28 17:41:29 +00:00
|
|
|
goto found_buffer;
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 22:41:18 +00:00
|
|
|
__check_watermark(c, write_list);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
b = new_b;
|
|
|
|
b->hold_count = 1;
|
|
|
|
b->read_error = 0;
|
|
|
|
b->write_error = 0;
|
|
|
|
__link_buffer(b, block, LIST_CLEAN);
|
|
|
|
|
|
|
|
if (nf == NF_FRESH) {
|
|
|
|
b->state = 0;
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
b->state = 1 << B_READING;
|
|
|
|
*need_submit = 1;
|
|
|
|
|
|
|
|
return b;
|
2012-03-28 17:41:29 +00:00
|
|
|
|
|
|
|
found_buffer:
|
|
|
|
if (nf == NF_PREFETCH)
|
|
|
|
return NULL;
|
|
|
|
/*
|
|
|
|
* Note: it is essential that we don't wait for the buffer to be
|
|
|
|
* read if dm_bufio_get function is used. Both dm_bufio_get and
|
|
|
|
* dm_bufio_prefetch can be used in the driver request routine.
|
|
|
|
* If the user called both dm_bufio_prefetch and dm_bufio_get on
|
|
|
|
* the same buffer, it would deadlock if we waited.
|
|
|
|
*/
|
|
|
|
if (nf == NF_GET && unlikely(test_bit(B_READING, &b->state)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
b->hold_count++;
|
|
|
|
__relink_lru(b, test_bit(B_DIRTY, &b->state) ||
|
|
|
|
test_bit(B_WRITING, &b->state));
|
|
|
|
return b;
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The endio routine for reading: set the error, clear the bit and wake up
|
|
|
|
* anyone waiting on the buffer.
|
|
|
|
*/
|
2018-03-26 18:29:47 +00:00
|
|
|
static void read_endio(struct dm_buffer *b, blk_status_t status)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
2018-03-26 18:29:47 +00:00
|
|
|
b->read_error = status;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
BUG_ON(!test_bit(B_READING, &b->state));
|
|
|
|
|
2014-03-17 17:06:10 +00:00
|
|
|
smp_mb__before_atomic();
|
2011-10-31 20:19:09 +00:00
|
|
|
clear_bit(B_READING, &b->state);
|
2014-03-17 17:06:10 +00:00
|
|
|
smp_mb__after_atomic();
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
wake_up_bit(&b->state, B_READING);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A common routine for dm_bufio_new and dm_bufio_read. Operation of these
|
|
|
|
* functions is similar except that dm_bufio_new doesn't read the
|
|
|
|
* buffer from the disk (assuming that the caller overwrites all the data
|
|
|
|
* and uses dm_bufio_mark_buffer_dirty to write new data back).
|
|
|
|
*/
|
|
|
|
static void *new_read(struct dm_bufio_client *c, sector_t block,
|
|
|
|
enum new_flag nf, struct dm_buffer **bp)
|
|
|
|
{
|
|
|
|
int need_submit;
|
|
|
|
struct dm_buffer *b;
|
|
|
|
|
2013-07-10 22:41:18 +00:00
|
|
|
LIST_HEAD(write_list);
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
dm_bufio_lock(c);
|
2013-07-10 22:41:18 +00:00
|
|
|
b = __bufio_new(c, block, nf, &need_submit, &write_list);
|
2015-11-24 00:20:06 +00:00
|
|
|
#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
|
|
|
|
if (b && b->hold_count == 1)
|
|
|
|
buffer_record_stack(b);
|
|
|
|
#endif
|
2011-10-31 20:19:09 +00:00
|
|
|
dm_bufio_unlock(c);
|
|
|
|
|
2013-07-10 22:41:18 +00:00
|
|
|
__flush_write_list(&write_list);
|
|
|
|
|
2012-03-28 17:41:29 +00:00
|
|
|
if (!b)
|
2015-11-24 00:11:32 +00:00
|
|
|
return NULL;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
if (need_submit)
|
2017-12-02 05:33:39 +00:00
|
|
|
submit_io(b, REQ_OP_READ, read_endio);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
sched: Remove proliferation of wait_on_bit() action functions
The current "wait_on_bit" interface requires an 'action'
function to be provided which does the actual waiting.
There are over 20 such functions, many of them identical.
Most cases can be satisfied by one of just two functions, one
which uses io_schedule() and one which just uses schedule().
So:
Rename wait_on_bit and wait_on_bit_lock to
wait_on_bit_action and wait_on_bit_lock_action
to make it explicit that they need an action function.
Introduce new wait_on_bit{,_lock} and wait_on_bit{,_lock}_io
which are *not* given an action function but implicitly use
a standard one.
The decision to error-out if a signal is pending is now made
based on the 'mode' argument rather than being encoded in the action
function.
All instances of the old wait_on_bit and wait_on_bit_lock which
can use the new version have been changed accordingly and their
action functions have been discarded.
wait_on_bit{_lock} does not return any specific error code in the
event of a signal so the caller must check for non-zero and
interpolate their own error code as appropriate.
The wait_on_bit() call in __fscache_wait_on_invalidate() was
ambiguous as it specified TASK_UNINTERRUPTIBLE but used
fscache_wait_bit_interruptible as an action function.
David Howells confirms this should be uniformly
"uninterruptible"
The main remaining user of wait_on_bit{,_lock}_action is NFS
which needs to use a freezer-aware schedule() call.
A comment in fs/gfs2/glock.c notes that having multiple 'action'
functions is useful as they display differently in the 'wchan'
field of 'ps'. (and /proc/$PID/wchan).
As the new bit_wait{,_io} functions are tagged "__sched", they
will not show up at all, but something higher in the stack. So
the distinction will still be visible, only with different
function names (gds2_glock_wait versus gfs2_glock_dq_wait in the
gfs2/glock.c case).
Since first version of this patch (against 3.15) two new action
functions appeared, on in NFS and one in CIFS. CIFS also now
uses an action function that makes the same freezer aware
schedule call as NFS.
Signed-off-by: NeilBrown <neilb@suse.de>
Acked-by: David Howells <dhowells@redhat.com> (fscache, keys)
Acked-by: Steven Whitehouse <swhiteho@redhat.com> (gfs2)
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Steve French <sfrench@samba.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20140707051603.28027.72349.stgit@notabene.brown
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2014-07-07 05:16:04 +00:00
|
|
|
wait_on_bit_io(&b->state, B_READING, TASK_UNINTERRUPTIBLE);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
if (b->read_error) {
|
2017-06-03 07:38:06 +00:00
|
|
|
int error = blk_status_to_errno(b->read_error);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
dm_bufio_release(b);
|
|
|
|
|
|
|
|
return ERR_PTR(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
*bp = b;
|
|
|
|
|
|
|
|
return b->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *dm_bufio_get(struct dm_bufio_client *c, sector_t block,
|
|
|
|
struct dm_buffer **bp)
|
|
|
|
{
|
|
|
|
return new_read(c, block, NF_GET, bp);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_get);
|
|
|
|
|
|
|
|
void *dm_bufio_read(struct dm_bufio_client *c, sector_t block,
|
|
|
|
struct dm_buffer **bp)
|
|
|
|
{
|
|
|
|
BUG_ON(dm_bufio_in_request());
|
|
|
|
|
|
|
|
return new_read(c, block, NF_READ, bp);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_read);
|
|
|
|
|
|
|
|
void *dm_bufio_new(struct dm_bufio_client *c, sector_t block,
|
|
|
|
struct dm_buffer **bp)
|
|
|
|
{
|
|
|
|
BUG_ON(dm_bufio_in_request());
|
|
|
|
|
|
|
|
return new_read(c, block, NF_FRESH, bp);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_new);
|
|
|
|
|
2012-03-28 17:41:29 +00:00
|
|
|
void dm_bufio_prefetch(struct dm_bufio_client *c,
|
|
|
|
sector_t block, unsigned n_blocks)
|
|
|
|
{
|
|
|
|
struct blk_plug plug;
|
|
|
|
|
2013-07-10 22:41:18 +00:00
|
|
|
LIST_HEAD(write_list);
|
|
|
|
|
2013-03-20 17:21:25 +00:00
|
|
|
BUG_ON(dm_bufio_in_request());
|
|
|
|
|
2012-03-28 17:41:29 +00:00
|
|
|
blk_start_plug(&plug);
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
|
|
|
|
for (; n_blocks--; block++) {
|
|
|
|
int need_submit;
|
|
|
|
struct dm_buffer *b;
|
2013-07-10 22:41:18 +00:00
|
|
|
b = __bufio_new(c, block, NF_PREFETCH, &need_submit,
|
|
|
|
&write_list);
|
|
|
|
if (unlikely(!list_empty(&write_list))) {
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
blk_finish_plug(&plug);
|
|
|
|
__flush_write_list(&write_list);
|
|
|
|
blk_start_plug(&plug);
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
}
|
2012-03-28 17:41:29 +00:00
|
|
|
if (unlikely(b != NULL)) {
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
|
|
|
|
if (need_submit)
|
2017-12-02 05:33:39 +00:00
|
|
|
submit_io(b, REQ_OP_READ, read_endio);
|
2012-03-28 17:41:29 +00:00
|
|
|
dm_bufio_release(b);
|
|
|
|
|
2016-09-13 08:45:20 +00:00
|
|
|
cond_resched();
|
2012-03-28 17:41:29 +00:00
|
|
|
|
|
|
|
if (!n_blocks)
|
|
|
|
goto flush_plug;
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
|
|
|
|
flush_plug:
|
|
|
|
blk_finish_plug(&plug);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_prefetch);
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
void dm_bufio_release(struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
struct dm_bufio_client *c = b->c;
|
|
|
|
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
|
|
|
|
BUG_ON(!b->hold_count);
|
|
|
|
|
|
|
|
b->hold_count--;
|
|
|
|
if (!b->hold_count) {
|
|
|
|
wake_up(&c->free_buffer_wait);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there were errors on the buffer, and the buffer is not
|
|
|
|
* to be written, free the buffer. There is no point in caching
|
|
|
|
* invalid buffer.
|
|
|
|
*/
|
|
|
|
if ((b->read_error || b->write_error) &&
|
2012-03-28 17:41:29 +00:00
|
|
|
!test_bit(B_READING, &b->state) &&
|
2011-10-31 20:19:09 +00:00
|
|
|
!test_bit(B_WRITING, &b->state) &&
|
|
|
|
!test_bit(B_DIRTY, &b->state)) {
|
|
|
|
__unlink_buffer(b);
|
|
|
|
__free_buffer_wake(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_release);
|
|
|
|
|
2017-04-30 21:31:22 +00:00
|
|
|
void dm_bufio_mark_partial_buffer_dirty(struct dm_buffer *b,
|
|
|
|
unsigned start, unsigned end)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
|
|
|
struct dm_bufio_client *c = b->c;
|
|
|
|
|
2017-04-30 21:31:22 +00:00
|
|
|
BUG_ON(start >= end);
|
|
|
|
BUG_ON(end > b->c->block_size);
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
dm_bufio_lock(c);
|
|
|
|
|
2012-03-28 17:41:29 +00:00
|
|
|
BUG_ON(test_bit(B_READING, &b->state));
|
|
|
|
|
2017-04-30 21:31:22 +00:00
|
|
|
if (!test_and_set_bit(B_DIRTY, &b->state)) {
|
|
|
|
b->dirty_start = start;
|
|
|
|
b->dirty_end = end;
|
2011-10-31 20:19:09 +00:00
|
|
|
__relink_lru(b, LIST_DIRTY);
|
2017-04-30 21:31:22 +00:00
|
|
|
} else {
|
|
|
|
if (start < b->dirty_start)
|
|
|
|
b->dirty_start = start;
|
|
|
|
if (end > b->dirty_end)
|
|
|
|
b->dirty_end = end;
|
|
|
|
}
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
}
|
2017-04-30 21:31:22 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_mark_partial_buffer_dirty);
|
|
|
|
|
|
|
|
void dm_bufio_mark_buffer_dirty(struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
dm_bufio_mark_partial_buffer_dirty(b, 0, b->c->block_size);
|
|
|
|
}
|
2011-10-31 20:19:09 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_mark_buffer_dirty);
|
|
|
|
|
|
|
|
void dm_bufio_write_dirty_buffers_async(struct dm_bufio_client *c)
|
|
|
|
{
|
2013-07-10 22:41:18 +00:00
|
|
|
LIST_HEAD(write_list);
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
BUG_ON(dm_bufio_in_request());
|
|
|
|
|
|
|
|
dm_bufio_lock(c);
|
2013-07-10 22:41:18 +00:00
|
|
|
__write_dirty_buffers_async(c, 0, &write_list);
|
2011-10-31 20:19:09 +00:00
|
|
|
dm_bufio_unlock(c);
|
2013-07-10 22:41:18 +00:00
|
|
|
__flush_write_list(&write_list);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_write_dirty_buffers_async);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For performance, it is essential that the buffers are written asynchronously
|
|
|
|
* and simultaneously (so that the block layer can merge the writes) and then
|
|
|
|
* waited upon.
|
|
|
|
*
|
|
|
|
* Finally, we flush hardware disk cache.
|
|
|
|
*/
|
|
|
|
int dm_bufio_write_dirty_buffers(struct dm_bufio_client *c)
|
|
|
|
{
|
2017-07-12 07:26:34 +00:00
|
|
|
int a, f;
|
2011-10-31 20:19:09 +00:00
|
|
|
unsigned long buffers_processed = 0;
|
|
|
|
struct dm_buffer *b, *tmp;
|
|
|
|
|
2013-07-10 22:41:18 +00:00
|
|
|
LIST_HEAD(write_list);
|
|
|
|
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
__write_dirty_buffers_async(c, 0, &write_list);
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
__flush_write_list(&write_list);
|
2011-10-31 20:19:09 +00:00
|
|
|
dm_bufio_lock(c);
|
|
|
|
|
|
|
|
again:
|
|
|
|
list_for_each_entry_safe_reverse(b, tmp, &c->lru[LIST_DIRTY], lru_list) {
|
|
|
|
int dropped_lock = 0;
|
|
|
|
|
|
|
|
if (buffers_processed < c->n_buffers[LIST_DIRTY])
|
|
|
|
buffers_processed++;
|
|
|
|
|
|
|
|
BUG_ON(test_bit(B_READING, &b->state));
|
|
|
|
|
|
|
|
if (test_bit(B_WRITING, &b->state)) {
|
|
|
|
if (buffers_processed < c->n_buffers[LIST_DIRTY]) {
|
|
|
|
dropped_lock = 1;
|
|
|
|
b->hold_count++;
|
|
|
|
dm_bufio_unlock(c);
|
sched: Remove proliferation of wait_on_bit() action functions
The current "wait_on_bit" interface requires an 'action'
function to be provided which does the actual waiting.
There are over 20 such functions, many of them identical.
Most cases can be satisfied by one of just two functions, one
which uses io_schedule() and one which just uses schedule().
So:
Rename wait_on_bit and wait_on_bit_lock to
wait_on_bit_action and wait_on_bit_lock_action
to make it explicit that they need an action function.
Introduce new wait_on_bit{,_lock} and wait_on_bit{,_lock}_io
which are *not* given an action function but implicitly use
a standard one.
The decision to error-out if a signal is pending is now made
based on the 'mode' argument rather than being encoded in the action
function.
All instances of the old wait_on_bit and wait_on_bit_lock which
can use the new version have been changed accordingly and their
action functions have been discarded.
wait_on_bit{_lock} does not return any specific error code in the
event of a signal so the caller must check for non-zero and
interpolate their own error code as appropriate.
The wait_on_bit() call in __fscache_wait_on_invalidate() was
ambiguous as it specified TASK_UNINTERRUPTIBLE but used
fscache_wait_bit_interruptible as an action function.
David Howells confirms this should be uniformly
"uninterruptible"
The main remaining user of wait_on_bit{,_lock}_action is NFS
which needs to use a freezer-aware schedule() call.
A comment in fs/gfs2/glock.c notes that having multiple 'action'
functions is useful as they display differently in the 'wchan'
field of 'ps'. (and /proc/$PID/wchan).
As the new bit_wait{,_io} functions are tagged "__sched", they
will not show up at all, but something higher in the stack. So
the distinction will still be visible, only with different
function names (gds2_glock_wait versus gfs2_glock_dq_wait in the
gfs2/glock.c case).
Since first version of this patch (against 3.15) two new action
functions appeared, on in NFS and one in CIFS. CIFS also now
uses an action function that makes the same freezer aware
schedule call as NFS.
Signed-off-by: NeilBrown <neilb@suse.de>
Acked-by: David Howells <dhowells@redhat.com> (fscache, keys)
Acked-by: Steven Whitehouse <swhiteho@redhat.com> (gfs2)
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Steve French <sfrench@samba.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20140707051603.28027.72349.stgit@notabene.brown
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2014-07-07 05:16:04 +00:00
|
|
|
wait_on_bit_io(&b->state, B_WRITING,
|
|
|
|
TASK_UNINTERRUPTIBLE);
|
2011-10-31 20:19:09 +00:00
|
|
|
dm_bufio_lock(c);
|
|
|
|
b->hold_count--;
|
|
|
|
} else
|
sched: Remove proliferation of wait_on_bit() action functions
The current "wait_on_bit" interface requires an 'action'
function to be provided which does the actual waiting.
There are over 20 such functions, many of them identical.
Most cases can be satisfied by one of just two functions, one
which uses io_schedule() and one which just uses schedule().
So:
Rename wait_on_bit and wait_on_bit_lock to
wait_on_bit_action and wait_on_bit_lock_action
to make it explicit that they need an action function.
Introduce new wait_on_bit{,_lock} and wait_on_bit{,_lock}_io
which are *not* given an action function but implicitly use
a standard one.
The decision to error-out if a signal is pending is now made
based on the 'mode' argument rather than being encoded in the action
function.
All instances of the old wait_on_bit and wait_on_bit_lock which
can use the new version have been changed accordingly and their
action functions have been discarded.
wait_on_bit{_lock} does not return any specific error code in the
event of a signal so the caller must check for non-zero and
interpolate their own error code as appropriate.
The wait_on_bit() call in __fscache_wait_on_invalidate() was
ambiguous as it specified TASK_UNINTERRUPTIBLE but used
fscache_wait_bit_interruptible as an action function.
David Howells confirms this should be uniformly
"uninterruptible"
The main remaining user of wait_on_bit{,_lock}_action is NFS
which needs to use a freezer-aware schedule() call.
A comment in fs/gfs2/glock.c notes that having multiple 'action'
functions is useful as they display differently in the 'wchan'
field of 'ps'. (and /proc/$PID/wchan).
As the new bit_wait{,_io} functions are tagged "__sched", they
will not show up at all, but something higher in the stack. So
the distinction will still be visible, only with different
function names (gds2_glock_wait versus gfs2_glock_dq_wait in the
gfs2/glock.c case).
Since first version of this patch (against 3.15) two new action
functions appeared, on in NFS and one in CIFS. CIFS also now
uses an action function that makes the same freezer aware
schedule call as NFS.
Signed-off-by: NeilBrown <neilb@suse.de>
Acked-by: David Howells <dhowells@redhat.com> (fscache, keys)
Acked-by: Steven Whitehouse <swhiteho@redhat.com> (gfs2)
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Steve French <sfrench@samba.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20140707051603.28027.72349.stgit@notabene.brown
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2014-07-07 05:16:04 +00:00
|
|
|
wait_on_bit_io(&b->state, B_WRITING,
|
|
|
|
TASK_UNINTERRUPTIBLE);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!test_bit(B_DIRTY, &b->state) &&
|
|
|
|
!test_bit(B_WRITING, &b->state))
|
|
|
|
__relink_lru(b, LIST_CLEAN);
|
|
|
|
|
2016-09-13 08:45:20 +00:00
|
|
|
cond_resched();
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we dropped the lock, the list is no longer consistent,
|
|
|
|
* so we must restart the search.
|
|
|
|
*
|
|
|
|
* In the most common case, the buffer just processed is
|
|
|
|
* relinked to the clean list, so we won't loop scanning the
|
|
|
|
* same buffer again and again.
|
|
|
|
*
|
|
|
|
* This may livelock if there is another thread simultaneously
|
|
|
|
* dirtying buffers, so we count the number of buffers walked
|
|
|
|
* and if it exceeds the total number of buffers, it means that
|
|
|
|
* someone is doing some writes simultaneously with us. In
|
|
|
|
* this case, stop, dropping the lock.
|
|
|
|
*/
|
|
|
|
if (dropped_lock)
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
wake_up(&c->free_buffer_wait);
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
|
|
|
|
a = xchg(&c->async_write_error, 0);
|
|
|
|
f = dm_bufio_issue_flush(c);
|
|
|
|
if (a)
|
|
|
|
return a;
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_write_dirty_buffers);
|
|
|
|
|
|
|
|
/*
|
2018-10-30 07:35:54 +00:00
|
|
|
* Use dm-io to send an empty barrier to flush the device.
|
2011-10-31 20:19:09 +00:00
|
|
|
*/
|
|
|
|
int dm_bufio_issue_flush(struct dm_bufio_client *c)
|
|
|
|
{
|
|
|
|
struct dm_io_request io_req = {
|
2016-06-05 19:32:04 +00:00
|
|
|
.bi_op = REQ_OP_WRITE,
|
2017-05-31 07:44:32 +00:00
|
|
|
.bi_op_flags = REQ_PREFLUSH | REQ_SYNC,
|
2011-10-31 20:19:09 +00:00
|
|
|
.mem.type = DM_IO_KMEM,
|
|
|
|
.mem.ptr.addr = NULL,
|
|
|
|
.client = c->dm_io,
|
|
|
|
};
|
|
|
|
struct dm_io_region io_reg = {
|
|
|
|
.bdev = c->bdev,
|
|
|
|
.sector = 0,
|
|
|
|
.count = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
BUG_ON(dm_bufio_in_request());
|
|
|
|
|
|
|
|
return dm_io(&io_req, 1, &io_reg, NULL);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_issue_flush);
|
|
|
|
|
2020-02-07 20:59:25 +00:00
|
|
|
/*
|
|
|
|
* Use dm-io to send a discard request to flush the device.
|
|
|
|
*/
|
|
|
|
int dm_bufio_issue_discard(struct dm_bufio_client *c, sector_t block, sector_t count)
|
|
|
|
{
|
|
|
|
struct dm_io_request io_req = {
|
|
|
|
.bi_op = REQ_OP_DISCARD,
|
|
|
|
.bi_op_flags = REQ_SYNC,
|
|
|
|
.mem.type = DM_IO_KMEM,
|
|
|
|
.mem.ptr.addr = NULL,
|
|
|
|
.client = c->dm_io,
|
|
|
|
};
|
|
|
|
struct dm_io_region io_reg = {
|
|
|
|
.bdev = c->bdev,
|
|
|
|
.sector = block_to_sector(c, block),
|
|
|
|
.count = block_to_sector(c, count),
|
|
|
|
};
|
|
|
|
|
|
|
|
BUG_ON(dm_bufio_in_request());
|
|
|
|
|
|
|
|
return dm_io(&io_req, 1, &io_reg, NULL);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_issue_discard);
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
/*
|
|
|
|
* We first delete any other buffer that may be at that new location.
|
|
|
|
*
|
|
|
|
* Then, we write the buffer to the original location if it was dirty.
|
|
|
|
*
|
|
|
|
* Then, if we are the only one who is holding the buffer, relink the buffer
|
2018-10-30 07:35:54 +00:00
|
|
|
* in the buffer tree for the new location.
|
2011-10-31 20:19:09 +00:00
|
|
|
*
|
|
|
|
* If there was someone else holding the buffer, we write it to the new
|
|
|
|
* location but not relink it, because that other user needs to have the buffer
|
|
|
|
* at the same place.
|
|
|
|
*/
|
|
|
|
void dm_bufio_release_move(struct dm_buffer *b, sector_t new_block)
|
|
|
|
{
|
|
|
|
struct dm_bufio_client *c = b->c;
|
|
|
|
struct dm_buffer *new;
|
|
|
|
|
|
|
|
BUG_ON(dm_bufio_in_request());
|
|
|
|
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
|
|
|
|
retry:
|
|
|
|
new = __find(c, new_block);
|
|
|
|
if (new) {
|
|
|
|
if (new->hold_count) {
|
|
|
|
__wait_for_free_buffer(c);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: Is there any point waiting for a write that's going
|
|
|
|
* to be overwritten in a bit?
|
|
|
|
*/
|
|
|
|
__make_buffer_clean(new);
|
|
|
|
__unlink_buffer(new);
|
|
|
|
__free_buffer_wake(new);
|
|
|
|
}
|
|
|
|
|
|
|
|
BUG_ON(!b->hold_count);
|
|
|
|
BUG_ON(test_bit(B_READING, &b->state));
|
|
|
|
|
2013-07-10 22:41:18 +00:00
|
|
|
__write_dirty_buffer(b, NULL);
|
2011-10-31 20:19:09 +00:00
|
|
|
if (b->hold_count == 1) {
|
sched: Remove proliferation of wait_on_bit() action functions
The current "wait_on_bit" interface requires an 'action'
function to be provided which does the actual waiting.
There are over 20 such functions, many of them identical.
Most cases can be satisfied by one of just two functions, one
which uses io_schedule() and one which just uses schedule().
So:
Rename wait_on_bit and wait_on_bit_lock to
wait_on_bit_action and wait_on_bit_lock_action
to make it explicit that they need an action function.
Introduce new wait_on_bit{,_lock} and wait_on_bit{,_lock}_io
which are *not* given an action function but implicitly use
a standard one.
The decision to error-out if a signal is pending is now made
based on the 'mode' argument rather than being encoded in the action
function.
All instances of the old wait_on_bit and wait_on_bit_lock which
can use the new version have been changed accordingly and their
action functions have been discarded.
wait_on_bit{_lock} does not return any specific error code in the
event of a signal so the caller must check for non-zero and
interpolate their own error code as appropriate.
The wait_on_bit() call in __fscache_wait_on_invalidate() was
ambiguous as it specified TASK_UNINTERRUPTIBLE but used
fscache_wait_bit_interruptible as an action function.
David Howells confirms this should be uniformly
"uninterruptible"
The main remaining user of wait_on_bit{,_lock}_action is NFS
which needs to use a freezer-aware schedule() call.
A comment in fs/gfs2/glock.c notes that having multiple 'action'
functions is useful as they display differently in the 'wchan'
field of 'ps'. (and /proc/$PID/wchan).
As the new bit_wait{,_io} functions are tagged "__sched", they
will not show up at all, but something higher in the stack. So
the distinction will still be visible, only with different
function names (gds2_glock_wait versus gfs2_glock_dq_wait in the
gfs2/glock.c case).
Since first version of this patch (against 3.15) two new action
functions appeared, on in NFS and one in CIFS. CIFS also now
uses an action function that makes the same freezer aware
schedule call as NFS.
Signed-off-by: NeilBrown <neilb@suse.de>
Acked-by: David Howells <dhowells@redhat.com> (fscache, keys)
Acked-by: Steven Whitehouse <swhiteho@redhat.com> (gfs2)
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Steve French <sfrench@samba.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20140707051603.28027.72349.stgit@notabene.brown
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2014-07-07 05:16:04 +00:00
|
|
|
wait_on_bit_io(&b->state, B_WRITING,
|
|
|
|
TASK_UNINTERRUPTIBLE);
|
2011-10-31 20:19:09 +00:00
|
|
|
set_bit(B_DIRTY, &b->state);
|
2017-04-30 21:31:22 +00:00
|
|
|
b->dirty_start = 0;
|
|
|
|
b->dirty_end = c->block_size;
|
2011-10-31 20:19:09 +00:00
|
|
|
__unlink_buffer(b);
|
|
|
|
__link_buffer(b, new_block, LIST_DIRTY);
|
|
|
|
} else {
|
|
|
|
sector_t old_block;
|
sched: Remove proliferation of wait_on_bit() action functions
The current "wait_on_bit" interface requires an 'action'
function to be provided which does the actual waiting.
There are over 20 such functions, many of them identical.
Most cases can be satisfied by one of just two functions, one
which uses io_schedule() and one which just uses schedule().
So:
Rename wait_on_bit and wait_on_bit_lock to
wait_on_bit_action and wait_on_bit_lock_action
to make it explicit that they need an action function.
Introduce new wait_on_bit{,_lock} and wait_on_bit{,_lock}_io
which are *not* given an action function but implicitly use
a standard one.
The decision to error-out if a signal is pending is now made
based on the 'mode' argument rather than being encoded in the action
function.
All instances of the old wait_on_bit and wait_on_bit_lock which
can use the new version have been changed accordingly and their
action functions have been discarded.
wait_on_bit{_lock} does not return any specific error code in the
event of a signal so the caller must check for non-zero and
interpolate their own error code as appropriate.
The wait_on_bit() call in __fscache_wait_on_invalidate() was
ambiguous as it specified TASK_UNINTERRUPTIBLE but used
fscache_wait_bit_interruptible as an action function.
David Howells confirms this should be uniformly
"uninterruptible"
The main remaining user of wait_on_bit{,_lock}_action is NFS
which needs to use a freezer-aware schedule() call.
A comment in fs/gfs2/glock.c notes that having multiple 'action'
functions is useful as they display differently in the 'wchan'
field of 'ps'. (and /proc/$PID/wchan).
As the new bit_wait{,_io} functions are tagged "__sched", they
will not show up at all, but something higher in the stack. So
the distinction will still be visible, only with different
function names (gds2_glock_wait versus gfs2_glock_dq_wait in the
gfs2/glock.c case).
Since first version of this patch (against 3.15) two new action
functions appeared, on in NFS and one in CIFS. CIFS also now
uses an action function that makes the same freezer aware
schedule call as NFS.
Signed-off-by: NeilBrown <neilb@suse.de>
Acked-by: David Howells <dhowells@redhat.com> (fscache, keys)
Acked-by: Steven Whitehouse <swhiteho@redhat.com> (gfs2)
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Steve French <sfrench@samba.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20140707051603.28027.72349.stgit@notabene.brown
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2014-07-07 05:16:04 +00:00
|
|
|
wait_on_bit_lock_io(&b->state, B_WRITING,
|
|
|
|
TASK_UNINTERRUPTIBLE);
|
2011-10-31 20:19:09 +00:00
|
|
|
/*
|
|
|
|
* Relink buffer to "new_block" so that write_callback
|
|
|
|
* sees "new_block" as a block number.
|
|
|
|
* After the write, link the buffer back to old_block.
|
|
|
|
* All this must be done in bufio lock, so that block number
|
|
|
|
* change isn't visible to other threads.
|
|
|
|
*/
|
|
|
|
old_block = b->block;
|
|
|
|
__unlink_buffer(b);
|
|
|
|
__link_buffer(b, new_block, b->list_mode);
|
2017-12-02 05:33:39 +00:00
|
|
|
submit_io(b, REQ_OP_WRITE, write_endio);
|
sched: Remove proliferation of wait_on_bit() action functions
The current "wait_on_bit" interface requires an 'action'
function to be provided which does the actual waiting.
There are over 20 such functions, many of them identical.
Most cases can be satisfied by one of just two functions, one
which uses io_schedule() and one which just uses schedule().
So:
Rename wait_on_bit and wait_on_bit_lock to
wait_on_bit_action and wait_on_bit_lock_action
to make it explicit that they need an action function.
Introduce new wait_on_bit{,_lock} and wait_on_bit{,_lock}_io
which are *not* given an action function but implicitly use
a standard one.
The decision to error-out if a signal is pending is now made
based on the 'mode' argument rather than being encoded in the action
function.
All instances of the old wait_on_bit and wait_on_bit_lock which
can use the new version have been changed accordingly and their
action functions have been discarded.
wait_on_bit{_lock} does not return any specific error code in the
event of a signal so the caller must check for non-zero and
interpolate their own error code as appropriate.
The wait_on_bit() call in __fscache_wait_on_invalidate() was
ambiguous as it specified TASK_UNINTERRUPTIBLE but used
fscache_wait_bit_interruptible as an action function.
David Howells confirms this should be uniformly
"uninterruptible"
The main remaining user of wait_on_bit{,_lock}_action is NFS
which needs to use a freezer-aware schedule() call.
A comment in fs/gfs2/glock.c notes that having multiple 'action'
functions is useful as they display differently in the 'wchan'
field of 'ps'. (and /proc/$PID/wchan).
As the new bit_wait{,_io} functions are tagged "__sched", they
will not show up at all, but something higher in the stack. So
the distinction will still be visible, only with different
function names (gds2_glock_wait versus gfs2_glock_dq_wait in the
gfs2/glock.c case).
Since first version of this patch (against 3.15) two new action
functions appeared, on in NFS and one in CIFS. CIFS also now
uses an action function that makes the same freezer aware
schedule call as NFS.
Signed-off-by: NeilBrown <neilb@suse.de>
Acked-by: David Howells <dhowells@redhat.com> (fscache, keys)
Acked-by: Steven Whitehouse <swhiteho@redhat.com> (gfs2)
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Steve French <sfrench@samba.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20140707051603.28027.72349.stgit@notabene.brown
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2014-07-07 05:16:04 +00:00
|
|
|
wait_on_bit_io(&b->state, B_WRITING,
|
|
|
|
TASK_UNINTERRUPTIBLE);
|
2011-10-31 20:19:09 +00:00
|
|
|
__unlink_buffer(b);
|
|
|
|
__link_buffer(b, old_block, b->list_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
dm_bufio_release(b);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_release_move);
|
|
|
|
|
2020-06-02 13:34:40 +00:00
|
|
|
static void forget_buffer_locked(struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
if (likely(!b->hold_count) && likely(!b->state)) {
|
|
|
|
__unlink_buffer(b);
|
|
|
|
__free_buffer_wake(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-14 00:12:36 +00:00
|
|
|
/*
|
|
|
|
* Free the given buffer.
|
|
|
|
*
|
|
|
|
* This is just a hint, if the buffer is in use or dirty, this function
|
|
|
|
* does nothing.
|
|
|
|
*/
|
|
|
|
void dm_bufio_forget(struct dm_bufio_client *c, sector_t block)
|
|
|
|
{
|
|
|
|
struct dm_buffer *b;
|
|
|
|
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
|
|
|
|
b = __find(c, block);
|
2020-06-02 13:34:40 +00:00
|
|
|
if (b)
|
|
|
|
forget_buffer_locked(b);
|
2014-01-14 00:12:36 +00:00
|
|
|
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
}
|
2018-03-15 20:02:31 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_forget);
|
2014-01-14 00:12:36 +00:00
|
|
|
|
2020-06-02 13:34:40 +00:00
|
|
|
void dm_bufio_forget_buffers(struct dm_bufio_client *c, sector_t block, sector_t n_blocks)
|
|
|
|
{
|
|
|
|
struct dm_buffer *b;
|
|
|
|
sector_t end_block = block + n_blocks;
|
|
|
|
|
|
|
|
while (block < end_block) {
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
|
|
|
|
b = __find_next(c, block);
|
|
|
|
if (b) {
|
|
|
|
block = b->block + 1;
|
|
|
|
forget_buffer_locked(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
|
|
|
|
if (!b)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_forget_buffers);
|
|
|
|
|
2014-01-14 00:13:05 +00:00
|
|
|
void dm_bufio_set_minimum_buffers(struct dm_bufio_client *c, unsigned n)
|
|
|
|
{
|
|
|
|
c->minimum_buffers = n;
|
|
|
|
}
|
2018-03-15 20:02:31 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_set_minimum_buffers);
|
2014-01-14 00:13:05 +00:00
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
unsigned dm_bufio_get_block_size(struct dm_bufio_client *c)
|
|
|
|
{
|
|
|
|
return c->block_size;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_get_block_size);
|
|
|
|
|
|
|
|
sector_t dm_bufio_get_device_size(struct dm_bufio_client *c)
|
|
|
|
{
|
2021-10-18 10:11:05 +00:00
|
|
|
sector_t s = bdev_nr_sectors(c->bdev);
|
2021-02-23 20:21:20 +00:00
|
|
|
if (s >= c->start)
|
|
|
|
s -= c->start;
|
|
|
|
else
|
|
|
|
s = 0;
|
2018-03-26 18:29:46 +00:00
|
|
|
if (likely(c->sectors_per_block_bits >= 0))
|
|
|
|
s >>= c->sectors_per_block_bits;
|
|
|
|
else
|
|
|
|
sector_div(s, c->block_size >> SECTOR_SHIFT);
|
|
|
|
return s;
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_get_device_size);
|
|
|
|
|
2021-01-08 16:15:56 +00:00
|
|
|
struct dm_io_client *dm_bufio_get_dm_io_client(struct dm_bufio_client *c)
|
|
|
|
{
|
|
|
|
return c->dm_io;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_get_dm_io_client);
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
sector_t dm_bufio_get_block_number(struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
return b->block;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_get_block_number);
|
|
|
|
|
|
|
|
void *dm_bufio_get_block_data(struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
return b->data;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_get_block_data);
|
|
|
|
|
|
|
|
void *dm_bufio_get_aux_data(struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
return b + 1;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_get_aux_data);
|
|
|
|
|
|
|
|
struct dm_bufio_client *dm_bufio_get_client(struct dm_buffer *b)
|
|
|
|
{
|
|
|
|
return b->c;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_get_client);
|
|
|
|
|
|
|
|
static void drop_buffers(struct dm_bufio_client *c)
|
|
|
|
{
|
|
|
|
struct dm_buffer *b;
|
|
|
|
int i;
|
2015-11-24 00:20:06 +00:00
|
|
|
bool warned = false;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
BUG_ON(dm_bufio_in_request());
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An optimization so that the buffers are not written one-by-one.
|
|
|
|
*/
|
|
|
|
dm_bufio_write_dirty_buffers_async(c);
|
|
|
|
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
|
|
|
|
while ((b = __get_unclaimed_buffer(c)))
|
|
|
|
__free_buffer_wake(b);
|
|
|
|
|
|
|
|
for (i = 0; i < LIST_SIZE; i++)
|
2015-11-24 00:20:06 +00:00
|
|
|
list_for_each_entry(b, &c->lru[i], lru_list) {
|
|
|
|
WARN_ON(!warned);
|
|
|
|
warned = true;
|
2011-10-31 20:19:09 +00:00
|
|
|
DMERR("leaked buffer %llx, hold count %u, list %d",
|
|
|
|
(unsigned long long)b->block, b->hold_count, i);
|
2015-11-24 00:20:06 +00:00
|
|
|
#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
|
2019-04-25 09:45:07 +00:00
|
|
|
stack_trace_print(b->stack_entries, b->stack_len, 1);
|
|
|
|
/* mark unclaimed to avoid BUG_ON below */
|
|
|
|
b->hold_count = 0;
|
2015-11-24 00:20:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
|
|
|
|
while ((b = __get_unclaimed_buffer(c)))
|
|
|
|
__free_buffer_wake(b);
|
|
|
|
#endif
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
for (i = 0; i < LIST_SIZE; i++)
|
|
|
|
BUG_ON(!list_empty(&c->lru[i]));
|
|
|
|
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-10-09 10:10:25 +00:00
|
|
|
* We may not be able to evict this buffer if IO pending or the client
|
|
|
|
* is still using it. Caller is expected to know buffer is too old.
|
|
|
|
*
|
2014-10-16 18:45:20 +00:00
|
|
|
* And if GFP_NOFS is used, we must not do any I/O because we hold
|
|
|
|
* dm_bufio_clients_lock and we would risk deadlock if the I/O gets
|
|
|
|
* rerouted to different bufio client.
|
2011-10-31 20:19:09 +00:00
|
|
|
*/
|
2014-10-09 10:10:25 +00:00
|
|
|
static bool __try_evict_buffer(struct dm_buffer *b, gfp_t gfp)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
2014-10-16 18:45:20 +00:00
|
|
|
if (!(gfp & __GFP_FS)) {
|
2011-10-31 20:19:09 +00:00
|
|
|
if (test_bit(B_READING, &b->state) ||
|
|
|
|
test_bit(B_WRITING, &b->state) ||
|
|
|
|
test_bit(B_DIRTY, &b->state))
|
2014-10-09 10:10:25 +00:00
|
|
|
return false;
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->hold_count)
|
2014-10-09 10:10:25 +00:00
|
|
|
return false;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
__make_buffer_clean(b);
|
|
|
|
__unlink_buffer(b);
|
|
|
|
__free_buffer_wake(b);
|
|
|
|
|
2014-10-09 10:10:25 +00:00
|
|
|
return true;
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 21:32:28 +00:00
|
|
|
static unsigned long get_retain_buffers(struct dm_bufio_client *c)
|
2014-10-09 10:10:25 +00:00
|
|
|
{
|
2018-03-26 18:29:46 +00:00
|
|
|
unsigned long retain_bytes = READ_ONCE(dm_bufio_retain_bytes);
|
|
|
|
if (likely(c->sectors_per_block_bits >= 0))
|
|
|
|
retain_bytes >>= c->sectors_per_block_bits + SECTOR_SHIFT;
|
|
|
|
else
|
|
|
|
retain_bytes /= c->block_size;
|
|
|
|
return retain_bytes;
|
2014-10-09 10:10:25 +00:00
|
|
|
}
|
|
|
|
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
static void __scan(struct dm_bufio_client *c)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
|
|
|
int l;
|
|
|
|
struct dm_buffer *b, *tmp;
|
2014-10-09 10:10:25 +00:00
|
|
|
unsigned long freed = 0;
|
2017-12-06 17:27:30 +00:00
|
|
|
unsigned long count = c->n_buffers[LIST_CLEAN] +
|
|
|
|
c->n_buffers[LIST_DIRTY];
|
2017-04-30 21:32:28 +00:00
|
|
|
unsigned long retain_target = get_retain_buffers(c);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
for (l = 0; l < LIST_SIZE; l++) {
|
drivers: convert shrinkers to new count/scan API
Convert the driver shrinkers to the new API. Most changes are compile
tested only because I either don't have the hardware or it's staging
stuff.
FWIW, the md and android code is pretty good, but the rest of it makes me
want to claw my eyes out. The amount of broken code I just encountered is
mind boggling. I've added comments explaining what is broken, but I fear
that some of the code would be best dealt with by being dragged behind the
bike shed, burying in mud up to it's neck and then run over repeatedly
with a blunt lawn mower.
Special mention goes to the zcache/zcache2 drivers. They can't co-exist
in the build at the same time, they are under different menu options in
menuconfig, they only show up when you've got the right set of mm
subsystem options configured and so even compile testing is an exercise in
pulling teeth. And that doesn't even take into account the horrible,
broken code...
[glommer@openvz.org: fixes for i915, android lowmem, zcache, bcache]
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Glauber Costa <glommer@openvz.org>
Acked-by: Mel Gorman <mgorman@suse.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: Arve Hjønnevåg <arve@android.com>
Cc: Carlos Maiolino <cmaiolino@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: David Rientjes <rientjes@google.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: J. Bruce Fields <bfields@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2013-08-28 00:18:11 +00:00
|
|
|
list_for_each_entry_safe_reverse(b, tmp, &c->lru[l], lru_list) {
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
if (count - freed <= retain_target)
|
|
|
|
atomic_long_set(&c->need_shrink, 0);
|
|
|
|
if (!atomic_long_read(&c->need_shrink))
|
|
|
|
return;
|
|
|
|
if (__try_evict_buffer(b, GFP_KERNEL)) {
|
|
|
|
atomic_long_dec(&c->need_shrink);
|
2014-10-09 10:10:25 +00:00
|
|
|
freed++;
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
}
|
2016-09-13 08:45:20 +00:00
|
|
|
cond_resched();
|
drivers: convert shrinkers to new count/scan API
Convert the driver shrinkers to the new API. Most changes are compile
tested only because I either don't have the hardware or it's staging
stuff.
FWIW, the md and android code is pretty good, but the rest of it makes me
want to claw my eyes out. The amount of broken code I just encountered is
mind boggling. I've added comments explaining what is broken, but I fear
that some of the code would be best dealt with by being dragged behind the
bike shed, burying in mud up to it's neck and then run over repeatedly
with a blunt lawn mower.
Special mention goes to the zcache/zcache2 drivers. They can't co-exist
in the build at the same time, they are under different menu options in
menuconfig, they only show up when you've got the right set of mm
subsystem options configured and so even compile testing is an exercise in
pulling teeth. And that doesn't even take into account the horrible,
broken code...
[glommer@openvz.org: fixes for i915, android lowmem, zcache, bcache]
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Glauber Costa <glommer@openvz.org>
Acked-by: Mel Gorman <mgorman@suse.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: Arve Hjønnevåg <arve@android.com>
Cc: Carlos Maiolino <cmaiolino@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: David Rientjes <rientjes@google.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: J. Bruce Fields <bfields@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2013-08-28 00:18:11 +00:00
|
|
|
}
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
static void shrink_work(struct work_struct *w)
|
|
|
|
{
|
|
|
|
struct dm_bufio_client *c = container_of(w, struct dm_bufio_client, shrink_work);
|
|
|
|
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
__scan(c);
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
drivers: convert shrinkers to new count/scan API
Convert the driver shrinkers to the new API. Most changes are compile
tested only because I either don't have the hardware or it's staging
stuff.
FWIW, the md and android code is pretty good, but the rest of it makes me
want to claw my eyes out. The amount of broken code I just encountered is
mind boggling. I've added comments explaining what is broken, but I fear
that some of the code would be best dealt with by being dragged behind the
bike shed, burying in mud up to it's neck and then run over repeatedly
with a blunt lawn mower.
Special mention goes to the zcache/zcache2 drivers. They can't co-exist
in the build at the same time, they are under different menu options in
menuconfig, they only show up when you've got the right set of mm
subsystem options configured and so even compile testing is an exercise in
pulling teeth. And that doesn't even take into account the horrible,
broken code...
[glommer@openvz.org: fixes for i915, android lowmem, zcache, bcache]
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Glauber Costa <glommer@openvz.org>
Acked-by: Mel Gorman <mgorman@suse.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: Arve Hjønnevåg <arve@android.com>
Cc: Carlos Maiolino <cmaiolino@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: David Rientjes <rientjes@google.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: J. Bruce Fields <bfields@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2013-08-28 00:18:11 +00:00
|
|
|
struct dm_bufio_client *c;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
drivers: convert shrinkers to new count/scan API
Convert the driver shrinkers to the new API. Most changes are compile
tested only because I either don't have the hardware or it's staging
stuff.
FWIW, the md and android code is pretty good, but the rest of it makes me
want to claw my eyes out. The amount of broken code I just encountered is
mind boggling. I've added comments explaining what is broken, but I fear
that some of the code would be best dealt with by being dragged behind the
bike shed, burying in mud up to it's neck and then run over repeatedly
with a blunt lawn mower.
Special mention goes to the zcache/zcache2 drivers. They can't co-exist
in the build at the same time, they are under different menu options in
menuconfig, they only show up when you've got the right set of mm
subsystem options configured and so even compile testing is an exercise in
pulling teeth. And that doesn't even take into account the horrible,
broken code...
[glommer@openvz.org: fixes for i915, android lowmem, zcache, bcache]
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Glauber Costa <glommer@openvz.org>
Acked-by: Mel Gorman <mgorman@suse.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: Arve Hjønnevåg <arve@android.com>
Cc: Carlos Maiolino <cmaiolino@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: David Rientjes <rientjes@google.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: J. Bruce Fields <bfields@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2013-08-28 00:18:11 +00:00
|
|
|
c = container_of(shrink, struct dm_bufio_client, shrinker);
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
atomic_long_add(sc->nr_to_scan, &c->need_shrink);
|
|
|
|
queue_work(dm_bufio_wq, &c->shrink_work);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
return sc->nr_to_scan;
|
drivers: convert shrinkers to new count/scan API
Convert the driver shrinkers to the new API. Most changes are compile
tested only because I either don't have the hardware or it's staging
stuff.
FWIW, the md and android code is pretty good, but the rest of it makes me
want to claw my eyes out. The amount of broken code I just encountered is
mind boggling. I've added comments explaining what is broken, but I fear
that some of the code would be best dealt with by being dragged behind the
bike shed, burying in mud up to it's neck and then run over repeatedly
with a blunt lawn mower.
Special mention goes to the zcache/zcache2 drivers. They can't co-exist
in the build at the same time, they are under different menu options in
menuconfig, they only show up when you've got the right set of mm
subsystem options configured and so even compile testing is an exercise in
pulling teeth. And that doesn't even take into account the horrible,
broken code...
[glommer@openvz.org: fixes for i915, android lowmem, zcache, bcache]
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Glauber Costa <glommer@openvz.org>
Acked-by: Mel Gorman <mgorman@suse.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: Arve Hjønnevåg <arve@android.com>
Cc: Carlos Maiolino <cmaiolino@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: David Rientjes <rientjes@google.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: J. Bruce Fields <bfields@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2013-08-28 00:18:11 +00:00
|
|
|
}
|
2011-10-31 20:19:09 +00:00
|
|
|
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
static unsigned long dm_bufio_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
|
drivers: convert shrinkers to new count/scan API
Convert the driver shrinkers to the new API. Most changes are compile
tested only because I either don't have the hardware or it's staging
stuff.
FWIW, the md and android code is pretty good, but the rest of it makes me
want to claw my eyes out. The amount of broken code I just encountered is
mind boggling. I've added comments explaining what is broken, but I fear
that some of the code would be best dealt with by being dragged behind the
bike shed, burying in mud up to it's neck and then run over repeatedly
with a blunt lawn mower.
Special mention goes to the zcache/zcache2 drivers. They can't co-exist
in the build at the same time, they are under different menu options in
menuconfig, they only show up when you've got the right set of mm
subsystem options configured and so even compile testing is an exercise in
pulling teeth. And that doesn't even take into account the horrible,
broken code...
[glommer@openvz.org: fixes for i915, android lowmem, zcache, bcache]
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Glauber Costa <glommer@openvz.org>
Acked-by: Mel Gorman <mgorman@suse.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: Arve Hjønnevåg <arve@android.com>
Cc: Carlos Maiolino <cmaiolino@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: David Rientjes <rientjes@google.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: J. Bruce Fields <bfields@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2013-08-28 00:18:11 +00:00
|
|
|
{
|
2016-11-23 21:52:01 +00:00
|
|
|
struct dm_bufio_client *c = container_of(shrink, struct dm_bufio_client, shrinker);
|
2017-12-06 17:27:30 +00:00
|
|
|
unsigned long count = READ_ONCE(c->n_buffers[LIST_CLEAN]) +
|
|
|
|
READ_ONCE(c->n_buffers[LIST_DIRTY]);
|
|
|
|
unsigned long retain_target = get_retain_buffers(c);
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
unsigned long queued_for_cleanup = atomic_long_read(&c->need_shrink);
|
|
|
|
|
|
|
|
if (unlikely(count < retain_target))
|
|
|
|
count = 0;
|
|
|
|
else
|
|
|
|
count -= retain_target;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
if (unlikely(count < queued_for_cleanup))
|
|
|
|
count = 0;
|
|
|
|
else
|
|
|
|
count -= queued_for_cleanup;
|
|
|
|
|
|
|
|
return count;
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the buffering interface
|
|
|
|
*/
|
|
|
|
struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsigned block_size,
|
|
|
|
unsigned reserved_buffers, unsigned aux_size,
|
|
|
|
void (*alloc_callback)(struct dm_buffer *),
|
2022-07-22 09:38:21 +00:00
|
|
|
void (*write_callback)(struct dm_buffer *),
|
|
|
|
unsigned int flags)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct dm_bufio_client *c;
|
|
|
|
unsigned i;
|
2018-03-26 18:29:45 +00:00
|
|
|
char slab_name[27];
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2018-03-26 18:29:46 +00:00
|
|
|
if (!block_size || block_size & ((1 << SECTOR_SHIFT) - 1)) {
|
|
|
|
DMERR("%s: block size not specified or is not multiple of 512b", __func__);
|
|
|
|
r = -EINVAL;
|
|
|
|
goto bad_client;
|
|
|
|
}
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2014-07-31 16:07:19 +00:00
|
|
|
c = kzalloc(sizeof(*c), GFP_KERNEL);
|
2011-10-31 20:19:09 +00:00
|
|
|
if (!c) {
|
|
|
|
r = -ENOMEM;
|
|
|
|
goto bad_client;
|
|
|
|
}
|
2014-10-06 12:48:51 +00:00
|
|
|
c->buffer_tree = RB_ROOT;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
c->bdev = bdev;
|
|
|
|
c->block_size = block_size;
|
2018-03-26 18:29:46 +00:00
|
|
|
if (is_power_of_2(block_size))
|
|
|
|
c->sectors_per_block_bits = __ffs(block_size) - SECTOR_SHIFT;
|
|
|
|
else
|
|
|
|
c->sectors_per_block_bits = -1;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
c->alloc_callback = alloc_callback;
|
|
|
|
c->write_callback = write_callback;
|
|
|
|
|
2022-07-25 22:26:48 +00:00
|
|
|
if (flags & DM_BUFIO_CLIENT_NO_SLEEP) {
|
2022-07-22 09:38:22 +00:00
|
|
|
c->no_sleep = true;
|
2022-07-25 22:26:48 +00:00
|
|
|
static_branch_inc(&no_sleep_enabled);
|
|
|
|
}
|
2022-07-22 09:38:22 +00:00
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
for (i = 0; i < LIST_SIZE; i++) {
|
|
|
|
INIT_LIST_HEAD(&c->lru[i]);
|
|
|
|
c->n_buffers[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_init(&c->lock);
|
2022-07-22 09:38:22 +00:00
|
|
|
spin_lock_init(&c->spinlock);
|
2011-10-31 20:19:09 +00:00
|
|
|
INIT_LIST_HEAD(&c->reserved_buffers);
|
|
|
|
c->need_reserved_buffers = reserved_buffers;
|
|
|
|
|
2018-03-15 20:02:31 +00:00
|
|
|
dm_bufio_set_minimum_buffers(c, DM_BUFIO_MIN_BUFFERS);
|
2014-01-14 00:13:05 +00:00
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
init_waitqueue_head(&c->free_buffer_wait);
|
|
|
|
c->async_write_error = 0;
|
|
|
|
|
|
|
|
c->dm_io = dm_io_client_create();
|
|
|
|
if (IS_ERR(c->dm_io)) {
|
|
|
|
r = PTR_ERR(c->dm_io);
|
|
|
|
goto bad_dm_io;
|
|
|
|
}
|
|
|
|
|
2018-03-26 18:29:46 +00:00
|
|
|
if (block_size <= KMALLOC_MAX_SIZE &&
|
|
|
|
(block_size < PAGE_SIZE || !is_power_of_2(block_size))) {
|
2018-04-19 12:33:00 +00:00
|
|
|
unsigned align = min(1U << __ffs(block_size), (unsigned)PAGE_SIZE);
|
|
|
|
snprintf(slab_name, sizeof slab_name, "dm_bufio_cache-%u", block_size);
|
|
|
|
c->slab_cache = kmem_cache_create(slab_name, block_size, align,
|
2018-03-15 21:22:00 +00:00
|
|
|
SLAB_RECLAIM_ACCOUNT, NULL);
|
2018-03-26 18:29:42 +00:00
|
|
|
if (!c->slab_cache) {
|
|
|
|
r = -ENOMEM;
|
|
|
|
goto bad;
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-26 18:29:45 +00:00
|
|
|
if (aux_size)
|
|
|
|
snprintf(slab_name, sizeof slab_name, "dm_bufio_buffer-%u", aux_size);
|
|
|
|
else
|
|
|
|
snprintf(slab_name, sizeof slab_name, "dm_bufio_buffer");
|
|
|
|
c->slab_buffer = kmem_cache_create(slab_name, sizeof(struct dm_buffer) + aux_size,
|
|
|
|
0, SLAB_RECLAIM_ACCOUNT, NULL);
|
|
|
|
if (!c->slab_buffer) {
|
|
|
|
r = -ENOMEM;
|
|
|
|
goto bad;
|
|
|
|
}
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
while (c->need_reserved_buffers) {
|
|
|
|
struct dm_buffer *b = alloc_buffer(c, GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!b) {
|
|
|
|
r = -ENOMEM;
|
2018-01-04 17:14:57 +00:00
|
|
|
goto bad;
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
__free_buffer_wake(b);
|
|
|
|
}
|
|
|
|
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
INIT_WORK(&c->shrink_work, shrink_work);
|
|
|
|
atomic_long_set(&c->need_shrink, 0);
|
|
|
|
|
2017-12-23 10:27:04 +00:00
|
|
|
c->shrinker.count_objects = dm_bufio_shrink_count;
|
|
|
|
c->shrinker.scan_objects = dm_bufio_shrink_scan;
|
|
|
|
c->shrinker.seeks = 1;
|
|
|
|
c->shrinker.batch = 0;
|
|
|
|
r = register_shrinker(&c->shrinker);
|
|
|
|
if (r)
|
2018-01-04 17:14:57 +00:00
|
|
|
goto bad;
|
2017-12-23 10:27:04 +00:00
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
mutex_lock(&dm_bufio_clients_lock);
|
|
|
|
dm_bufio_client_count++;
|
|
|
|
list_add(&c->client_list, &dm_bufio_all_clients);
|
|
|
|
__cache_size_refresh();
|
|
|
|
mutex_unlock(&dm_bufio_clients_lock);
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
2018-01-04 17:14:57 +00:00
|
|
|
bad:
|
2011-10-31 20:19:09 +00:00
|
|
|
while (!list_empty(&c->reserved_buffers)) {
|
|
|
|
struct dm_buffer *b = list_entry(c->reserved_buffers.next,
|
|
|
|
struct dm_buffer, lru_list);
|
|
|
|
list_del(&b->lru_list);
|
|
|
|
free_buffer(b);
|
|
|
|
}
|
2018-03-26 18:29:42 +00:00
|
|
|
kmem_cache_destroy(c->slab_cache);
|
2018-03-26 18:29:45 +00:00
|
|
|
kmem_cache_destroy(c->slab_buffer);
|
2011-10-31 20:19:09 +00:00
|
|
|
dm_io_client_destroy(c->dm_io);
|
|
|
|
bad_dm_io:
|
2017-12-23 10:27:03 +00:00
|
|
|
mutex_destroy(&c->lock);
|
2011-10-31 20:19:09 +00:00
|
|
|
kfree(c);
|
|
|
|
bad_client:
|
|
|
|
return ERR_PTR(r);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_client_create);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the buffering interface.
|
|
|
|
* It is required that there are no references on any buffers.
|
|
|
|
*/
|
|
|
|
void dm_bufio_client_destroy(struct dm_bufio_client *c)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
drop_buffers(c);
|
|
|
|
|
|
|
|
unregister_shrinker(&c->shrinker);
|
dm bufio: do buffer cleanup from a workqueue
Until now, DM bufio's waiting for IO from reclaim context in its
shrinker has caused kswapd to block; which results in systemic IO
stalls and even deadlock, e.g.:
https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html
Here is Dave Chinner's problem description that motivated this fix,
from: https://lore.kernel.org/linux-fsdevel/20190809215733.GZ7777@dread.disaster.area/
"Waiting for IO in kswapd reclaim context is considered harmful -
kswapd context shrinker reclaim should be as non-blocking as possible,
and any back-off to wait for IO to complete should be done by the high
level reclaim core once it's completed an entire reclaim scan cycle of
everything....
What follows from that, and is pertinent in this situation, is that if
you don't block kswapd, then other reclaim contexts are not going to
get stuck waiting for it regardless of the reclaim context they use."
Continued elsewhere:
"The only way to fix this problem once and for all is to stop using
the shrinker as a mechanism to issue and wait on IO. If you need
background writeback of dirty buffers, do it from a WQ_MEM_RECLAIM
workqueue that isn't directly in the memory reclaim path and so can
issue writeback and block safely from a GFP_KERNEL context. Kick the
workqueue from the shrinker context, but get rid of the IO submission
and waiting from the shrinker and all the GFP_NOFS memory reclaim
recursion problems go away."
As such, this commit moves buffer cleanup to a workqueue.
Suggested-by: Dave Chinner <dchinner@redhat.com>
Reported-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2020-07-03 14:26:46 +00:00
|
|
|
flush_work(&c->shrink_work);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
mutex_lock(&dm_bufio_clients_lock);
|
|
|
|
|
|
|
|
list_del(&c->client_list);
|
|
|
|
dm_bufio_client_count--;
|
|
|
|
__cache_size_refresh();
|
|
|
|
|
|
|
|
mutex_unlock(&dm_bufio_clients_lock);
|
|
|
|
|
2014-10-06 12:48:51 +00:00
|
|
|
BUG_ON(!RB_EMPTY_ROOT(&c->buffer_tree));
|
2011-10-31 20:19:09 +00:00
|
|
|
BUG_ON(c->need_reserved_buffers);
|
|
|
|
|
|
|
|
while (!list_empty(&c->reserved_buffers)) {
|
|
|
|
struct dm_buffer *b = list_entry(c->reserved_buffers.next,
|
|
|
|
struct dm_buffer, lru_list);
|
|
|
|
list_del(&b->lru_list);
|
|
|
|
free_buffer(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < LIST_SIZE; i++)
|
|
|
|
if (c->n_buffers[i])
|
|
|
|
DMERR("leaked buffer count %d: %ld", i, c->n_buffers[i]);
|
|
|
|
|
|
|
|
for (i = 0; i < LIST_SIZE; i++)
|
|
|
|
BUG_ON(c->n_buffers[i]);
|
|
|
|
|
2018-03-26 18:29:42 +00:00
|
|
|
kmem_cache_destroy(c->slab_cache);
|
2018-03-26 18:29:45 +00:00
|
|
|
kmem_cache_destroy(c->slab_buffer);
|
2011-10-31 20:19:09 +00:00
|
|
|
dm_io_client_destroy(c->dm_io);
|
2017-12-23 10:27:03 +00:00
|
|
|
mutex_destroy(&c->lock);
|
2022-07-25 22:26:48 +00:00
|
|
|
if (c->no_sleep)
|
|
|
|
static_branch_dec(&no_sleep_enabled);
|
2011-10-31 20:19:09 +00:00
|
|
|
kfree(c);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_client_destroy);
|
|
|
|
|
2017-01-04 19:23:52 +00:00
|
|
|
void dm_bufio_set_sector_offset(struct dm_bufio_client *c, sector_t start)
|
|
|
|
{
|
|
|
|
c->start = start;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_bufio_set_sector_offset);
|
|
|
|
|
2014-10-09 10:10:25 +00:00
|
|
|
static unsigned get_max_age_hz(void)
|
2011-10-31 20:19:09 +00:00
|
|
|
{
|
locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()
Please do not apply this to mainline directly, instead please re-run the
coccinelle script shown below and apply its output.
For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
preference to ACCESS_ONCE(), and new code is expected to use one of the
former. So far, there's been no reason to change most existing uses of
ACCESS_ONCE(), as these aren't harmful, and changing them results in
churn.
However, for some features, the read/write distinction is critical to
correct operation. To distinguish these cases, separate read/write
accessors must be used. This patch migrates (most) remaining
ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following
coccinelle script:
----
// Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and
// WRITE_ONCE()
// $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch
virtual patch
@ depends on patch @
expression E1, E2;
@@
- ACCESS_ONCE(E1) = E2
+ WRITE_ONCE(E1, E2)
@ depends on patch @
expression E;
@@
- ACCESS_ONCE(E)
+ READ_ONCE(E)
----
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: davem@davemloft.net
Cc: linux-arch@vger.kernel.org
Cc: mpe@ellerman.id.au
Cc: shuah@kernel.org
Cc: snitzer@redhat.com
Cc: thor.thayer@linux.intel.com
Cc: tj@kernel.org
Cc: viro@zeniv.linux.org.uk
Cc: will.deacon@arm.com
Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-10-23 21:07:29 +00:00
|
|
|
unsigned max_age = READ_ONCE(dm_bufio_max_age);
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2014-10-09 10:10:25 +00:00
|
|
|
if (max_age > UINT_MAX / HZ)
|
|
|
|
max_age = UINT_MAX / HZ;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2014-10-09 10:10:25 +00:00
|
|
|
return max_age * HZ;
|
|
|
|
}
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2014-10-09 10:10:25 +00:00
|
|
|
static bool older_than(struct dm_buffer *b, unsigned long age_hz)
|
|
|
|
{
|
2015-01-06 13:44:15 +00:00
|
|
|
return time_after_eq(jiffies, b->last_accessed + age_hz);
|
2014-10-09 10:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __evict_old_buffers(struct dm_bufio_client *c, unsigned long age_hz)
|
|
|
|
{
|
|
|
|
struct dm_buffer *b, *tmp;
|
2017-04-30 21:32:28 +00:00
|
|
|
unsigned long retain_target = get_retain_buffers(c);
|
|
|
|
unsigned long count;
|
2017-04-30 21:34:53 +00:00
|
|
|
LIST_HEAD(write_list);
|
2014-10-09 10:10:25 +00:00
|
|
|
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
|
2017-04-30 21:34:53 +00:00
|
|
|
__check_watermark(c, &write_list);
|
|
|
|
if (unlikely(!list_empty(&write_list))) {
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
__flush_write_list(&write_list);
|
|
|
|
dm_bufio_lock(c);
|
|
|
|
}
|
|
|
|
|
2014-10-09 10:10:25 +00:00
|
|
|
count = c->n_buffers[LIST_CLEAN] + c->n_buffers[LIST_DIRTY];
|
|
|
|
list_for_each_entry_safe_reverse(b, tmp, &c->lru[LIST_CLEAN], lru_list) {
|
|
|
|
if (count <= retain_target)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!older_than(b, age_hz))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (__try_evict_buffer(b, 0))
|
|
|
|
count--;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
2016-09-13 08:45:20 +00:00
|
|
|
cond_resched();
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
2014-10-09 10:10:25 +00:00
|
|
|
|
|
|
|
dm_bufio_unlock(c);
|
|
|
|
}
|
|
|
|
|
2019-09-12 16:07:23 +00:00
|
|
|
static void do_global_cleanup(struct work_struct *w)
|
|
|
|
{
|
|
|
|
struct dm_bufio_client *locked_client = NULL;
|
|
|
|
struct dm_bufio_client *current_client;
|
|
|
|
struct dm_buffer *b;
|
|
|
|
unsigned spinlock_hold_count;
|
|
|
|
unsigned long threshold = dm_bufio_cache_size -
|
|
|
|
dm_bufio_cache_size / DM_BUFIO_LOW_WATERMARK_RATIO;
|
|
|
|
unsigned long loops = global_num * 2;
|
|
|
|
|
|
|
|
mutex_lock(&dm_bufio_clients_lock);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
cond_resched();
|
|
|
|
|
|
|
|
spin_lock(&global_spinlock);
|
|
|
|
if (unlikely(dm_bufio_current_allocated <= threshold))
|
|
|
|
break;
|
|
|
|
|
|
|
|
spinlock_hold_count = 0;
|
|
|
|
get_next:
|
|
|
|
if (!loops--)
|
|
|
|
break;
|
|
|
|
if (unlikely(list_empty(&global_queue)))
|
|
|
|
break;
|
|
|
|
b = list_entry(global_queue.prev, struct dm_buffer, global_list);
|
|
|
|
|
|
|
|
if (b->accessed) {
|
|
|
|
b->accessed = 0;
|
|
|
|
list_move(&b->global_list, &global_queue);
|
|
|
|
if (likely(++spinlock_hold_count < 16))
|
|
|
|
goto get_next;
|
|
|
|
spin_unlock(&global_spinlock);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_client = b->c;
|
|
|
|
if (unlikely(current_client != locked_client)) {
|
|
|
|
if (locked_client)
|
|
|
|
dm_bufio_unlock(locked_client);
|
|
|
|
|
|
|
|
if (!dm_bufio_trylock(current_client)) {
|
|
|
|
spin_unlock(&global_spinlock);
|
|
|
|
dm_bufio_lock(current_client);
|
|
|
|
locked_client = current_client;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
locked_client = current_client;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&global_spinlock);
|
|
|
|
|
|
|
|
if (unlikely(!__try_evict_buffer(b, GFP_KERNEL))) {
|
|
|
|
spin_lock(&global_spinlock);
|
|
|
|
list_move(&b->global_list, &global_queue);
|
|
|
|
spin_unlock(&global_spinlock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&global_spinlock);
|
|
|
|
|
|
|
|
if (locked_client)
|
|
|
|
dm_bufio_unlock(locked_client);
|
|
|
|
|
|
|
|
mutex_unlock(&dm_bufio_clients_lock);
|
|
|
|
}
|
|
|
|
|
2014-10-09 10:10:25 +00:00
|
|
|
static void cleanup_old_buffers(void)
|
|
|
|
{
|
|
|
|
unsigned long max_age_hz = get_max_age_hz();
|
|
|
|
struct dm_bufio_client *c;
|
|
|
|
|
|
|
|
mutex_lock(&dm_bufio_clients_lock);
|
|
|
|
|
2017-04-30 21:34:53 +00:00
|
|
|
__cache_size_refresh();
|
|
|
|
|
2014-10-09 10:10:25 +00:00
|
|
|
list_for_each_entry(c, &dm_bufio_all_clients, client_list)
|
|
|
|
__evict_old_buffers(c, max_age_hz);
|
|
|
|
|
2011-10-31 20:19:09 +00:00
|
|
|
mutex_unlock(&dm_bufio_clients_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void work_fn(struct work_struct *w)
|
|
|
|
{
|
|
|
|
cleanup_old_buffers();
|
|
|
|
|
2019-09-12 16:07:23 +00:00
|
|
|
queue_delayed_work(dm_bufio_wq, &dm_bufio_cleanup_old_work,
|
2011-10-31 20:19:09 +00:00
|
|
|
DM_BUFIO_WORK_TIMER_SECS * HZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------
|
|
|
|
* Module setup
|
|
|
|
*--------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called only once for the whole dm_bufio module.
|
|
|
|
* It initializes memory limit.
|
|
|
|
*/
|
|
|
|
static int __init dm_bufio_init(void)
|
|
|
|
{
|
|
|
|
__u64 mem;
|
|
|
|
|
2013-12-05 22:33:29 +00:00
|
|
|
dm_bufio_allocated_kmem_cache = 0;
|
|
|
|
dm_bufio_allocated_get_free_pages = 0;
|
|
|
|
dm_bufio_allocated_vmalloc = 0;
|
|
|
|
dm_bufio_current_allocated = 0;
|
|
|
|
|
2018-12-28 08:34:29 +00:00
|
|
|
mem = (__u64)mult_frac(totalram_pages() - totalhigh_pages(),
|
2017-11-16 00:38:09 +00:00
|
|
|
DM_BUFIO_MEMORY_PERCENT, 100) << PAGE_SHIFT;
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
if (mem > ULONG_MAX)
|
|
|
|
mem = ULONG_MAX;
|
|
|
|
|
|
|
|
#ifdef CONFIG_MMU
|
2017-11-16 00:38:09 +00:00
|
|
|
if (mem > mult_frac(VMALLOC_TOTAL, DM_BUFIO_VMALLOC_PERCENT, 100))
|
|
|
|
mem = mult_frac(VMALLOC_TOTAL, DM_BUFIO_VMALLOC_PERCENT, 100);
|
2011-10-31 20:19:09 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
dm_bufio_default_cache_size = mem;
|
|
|
|
|
|
|
|
mutex_lock(&dm_bufio_clients_lock);
|
|
|
|
__cache_size_refresh();
|
|
|
|
mutex_unlock(&dm_bufio_clients_lock);
|
|
|
|
|
2016-08-30 16:49:11 +00:00
|
|
|
dm_bufio_wq = alloc_workqueue("dm_bufio_cache", WQ_MEM_RECLAIM, 0);
|
2011-10-31 20:19:09 +00:00
|
|
|
if (!dm_bufio_wq)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-09-12 16:07:23 +00:00
|
|
|
INIT_DELAYED_WORK(&dm_bufio_cleanup_old_work, work_fn);
|
|
|
|
INIT_WORK(&dm_bufio_replacement_work, do_global_cleanup);
|
|
|
|
queue_delayed_work(dm_bufio_wq, &dm_bufio_cleanup_old_work,
|
2011-10-31 20:19:09 +00:00
|
|
|
DM_BUFIO_WORK_TIMER_SECS * HZ);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called once when unloading the dm_bufio module.
|
|
|
|
*/
|
|
|
|
static void __exit dm_bufio_exit(void)
|
|
|
|
{
|
|
|
|
int bug = 0;
|
|
|
|
|
2019-09-12 16:07:23 +00:00
|
|
|
cancel_delayed_work_sync(&dm_bufio_cleanup_old_work);
|
2011-10-31 20:19:09 +00:00
|
|
|
destroy_workqueue(dm_bufio_wq);
|
|
|
|
|
|
|
|
if (dm_bufio_client_count) {
|
|
|
|
DMCRIT("%s: dm_bufio_client_count leaked: %d",
|
|
|
|
__func__, dm_bufio_client_count);
|
|
|
|
bug = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dm_bufio_current_allocated) {
|
|
|
|
DMCRIT("%s: dm_bufio_current_allocated leaked: %lu",
|
|
|
|
__func__, dm_bufio_current_allocated);
|
|
|
|
bug = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dm_bufio_allocated_get_free_pages) {
|
|
|
|
DMCRIT("%s: dm_bufio_allocated_get_free_pages leaked: %lu",
|
|
|
|
__func__, dm_bufio_allocated_get_free_pages);
|
|
|
|
bug = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dm_bufio_allocated_vmalloc) {
|
|
|
|
DMCRIT("%s: dm_bufio_vmalloc leaked: %lu",
|
|
|
|
__func__, dm_bufio_allocated_vmalloc);
|
|
|
|
bug = 1;
|
|
|
|
}
|
|
|
|
|
2015-11-25 10:16:05 +00:00
|
|
|
BUG_ON(bug);
|
2011-10-31 20:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(dm_bufio_init)
|
|
|
|
module_exit(dm_bufio_exit)
|
|
|
|
|
|
|
|
module_param_named(max_cache_size_bytes, dm_bufio_cache_size, ulong, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(max_cache_size_bytes, "Size of metadata cache");
|
|
|
|
|
|
|
|
module_param_named(max_age_seconds, dm_bufio_max_age, uint, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(max_age_seconds, "Max age of a buffer in seconds");
|
2014-10-09 10:10:25 +00:00
|
|
|
|
2017-04-30 21:32:28 +00:00
|
|
|
module_param_named(retain_bytes, dm_bufio_retain_bytes, ulong, S_IRUGO | S_IWUSR);
|
2014-10-09 10:10:25 +00:00
|
|
|
MODULE_PARM_DESC(retain_bytes, "Try to keep at least this many bytes cached in memory");
|
2011-10-31 20:19:09 +00:00
|
|
|
|
|
|
|
module_param_named(peak_allocated_bytes, dm_bufio_peak_allocated, ulong, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(peak_allocated_bytes, "Tracks the maximum allocated memory");
|
|
|
|
|
|
|
|
module_param_named(allocated_kmem_cache_bytes, dm_bufio_allocated_kmem_cache, ulong, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(allocated_kmem_cache_bytes, "Memory allocated with kmem_cache_alloc");
|
|
|
|
|
|
|
|
module_param_named(allocated_get_free_pages_bytes, dm_bufio_allocated_get_free_pages, ulong, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(allocated_get_free_pages_bytes, "Memory allocated with get_free_pages");
|
|
|
|
|
|
|
|
module_param_named(allocated_vmalloc_bytes, dm_bufio_allocated_vmalloc, ulong, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(allocated_vmalloc_bytes, "Memory allocated with vmalloc");
|
|
|
|
|
|
|
|
module_param_named(current_allocated_bytes, dm_bufio_current_allocated, ulong, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(current_allocated_bytes, "Memory currently used by the cache");
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Mikulas Patocka <dm-devel@redhat.com>");
|
|
|
|
MODULE_DESCRIPTION(DM_NAME " buffered I/O library");
|
|
|
|
MODULE_LICENSE("GPL");
|