From owner-freebsd-hackers@freebsd.org Thu Nov 22 23:20:24 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B65591133C23 for ; Thu, 22 Nov 2018 23:20:24 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C90206D43B for ; Thu, 22 Nov 2018 23:20:23 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-io1-xd35.google.com with SMTP id a3so7581160ioc.4 for ; Thu, 22 Nov 2018 15:20:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ib7Roiw6HVomcORvmY9bkppGJJqna4XoYuIp+aOxH9M=; b=oeoasWoZsHz+fGNDMFrxvmRcXUMGOeBreASl6GpzqLPx6S8NSQxh9x8b/z9YaDiafa TyWMyosEFZskDExNDcBtWEpq3AJxWFVfomdoZCVZ29KgbvL7QrsxnvxBclvAxkVveKVs QKoP+6/n/+OF5w45w66fySyYk+j6Dt70TDk/zULjk+UxUTpjFgXJMfo9FInMGDnsrKIL g8AXM8XIJpv5Fa+hB42w0YhAVo72OOloQE5HQ7WjxHb0r62UTcuhAfARoZRHrvp3RapM fjxtFyumwbI3v7M77tUNFdntGu9syVAmkBPo0P6MLe60BFUwRcBlcyIJoagdhC/cjbND +/vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ib7Roiw6HVomcORvmY9bkppGJJqna4XoYuIp+aOxH9M=; b=Zfthgo08gYsxAsd0kpAtFnk2HevPsdIZ1Uyl/Ss592FYwJC1JPOtHjfU95SWsC8i7I qMdCMyusHedOVzJCm8+qF6SJHSkvnI1xCbxfLEQzoRRu/Voex/karmXJ2xynVWC8VkLs W1ZUZ33X75Pe5TXq2hpH+ZH1PWPDZN3w4wPU3v4NGWGfHy9pUAeHHrDOOD8/Vms8GnVq K5hEh0Td/o1BoxzRvRfpS9ahA0vJhvcTbc2VHu1O6yKaC5rRdfruz5CJ+OQ/J1ia7JAl SDsry16uoSSLC9xcRz8psCIor3Uh3ETN5wYw7poo0/7jzN8osplOHAWxH6hbZMQiGaR9 riwg== X-Gm-Message-State: AA+aEWZs3C2J1TiwG7/bv0aOEcC21FzbpBCdUawOK2o9/olYyaL/agDE xW4zKeTdaYFWcvxYhDYfLNCjQq4kz/8ol7pbZlQq6pe9 X-Google-Smtp-Source: AFSGD/WDn/AtuyQYkEJ66qJ7K2qNsLp59Yym6CUScHXX+bOfhT2Qu95YjONi2WiA03QG3Ok8CxdGJ3LGzt2IdIrkMUw= X-Received: by 2002:a6b:7809:: with SMTP id j9-v6mr9183689iom.299.1542928822690; Thu, 22 Nov 2018 15:20:22 -0800 (PST) MIME-Version: 1.0 References: <7699de57-d903-1d61-ee42-062ed312b20d@grosbein.net> In-Reply-To: <7699de57-d903-1d61-ee42-062ed312b20d@grosbein.net> From: Warner Losh Date: Thu, 22 Nov 2018 16:20:10 -0700 Message-ID: Subject: Re: TRIM utility To: Eugene Grosbein Cc: FreeBSD Hackers X-Rspamd-Queue-Id: C90206D43B X-Spamd-Result: default: False [-5.52 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[bsdimp-com.20150623.gappssmtp.com]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_SHORT(-0.96)[-0.963,0]; NEURAL_HAM_LONG(-1.00)[-0.999,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; DMARC_NA(0.00)[bsdimp.com]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.01)[cached: ALT1.aspmx.l.google.com]; DKIM_TRACE(0.00)[bsdimp-com.20150623.gappssmtp.com:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[5.3.d.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; R_SPF_NA(0.00)[]; FORGED_SENDER(0.30)[imp@bsdimp.com,wlosh@bsdimp.com]; RCVD_TLS_LAST(0.00)[]; IP_SCORE(-2.55)[ip: (-9.05), ipnet: 2607:f8b0::/32(-2.10), asn: 15169(-1.51), country: US(-0.09)]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[imp@bsdimp.com,wlosh@bsdimp.com]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Server: mx1.freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Nov 2018 23:20:24 -0000 On Thu, Nov 22, 2018, 1:36 PM Eugene Grosbein Hi! > > I found we have no utility capable to perform TRIM for the whole SSD device > or arbitrary part of it, so I wrote simple one. I can't think of nice name > for it, so proposal are welcome! Draft name is "erase". > > I ask for pre-commit code review, too. > The code is tested with TRIM-capable SSD and non-capable other devices. > > Currently it has four options, all of them are, hmm, optional: > > -b: to specify offset from the beginning of the device for trimmed region > instead of default 0; > -l: to specify offset from the "-b" margin - length - for trimmed region > instead of whole device; > -r rfile: for alternative way to specify length as length of referenced > file; > This seems really obscure and would be better handled by a stat command. -v: for verbose mode that shows final values for the beginning offset and > length. > > Later options override previous ones. Then it expects a list of device > names as arguments: > > erase ada0 > erase /dev/ada0s1 > erase -b 4096 -r file.img -v /dev/da0 /dev/da1 /dev/da2 > > The code: > > http://www.grosbein.net/freebsd/erase.c > http://www.grosbein.net/freebsd/Makefile.erase > > My "mandoc" skills are very poor and English is not my native language, > so any help with manual page creation will be appreciated. > > Eugene Grosbein > > P.S. I realized that our kernel-level TRIM support has no connection to > cam(4) nor to geom(4), > so distinct utility instead of addition to camcontrol(8) or geom(8). > "erase" is a really bad name. It's fraught with too many overloaded meanings. "trim" is likely the least bad name we can use. "delete" is similarly bad, even though that name is in the ioctl and in BIO_DELETE. "unmap" is the SCSI term, so it wouldn't be terrible, though the term is less widely used than "trim" is for this stuff. None of the other command names for more obscure technologies are general enough or widely enough known. "discard" is the Linux mount option, which seems less descriptive. Linux has a fstrim command, which does something kinda similar (it's a lot like fsck -E to erase unused parts of the filesystem), so there is some overlap. I couldn't find a dedicated command to do that, but if it does, we should follow that convention to reimplement. It feels to me to be a dd conv= option, but that isn't reflected in any implementation I could find, so that suggests I'm nuts (though sparse is a weak match). Warner >