From patchwork Mon Apr 3 08:47:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13197809 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 8D62BC761A6 for ; Mon, 3 Apr 2023 08:48:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A98A6B0074; Mon, 3 Apr 2023 04:48:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 231EF6B0075; Mon, 3 Apr 2023 04:48:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D4746B0078; Mon, 3 Apr 2023 04:48:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EE09C6B0074 for ; Mon, 3 Apr 2023 04:48:20 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A73E81C5B98 for ; Mon, 3 Apr 2023 08:48:20 +0000 (UTC) X-FDA: 80639453160.26.53ABF99 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf20.hostedemail.com (Postfix) with ESMTP id 72D311C0005 for ; Mon, 3 Apr 2023 08:48:18 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mXZ7yyaV; spf=pass (imf20.hostedemail.com: domain of cem@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680511699; 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=fVGqjqOK9uvqth8Dv0lpHrrEdaH0ZEtv214cwJfuAb0=; b=x8UXW0ylWGAisKRt4wQHb8JStuZgpOHSm/g7L1SYqgj+d0pCA0Bzh7psP2SZRy6E7AljMF hunLE/1XY3dnZGfGABE6dNaeFg0ZXCrSmfh/jBLaVwVEymVGYwJh2sIrd6AaIdteAH5+JJ UaLVl4++FqiNLyAngxNyhavaiKH2+Zc= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mXZ7yyaV; spf=pass (imf20.hostedemail.com: domain of cem@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680511699; a=rsa-sha256; cv=none; b=6DGPI31HR5e/0ozSQ6TxYcYqzRo+JLRrr4ZPmswsgvSnclcgqYmdSDo/058EsDQuj3qGp7 FbcuAHsPyFX9Y0d4KT1+9cfa077NxzUnzGGE5sXLJkwbudpr+MDRk3lps6XE77MWj/sSq7 ABmSryAPJSNIRoibIEVsiLjMopIJOek= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 12F5CCE0949; Mon, 3 Apr 2023 08:48:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4152C433D2; Mon, 3 Apr 2023 08:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680511693; bh=WFpcu3jPpBE2YFKVZd2NuKIP5d21v3quSUR0d+rf6yU=; h=From:To:Cc:Subject:Date:From; b=mXZ7yyaVOVp7KOPzUUqJeiiHWQC8V25Hlhr9HKtDNhmEnkQ2KSQHlFzRRuTWJFL8g Ob1dVuZt5qWBIG0Q0CqjXld47rTcEg/u57m7ISrAqvFa2rMDYYWIrohftUHjExdzkq aCZZb/RTUaFOJXyg4pU3+839XTi3caY3l93GktdNYnjWBf2e/0zlTqrlEt+/q0CH57 zx7bdsxeffEsd0tdHuiqkuvhJ9tJI+M094HrqaeLVG9RD4gmGqTBT6/UE3kTtQXEZM nBGk6I/zm7ZZkn5UemaQoYoS5DtU+c8zbjPA4in1kyJsHrRZORe+p84SOsekEfXo4i LMn6Y1vKAjJ8g== From: cem@kernel.org To: hughd@google.com Cc: jack@suse.cz, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, djwong@kernel.org Subject: [PATCH 0/6] shmem: Add user and group quota support for tmpfs Date: Mon, 3 Apr 2023 10:47:53 +0200 Message-Id: <20230403084759.884681-1-cem@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 72D311C0005 X-Stat-Signature: 4w9o6deunfcpj1dga4kjmxjr3fipko4o X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680511698-509450 X-HE-Meta: U2FsdGVkX18LnSCwQaUI7kvSvD5oEn0U4SIJBVXaf92lBj85gwuVa58VyKCHmbIU1tcAy+p7rWA1L2A+i02DUPDCpz6uf05SNNMwBvC12yVhnpbn6oKCvKsGs/PQDHkqxT70az8qxYETWVjtZvWz9XDIi1k3bcHJIFzvM1MlEmguVk2YP2ilFOMNCRvfyPjgpgjBe9Co2Fwc3PyMf1uRDNlRU+Flh6ekySfFB2YpgTjFxYenvxDR4QyU9qO9Lqv48tMIDfALv6aFXQyRlICG6E/EBCAS/n3qXqelLSuEDIXutKdMX6ygMtM92E7hD1Ztow9Zekehe/RmSTffY7oDiOzS96OL1ob/ihhK7k8O9poFZqd6HgyUVx3XFQvCX+O07SVd/0eFXfZOcyh1/yWvQKE4SPvrkSa5j03wKoQZ84vBzc3ntxfYPYRBw7I2ckiB9w84gwiRhmZSuWT9bJvDGDD133XNY5JzN9jewrqxjd81tzgMhqZzlZj0817evPUu+URvZvkaDGZ/wMOEz91wpwCx0UVxlgl05B3GbgyPoRQlkHY3KpAQdqFiDIGzIFzFDV0hRSPvbYWam5BcqM8vreMNyrLuTA+9j+pZ3yICo0qVvjTbQIcgfhDxLYCpG0DkXCr63tS6FO+8oF3HXFuuLHZuoLps7ZlQky/4Hw3bTyJs3Nn8hznuhSrZkS8c+unBfa6NI+P3uIKqTbnvO+XISQWJTXoJ+8jxPr1TFx+BhBdpoj+yD2e0fy/ywr81tMtFBQUq9OfwTNNraCQvY4aq0Jgxu7v+BLiYRux8+MaXLNHI35WMjgVb7QOJWRuug9kuEGlK+QmBR1s80IOuXvp9360GAeRpPg7un3SYX9/em5z/CsTFAMY7CrdHgXhcy1UciQSbyUOCRcRMzX2FY5MEZ2X2Q1LBfvCk7zycAMY9q7uYyz4tbSWU+nRNb0yz3oFOY67hc/eovbwncN+T7xS vZTVHWUW iRtvCuOJTt/2LTSOckWfB0J1YLUdWXdLXTLaK0EaxKYS3+R8QKYdHLFwLrctZmZV+8PHJW6LqXGS34M4B754x6CtETyy9N98P9pOMF0og92D9MrpIDY3L1hOcpzHxhZZzAqkpOA8k3/Vc0G4jElo/6eXwS1wyIsrnsJQKvDyk/9qUBOb5EW16+x5gxVEf3S+FAi8EUuxOo0UQS04+ZYBYKDKaQss5SZShyBrXFXLenSUTCDYGg1ccyhf9FHSFnVRyk5gjHQD54y/Yrj5QGGVf2huacVrnpXWLcupxyh9dWs8PEytvB9FN+sxftwfmrQ3XyBNY 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: From: Carlos Maiolino Hi folks. this work has been done originally by Lukas, but he left the company, so I'm taking over his work from where he left it of. This series is virtually done, and he had updated it with comments from the last version, but, I'm initially posting it as a RFC because it's been a while since he posted the last version. Most of what I did here was rebase his last work on top of current Linus's tree. Honza, there is one patch from you in this series, which I believe you had it suggested to Lukas on a previous version. The original cover-letter follows... people have been asking for quota support in tmpfs many times in the past mostly to avoid one malicious user, or misbehaving user/program to consume all of the system memory. This has been partially solved with the size mount option, but some problems still prevail. One of the problems is the fact that /dev/shm is still generally unprotected with this and another is administration overhead of managing multiple tmpfs mounts and lack of more fine grained control. Quota support can solve all these problems in a somewhat standard way people are already familiar with from regular file systems. It can give us more fine grained control over how much memory user/groups can consume. Additionally it can also control number of inodes and with special quota mount options introduced with a second patch we can set global limits allowing us to replace the size mount option with quota entirely. Currently the standard userspace quota tools (quota, xfs_quota) are only using quotactl ioctl which is expecting a block device. I patched quota [1] and xfs_quota [2] to use quotactl_fd in case we want to run the tools on mount point directory to work nicely with tmpfs. The implementation was tested on patched version of xfstests [3]. Jan Kara (1): quota: Check presence of quota operation structures instead of ->quota_read and ->quota_write callbacks Lukas Czerner (5): shmem: make shmem_inode_acct_block() return error shmem: make shmem_get_inode() return ERR_PTR instead of NULL shmem: prepare shmem quota infrastructure shmem: quota support Add default quota limit mount options Documentation/filesystems/tmpfs.rst | 28 ++ fs/Kconfig | 12 + fs/quota/dquot.c | 2 +- include/linux/shmem_fs.h | 25 ++ include/uapi/linux/quota.h | 1 + mm/Makefile | 2 +- mm/shmem.c | 452 +++++++++++++++++++++------- mm/shmem_quota.c | 327 ++++++++++++++++++++ 8 files changed, 740 insertions(+), 109 deletions(-) create mode 100644 mm/shmem_quota.c