From patchwork Wed Apr 26 10:20:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13224371 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 84D48C77B7F for ; Wed, 26 Apr 2023 10:20:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1324C6B00B6; Wed, 26 Apr 2023 06:20:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E4886B00B7; Wed, 26 Apr 2023 06:20:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDA896B00B8; Wed, 26 Apr 2023 06:20:19 -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 CF00D6B00B6 for ; Wed, 26 Apr 2023 06:20:19 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A6DC314014D for ; Wed, 26 Apr 2023 10:20:19 +0000 (UTC) X-FDA: 80723147358.17.AD46274 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id DFFB012000D for ; Wed, 26 Apr 2023 10:20:17 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=oHk783SY; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.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=1682504418; 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=a4+Hi3kvLGZ7wX/I/MLyA8qhrImfspY9oCA46YvbNIs=; b=JbTk6jvNMaIBNOmmUU0ItJ10KbQJnElnbAwghhHkoIK0S/RETMWSXYKxc6YQbV9n/LLYIW 4poE+X5RQIei29PffqlIggKkB9/8Dgo+Lpo5ANUzaEmdskRs5BzIS/hsW7y/DT/KpDNKNR jJKyZMNvUz/sTLh/xvWsJKZXsO8E48w= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=oHk783SY; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.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=1682504418; a=rsa-sha256; cv=none; b=L647MppJwEI6PXjs/gMCrZ0MTh5hXuFwtIj9orZVusbZ1xwZ3IllKNkuxq+cVjqUH4Q9rM WUfoJMqHPuCaDSIN550AlyQa+hOEuM/GF9oTqEzEHeKMpzesv47mfkYPPz/qKKoLz0RmUW 8MwEJIPQB4cK8M30Bqg1soZJxcRcN1w= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 01EFE63200; Wed, 26 Apr 2023 10:20:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C341C4339B; Wed, 26 Apr 2023 10:20:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682504416; bh=yQxEH8B7hcia0LdUCOjtWF8FC0yJn1kyiVdffv5361U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oHk783SYrc9I9mMYpULwfhg3/zQNX6ji12MXF4SlZYPJ10EhLGFxJLhSwEMataGU7 HJNDyqcqXCqG7wspV3IQcYqnQg2b2ogrcCu1yJG00TdUGvkVAyodSQ6piMvgzeViaa a2CjwQ+FeoEROBTsiT9kvFXWXC6R4NOEpHIhwjWeR/BINgSIsHJb9rK3Avd9bV4BYQ I/GcekEsiB7AjnsW+/9WrPB/6N2TjEEqumaOBGSgJ82lqlI2cYPE8kphXIUr/7gsNS N+eCSjDyQeagwVgN3hy/RwCQhWVALX1cSYwI7kTqn3RtNjntAOkJ8rP0iOiWD4M6XE Bp9gdo1MXUR8g== From: cem@kernel.org To: hughd@google.com Cc: jack@suse.cz, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, djwong@kernel.org Subject: [PATCH 1/6] shmem: make shmem_inode_acct_block() return error Date: Wed, 26 Apr 2023 12:20:03 +0200 Message-Id: <20230426102008.2930932-2-cem@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230426102008.2930932-1-cem@kernel.org> References: <20230426102008.2930932-1-cem@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: DFFB012000D X-Stat-Signature: fwic5enosk45xftia1p78bq9jjoyjr6e X-HE-Tag: 1682504417-178368 X-HE-Meta: U2FsdGVkX1/Ev/gVmcLc/1TGuTlJx3l18Arl77+5zDt83F9mH8rkLYVIigpkkn1qzX8qykx8HFniWrpSFsPpMgiZcioZFC/v00h1aGwlW9hLpXcTteRU0al/mhogLE85lnqhRwbHELKmgTdnZLylMB4GebZE1q/e+uGKaYGx3x7Naa/h/Wn+HPo2BFYyJyQiyXPAl0D2VQPEo2Jh4ZOLc3QxN3vhWEeTLZZBF5CfgDn2k5Ei/f3NpittDwVlq/j0RwhVPNnaJH7ELvX6isBpD3BgD+KTZOOrY54u/DbF8KPq79K9ieq7yg1Q1PnJpBHksu4UZM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000, version=1.2.4 Sender: owner-linux-mm@kvack.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 448f393d8ab2b..b1b3b826f6189 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -198,13 +198,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, @@ -213,11 +214,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) @@ -369,7 +370,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 */ @@ -1583,13 +1584,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) @@ -2433,7 +2435,7 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, 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