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 67A32C001E0 for ; Wed, 9 Aug 2023 09:33:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C79366B0071; Wed, 9 Aug 2023 05:33:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2A3A8E0002; Wed, 9 Aug 2023 05:33:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF1548E0001; Wed, 9 Aug 2023 05:33:47 -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 9E9926B0071 for ; Wed, 9 Aug 2023 05:33:47 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7B0C41C9DFD for ; Wed, 9 Aug 2023 09:33:47 +0000 (UTC) X-FDA: 81104054094.20.56147A7 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf13.hostedemail.com (Postfix) with ESMTP id 652302001B for ; Wed, 9 Aug 2023 09:33:45 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=G9BMtRzZ; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=i8D+rLkm; dmarc=none; spf=pass (imf13.hostedemail.com: domain of jack@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691573625; a=rsa-sha256; cv=none; b=Va2vIQWT5EZPbz8fjR0dQvACwvQwa+Ooa6wVbuTyQLQ5N+jEBicraFhVKnYxMGyjCWnRsd fEdYDSceblkV4tR8WqFkmnh/zU8JWotBt88ZPbBcZNImGIRFj4q85puqq/O52YZnsV3yoE NPjZ0hkpaUqZaBw6406+vEJySPRCux4= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=G9BMtRzZ; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=i8D+rLkm; dmarc=none; spf=pass (imf13.hostedemail.com: domain of jack@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691573625; 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=Mj+K1aNZJ1uaFnsL24bOcXEwStC6A27y5q3AB//p7H8=; b=nSvnfXZz+AetY98vMKq6WiBpsyc4/KA7froiffgQT442jgiAryes6OA6SUweGzqSYieled /wcr3WwE5GtC901WvreTU8dtxZHzhm0hABqJIe9Qx1bIDxSbxFGNRXhyR9v8kLv042Ggoc a7t0Bx4yqJbVvh/rVYqIX1xpPcE1oKU= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 063132185F; Wed, 9 Aug 2023 09:33:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1691573624; h=from:from:reply-to: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=Mj+K1aNZJ1uaFnsL24bOcXEwStC6A27y5q3AB//p7H8=; b=G9BMtRzZ2nbYvJkJii51EcoKrr1yZDN20yh1rOM8f8mJsIsS99Ibx4r4NWgCb/9+i39Q03 hY8pdeZkbYXkv5vUHEnBgt67/shPbah9ovPykD+qYP+H5DyuefBvFVsaXJkqpSQhikML3w /gbJ7zQz9lFm27VwJv6Lu/YKZ1B9fUo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1691573624; h=from:from:reply-to: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=Mj+K1aNZJ1uaFnsL24bOcXEwStC6A27y5q3AB//p7H8=; b=i8D+rLkmodjqW86R3R0Q405lndRiUvr5KdGS/rc4GDr7Ty0DzhH2CLOX4M0WbxpBXsIQVM nYgF/6SEOBClpiDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DD517133B5; Wed, 9 Aug 2023 09:33:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id x+6cNXdd02RqFAAAMHmgww (envelope-from ); Wed, 09 Aug 2023 09:33:43 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 499A6A0769; Wed, 9 Aug 2023 11:33:43 +0200 (CEST) Date: Wed, 9 Aug 2023 11:33:43 +0200 From: Jan Kara To: Hugh Dickins Cc: Christian Brauner , Andrew Morton , Oleksandr Tymoshenko , Carlos Maiolino , Jeff Layton , Chuck Lever , Jan Kara , Miklos Szeredi , Daniel Xu , Chris Down , Tejun Heo , Greg Kroah-Hartman , Matthew Wilcox , Christoph Hellwig , Pete Zaitcev , Helge Deller , Topi Miettinen , Yu Kuai , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH vfs.tmpfs 2/5] tmpfs: track free_ispace instead of free_inodes Message-ID: <20230809093343.f72rf5zxwknljkjv@quack3> References: <4fe1739-d9e7-8dfd-5bce-12e7339711da@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4fe1739-d9e7-8dfd-5bce-12e7339711da@google.com> X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 652302001B X-Stat-Signature: rn1zjq9bnr6rtnsi1ymtjqmnujtow9au X-HE-Tag: 1691573625-777346 X-HE-Meta: U2FsdGVkX1+vjqYCROdRg1zu9AmitI4ZMYWUOxsNBkRV9TSih72A6nwPpNBA8DI/Im+Soza383fr5xBQBXKq5v95hzMURksbM5AqWt6MmFZoY8xIctSsCV10gP/hzS+UmCESJR5GEDeahLquLkruI6s4DfBSzPXSPvCm/jD2ZiY9WLmcq/yPU8qcBe+iVo35y8EFenOMRKlVdowCIhutZuW4DI6PfOhEkSuaGlnxLG4LLY2jJXp79q3QSrP2sLJMKYgc5WTnuEb11MZ4r1VevBHiYPWwNgZm/XR9d4MKecv5gTcMaDrdj2tqzupiPzXfyzn6/bpe9blsHmS0zF5ZFzA90vff0vq0BOG9/Cr1Pvd4PRLzV630xtMzabiQGOk4i85jruYZTX5svGBVLoEAHzmGNSZ9VFFpuV0o/jr90KVTqNEcBkTp/clS3/psZeKvs5FcNonC6RzC/YgRoTgUOCfAe2cgxm5RiSBW1cElPp3xNOdcdqed13Fk6wSsHQ89Jp7l0VIfM7rtsZkJXXoCiCUuLZ+92o9i3/3Hr+0796cmk1QgdsWSbQs5Hj31z57eLnqUrbUi9Zb9K1YwoZ612gN1zCcgLwaroc6ik11oNgmuTQPURv5IxjFddAUpUUGEftI8bg6tUwYOu7A+crmOENcFROY8h51VQs8BX/uoh2rm8fpRGdC8iws6KfMzZ24ZfYgc+qyHOsANuCC4jF5KRqZrZGS/g2WASVwitmFTzwXEN/goqzspI/B9Yf2eEXUSl8SYopOQlMsplNa4EQ7ajfTznaYFZijwv2qsmo19EVwrrE8vLFO4Wr9kt+Qtj2HcxUS5Ut295PMcioaO8+2U8CUo8DK15VY4rzb0wXubdT2XWRIVC+EQJUZLnnieDhF0z3PWRtNhBwE+EeKPyc9thubTDt6rKLMsvOTaeAgElkTZvHTprpg9sBfDX+JaFfijHM6Bq7kj7jb+WnNKzIz Kst3/h3Q SuHaZQ9L00kevbVOKQTewYMuST2bCgt0RfAalTlRCJTOMD5ZqkgTC+1RW4pKU4frXrJkZwIPVuSmLiBFiPjWrS0bpO20S6TfuSCVmvAcM4E5dtRUI0JNbuQ/oPTpSCSeXI9au9E0uADv0LH79mX330CL+ygAALxjy2mhD3wYGe+WO3Mr4XbyZwMaiM3wAialpXIasw4wPe5muosPGC9fVDB0vghO9/cwJpOcvkWWme0ObsxeKVz5Mf/0YYyIYlINRXFeT/C60YbwILiMof0hmt+QASSPuojKxlhgleX4iBPafUBTGcVgN3Pn7o9c1RfHcu/1gFp1yVnC1Ddv/tLyrQdHf8ZXIf3Iu2zkG 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 08-08-23 21:32:21, Hugh Dickins wrote: > In preparation for assigning some inode space to extended attributes, > keep track of free_ispace instead of number of free_inodes: as if one > tmpfs inode (and accompanying dentry) occupies very approximately 1KiB. > > Unsigned long is large enough for free_ispace, on 64-bit and on 32-bit: > but take care to enforce the maximum. And fix the nr_blocks maximum on > 32-bit: S64_MAX would be too big for it there, so say LONG_MAX instead. > > Delete the incorrect limited<->unlimited blocks/inodes comment above > shmem_reconfigure(): leave it to the error messages below to describe. > > Signed-off-by: Hugh Dickins Looks good to me. Feel free to add: Reviewed-by: Jan Kara Honza > --- > include/linux/shmem_fs.h | 2 +- > mm/shmem.c | 33 +++++++++++++++++---------------- > 2 files changed, 18 insertions(+), 17 deletions(-) > > diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h > index 9b2d2faff1d0..6b0c626620f5 100644 > --- a/include/linux/shmem_fs.h > +++ b/include/linux/shmem_fs.h > @@ -54,7 +54,7 @@ struct shmem_sb_info { > unsigned long max_blocks; /* How many blocks are allowed */ > struct percpu_counter used_blocks; /* How many are allocated */ > unsigned long max_inodes; /* How many inodes are allowed */ > - unsigned long free_inodes; /* How many are left for allocation */ > + unsigned long free_ispace; /* How much ispace left for allocation */ > raw_spinlock_t stat_lock; /* Serialize shmem_sb_info changes */ > umode_t mode; /* Mount mode for root directory */ > unsigned char huge; /* Whether to try for hugepages */ > diff --git a/mm/shmem.c b/mm/shmem.c > index df3cabf54206..c39471384168 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -90,6 +90,9 @@ static struct vfsmount *shm_mnt; > /* Pretend that each entry is of this size in directory's i_size */ > #define BOGO_DIRENT_SIZE 20 > > +/* Pretend that one inode + its dentry occupy this much memory */ > +#define BOGO_INODE_SIZE 1024 > + > /* Symlink up to this size is kmalloc'ed instead of using a swappable page */ > #define SHORT_SYMLINK_LEN 128 > > @@ -137,7 +140,8 @@ static unsigned long shmem_default_max_inodes(void) > { > unsigned long nr_pages = totalram_pages(); > > - return min(nr_pages - totalhigh_pages(), nr_pages / 2); > + return min3(nr_pages - totalhigh_pages(), nr_pages / 2, > + ULONG_MAX / BOGO_INODE_SIZE); > } > #endif > > @@ -331,11 +335,11 @@ static int shmem_reserve_inode(struct super_block *sb, ino_t *inop) > if (!(sb->s_flags & SB_KERNMOUNT)) { > raw_spin_lock(&sbinfo->stat_lock); > if (sbinfo->max_inodes) { > - if (!sbinfo->free_inodes) { > + if (sbinfo->free_ispace < BOGO_INODE_SIZE) { > raw_spin_unlock(&sbinfo->stat_lock); > return -ENOSPC; > } > - sbinfo->free_inodes--; > + sbinfo->free_ispace -= BOGO_INODE_SIZE; > } > if (inop) { > ino = sbinfo->next_ino++; > @@ -394,7 +398,7 @@ static void shmem_free_inode(struct super_block *sb) > struct shmem_sb_info *sbinfo = SHMEM_SB(sb); > if (sbinfo->max_inodes) { > raw_spin_lock(&sbinfo->stat_lock); > - sbinfo->free_inodes++; > + sbinfo->free_ispace += BOGO_INODE_SIZE; > raw_spin_unlock(&sbinfo->stat_lock); > } > } > @@ -3155,7 +3159,7 @@ static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf) > } > if (sbinfo->max_inodes) { > buf->f_files = sbinfo->max_inodes; > - buf->f_ffree = sbinfo->free_inodes; > + buf->f_ffree = sbinfo->free_ispace / BOGO_INODE_SIZE; > } > /* else leave those fields 0 like simple_statfs */ > > @@ -3815,13 +3819,13 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) > break; > case Opt_nr_blocks: > ctx->blocks = memparse(param->string, &rest); > - if (*rest || ctx->blocks > S64_MAX) > + if (*rest || ctx->blocks > LONG_MAX) > goto bad_value; > ctx->seen |= SHMEM_SEEN_BLOCKS; > break; > case Opt_nr_inodes: > ctx->inodes = memparse(param->string, &rest); > - if (*rest) > + if (*rest || ctx->inodes > ULONG_MAX / BOGO_INODE_SIZE) > goto bad_value; > ctx->seen |= SHMEM_SEEN_INODES; > break; > @@ -4002,21 +4006,17 @@ static int shmem_parse_options(struct fs_context *fc, void *data) > > /* > * Reconfigure a shmem filesystem. > - * > - * Note that we disallow change from limited->unlimited blocks/inodes while any > - * are in use; but we must separately disallow unlimited->limited, because in > - * that case we have no record of how much is already in use. > */ > static int shmem_reconfigure(struct fs_context *fc) > { > struct shmem_options *ctx = fc->fs_private; > struct shmem_sb_info *sbinfo = SHMEM_SB(fc->root->d_sb); > - unsigned long inodes; > + unsigned long used_isp; > struct mempolicy *mpol = NULL; > const char *err; > > raw_spin_lock(&sbinfo->stat_lock); > - inodes = sbinfo->max_inodes - sbinfo->free_inodes; > + used_isp = sbinfo->max_inodes * BOGO_INODE_SIZE - sbinfo->free_ispace; > > if ((ctx->seen & SHMEM_SEEN_BLOCKS) && ctx->blocks) { > if (!sbinfo->max_blocks) { > @@ -4034,7 +4034,7 @@ static int shmem_reconfigure(struct fs_context *fc) > err = "Cannot retroactively limit inodes"; > goto out; > } > - if (ctx->inodes < inodes) { > + if (ctx->inodes * BOGO_INODE_SIZE < used_isp) { > err = "Too few inodes for current use"; > goto out; > } > @@ -4080,7 +4080,7 @@ static int shmem_reconfigure(struct fs_context *fc) > sbinfo->max_blocks = ctx->blocks; > if (ctx->seen & SHMEM_SEEN_INODES) { > sbinfo->max_inodes = ctx->inodes; > - sbinfo->free_inodes = ctx->inodes - inodes; > + sbinfo->free_ispace = ctx->inodes * BOGO_INODE_SIZE - used_isp; > } > > /* > @@ -4211,7 +4211,8 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) > sb->s_flags |= SB_NOUSER; > #endif > sbinfo->max_blocks = ctx->blocks; > - sbinfo->free_inodes = sbinfo->max_inodes = ctx->inodes; > + sbinfo->max_inodes = ctx->inodes; > + sbinfo->free_ispace = sbinfo->max_inodes * BOGO_INODE_SIZE; > if (sb->s_flags & SB_KERNMOUNT) { > sbinfo->ino_batch = alloc_percpu(ino_t); > if (!sbinfo->ino_batch) > -- > 2.35.3 > -- Jan Kara SUSE Labs, CR