From owner-freebsd-current@freebsd.org Tue Nov 13 22:58:48 2018 Return-Path: Delivered-To: freebsd-current@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 E293F1135C0B; Tue, 13 Nov 2018 22:58:47 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (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 2FEB47D331; Tue, 13 Nov 2018 22:58:47 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-lj1-f176.google.com with SMTP id z80-v6so12393409ljb.8; Tue, 13 Nov 2018 14:58:47 -0800 (PST) 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=DPf/CmtPspLOBYHDGh2sS9n6Y0SVtBnwrdowwYhItZM=; b=BpBJK9R1xttSJT/keHXAH8MEM2cltEiVaoTZ21iId+iWx8/1SztvUmjsjoANzr/tHK 4oTtSJ18IwmwESH5ZyyCgKyP1cWuhtIL188XHwnpcEf65VM1KU01nwXkItDwpPuqdIXO +NTnS1W75n4yjwtDvh5veus8G4GA74VdUrjUlFXHpSq13qpDSyyogx0WZaP5mt9EpD1f GErts28fxym3DeBeX1wKgzCNhUJ74cK1EsjDjB90uLV6nHLFbUHBqm7Oq5ayDz59RnIh o08gUUZacAblqEiNOWmfhyVWkDPNi2Z2MWeSNCdKQ/vYNuEgNBOD4rH9Pbnrf6g+FF0w A97Q== X-Gm-Message-State: AGRZ1gIpIHEGXcwUYG+ZXLBzDkKYDlMORvZEeJcMyZv/28WLeDFe94vr AY5rW4HWyxJuFtMeM26bk1xd9ZM7dRFhEhlzL1iZqQ== X-Google-Smtp-Source: AJdET5fuShSOKx89sTzrkUQgE/J5ru2Muf3WOGoXRSpQmEVHfwxp8uRnFpK0hX+D9WBeHYMK1CQipXkC/E07ZH1uPzM= X-Received: by 2002:a2e:9356:: with SMTP id m22-v6mr4156127ljh.135.1542149918206; Tue, 13 Nov 2018 14:58:38 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Alan Somers Date: Tue, 13 Nov 2018 15:58:26 -0700 Message-ID: Subject: Re: Hole-punching, TRIM, etc To: "Conrad E. Meyer" Cc: freebsd-arch@freebsd.org, freebsd-fs , FreeBSD CURRENT X-Rspamd-Queue-Id: 2FEB47D331 X-Spamd-Result: default: False [-4.07 / 200.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; RCVD_TLS_LAST(0.00)[]; DMARC_NA(0.00)[freebsd.org]; TO_DN_SOME(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; IP_SCORE(-1.09)[ipnet: 209.85.128.0/17(-3.46), asn: 15169(-1.91), country: US(-0.09)]; MX_GOOD(-0.01)[cached: alt3.gmail-smtp-in.l.google.com]; NEURAL_HAM_SHORT(-0.97)[-0.968,0]; RCVD_IN_DNSWL_NONE(0.00)[176.208.85.209.list.dnswl.org : 127.0.5.0]; FORGED_SENDER(0.30)[asomers@freebsd.org,asomers@gmail.com]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; FROM_NEQ_ENVFROM(0.00)[asomers@freebsd.org,asomers@gmail.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-current@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Nov 2018 22:58:48 -0000 On Tue, Nov 13, 2018 at 3:51 PM Conrad Meyer wrote: > Hi Alan, > > On Tue, Nov 13, 2018 at 2:10 PM Alan Somers wrote: > > > > Hole-punching has been discussed on these lists before[1]. It basically > > means to turn a dense file into a sparse file by deallocating storage for > > some of the blocks in the middle. There's no standard API for it. Linux > > uses fallocate(2); Solaris and OSX add a new opcode to fcntl(2). > > > > A related concept is telling a block device that some blocks are no > longer > > used. SATA calls this "TRIM", SCSI calls it "UNMAP", NVMe calls it > > "Deallocate", ZBC and ZAC call it "Reset Write Pointer". They all do > > basically the same thing, and it's analogous to hole-punching for regular > > files. They are also all inaccessible from FreeBSD's userland except by > > using pass(4), which is inconvenient and protocol-specific. > > Geom devices have the DIOCGDELETE ioctl, which translates into > BIO_DELETE (which is TRIM, as I understand it). It's available in > libgeom as g_delete() and used by hastd, newfs_nandfs, and nandtool. > Ahh, I thought there must be such a thing, but I couldn't find it. > > > Linux has a BLKDISCARD ioctl for issuing TRIM-like commands from > userland, > > but it's totally undocumented and doesn't work on regular files. > > > > I propose adding support for all of these things using the fcntl(2) API. > > Using the same syntax that Solaris defined, you would be able to punch a > > hole in a regular file or TRIM blocks from an SSD. ZFS already supports > it > > (though FreeBSD's port never did, and the code was deleted in r303763). > > Here's what I would do: > > > > 1) Add the F_FREESP command to fcntl(2). > > 2) Add a .fo_space field for struct fileops > > 3) Add a devfs_space method that implements .fo_space > > 4) Add a .d_space field to struct cdevsw > > 5) Add a g_dev_space method for GEOM that implements .d_space using > > BIO_DELETE. > > 6) Add a VOP_SPACE vop > > 7) Implement VOP_SPACE for tmpfs > > 8) Add aio_freesp(2), an asynchronous version of fcntl(F_FREESP). > > Why not just add DIOCGDELETE support to various VOP_IOCTL > implementations? The file objects forward correctly through vn_ioctl > to VOP_IOCTL for both regular files and devfs VCHR nodes. > > We can emulate the Linux API if we want to be compatible there, but I > wouldn't bother with Solaris. > The only reason that I prefer the Solaris API is because it doesn't require adding another syscall, and because Linux's fallocate(2) does a whole bunch of other things besides hole-punching. What about an asynchronous version? ioctl(2) is still synchronous. Do you see any better way to hole-punch/TRIM asynchronously than with aio? > > Best, > Conrad >