From mboxrd@z Thu Jan 1 00:00:00 1970 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 B8FCFC433FE for ; Wed, 9 Nov 2022 09:43:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC4628E0001; Wed, 9 Nov 2022 04:43:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D74606B0073; Wed, 9 Nov 2022 04:43:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3BB98E0001; Wed, 9 Nov 2022 04:43:54 -0500 (EST) 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 B205D6B0072 for ; Wed, 9 Nov 2022 04:43:54 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 83F4D1A14D8 for ; Wed, 9 Nov 2022 09:43:49 +0000 (UTC) X-FDA: 80113416978.19.123DE0A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 313C41C0017 for ; Wed, 9 Nov 2022 09:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667986966; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3k4TxBqmNoHo3xG4obIRqkSktK8qyaCub3q4JLx4HAw=; b=U0p9AlnYqjtaQ6tLiCHBoElrMvPBVFPEONfge3I/7m+UOu231dIq0j865fDR4lnyZngAkS HLRMTZZzJnlZd34FaWJ/5Ioi+X6HBtff7dctVGRwi0DnxO5I9IbAD8SUSFbqySFo2xHVGi 2UC3TYxp+h/qj5NP6Oy1Pv0AmpKKhDw= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-433-yE3I9mc3Np6jde4toq53uw-1; Wed, 09 Nov 2022 04:42:03 -0500 X-MC-Unique: yE3I9mc3Np6jde4toq53uw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9A24A1C09041; Wed, 9 Nov 2022 09:42:02 +0000 (UTC) Received: from fedora (ovpn-193-254.brq.redhat.com [10.40.193.254]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 79AB0112131B; Wed, 9 Nov 2022 09:42:01 +0000 (UTC) Date: Wed, 9 Nov 2022 10:41:58 +0100 From: Lukas Czerner To: Jan Kara Cc: Hugh Dickins , Jan Kara , Eric Sandeen , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 0/2] [RFC] shmem: user and group quota support for tmpfs Message-ID: <20221109094158.c2mubinj7g66iw6e@fedora> References: <20221108133010.75226-1-lczerner@redhat.com> <20221108174326.hkgtrt72rpkmelyq@quack3> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221108174326.hkgtrt72rpkmelyq@quack3> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667987024; a=rsa-sha256; cv=none; b=xFB06FHnZg8w68SdtfEifBiTimfZHOAFu8XeHnWA28zHqvRjMHD5UhIsthedLrtI54y+hp XiRbfopXFAWjUAM7drn3xt31pRtWuMwnoB65qnGOWlInN0JhVADdJb8+pGnHncziktV1vE tJaVfrba6tDOB5CwCfARbkesg2PBPno= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=U0p9AlnY; spf=pass (imf21.hostedemail.com: domain of lczerner@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=lczerner@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667987024; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3k4TxBqmNoHo3xG4obIRqkSktK8qyaCub3q4JLx4HAw=; b=lO8c70h4UaitUIFSrcBVbLYVr7x/TtPuAfEaQBumWt/bp7rN1Kn0JZTQQ/+2a2+hqqFu6Q k7YDNtxp7YFM1luVOZ9EQVozf34GVtEF47N5cpvl18uVzCx2gZ18Wzki1TarS+IP2uO7d6 sdAiGq6QrEfoEs1tzcYmkyLoZMyyaB4= Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=U0p9AlnY; spf=pass (imf21.hostedemail.com: domain of lczerner@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=lczerner@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 313C41C0017 X-Stat-Signature: 8acdh64qfi8beozjaaa4uhe4qtjych9n X-HE-Tag: 1667987024-877663 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: On Tue, Nov 08, 2022 at 06:43:26PM +0100, Jan Kara wrote: > On Tue 08-11-22 14:30:08, Lukas Czerner wrote: > > 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]. > > > > Thoughts? > > Thanks for the work Lukas! I have one general note regarding this quota > support: IMO it is pointless to try to retrofit how quota files work on > block-based filesystems to tmpfs. All the bothering with converting between > on-disk and in-mem representation, formatting of btree nodes is just > pointless waste of CPU and code. Hi Jan, you're right and I did have some thoughts along the same lines. I wasn't sure how the idea of quota on tmpfs is going to be received and so I wanted to limit the scope of changes and make my job easier. It works well as a proof-of-concept but I agree that storing quota data in some in-memory representation is an ultimate way to go for tmpfs. > > I think much simpler approach would be to keep some internal rbtree with > quota structures carrying struct mem_dqblk and id. Then your .acquire_dquot > handler will fill in quota information from the structure and > .release_dquot will copy new data into the structure. > > So basically all operations you'd need to provide in your implementation > are .acquire_dquot, .release_dquot, and .get_next_id. And then you'll > probably need to define new quota format with .read_file_info callback > filling in some limits of the format (and some other stub callbacks doing > nothing). If there's too much boilerplate code doing nothing, we can have a > look into making quota core more clever to make life simpler for in-memory > filesystems (hidden behind something like DQUOT_QUOTA_IN_MEMORY flag in > struct quota_info) but currently I don't think it will be too bad. Thanks for the insight and suggestions. I'll see what I can do with this and prepare v2. Thanks! -Lukas > > Honza > > > [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 > SUSE Labs, CR >