From patchwork Mon Feb 5 12:01:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gowans, James" X-Patchwork-Id: 13545316 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 1AC13C4828D for ; Mon, 5 Feb 2024 12:03:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8923A6B0088; Mon, 5 Feb 2024 07:03:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 842C56B0089; Mon, 5 Feb 2024 07:03:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70A8C6B008A; Mon, 5 Feb 2024 07:03:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 613396B0088 for ; Mon, 5 Feb 2024 07:03:03 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3856BA19B6 for ; Mon, 5 Feb 2024 12:03:03 +0000 (UTC) X-FDA: 81757614246.28.AC180BA Received: from smtp-fw-80008.amazon.com (smtp-fw-80008.amazon.com [99.78.197.219]) by imf27.hostedemail.com (Postfix) with ESMTP id 41CF940020 for ; Mon, 5 Feb 2024 12:03:01 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b="iSaSySX/"; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf27.hostedemail.com: domain of "prvs=75897cb1d=jgowans@amazon.com" designates 99.78.197.219 as permitted sender) smtp.mailfrom="prvs=75897cb1d=jgowans@amazon.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707134581; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=09HM9kCtJQ5fhByhNyO/r0il26Ag7KNxaSp1FSa3SKw=; b=1mi+xH2b8UB2d7Y0CWM7tyzKNQLPhqYfTxvBcPB1DV+bpmZTphuToBgOsCMy8ljIfRsEya n8qUUKYlVqQ4gzLDvEgoip1+CsDAui5WK5h2uYSrmTJkwk5wpVKtd+IWalVMTjRDmkcp+h n9XWAid3WOJyBbBO9uQ6Ax9+fCKe7Vs= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b="iSaSySX/"; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf27.hostedemail.com: domain of "prvs=75897cb1d=jgowans@amazon.com" designates 99.78.197.219 as permitted sender) smtp.mailfrom="prvs=75897cb1d=jgowans@amazon.com" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707134581; a=rsa-sha256; cv=none; b=OL8BzANwge1zylE4DlHgXfNVgJOoQ3arPomSlstLEBQI6ZqrQQTQub1OwB7NmZ6s3wVwYF wPN5za9QUCXAKE3IZv5cPkRK8FBOlMmFhPSAWuz37UxDnNV5a7pb3ZjozxP5jq1hYqqSIp bS0vqqH1/KEP/CBcWuG65fwJPxnSrIw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1707134581; x=1738670581; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=09HM9kCtJQ5fhByhNyO/r0il26Ag7KNxaSp1FSa3SKw=; b=iSaSySX/2VHK2qQ/n1P9KE1HzOSCGKtuHHAM3/aaRwU6Zb63zzsyw1iG 2esS60m9X5pHDEKbrgThqcAljI3kYQXKLvawewkiwdV704mcegegX1SG+ isdSOpZHjALWdI5M/eEv1jjhv0S363Vd3sBtzj/8FblKhUscDpnDPrR9p g=; X-IronPort-AV: E=Sophos;i="6.05,245,1701129600"; d="scan'208";a="63755246" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80008.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 12:02:58 +0000 Received: from EX19MTAEUA001.ant.amazon.com [10.0.10.100:37383] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.33.186:2525] with esmtp (Farcaster) id 0e22be1f-cb32-4c25-b8b9-6a540783cffe; Mon, 5 Feb 2024 12:02:57 +0000 (UTC) X-Farcaster-Flow-ID: 0e22be1f-cb32-4c25-b8b9-6a540783cffe Received: from EX19D014EUC004.ant.amazon.com (10.252.51.182) by EX19MTAEUA001.ant.amazon.com (10.252.50.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 12:02:57 +0000 Received: from dev-dsk-jgowans-1a-a3faec1f.eu-west-1.amazon.com (172.19.112.191) by EX19D014EUC004.ant.amazon.com (10.252.51.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 12:02:50 +0000 From: James Gowans To: CC: Eric Biederman , , "Joerg Roedel" , Will Deacon , , Alexander Viro , "Christian Brauner" , , Paolo Bonzini , Sean Christopherson , , Andrew Morton , , Alexander Graf , David Woodhouse , "Jan H . Schoenherr" , Usama Arif , Anthony Yznaga , Stanislav Kinsburskii , , , Subject: [RFC 03/18] pkernfs: Define an allocator for persistent pages Date: Mon, 5 Feb 2024 12:01:48 +0000 Message-ID: <20240205120203.60312-4-jgowans@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205120203.60312-1-jgowans@amazon.com> References: <20240205120203.60312-1-jgowans@amazon.com> MIME-Version: 1.0 X-Originating-IP: [172.19.112.191] X-ClientProxiedBy: EX19D044UWB004.ant.amazon.com (10.13.139.134) To EX19D014EUC004.ant.amazon.com (10.252.51.182) X-Rspamd-Queue-Id: 41CF940020 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 3yc1ghpbbyoxcm4dk7xes49bqgkppk3e X-HE-Tag: 1707134581-644027 X-HE-Meta: U2FsdGVkX18KNfVVSN6MTEWEubtu3o8x3uXjX0ppb8zv436qtIuqb/UoTIIMrIQHp10oQSXlNI8n0svBU+O1xHgaUeubl9bjwgkSanKs1tVJwGJZuTOhxDV4aeQlKeNyI0WINpPHw43E8H0QUXkIDob+jsrBMAB3AoHxJs6WO1kWs83u1Uq2ni2eq0J5Otfk7aGEXkYDKxMrjJHd+x2jf6zo22RKxPZhjDR1/fAG/OV3NXh7jse4tyF3Qeae8lNQiBNozIRZo/3NPakOyb1TVcv/xaHCVYgHLnqbKyw8nvesodZdQs7qbCycmiqCqpoqfivT8+lCVyrAUCOvwGp744xH4q7kTN2ILm3qmWrfiO6KLfY9EAn8jMKjWFyrPXWuKpAm7UiQqtauq1FLgpUQf4QwH3hKrfcv8fh4l2/sPJTBFRlhkTbHHFBBRRt8LQKibhkejan0xNlJx+QoBIRF/ECEYa4dFioNAZaRDPvZcnyGmH1UEtNXAyaIfeb/WfOoNl+b7EQXBNkKbfDrGEIdtwWWp1xVd87RULlv5h356Q0UFXzY6YYuY1iKh2P9VONpCBwFsCZvhOw0jerjNMCiKyoqrZ/S5wa7Q6ZMoFY8eZyqXt3/zRGgW6LoH1ZjD9DWUhgNCOZPHPx71vAn3r2QYRe1NfJtLCFors54LS+rIdYjQ2QF4UQYI7R2Td6mvFPBC1FjVTIVlEsJZ9gptV4KBx+Ev0HpEXkkPWHW2Vt2S9rVUnuhOZi5WAGhyJR+ufhsdCA1DxDS33lc+3JZJeH8zlPhvfcTzv8qgnqIDyg2Wkr29l53kBNJBYVlGYK9Uu13gZehyRwPeS8K9EOJZZc5bhXD8vOOyQ73wnb6aifn/LkNE6Iug4h4ekT1d+U5y41MeG7gdvSHwy0N8czP1J+Bp4Ir6T7BooIfUrXhNILS1Z5zFIelEkL/ypuItdgDwnK+O/UNxXz1kM4al5au5lr vStXlXM3 o2J7UMvz1p8CBegAN2pEFZ2YIGmZC5iCwgoSCaJ/aoCk4UWZrRm+j1Fpcd1qujcAAzxZ1nXagtPoTKGnx1OnKD/f6XVT8kjHahlD0RUgiOxONNzpk/v3UlgAaEdxyVAXhoipCaZ3vhfjn/2KR8A8QA0mhvkhZZZ8K55FJulTtkBrqgXgj8ryjLwKZlfkKBM/TrGJE4iczo7FdJBvUlv7eNX7cCUYWFHvFxcZU7hvThh7/1gymymUvaAe3gfcggj8uJEvaoPXfyBtdcIJ+UeYuhE3yN2Xq1SKRB3s8tp5L3suUuoM= 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: This introduces the concept of a bitmap allocator for pages from the pkernfs filesystem. The allocation bitmap is stored in the second half of the first page. This imposes an artificial limit of the maximum size of the filesystem; this needs to be made extensible. The allocations can be zeroed, that's it so far. The next commit will add the ability to allocate and use it. --- fs/pkernfs/Makefile | 2 +- fs/pkernfs/allocator.c | 27 +++++++++++++++++++++++++++ fs/pkernfs/pkernfs.c | 1 + fs/pkernfs/pkernfs.h | 1 + 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 fs/pkernfs/allocator.c diff --git a/fs/pkernfs/Makefile b/fs/pkernfs/Makefile index 0a66e98bda07..d8b92a74fbc6 100644 --- a/fs/pkernfs/Makefile +++ b/fs/pkernfs/Makefile @@ -3,4 +3,4 @@ # Makefile for persistent kernel filesystem # -obj-$(CONFIG_PKERNFS_FS) += pkernfs.o inode.o dir.o +obj-$(CONFIG_PKERNFS_FS) += pkernfs.o inode.o allocator.o dir.o diff --git a/fs/pkernfs/allocator.c b/fs/pkernfs/allocator.c new file mode 100644 index 000000000000..1d4aac9c4545 --- /dev/null +++ b/fs/pkernfs/allocator.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include "pkernfs.h" + +/** + * For allocating blocks from the pkernfs filesystem. + * The first two blocks are special: + * - the first block is persitent filesystme metadata and + * a bitmap of allocated blocks + * - the second block is an array of persisted inodes; the + * inode store. + */ + +void *pkernfs_allocations_bitmap(struct super_block *sb) +{ + /* Allocations is 2nd half of first block */ + return pkernfs_mem + (1 << 20); +} + +void pkernfs_zero_allocations(struct super_block *sb) +{ + memset(pkernfs_allocations_bitmap(sb), 0, (1 << 20)); + /* First page is persisted super block and allocator bitmap */ + set_bit(0, pkernfs_allocations_bitmap(sb)); + /* Second page is inode store */ + set_bit(1, pkernfs_allocations_bitmap(sb)); +} diff --git a/fs/pkernfs/pkernfs.c b/fs/pkernfs/pkernfs.c index 518c610e3877..199c2c648bca 100644 --- a/fs/pkernfs/pkernfs.c +++ b/fs/pkernfs/pkernfs.c @@ -25,6 +25,7 @@ static int pkernfs_fill_super(struct super_block *sb, struct fs_context *fc) } else { pr_info("pkernfs: Clean super block; initialising\n"); pkernfs_initialise_inode_store(sb); + pkernfs_zero_allocations(sb); psb->magic_number = PKERNFS_MAGIC_NUMBER; pkernfs_get_persisted_inode(sb, 1)->flags = PKERNFS_INODE_FLAG_DIR; strscpy(pkernfs_get_persisted_inode(sb, 1)->filename, ".", PKERNFS_FILENAME_LEN); diff --git a/fs/pkernfs/pkernfs.h b/fs/pkernfs/pkernfs.h index 192e089b3151..4655780f31f2 100644 --- a/fs/pkernfs/pkernfs.h +++ b/fs/pkernfs/pkernfs.h @@ -34,6 +34,7 @@ struct pkernfs_inode { }; void pkernfs_initialise_inode_store(struct super_block *sb); +void pkernfs_zero_allocations(struct super_block *sb); struct inode *pkernfs_inode_get(struct super_block *sb, unsigned long ino); struct pkernfs_inode *pkernfs_get_persisted_inode(struct super_block *sb, int ino);