From patchwork Sat Aug 24 19:10:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13776499 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 B8BE7C5320E for ; Sat, 24 Aug 2024 19:10:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB04E800EE; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B3F94800F3; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FBFF800F0; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 51095800EE for ; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C8B221A082F for ; Sat, 24 Aug 2024 19:10:38 +0000 (UTC) X-FDA: 82488080556.06.A0060ED Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf10.hostedemail.com (Postfix) with ESMTP id 27808C0003 for ; Sat, 24 Aug 2024 19:10:36 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=wTNonfQ8; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724526575; a=rsa-sha256; cv=none; b=mkTm/R++yMP0scvwl97XLb/24haaNJh3r0Ggt3ePyeM6ETU3xKpvEi8bbB17kLc7t5rgTK XX9DW7uREEiL/qnsMXINdmhO54s/qkykxNy1Yn7DX/onFpR/TZnEyleReHDm6wrlhVozmt R7c+rVHEkotowSCrhtz2plOlxgjgCMM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=wTNonfQ8; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724526575; 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:in-reply-to:references:references:dkim-signature; bh=bkjDXacJBIE1tnl8yjf2hTWkksioVHF2A/Lmh31BWug=; b=KtMrF4lpSk8mCozn4SPSGRqsNqDChWGqIloZOZOKBFuTFPO7nbUXoSB3h5yQ0GuWi0jab0 INHVbeDEtvu0+DelE+UCO1B8VtdpH4W7ATmdUM4ti8JdkkZcGpEqiPQaL1tkm/+vfjLq5P iU22SyN6Le7mxJbyhfHZNucbveoQzAs= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724526635; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bkjDXacJBIE1tnl8yjf2hTWkksioVHF2A/Lmh31BWug=; b=wTNonfQ8/pgi2wT6SpzNvV1SNBGipnFrxT4NfhyDeL4N7vyQtDB52h1ymy/Cw91TCBmyq4 NMuN/t0hl+jsEGr3Jii46H75JjUhzOIlcDwgZ49INWfPV4i/Kqp/X+vVMVTrZK4R5juNwe 482emWvPc/dZrYuIJGexZ6pMGuggzW0= From: Kent Overstreet To: david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Kent Overstreet , Alexander Viro , Christian Brauner Subject: [PATCH 08/10] fs: Add super_block->s_inodes_nr Date: Sat, 24 Aug 2024 15:10:15 -0400 Message-ID: <20240824191020.3170516-9-kent.overstreet@linux.dev> In-Reply-To: <20240824191020.3170516-1-kent.overstreet@linux.dev> References: <20240824191020.3170516-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 27808C0003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: z9b1uaketwtt5ajpu65699tf3zy63tqp X-HE-Tag: 1724526636-211118 X-HE-Meta: U2FsdGVkX19JA0+vwglMGlcA8Kv2mPFWk/XM3mYv8y13tYnCZgYuRcxMASHZV1gasqWCN/b9/cQIj/MjA5eTprSgNOgasdF/h+OVH+aJTCczexZJM2C6b2A6xNTNoHBWuKhr7iwK9LH2W0AxgPqeIOc2V4w0fdBjx9+WIxcIjQIe873IYjhHIWDUyKU0JjkSyJZYtaNC5IGZuaIhdfzFPpZp+mIbwTKdUSUotwrv5tPLI+RakZFPlEA7dfSrx2sTcASSs+0OSpdV0JpdQl1T9oQr18DYxUDirKlDxNaftIjH3hg+HBC+bRTvY/4PL0CGlqZU1DnUeqmxMrBTXpgC2+KBLfeH0Ch+jgb9txvLYO7LH6OC8mZlLh7aT6Dq6ZPd/69VXXUpCUAwNe4Ar9XZ0PSwKe+/f5IH5kUfRN6cTlDGs5U6lMgnFUNndcYdyinYgezRZa0zmgi96h+7xuDaHvPsARE1h7aJO/uRPvQm/95XYDf1e8GNUFnw5T9a83f7xA0ywqzg6Joa2Gu619rEEcQN3G6uo5CL2U/gIg2pTOwH5UsIM4CexDX5YYVQmdxim6rcF2O80sDZ7ELsjv9BJAHwSfBHn/R2PKPFV2k5INiemB98kHXqBX5IfTiimDD1VhFuCe4FyS8aOxkXaEuyjDI4xXxTql6J1bM4ZuKd+1fQ9+WdorSTdVmC3a0NILq/70soPm015tzoTHrhva0y+VLwKmrz5AERaxWzaw3jvk6zdEYozeky+wmN3KGGic3qkGAeyPeLRGDH0RHc83ZLUvmSlYAZBEh1YCxXGlI6SY5aUv4d6ofO2s7nWAi4PefVsVAbqagBmu8rkalHohaHznHJp1Z6w3pDTIlEZUpGNRos62Bl1HX6VBXUvNYgQ2CUwKLzM2jkqqpoNViTej7fN710Pkx16bEscXHJ7ZqzL5h3j4hpby8TqF0UMV9WW1UI9lfjJvHC8R2Faq2b+TU uSXKam0u b3Rl72J0XTk90r0ag3saGTMK2hD8Jp8UdVOANov1JO2/fxk22ddVGD6h1AEybsFQhWbfefz4fk7S4I8JO+oLv9cHm2o3SDuzM9YeyTP5Izhqd0D2VFtDmkax++TYz9yrzIOyLWbF8ib2ka08o82/bMwNsc/qSF509JobadsuBMJfCd/EGfO8jM+Srvk2C2iL+ZtmkfIexAlnYd3ZRNsLUw+LXjMfAnF8kDmyyEgE557tqQuV2l7mxGj8tFxh7M0NAcpa3yDpNxJfDnB4Mw8ZiUIvKDbPO5IC5LLKkSmihLPaPY07ZFo/8cYrOnPiIhKlVg7oZtG8qn6Jq63hKHWRXUroSFg== 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: Upcoming shrinker debugging patchset is going to give us a callback for reporting on all memory owned by a shrinker. This adds a counter for total number of inodes allocated for a given superblock, so we can compare with the number of reclaimable inodes we already have. Cc: Alexander Viro Cc: Christian Brauner Cc: Dave Chinner Signed-off-by: Kent Overstreet --- fs/inode.c | 2 ++ fs/super.c | 7 +++++++ include/linux/fs.h | 1 + 3 files changed, 10 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index 5e7dcdeedd4d..2650c5ce74e1 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -489,12 +489,14 @@ void inode_sb_list_add(struct inode *inode) spin_lock(&inode->i_sb->s_inode_list_lock); list_add(&inode->i_sb_list, &inode->i_sb->s_inodes); spin_unlock(&inode->i_sb->s_inode_list_lock); + this_cpu_inc(*inode->i_sb->s_inodes_nr); } EXPORT_SYMBOL_GPL(inode_sb_list_add); static inline void inode_sb_list_del(struct inode *inode) { if (!list_empty(&inode->i_sb_list)) { + this_cpu_dec(*inode->i_sb->s_inodes_nr); spin_lock(&inode->i_sb->s_inode_list_lock); list_del_init(&inode->i_sb_list); spin_unlock(&inode->i_sb->s_inode_list_lock); diff --git a/fs/super.c b/fs/super.c index b7913b55debc..b1b6ae491b6c 100644 --- a/fs/super.c +++ b/fs/super.c @@ -278,6 +278,7 @@ static void destroy_super_work(struct work_struct *work) security_sb_free(s); put_user_ns(s->s_user_ns); kfree(s->s_subtype); + free_percpu(s->s_inodes_nr); for (int i = 0; i < SB_FREEZE_LEVELS; i++) percpu_free_rwsem(&s->s_writers.rw_sem[i]); kfree(s); @@ -298,6 +299,7 @@ static void destroy_unused_super(struct super_block *s) super_unlock_excl(s); list_lru_destroy(&s->s_dentry_lru); list_lru_destroy(&s->s_inode_lru); + free_percpu(s->s_inodes_nr); shrinker_free(s->s_shrink); /* no delays needed */ destroy_super_work(&s->destroy_work); @@ -375,6 +377,10 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, s->s_time_min = TIME64_MIN; s->s_time_max = TIME64_MAX; + s->s_inodes_nr = alloc_percpu(size_t); + if (!s->s_inodes_nr) + goto fail; + s->s_shrink = shrinker_alloc(SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, "sb-%s", type->name); if (!s->s_shrink) @@ -408,6 +414,7 @@ static void __put_super(struct super_block *s) WARN_ON(s->s_dentry_lru.node); WARN_ON(s->s_inode_lru.node); WARN_ON(!list_empty(&s->s_mounts)); + WARN_ON(per_cpu_sum(s->s_inodes_nr)); call_rcu(&s->rcu, destroy_super_rcu); } } diff --git a/include/linux/fs.h b/include/linux/fs.h index 8fc4bad3b6ae..86636831b9d0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1346,6 +1346,7 @@ struct super_block { /* s_inode_list_lock protects s_inodes */ spinlock_t s_inode_list_lock ____cacheline_aligned_in_smp; struct list_head s_inodes; /* all inodes */ + size_t __percpu *s_inodes_nr; spinlock_t s_inode_wblist_lock; struct list_head s_inodes_wb; /* writeback inodes */