2019-12-14 00:22:14 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
#ifndef BTRFS_DISCARD_H
|
|
|
|
#define BTRFS_DISCARD_H
|
|
|
|
|
2020-01-02 21:26:37 +00:00
|
|
|
#include <linux/sizes.h>
|
|
|
|
|
2019-12-14 00:22:14 +00:00
|
|
|
struct btrfs_fs_info;
|
|
|
|
struct btrfs_discard_ctl;
|
|
|
|
struct btrfs_block_group;
|
|
|
|
|
2020-01-02 21:26:37 +00:00
|
|
|
/* Discard size limits */
|
2020-01-02 21:26:38 +00:00
|
|
|
#define BTRFS_ASYNC_DISCARD_DEFAULT_MAX_SIZE (SZ_64M)
|
2020-01-02 21:26:39 +00:00
|
|
|
#define BTRFS_ASYNC_DISCARD_MAX_FILTER (SZ_1M)
|
|
|
|
#define BTRFS_ASYNC_DISCARD_MIN_FILTER (SZ_32K)
|
|
|
|
|
|
|
|
/* List operations */
|
|
|
|
void btrfs_discard_check_filter(struct btrfs_block_group *block_group, u64 bytes);
|
2020-01-02 21:26:37 +00:00
|
|
|
|
btrfs: handle empty block_group removal for async discard
block_group removal is a little tricky. It can race with the extent
allocator, the cleaner thread, and balancing. The current path is for a
block_group to be added to the unused_bgs list. Then, when the cleaner
thread comes around, it starts a transaction and then proceeds with
removing the block_group. Extents that are pinned are subsequently
removed from the pinned trees and then eventually a discard is issued
for the entire block_group.
Async discard introduces another player into the game, the discard
workqueue. While it has none of the racing issues, the new problem is
ensuring we don't leave free space untrimmed prior to forgetting the
block_group. This is handled by placing fully free block_groups on a
separate discard queue. This is necessary to maintain discarding order
as in the future we will slowly trim even fully free block_groups. The
ordering helps us make progress on the same block_group rather than say
the last fully freed block_group or needing to search through the fully
freed block groups at the beginning of a list and insert after.
The new order of events is a fully freed block group gets placed on the
unused discard queue first. Once it's processed, it will be placed on
the unusued_bgs list and then the original sequence of events will
happen, just without the final whole block_group discard.
The mount flags can change when processing unused_bgs, so when flipping
from DISCARD to DISCARD_ASYNC, the unused_bgs must be punted to the
discard_list to be trimmed. If we flip off DISCARD_ASYNC, we punt
free block groups on the discard_list to the unused_bg queue which will
do the final discard for us.
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Dennis Zhou <dennis@kernel.org>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-12-14 00:22:15 +00:00
|
|
|
/* Work operations */
|
2019-12-14 00:22:14 +00:00
|
|
|
void btrfs_discard_cancel_work(struct btrfs_discard_ctl *discard_ctl,
|
|
|
|
struct btrfs_block_group *block_group);
|
|
|
|
void btrfs_discard_queue_work(struct btrfs_discard_ctl *discard_ctl,
|
|
|
|
struct btrfs_block_group *block_group);
|
|
|
|
void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl,
|
|
|
|
bool override);
|
|
|
|
bool btrfs_run_discard_work(struct btrfs_discard_ctl *discard_ctl);
|
|
|
|
|
2019-12-14 00:22:20 +00:00
|
|
|
/* Update operations */
|
2020-01-02 21:26:35 +00:00
|
|
|
void btrfs_discard_calc_delay(struct btrfs_discard_ctl *discard_ctl);
|
2019-12-14 00:22:20 +00:00
|
|
|
void btrfs_discard_update_discardable(struct btrfs_block_group *block_group,
|
|
|
|
struct btrfs_free_space_ctl *ctl);
|
|
|
|
|
btrfs: handle empty block_group removal for async discard
block_group removal is a little tricky. It can race with the extent
allocator, the cleaner thread, and balancing. The current path is for a
block_group to be added to the unused_bgs list. Then, when the cleaner
thread comes around, it starts a transaction and then proceeds with
removing the block_group. Extents that are pinned are subsequently
removed from the pinned trees and then eventually a discard is issued
for the entire block_group.
Async discard introduces another player into the game, the discard
workqueue. While it has none of the racing issues, the new problem is
ensuring we don't leave free space untrimmed prior to forgetting the
block_group. This is handled by placing fully free block_groups on a
separate discard queue. This is necessary to maintain discarding order
as in the future we will slowly trim even fully free block_groups. The
ordering helps us make progress on the same block_group rather than say
the last fully freed block_group or needing to search through the fully
freed block groups at the beginning of a list and insert after.
The new order of events is a fully freed block group gets placed on the
unused discard queue first. Once it's processed, it will be placed on
the unusued_bgs list and then the original sequence of events will
happen, just without the final whole block_group discard.
The mount flags can change when processing unused_bgs, so when flipping
from DISCARD to DISCARD_ASYNC, the unused_bgs must be punted to the
discard_list to be trimmed. If we flip off DISCARD_ASYNC, we punt
free block groups on the discard_list to the unused_bg queue which will
do the final discard for us.
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Dennis Zhou <dennis@kernel.org>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-12-14 00:22:15 +00:00
|
|
|
/* Setup/cleanup operations */
|
|
|
|
void btrfs_discard_punt_unused_bgs_list(struct btrfs_fs_info *fs_info);
|
2019-12-14 00:22:14 +00:00
|
|
|
void btrfs_discard_resume(struct btrfs_fs_info *fs_info);
|
|
|
|
void btrfs_discard_stop(struct btrfs_fs_info *fs_info);
|
|
|
|
void btrfs_discard_init(struct btrfs_fs_info *fs_info);
|
|
|
|
void btrfs_discard_cleanup(struct btrfs_fs_info *fs_info);
|
|
|
|
|
|
|
|
#endif
|