From: Thomas Huth <thuth@redhat.com>
To: Niklas Cassel <cassel@kernel.org>, Damien Le Moal <dlemoal@kernel.org>
Cc: linux-ide@vger.kernel.org, Shaun Tancheff <shaun@tancheff.com>,
Hannes Reinecke <hare@kernel.org>
Subject: Re: [PATCH v3 2/2] ata: libata-scsi: scale DSM TRIM payload by MAX PAGES PER DSM COMMAND
Date: Wed, 16 Sep 2026 12:18:12 +0200 [thread overview]
Message-ID: <b0a0b8e8-cc4f-4c7b-8bc5-fee0712d405a@redhat.com> (raw)
In-Reply-To: <20260702105956.2058733-6-cassel@kernel.org>
On 02/07/2026 12.59, Niklas Cassel wrote:
> DSM TRIM currently always emits a single 512-byte page of LBA Range Entries
> (ATA_MAX_TRIM_RNUM == 64 ranges), regardless of how many pages the device
> can accept in one DATA SET MANAGEMENT command.
>
> The maximum is reported by MAX PAGES PER DSM COMMAND (IDENTIFY DEVICE word
> 105). Honour it: size the TRIM descriptor as a whole number of 512-byte
> pages, bounded by that limit and by the logical sector size (the WRITE SAME
> data-out buffer is a single logical block). Build and transfer only as
> many pages as the request needs, and set the DSM COUNT field, qc->nbytes
> and the maximum WRITE SAME length in the Block Limits VPD page accordingly.
>
> Build the descriptor straight into the WRITE SAME data-out buffer using an
> atomic sg_miter mapping, instead of staging it in the shared ata_scsi_rbuf
> and copying it out. This removes the global ata_scsi_rbuf_lock and a
> memcpy from the TRIM path.
>
> While commit 9379e6b8e0f9 ("libata: Safely overwrite attached page in WRITE
> SAME xlat") replaced direct access to the data-out buffer with an
> intermediate step that writes the entries in the ata_scsi_rbuf buffer, this
> solution writes to the data-out buffer using sg_miter, which maps each
> segment with kmap_atomic (SG_MITER_ATOMIC), so it's highmem- and
> multi-segment-safe, and it's usable from the non-sleeping
> command-submission path (unlike the page_address() access that
> ata_scsi_rbuf originally replaced).
>
> A 512-byte-sector device still uses a single page, so its behaviour is
> unchanged.
>
> Add ata_id_dsm_max_pages() to read IDENTIFY DEVICE word 105.
>
> Reviewed-by: Hannes Reinecke <hare@kernel.org>
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
> ---
> drivers/ata/libata-scsi.c | 135 ++++++++++++++++++++++++++------------
> include/linux/ata.h | 13 ++++
> 2 files changed, 107 insertions(+), 41 deletions(-)
>
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index 429b03a08071..5d56ad66af77 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
> @@ -2198,6 +2198,39 @@ static unsigned int ata_scsiop_inq_89(struct ata_device *dev,
> return get_unaligned_be16(&rbuf[2]) + 4;
> }
>
> +/**
> + * ata_dsm_trim_pages - maximum DSM TRIM payload for a device, in 512-byte pages
> + * @dev: ATA device the DATA SET MANAGEMENT TRIM command will be sent to
> + *
> + * A DATA SET MANAGEMENT TRIM payload is a list of 512-byte pages, each holding
> + * up to ATA_MAX_TRIM_RNUM (64) LBA Range Entries; the format is page-based and
> + * unrelated to the logical sector size.
> + *
> + * The logical sector size still bounds it, though: the descriptor is written
> + * directly into the WRITE SAME data-out buffer, which sd sizes to a single
> + * logical block, so it can hold at most sector_size / 512 pages.
> + *
> + * Return: the maximum number of 512-byte pages a single translated WRITE SAME
> + * command may send to @dev (never less than one), that is the smaller of:
> + * - MAX PAGES PER DSM COMMAND (IDENTIFY DEVICE word 105), when the device
> + * reports a non-zero limit; and
> + * - the logical sector size expressed in 512-byte pages (see above).
> + */
Hi,
not sure whether anybody noticed it already (I did not spot a patch on
lore), but this causes an ERROR during "make htmldoc":
Documentation/driver-api/libata:604: drivers/ata/libata-scsi.c:2301: ERROR:
Unexpected indentation. [docutils]
Thomas
next prev parent reply other threads:[~2026-09-16 10:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 10:59 [PATCH v3 0/2] ata: DSM TRIM fix and improvements Niklas Cassel
2026-07-02 10:59 ` [PATCH v3 1/2] ata: libata-scsi: fix DSM TRIM for sector sizes larger than 2048 bytes Niklas Cassel
2026-07-02 10:59 ` [PATCH v3 2/2] ata: libata-scsi: scale DSM TRIM payload by MAX PAGES PER DSM COMMAND Niklas Cassel
2026-09-16 10:18 ` Thomas Huth [this message]
2026-07-06 1:26 ` [PATCH v3 0/2] ata: DSM TRIM fix and improvements Damien Le Moal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b0a0b8e8-cc4f-4c7b-8bc5-fee0712d405a@redhat.com \
--to=thuth@redhat.com \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=hare@kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=shaun@tancheff.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox