From owner-freebsd-current@freebsd.org Tue Nov 13 22:50:49 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 C7ABE1135318 for ; Tue, 13 Nov 2018 22:50:48 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-it1-x12b.google.com (mail-it1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) (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 B7C4C7C779 for ; Tue, 13 Nov 2018 22:50:47 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-it1-x12b.google.com with SMTP id r12-v6so21006686ita.3 for ; Tue, 13 Nov 2018 14:50:47 -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=Ws4zhpBlCIfAr0x3JvA2o1yRCxRrylKMoR6MwFPBvaE=; b=1R+KTNqoF1Z4nStNPyYG7CucyA2U+za7fsnNc3kheEpPciZIPQdOeFLzaS6+n//J60 HkBg+Or22y8O0VpoxKN0JbTrpyBMyPPQiubvrx0xSnI+7goCblXqzzt93fxn8JhcOm13 gelIb4gGLhpdy3XNBXKi/tR2SxFIk/l8DG/fOJ9p+kpEwIGRth5tCEVikXTYrhHLmIJW FdpISED3upbDFP9SB6SQSpQ1nfKd2bVLqRuHVcVDibd2JihJpLY2PcTucMYdMi0Mdkpz hHOq/ntYFjrRW9BjKWYBrA01guXDnXENkLsZ30dUoYxsQlo1vVXAa6ks0aQ6Vq+tsUxL jI2g== 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=Ws4zhpBlCIfAr0x3JvA2o1yRCxRrylKMoR6MwFPBvaE=; b=bsrJapMBnPY4BVgr94qYN1byxcXYtUrKZDkGP3y992nnP1Kp9t3+bHwCkQM072PRfE mup4JRWvc01ND1h4qPliELaQN4GJKW736qENCT4WK9ftKVseVKW7gqNB3zjWPzsVrpjU L+JiLTnEhSVg8KrrSuJmi/p1ce+N8P7vmvirPPFcR/Ohu190T92+cwklVMT+0i+AKlz+ tyDmPbFjohwe9NpdK8MZ0E4WPgeXQhZ54nPVvyctrU8Yl2MByyF9uxC+aPWsl0vwIIRl pgChu2dbQlkpCuc/AZ54rQbCW71hCRHn6N9xOuROLpjjkK+ruPJK9/5GhlwhwczYbSfJ nA0w== X-Gm-Message-State: AGRZ1gJvg+HLV9mOT+2NFCYIUiXMU7yYbtWfC5rCspqCTqEKwmJWgfwS MhV686V9cBxXpZ2IWQ+dXWBDo7EnUtxvIc1lziNS0/Xy X-Google-Smtp-Source: AJdET5cadNmAB1aQwTMDeQsVM8FPmwqWdweg09TChImN/MG1LLTwFQJbtIaUDzfr2Dbiof3Aak0RpVrTeJjhBuiB3VQ= X-Received: by 2002:a24:eb0b:: with SMTP id h11-v6mr5341529itj.47.1542149446783; Tue, 13 Nov 2018 14:50:46 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Warner Losh Date: Tue, 13 Nov 2018 15:50:35 -0700 Message-ID: Subject: Re: Hole-punching, TRIM, etc To: Alan Somers Cc: "freebsd-arch@freebsd.org" , FreeBSD FS , FreeBSD Current X-Rspamd-Queue-Id: B7C4C7C779 X-Spamd-Result: default: False [-5.36 / 200.00]; ARC_NA(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; R_DKIM_ALLOW(-0.20)[bsdimp-com.20150623.gappssmtp.com]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-current@freebsd.org]; DMARC_NA(0.00)[bsdimp.com]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[bsdimp-com.20150623.gappssmtp.com:+]; MX_GOOD(-0.01)[cached: ALT1.aspmx.l.google.com]; RCVD_IN_DNSWL_NONE(0.00)[b.2.1.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]; NEURAL_HAM_SHORT(-0.98)[-0.977,0]; R_SPF_NA(0.00)[]; FORGED_SENDER(0.30)[imp@bsdimp.com,wlosh@bsdimp.com]; RCVD_TLS_LAST(0.00)[]; IP_SCORE(-2.37)[ip: (-6.94), ipnet: 2607:f8b0::/32(-2.89), asn: 15169(-1.92), 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-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:50:49 -0000 On Tue, Nov 13, 2018 at 3: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. > > 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). > > The greatest beneficiaries of this work would be type 2 hypervisors like > QEMU and VirtualBox with guests that use TRIM, and userland filesystems > such as fusefs-ext2 and fusefs-exfat. High-performance storage systems > using SPDK would also benefit. The last item, aio_freesp(2), may seem > unnecessary but it would really benefit my application. > > Questions, objections, flames? > So the fcntl would deallocate blocks from a filesystem only. The filesystem may issue BIO_DELETE as a result, but that's up to the filesystem, correct? On a raw device it would be translated into a BIO_DELETE command directly, correct? Warner