From patchwork Thu Jul 13 13:48:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13312233 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 37CD7C001DF for ; Thu, 13 Jul 2023 13:49:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C710C90000C; Thu, 13 Jul 2023 09:49:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C208590000B; Thu, 13 Jul 2023 09:49:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC20690000C; Thu, 13 Jul 2023 09:49:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9F4AD90000B for ; Thu, 13 Jul 2023 09:49:01 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 78A321202AF for ; Thu, 13 Jul 2023 13:49:01 +0000 (UTC) X-FDA: 81006719682.03.D6A7CD4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf24.hostedemail.com (Postfix) with ESMTP id BE542180012 for ; Thu, 13 Jul 2023 13:48:58 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=d5yn2rYS; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf24.hostedemail.com: domain of cem@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cem@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689256138; 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=2l7uBDEuVAvq/bvPwf99ZDVY9ZYlNh3d/pkciFgioYo=; b=hcB954HEaQLSZsu3jEmb8AwB+ydvuzOLLjkdTv9d9MUVioxihEM54S8ZsUZeGCjn0Pv6Gn DbE72Z1zLI5w/pddOnNauz58DeKszw1JZKGQgAS4eFhZ1adWd8p7wEobelQ/gZDr9MmPfg NrWrpxSlysXVragZ/2mZLtzKbz2oMu8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=d5yn2rYS; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf24.hostedemail.com: domain of cem@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cem@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689256138; a=rsa-sha256; cv=none; b=HuM7OdZEDbuGi5YB36rgMVENfX3BtaO/W4ZpPQTqPCsBmgZazWrEYXbFVucfDDtokw8Q4Q pcgOA9MV5OeOI3yAVBQsjZDh3wWwuU7OstC1z7RF1/RYk6eDvhI1zvHRh12fugtqS3q1eo lpVk2NddNfZYk4la6JPChIyMK6kyfvE= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D6596612BC; Thu, 13 Jul 2023 13:48:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA6F5C433C7; Thu, 13 Jul 2023 13:48:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689256137; bh=90mXiZse+BHfNBhJ3GG+vQpv2SgqoFPexn6sEx8uBiA=; h=From:To:Cc:Subject:Date:From; b=d5yn2rYS/mwswPC8cUiYEU8mKra7klkcSV9JPqQqfgc41GlVbYoMKA2iqSMxIVNzP axoaGh95KFyRGAoJP4sga/XHEDnetgDhfZh4jhnZf40Tbt5LTaBxVCiW0hdvuXTf2Q kJIynaRUNtgxyn81+2uhFdrg6eNLBRQGBnJK6/VGu7DipyrJd09te3ght7eJ3SoxIv B/Ipa7vVjYgAYxuQhuTW9jN/uf7tWVuCUrkdyi7cKZnZhlcA6jHXfwWysCI0m9xPg6 AGh6F+SRNnWKhlpxQeFXXkYTA+1nchabbcBLo0ooVmCLIwgt3UgH3R4cVNngTtoTB8 p4BaUQLB73Rlw== From: cem@kernel.org To: linux-fsdevel@vger.kernel.org Cc: jack@suse.cz, akpm@linux-foundation.org, viro@zeniv.linux.org.uk, linux-mm@kvack.org, djwong@kernel.org, hughd@google.com, brauner@kernel.org, mcgrof@kernel.org Subject: [PATCH RESEND V4 0/6] shmem: Add user and group quota support for tmpfs Date: Thu, 13 Jul 2023 15:48:42 +0200 Message-Id: <20230713134848.249779-1-cem@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: BE542180012 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ar7kgnnf5sbpg1xok77z3cdsuutwd1jw X-HE-Tag: 1689256138-747354 X-HE-Meta: U2FsdGVkX19bDtx1x8/K9qwyycwk6B5SSRexeNsP4tLhBV/u16XNf9GMzoQTTOWgeKHGvL8Q9+NnuXH4xVd8OF5HkXwrdJRhCUD46HLkjh/NHTUJ+po9eyALyPyG9Tmjh3IyBDfZEVdIkgvF529FnNk90gPKriA8rIlOx/zovHiY7xngmU7qNTH5oTQtHB5OkBq5MUFkLo/SetZ6lW982Ej2PF4AHWk6+N87+zkwuOiA0zGc6M73ijdVS5D4mUrSN4Sx1lJtyGhgoVvw59i5Vkoqq5XC5S/KEG9ZbRg46HgXcnfXIZFSqBqjIhy5G+4mctEefZOWrLVJNLH4YCylzrUtC91iiSMSK8Mk3fKvM6/EK/oihtYjhedwclvLbrW4r/a5MdtuT9jhRrDODSZ3GYI28QAOj+CbOCJXTcfBrnflvX/LUsrGTJsYEOl5I75VBAUlUMBOCJcJmUCNwVA2QKGcJGiS76UQfE8J5D8XgF8yp6FbaBk2JPC85AYL5u+LCA9EjviRL10q+5CufCwywRAjLN3k9pEZt1yS5OBwB3CyRP7ceA3Fk8GYy5uATwbtIX5rhwNOPL21tl0SkjYOSS47k0IgfkhlCY2wLgTN5kK25KuwGF5cg/0p8PPuc7trlYbTDqIsz5GdS2GsSyjJaVAvstIQ9B5vueMpwtAGES37FJ6baI0pb5OeRVYLP8JEhMgPUfSWxZjDeFAQSKfI3XGDCPoC1zzPqXBMnrsxxzEBr6TrId7NTcuqJsOZgaYnIVuU/e6Zp+YFcrlIXEH2jj/PL3WXzPfTv6F9uHccPFEwub/JYCVJaLXjO56JDCBdI6C7y5O+Eb3HDo5RXp2Tjpdyd+0+f/v6Wt0UcznBs6sJwFkF/j8QXtuVvffMtDm+Rxw+kbBmHpgbKZSDDKM/MU7DI7sGHwO55AsYI4I0+cKdvkvY1ugT33xxPLFm7x0tKMKIB0DAQCCvgMgaszv wmh+i6xX tgbOMm80Gr7vL4JFzrIlHHUrYTNUW8dbtYgFpsDaWDGsNqINtQ0zSfkgVbbORtA6RaJvh3J9UQgJtL/fK33iSEeCkChsnF15cC4Ki6oxoFP1u7YrsKb95Aak+JLH+wyLXT0MQLuA8lzR13ozIgONtS2M/WIlC62KuuFJIR3D1/qwxfkvGPbrf4UruWMREFLlUd/t++65f97zhY782BWJBRQWBcMG1+4od9iiCPDc9Apcpo8xWgj7pABb4EUBnjGxoyhw+BDnDphM+VoAGNBmOroMqk5VeUp9Yd2XD 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 Hello folks. This is a resend of the quota support for tmpfs. This has been rebased on today Linus's TOT. These patches conflicted with Luis Chamberlain's series to include 'noswap' mount option to tmpfs, there was no code change since the previous version, other than moving the implementation of quota options 'after' 'noswap'. Honza, giving the fact the conflicts were basically due context, I thought it was ok to keep your RwB on the patches, could you please confirm it? My apologies if I should have removed the RwB tags. As before, details are within each patch. 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]. [1] https://github.com/lczerner/quota/tree/quotactl_fd_support [2] https://github.com/lczerner/xfsprogs/tree/quotactl_fd_support [3] https://github.com/lczerner/xfstests/tree/tmpfs_quota_support 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 | 31 ++ fs/Kconfig | 12 + fs/quota/dquot.c | 2 +- include/linux/shmem_fs.h | 28 ++ include/uapi/linux/quota.h | 1 + mm/Makefile | 2 +- mm/shmem.c | 465 +++++++++++++++++++++------- mm/shmem_quota.c | 350 +++++++++++++++++++++ 8 files changed, 783 insertions(+), 108 deletions(-) create mode 100644 mm/shmem_quota.c Signed-off-by: Carlos Maiolino