From patchwork Thu Jul 13 13:48:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13312234 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 8EFF0C001B0 for ; Thu, 13 Jul 2023 13:49:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 089E890000D; Thu, 13 Jul 2023 09:49:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 039E690000B; Thu, 13 Jul 2023 09:49:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E447B90000D; Thu, 13 Jul 2023 09:49:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D73A190000B for ; Thu, 13 Jul 2023 09:49:04 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A8E28402A9 for ; Thu, 13 Jul 2023 13:49:04 +0000 (UTC) X-FDA: 81006719808.05.7354CC1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf23.hostedemail.com (Postfix) with ESMTP id EBA25140023 for ; Thu, 13 Jul 2023 13:49:01 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Rs1ObEZG; spf=pass (imf23.hostedemail.com: domain of cem@kernel.org designates 139.178.84.217 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=1689256142; 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=XNS0pZWYtiz3eLlRvQaHMyf1ULXVatSDvn1Y8OwTP3s=; b=F0QQGUbd4ucpzYFQde6p1AYY904UXRMqLt/LdBzX8Q+wl+BZjTXf8wftdjrtrbXaQEKbnS ciOFwX2dNngnmH/bgcxWJSoRU3NHwfpjKa6g2QykwyWOFLFrq/LzsGc8YurZsSpeMfeCcd Trk2leMM6Gda4GmmlrkpJtTay/UL6jM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689256142; a=rsa-sha256; cv=none; b=a9y6xUNnmJFUO5KyLVz31iN6GI5KxMoqqmOXECAqp1daguQidTl5zbmrQjNCtztZZDCGAh 232KV4X2BGellGhrcQRf5dpwIXeUE016yrDczBBH9o22VS7JMQ5jz2btvgWGtvTzkosYDU 2mnG05IiqiFPXnavEQ2ZzMRfmCZhqbw= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Rs1ObEZG; spf=pass (imf23.hostedemail.com: domain of cem@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org 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 D30D16153D; Thu, 13 Jul 2023 13:49:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECD39C433C9; Thu, 13 Jul 2023 13:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689256140; bh=yJe4lhnTjof59vWoLkGO8Qqi3dVE6gVAeA03pQuGI1M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rs1ObEZGwNKqvhMlpwjar7f75Lki51FGjVqCmYvs2qf9HPDqfPZbBD+gMa8rXM0vp tEnaAdW8rTV88g0jlrKy8uHObcWL/auXaMhWjP9Gl9wTxSxQbah1NbxSXw+Oso1U6K v2PwJU/lW5PlSE7gOtIH3tlAwsxb7KDVvyxe5oqFQ2TBZAhJcQNxAEdAO5x9WG8u/j pXw60UM7mT+51vi02bGPEJf+BeOhKgDEg29BR9z6ya1kaRvHLzLRmSfiA1Y45SGN0D gd3xSzqBtEHHjYQc7cw8Q2gtFvQFxPHxV8eZzTMmrW0KkEvonsTUjKgPf0bjUHtQql zd2BVzpqWvS6A== 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 1/6] shmem: make shmem_inode_acct_block() return error Date: Thu, 13 Jul 2023 15:48:43 +0200 Message-Id: <20230713134848.249779-2-cem@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230713134848.249779-1-cem@kernel.org> References: <20230713134848.249779-1-cem@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: EBA25140023 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: mus9gazxy5q4aadjyzuumi3y1wfc9dna X-HE-Tag: 1689256141-40184 X-HE-Meta: U2FsdGVkX19TmFP3bkIVYdy8e9F1TcLGT9F7/i+YMrBRkanuDU/YlLfHeyuS7SGLSQwV9LjDKg+HiG04S8LQZZURAuq/Y1T7FtwYQdnahbWwa+nGAKAojXEcVxvpjB8FYjsNDG06H6FnqawyXmPtHroVtzHuF1xdEE2p4rlx1B/Abe8LyN2Yl7Ad+WdF/JcwO8QE+HpdtyVmGmy1qyCdE+w1x7Wrn6BH2rugOXrMMToGkzgRFd7xRud783sZl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vack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Lukas Czerner Make shmem_inode_acct_block() return proper error code instead of bool. This will be useful later when we introduce quota support. There should be no functional change. Signed-off-by: Lukas Czerner Signed-off-by: Carlos Maiolino Reviewed-by: Jan Kara --- mm/shmem.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 2f2e0e618072..51d17655a6e1 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -199,13 +199,14 @@ static inline void shmem_unacct_blocks(unsigned long flags, long pages) vm_unacct_memory(pages * VM_ACCT(PAGE_SIZE)); } -static inline bool shmem_inode_acct_block(struct inode *inode, long pages) +static inline int shmem_inode_acct_block(struct inode *inode, long pages) { struct shmem_inode_info *info = SHMEM_I(inode); struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); + int err = -ENOSPC; if (shmem_acct_block(info->flags, pages)) - return false; + return err; if (sbinfo->max_blocks) { if (percpu_counter_compare(&sbinfo->used_blocks, @@ -214,11 +215,11 @@ static inline bool shmem_inode_acct_block(struct inode *inode, long pages) percpu_counter_add(&sbinfo->used_blocks, pages); } - return true; + return 0; unacct: shmem_unacct_blocks(info->flags, pages); - return false; + return err; } static inline void shmem_inode_unacct_blocks(struct inode *inode, long pages) @@ -370,7 +371,7 @@ bool shmem_charge(struct inode *inode, long pages) struct shmem_inode_info *info = SHMEM_I(inode); unsigned long flags; - if (!shmem_inode_acct_block(inode, pages)) + if (shmem_inode_acct_block(inode, pages)) return false; /* nrpages adjustment first, then shmem_recalc_inode() when balanced */ @@ -1588,13 +1589,14 @@ static struct folio *shmem_alloc_and_acct_folio(gfp_t gfp, struct inode *inode, struct shmem_inode_info *info = SHMEM_I(inode); struct folio *folio; int nr; - int err = -ENOSPC; + int err; if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) huge = false; nr = huge ? HPAGE_PMD_NR : 1; - if (!shmem_inode_acct_block(inode, nr)) + err = shmem_inode_acct_block(inode, nr); + if (err) goto failed; if (huge) @@ -2445,7 +2447,7 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, int ret; pgoff_t max_off; - if (!shmem_inode_acct_block(inode, 1)) { + if (shmem_inode_acct_block(inode, 1)) { /* * We may have got a page, returned -ENOENT triggering a retry, * and now we find ourselves with -ENOMEM. Release the page, to