1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-17 06:04:23 +03:00

Improve the discard documentation. Also improve discard code in

pv_manip.c to properly account for case when pe_start=0 and the first
physical extent is to be released (currently skip the first extent to
avoid discarding the PV label).
This commit is contained in:
Mike Snitzer 2011-04-13 18:26:39 +00:00
parent 727373c176
commit ffcb1b9c2c
4 changed files with 31 additions and 20 deletions

View File

@ -1,7 +1,7 @@
Version 2.02.85 - Version 2.02.85 -
=================================== ===================================
Add "devices/issue_discards" to lvm.conf. Add "devices/issue_discards" to lvm.conf.
Issue discards on lvremove if enabled and both storage and kernel have support. Issue discards on lvremove, lvreduce, etc if enabled and supported.
Fix incorrect tests for dm_snprintf() failure. Fix incorrect tests for dm_snprintf() failure.
Fix some unmatching sign comparation gcc warnings in the code. Fix some unmatching sign comparation gcc warnings in the code.
Allow lv_extend() to work on zero length intrinsically layered LVs. Allow lv_extend() to work on zero length intrinsically layered LVs.

View File

@ -152,11 +152,15 @@ devices {
# pv_min_size = 2048 # pv_min_size = 2048
pv_min_size = 512 pv_min_size = 512
# Issue discards to an LV's underlying PV(s) when the LV is removed. # Issue discards to a logical volumes's underlying physical volume(s) when
# Discards inform the storage that a region is no longer in use. If set # the logical volume is no longer using the physical volumes' space (e.g.
# lvremove, lvreduce, etc). Discards inform the storage that a region is
# no longer in use. Storage that supports discards advertise the protocol
# specific way discards should be issued by the kernel (TRIM, UNMAP, or
# WRITE SAME with UNMAP bit set). Not all storage will support or benefit
# from discards but SSDs and thinly provisioned LUNs generally do. If set
# to 1, discards will only be issued if both the storage and kernel provide # to 1, discards will only be issued if both the storage and kernel provide
# support. Not all storage will support or benefit from discards but SSDs # support.
# or thinly provisioned LUNs generally do.
# 1 enables; 0 disables. # 1 enables; 0 disables.
issue_discards = 0 issue_discards = 0
} }

View File

@ -191,9 +191,9 @@ struct pv_segment *assign_peg_to_lvseg(struct physical_volume *pv,
int release_pv_segment(struct pv_segment *peg, uint32_t area_reduction) int release_pv_segment(struct pv_segment *peg, uint32_t area_reduction)
{ {
uint64_t discard_offset; uint64_t discard_offset_sectors;
uint64_t pe_start = peg->pv->pe_start; uint64_t pe_start = peg->pv->pe_start;
uint32_t discard_area_reduction = area_reduction; uint64_t discard_area_reduction = area_reduction;
if (!peg->lvseg) { if (!peg->lvseg) {
log_error("release_pv_segment with unallocated segment: " log_error("release_pv_segment with unallocated segment: "
@ -209,16 +209,20 @@ int release_pv_segment(struct pv_segment *peg, uint32_t area_reduction)
"devices/issue_discards", DEFAULT_ISSUE_DISCARDS) && "devices/issue_discards", DEFAULT_ISSUE_DISCARDS) &&
dev_discard_max_bytes(peg->pv->fmt->cmd->sysfs_dir, peg->pv->dev) && dev_discard_max_bytes(peg->pv->fmt->cmd->sysfs_dir, peg->pv->dev) &&
dev_discard_granularity(peg->pv->fmt->cmd->sysfs_dir, peg->pv->dev)) { dev_discard_granularity(peg->pv->fmt->cmd->sysfs_dir, peg->pv->dev)) {
if (!pe_start) { discard_offset_sectors = (peg->pe + peg->lvseg->area_len - area_reduction) *
/* skip the first extent */ peg->pv->vg->extent_size + pe_start;
pe_start = peg->pv->vg->extent_size; if (!discard_offset_sectors) {
/*
* pe_start=0 and the PV's first extent contains the label.
* Must skip past the first extent.
*/
discard_offset_sectors = peg->pv->vg->extent_size;
discard_area_reduction--; discard_area_reduction--;
} }
discard_offset = peg->pe + peg->lvseg->area_len - area_reduction; log_debug("Discarding %" PRIu64 " extents offset %" PRIu64 " sectors on %s.",
discard_offset = (discard_offset * peg->pv->vg->extent_size) + pe_start; discard_area_reduction, discard_offset_sectors, dev_name(peg->pv->dev));
log_debug("Discarding %" PRIu32 " extents offset %" PRIu64 " sectors on %s.", if (discard_area_reduction &&
discard_area_reduction, discard_offset, dev_name(peg->pv->dev)); !dev_discard_blocks(peg->pv->dev, discard_offset_sectors << SECTOR_SHIFT,
if (!dev_discard_blocks(peg->pv->dev, discard_offset << SECTOR_SHIFT,
discard_area_reduction * peg->pv->vg->extent_size * SECTOR_SIZE)) discard_area_reduction * peg->pv->vg->extent_size * SECTOR_SIZE))
return_0; return_0;
} }

View File

@ -181,11 +181,14 @@ ignore devices smaller than 2MB (i.e. floppy drives):
pv_min_size = 2048 pv_min_size = 2048
.IP .IP
\fBissue_discards\fP \(em \fBissue_discards\fP \(em
Issue discards to an LV's underlying PV(s) when the LV is removed. Discards Issue discards to a logical volumes's underlying physical volume(s) when the
inform the storage that a region is no longer in use. If set to 1, discards will logical volume is no longer using the physical volumes' space (e.g. lvremove,
only be issued if both the storage and kernel provide support. Not all storage lvreduce, etc). Discards inform the storage that a region is no longer in use.
will support or benefit from discards but SSDs or thinly provisioned LUNs Storage that supports discards advertise the protocol specific way discards
generally do. should be issued by the kernel (TRIM, UNMAP, or WRITE SAME with UNMAP bit set).
Not all storage will support or benefit from discards but SSDs and thinly
provisioned LUNs generally do. If set to 1, discards will only be issued if
both the storage and kernel provide support.
.IP .IP
.TP .TP
\fBallocation\fP \(em Space allocation policies \fBallocation\fP \(em Space allocation policies