From nobody Wed Nov 12 13:01:36 2025 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4d63T21Tflz6Gxh8 for ; Wed, 12 Nov 2025 13:01:58 +0000 (UTC) (envelope-from rick.macklem@gmail.com) Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4d63T15Gcwz3hlD for ; Wed, 12 Nov 2025 13:01:57 +0000 (UTC) (envelope-from rick.macklem@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-b72cbc24637so178383066b.0 for ; Wed, 12 Nov 2025 05:01:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762952511; x=1763557311; darn=freebsd.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HUsS2yro3SgBqO07A0Ga1QPxPIljdh8Odn9/6SmafAA=; b=ImKquqF6UgrIY2wwpLBFrQEb18zZb6+6Rd+lkAxHVVfCJOgeIBQ3qHZ6lrseUc9BB+ mMHF1pfI1HuO+yFrpwFrLNDgKhn7QB8u19p/nnaLQrOEp/hH/trZTr0cW8Lk42/9KYNl SCRJy12ZekoHOVXrxu5QcuXu+6B3GSoRcbiwlcxVF/zSTaTk5HF1RxxNGZ4dKGPNISVa c+6kSOs1VRj2V1Yt90byclFJSlPvd5V0ys6R4RzX2gDP9G3JFXJmA6qdlntabtCXMDvH J86lsREWRTX7kuNxaQsFUxBD79GKf1YpJ1tbb2Q7a4PNFy0APr/sZJUnjAcXKvKgzuXq 6tjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762952511; x=1763557311; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=HUsS2yro3SgBqO07A0Ga1QPxPIljdh8Odn9/6SmafAA=; b=N9TaJV80kL7UzVW0j88XLbdbCWSjisXOjtfrc0zCXsT8z3yj6vJs7FfQ75Q13Cy0tx khrVPsIGUObO1apLdFrwanCYFipfYUJm0aeSGJSSiy+I5mbN3lntDQWGU46i/fbF74+Q WdJ7EZZtnyQcT7jqRbw9fO+jemoocVr7FD268I60jzxcTYu0Cpp6Oc8n9BwQr32v/JkA yUmJF+dlZWfcVnjkx8DB4Be1lW6zWwK8aDGVZmK1PTjV+ecAF9pZKiq/l6qtxI2GRh4r Vfvuo4k2p5B/qhYTWLMPSV0DT3pHhPSCWQQ/0qPc3lXMM6i9ZO9yC55+3e0G8+yb0oaw joJw== X-Gm-Message-State: AOJu0YxLDEzmDs0+iRXPpEoCzWl+cmCN7dVH3JwKKf4Zf8BFX5F+lHWT WoI+vxn1HltoC40TXmw43YhEf1CjL1o/g6vNCtZ622lPCcNvQ+KRK+vFUET6gM6ocol1zNn846Q OAwtm5pGf04JgVuXj0xd9WcbmanQK/w== X-Gm-Gg: ASbGncupKW7mn/unmBj29rsoOW4UFZTokDs833CwoOEQJEHXnLFU7+EWCrVLIrRbXo2 HRJCLes02JNzgQRfJC/1JLikgaI318yKWkr6GUzUzuS2DSVg//zR3KHnRn0NrFQZLZih3bnKdCs SQPwF3l5viTyB0WMOz2RU3wmwT1c/rnDl7dXOueKPnmoxt9F6hTSm9C4VkEtCbrZm55+HPiG7vr AUCxAOdHL1Sj/9CQpAMZTfwsNN4XtyHrVds670HoZ8+W7CRI0qar7aSr0A= X-Google-Smtp-Source: AGHT+IHPtoBtPZCu3UfeT63FkRabl1ksja5cL/HRs8kgpOlw6Knxa2lpaou8TqFVKa+Y3X5E2E+/BJukc80mriZpubM= X-Received: by 2002:a17:907:96a6:b0:b73:27c4:fb7e with SMTP id a640c23a62f3a-b7331ad224amr279081266b.54.1762952510435; Wed, 12 Nov 2025 05:01:50 -0800 (PST) List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org MIME-Version: 1.0 References: In-Reply-To: From: Rick Macklem Date: Wed, 12 Nov 2025 05:01:36 -0800 X-Gm-Features: AWmQ_bkwIA8Zm_WwRcbJHlxweg-TVVmxfbo1zXWPd3x54YBw_R1IBrUs-i0AWKY Message-ID: Subject: Re: Implementing VOP_READPLUS() in FreeBSD 15? To: Lionel Cons Cc: freebsd-hackers@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; TAGGED_FROM(0.00)[]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 4d63T15Gcwz3hlD On Wed, Nov 12, 2025 at 3:54=E2=80=AFAM Lionel Cons wrote: > > On Fri, 7 Nov 2025 at 03:02, Rick Macklem wrote: > > > > On Thu, Nov 6, 2025 at 11:40=E2=80=AFAM Aur=C3=A9lien Couderc > > wrote: > > > > > > This is a followup to a discussion with the nfs-ganesha developers. > > > > > > Could FreeBSD implement a VOP_READPLUS() in FreeBSD 15, please? > > > > > > Citing Lionel Cons/CERN: > > > > But the point is to optimise the read(). First, you have less traff= ic over the wire (which is a > > > > thing if your reads are in the gigabyte range for large VMs), and i= t tells the VM host that it > > > > can just map all those MMU pages representing the hole to the "defa= ult zero page", which > > > > in turn saves lots of space in the L3 and L2 caches ----> THIS DOES= WONDERS to VM > > > > performance. > > > > > > > > Example: > > > > The performance benefit here comes from the fast that instead of ma= pping a 1TB hole > > > > (1099511627776 bytes) to individual 524288 2M pages (x86 2M hugepag= e size), and then > > > > potentially reading from them, you just have ONE 2M page in the cac= he, and all reads come > > > > from that. > > > > > > > > READ_PLUS is THE game changer for that kind of application, especia= lly in our case (HPC > > > > simulations). > > Why doesn't the application use lseek(SEEK_DATA/SEEK_HOLE) and only rea= d(2) the > > data segments? > > Because these are extra syscalls with extra latency, and this is not > applicable to Infiniband/RDMA. Note that FreeBSD's NFS does not currently handle RDMA. Since there has been no way for me to do testing (FreeBSD does not have the rxe or siw drivers that Linux does), I haven't worked on it until literally days a= go. I am now making an attempt to get that working over the next year, but I won't make any guarantees w.r.t. getting it working. (This is my "for fun" project for the next year.) > > But let's move back in history first: > The filesystem op READ_PLUS (and WRITE_PLUS) comes from Sun > Microsystems. Originally conceived by Eric Blake and Roland Mainz as > part of the "new VM system", and was slated to be integrated in > Solaris 12. > But when ORACLE bought SUN, Solaris 12 was canceled - but at least the > new VM system was backported to Solaris 11.3 and 11.4. > About the fate of the new IO system, I do not know. > > How would the new IO system look like: > 1. READ_PLUS, to issue a read, instead of getting a straight buffer > filled it returned a set of ranges+data. Each range is one of DATA, > HOLE, ADB (application data block). > 2. WRITE_PLUS is READ_PLUS in reverse, you pass a set of either DATA; > HOLE or ADB to the driver, plus flags which sets can be concurrently > written. > > For backwards compatibility there is a method to query which IO calls > are supported by a filesystem, and if no bits of READ_PLUS or > WRITE_PLUS are set, then it will be emulated. > > > > > This is implemented now in FreeBSD and in several other POSIX-like OSs > > and avoids > > problems like filling the buffer cache with blocks of all zeros or > > returning a lot of blocks > > with all zeros to the application via read(2). > > Yeah, but touching each page you read just to scan for zeros is > inefficient, especially if you have 2M large pages and RDMA. This > kills performance. > > > > > Right now, I not aware of any read_plus(2) syscall (please correct me > > if I am wrong on this), > > so applications that read(2) sparse files without bothering to do > > lseek(SEEK_DATA/SEEK_HOLE) will get a lot of 0s to process. > > > > To do VOP_READPLUS() is a lot of work. Once the VOP_READPLUS() is defin= ed, > > there needs to be implementations in the various local fs (ZFS, UFS, > > ..). That requires > > work by people who know these areas. I am only minimally conversant wit= h either > > ZFS or UFS and would not want to attempt to do a good VOP_READPLUS() > > implementation for either of them. (Without fs specific > > implementations, there isn't > > much point in doing it, imho.) > > Both UFS and ZFS can run via emulation, until there is a native implement= ation. A default VOP_READPLUS() could be implemented using SEEK_DATA/SEEK_HOLE. My concern is that this will result in a lot of overhead in the server, since SEEK_DATA/SEEK_HOLE can be expensive operations. - For ZFS, they are a killer for recently written files unless the sysctl called vfs.zfs..dsync, (sorry I don't have a system handy to look up an exact name) is set 0. When set to 0, holes in recently written files will be missed, but for VOP_READPLUS() that is only a performance issue. - For UFS, it is non-linear, since large files involve reading/searching mo= re indirect and doubly indirect blocks (if I recall my stale UFS correctly). Hopefully they all stay in the buffer cache once first read. Part of the problem is there is no way to know if a file is sparse without doing the SEEK_DATA/SEEK_HOLE and the worst case is probably a large file without any holes. -> VOP_READPLUS (and presumably NFSv4.2's READ_PLUS) will end up returning 1Mbyte of data. Then the next call will do the same, and so on. But unlike the normal NFS Read, every RPC will do a SEEK_DATA/SEEK_HOLE to look for the hole that doesn't exist. The result of all this is that the emulation isn't going to be very satisfactory and, if no one is working on the actual VOP_READPLUS() implementations for these file systems, it will be all there is and you're stuck with it. (In Linux, I believe there was an implementation of NFSv4.2 READ_PLUS that just did Read and didn't even look for holes, but that might have changed now and I might not be correct w.r.t. this.) A final reminder. I am one retired guy who does this as a hobby. If you really want this to happen, finding someone (volunteer or paid) that can do the VOP_READPLUS() for UFS and ZFS and contribute good patches that do it would pave the way for NFS support. rick > > Lionel >