DM-Crypt Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Milan Broz <mbroz@redhat.com>
To: Alexander Koch <mail@alexanderkoch.net>
Cc: dm-crypt@saout.de
Subject: Re: [dm-crypt] Testing TRIM with hdparm on dm-crypt
Date: Wed, 09 Nov 2011 19:54:24 +0100	[thread overview]
Message-ID: <4EBACC60.4010907@redhat.com> (raw)
In-Reply-To: <4EBAC310.6010104@alexanderkoch.net>


On 11/09/2011 07:14 PM, Alexander Koch wrote:
> Hello everyone,
> 
> I'm trying to verify that TRIM is actually working on my dm-crypt (LUKS) 
> encrypted LVM volume with the following layers:
> 
>    SSD (Crucial M4 128GB) -> LVM -> LUKS -> ext4
> 
> I followed the guide available at [1], which includes these steps:
> 
>   1) create a random-filled file, sync to disk
>   2) fetch LBAs via 'hdparm --fibmap'
>   3) pick one sector, raw-read contents with 'hdparm --read-sector'
>   4) delete the file, sync to disk
>   5) re-read the sector chosen above, verify it contains zeroes
> 
> Unfortunately I already get a zeroed sector in step three:
> 
>  > $ hdparm --read-sector 271984 /dev/sdd
>  >
>  > /dev/sdd:
>  > reading sector 271984: succeeded
>  > 0000 0000 0000 0000 0000 0000 0000 0000
>  > 0000 0000 0000 0000 0000 0000 0000 0000
>  > 0000 0000 0000 0000 0000 0000 0000 0000
>  > 0000 0000 0000 0000 0000 0000 0000 0000
>  > (...)
> 
> 
> Is there any LBA-calculation I must do because of the LVM layer?

If LVM provides just linear mapping of LV, it is about calculating
proper sector offset you need to add to calculated value here.

hdparm uses just top level device offset.

Also note you will NEVER get zeroes on top level device if dm-crypt
is involved. TRIM is bypassed to lower level device, so zeroes are
on hw, but dm-crypt interprets it as ciphertext, so you get "random"
noise on top level device (decrypted zeroes).

Maybe better an example - this is test config, ext4 on LUKS on LVM on sdb

# lsblk /dev/sdb -f
NAME                FSTYPE      LABEL MOUNTPOINT
sdb                 LVM2_member       
`-vg_test-lv (dm-0) crypto_LUKS       
  `-crypt_lv (dm-1) ext4              /mnt/tst

Here are the mapping tables:

# dmsetup table
crypt_lv: 0 405504 crypt aes-cbc-essiv:sha256 <key> 0 254:0 4096
vg_test-lv: 0 409600 linear 8:16 2048

So, crypt_lv has data offset 4096 sectors (LUKS metadata) and LV under
it has data offset 2048 sectors (LVM metadata).

So sector 0 of crypt_lv is mapped to sector 6144 (4096 + 2048) of /dev/sdb.
This is the offset you should use in calculations. Note this is always
in 512 bytes sectors but drive can use 4096 sectors.

So TRIM for sector 10 on /dev/mapper/crypt_lv should be forwarded
as TRIM for sector 6154 (6144 + 10) on /dev/sdb.

Moreover, if you have TRIM enabled, you should see "allow_discards"
in mapping table for LUKS. Otherwise TRIM is blocked.

You should be also able to trace discard (and other) block requests
using blktrace/btrace, this should be really more user friendly :)

Milan

  reply	other threads:[~2011-11-09 18:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-09 18:14 [dm-crypt] Testing TRIM with hdparm on dm-crypt Alexander Koch
2011-11-09 18:54 ` Milan Broz [this message]
2011-11-09 20:25   ` Alexander Koch
2011-11-09 20:58     ` Milan Broz

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=4EBACC60.4010907@redhat.com \
    --to=mbroz@redhat.com \
    --cc=dm-crypt@saout.de \
    --cc=mail@alexanderkoch.net \
    /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