From patchwork Mon Jun 3 00:32:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13683154 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6FCEC25B74 for ; Mon, 3 Jun 2024 00:33:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92DD76B00C7; Sun, 2 Jun 2024 20:33:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DE156B00CC; Sun, 2 Jun 2024 20:33:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A5626B00CE; Sun, 2 Jun 2024 20:33:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5DF816B00C7 for ; Sun, 2 Jun 2024 20:33:24 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B55A71A04C4 for ; Mon, 3 Jun 2024 00:33:23 +0000 (UTC) X-FDA: 82187703486.16.926802B Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) by imf01.hostedemail.com (Postfix) with ESMTP id A924640002 for ; Mon, 3 Jun 2024 00:33:21 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=OYnoPBg6; spf=pass (imf01.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717374801; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=IeBJ/5oPlb9g+ArFLQs0RP3mSJ+NwqtBpi4ZC0JDGNM=; b=tLlzxZ82wkj1cYZHtukcZffedtUR6ixirtIjbPAVMacrRhIgL1bloaLzQ30er1rJRrNNG1 b2YubnyXdkKHcy91w5wbAoX5Ew3Q0LZJ+jkkOxXsG/j7OnspoWQ1DzkxlBfaDbs3tWSEIE QJWHCQItZnVtjk8zhusnIC2ZUm9xf6c= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=OYnoPBg6; spf=pass (imf01.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717374801; a=rsa-sha256; cv=none; b=Mb213/JFn1uKd9TV4hUUgBtiO1jGL53OYVVVIq8os+YR1mOrDHjADrkzwuqkoftsLNQRMJ y31rrCixMmIUd253Qtj1KKBMNy/sBe1zYdOeRErTi3Fm9PoeRJQL0c4tnAg2bGSNyiyv7b 9ZldwO6tUVIe+iovLn5tHMUnYEHpdWA= X-Envelope-To: linux-fsdevel@vger.kernel.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1717374795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=IeBJ/5oPlb9g+ArFLQs0RP3mSJ+NwqtBpi4ZC0JDGNM=; b=OYnoPBg6pxl4poMMON/6TpyfKQJV7Y0DVjK8agLVjT7YDZCqb4rCj8ep3GjQBWBiuiRtg4 Ns95sq0QeN0vY9KOWQC64MQt557Z7lPLZph/zJHTbjdEc6ecOLmWxzbN+kSfjyQVZKj94x wgefjmPwxUuC2053ufGXu/pdKgHimPM= X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: axboe@kernel.dk X-Envelope-To: kent.overstreet@linux.dev X-Envelope-To: brauner@kernel.org X-Envelope-To: viro@zeniv.linux.org.uk X-Envelope-To: bernd.schubert@fastmail.fm X-Envelope-To: linux-mm@kvack.org X-Envelope-To: josef@toxicpanda.com X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Kent Overstreet , brauner@kernel.org, viro@zeniv.linux.org.uk, Bernd Schubert , linux-mm@kvack.org, Josef Bacik Subject: [PATCH 0/5] sys_ringbuffer Date: Sun, 2 Jun 2024 20:32:57 -0400 Message-ID: <20240603003306.2030491-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A924640002 X-Stat-Signature: 8sbge6u86mur3wyektmpygkqitkiy85j X-Rspam-User: X-HE-Tag: 1717374801-735996 X-HE-Meta: U2FsdGVkX1/I/ZfGCJ1IFtPyElyQHr6zmqRexIceIjVDk+L+Y+GnKeqFd00JMfjJ5V/Lgr1pjvdfysQBXf2fTWWdXAk3N9ufXzbO2y/8f9LAw+2KVjzrsnQpIFfn74Vw7NjoyPYl/+2cRHyg0+cTKG0TGnJgzWO28XH0TN8UXWE80wFJuTcZOEuUtdHC1o+mgssc1cWz2Z8/1Q9wfWd5wVLai4n8oAI/bi/aCdjaKHuhkrWJuG+2mS1+OEw2Yr6Bmf7UFzJvjZbvzDEmKftjv7rTzk1x71O9qRpIeaerlDwT/TtN6jjcr2kooB3WjzLJ5oHovFRuagDgXcu2vz1ZfFqb7bsi3J58Qxtbfb0HUkskKNjbiYnooCTol/JF7pY+t8lDbs4p3WDLyKrboZpnptrughNUzdXaUS6VIrbzDL87j4nZzUwZMgrAiv9UV6W5zFo9optdse20/WqRWMHppc7VAjPrKq1fmkrdMEE93X677GhAZOeki344rKngMYMSXZYSY38vaocSueRN7hDIouFh7Q/3EBFUmtOl0QERqELXhR+bhLkBSe9gJQXFb4qlXcv1WQIiJn+e5RbKW0oG8TU/IuQGT9aqxCDzbLYMWIEqJZn5gIYJdXDBrXNyD8wuN7A/1bIXZh34GWss52SnNgSk7xDcmcg+o0sW5+cRdnU6VlyNSz//d6Q4fWlNbXPnqlY+2ekmHNdEVB0ZBCeDii86B3PIJs2k9gbRd0IMEP3knc/rnEuWD6INRfUnOIYfNhx2fhsUb2iQ97hi2ROIm3IRgdm6lLsaJ//qU0nlZupEleLVD404j7OKSnatjySNN6HwvCjqC6DVfyM0jKHOwIH1QZrkBq7jbmBQbSAvztia3CBEW1gEH7OGNvlHdV/35NvLZ5WaoW7mda0cIcUdnRaJw3+yv2BcwjoVVMvw0UPCPWpaNq20YyFI80r00dCrQ42+bNP5QGhAYeIBvRi 5aMPywzp LcjCZXABc105GX1gsgRRaLCzlfpc3xWDsrWLtARiverLjDWm4x6RlZGA6mdRjuCUt3yHxvUe+4HXStxKzBpsSotwVIm0+ay8MR5DIsDANBPxPE9ag7lwPQ8fjV99ggaxQgDf6 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: New syscall for mapping generic ringbuffers for arbitary (supported) file descriptors. Ringbuffers can be created either when requested or at file open time, and can be mapped into multiple address spaces (naturally, since files can be shared as well). Initial motivation is for fuse, but I plan on adding support to pipes and possibly sockets as well - pipes are a particularly interesting use case, because if both the sender and receiver of a pipe opt in to the new ringbuffer interface, we can make them the _same_ ringbuffer for true zero copy IO, while being backwards compatible with existing pipes. the ringbuffer_wait and ringbuffer_wakeup syscalls are probably going away in a future iteration, in favor of just using futexes. In my testing, reading/writing from the ringbuffer 16 bytes at a time is ~7x faster than using read/write syscalls - and I was testing with mitigations off, real world benefit will be even higher. Kent Overstreet (5): darray: lift from bcachefs darray: Fix darray_for_each_reverse() when darray is empty fs: sys_ringbuffer ringbuffer: Test device ringbuffer: Userspace test helper MAINTAINERS | 7 + arch/x86/entry/syscalls/syscall_32.tbl | 3 + arch/x86/entry/syscalls/syscall_64.tbl | 3 + fs/Makefile | 2 + fs/bcachefs/Makefile | 1 - fs/bcachefs/btree_types.h | 2 +- fs/bcachefs/btree_update.c | 2 + fs/bcachefs/btree_write_buffer_types.h | 2 +- fs/bcachefs/fsck.c | 2 +- fs/bcachefs/journal_io.h | 2 +- fs/bcachefs/journal_sb.c | 2 +- fs/bcachefs/sb-downgrade.c | 3 +- fs/bcachefs/sb-errors_types.h | 2 +- fs/bcachefs/sb-members.h | 3 +- fs/bcachefs/subvolume.h | 1 - fs/bcachefs/subvolume_types.h | 2 +- fs/bcachefs/thread_with_file_types.h | 2 +- fs/bcachefs/util.h | 28 +- fs/ringbuffer.c | 474 ++++++++++++++++++++++++ fs/ringbuffer_test.c | 209 +++++++++++ {fs/bcachefs => include/linux}/darray.h | 61 +-- include/linux/darray_types.h | 22 ++ include/linux/fs.h | 2 + include/linux/mm_types.h | 4 + include/linux/ringbuffer_sys.h | 18 + include/uapi/linux/futex.h | 1 + include/uapi/linux/ringbuffer_sys.h | 40 ++ init/Kconfig | 9 + kernel/fork.c | 2 + lib/Kconfig.debug | 5 + lib/Makefile | 2 +- {fs/bcachefs => lib}/darray.c | 12 +- tools/ringbuffer/Makefile | 3 + tools/ringbuffer/ringbuffer-test.c | 254 +++++++++++++ 34 files changed, 1125 insertions(+), 62 deletions(-) create mode 100644 fs/ringbuffer.c create mode 100644 fs/ringbuffer_test.c rename {fs/bcachefs => include/linux}/darray.h (63%) create mode 100644 include/linux/darray_types.h create mode 100644 include/linux/ringbuffer_sys.h create mode 100644 include/uapi/linux/ringbuffer_sys.h rename {fs/bcachefs => lib}/darray.c (56%) create mode 100644 tools/ringbuffer/Makefile create mode 100644 tools/ringbuffer/ringbuffer-test.c