From patchwork Thu Apr 20 08:03:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13218085 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 99FB3C77B7A for ; Thu, 20 Apr 2023 08:04:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25105900002; Thu, 20 Apr 2023 04:04:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D7D5280001; Thu, 20 Apr 2023 04:04:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0515E900004; Thu, 20 Apr 2023 04:04:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id ED16D900002 for ; Thu, 20 Apr 2023 04:04:09 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C9B041601D1 for ; Thu, 20 Apr 2023 08:04:09 +0000 (UTC) X-FDA: 80701031418.11.FE2A5AF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id E8D551C0024 for ; Thu, 20 Apr 2023 08:04:07 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VTF3rSZg; spf=pass (imf20.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=1681977848; 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=12qeoW1RfL5fHYt58V94HmmufB4GThD+B5NpSiw3Wm0=; b=McFFpm5ZWQqvGIzbEZXmmy3BBR39bL3QguuJlnYkpTQAN4KtvF+lhFGWVLnME2/CBuXhai tB/7Fdv+xT0WMo5XCmBU6mASVJ6hVBuSH1Gqofw5+1o5Anf5D7X/IFSk0ML/pnrh5P2T3k DN3XEMfJra7cd/WieJAYihm4ozK8gW4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VTF3rSZg; spf=pass (imf20.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681977848; a=rsa-sha256; cv=none; b=8NnEDny9zOaCuoKY7ajB6yWx8X3KZedTFOWUlg7LOI8nOYRRPKJP+JxE1md++ToHD7MRC+ GR3wtUUMn16+CeoLl1n22a2BV+UE3FWlvED8UeZFcDEkTekDboi7evfvfyIoGeNlUCNP05 LRIutBMzx4wDIB7FLW4lJZ8ReFw0Fyc= 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 163FF645C6; Thu, 20 Apr 2023 08:04:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19701C4339C; Thu, 20 Apr 2023 08:04:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681977846; bh=/U6gTaWZnnp3Yqw9JFrBzoFaHYbrueaBpixPomPgEIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VTF3rSZgGHvHMKA6+CHecyqIN4ZwDN1K30wXjuWhCpUITWCjvr5oaWwMdaddusT5n c2QMzqaRTihAabgUhLAprD9EDTsD7xSG+3x48SXBx7HfsOmU15hzRRbmQOcxbKzxiD Idbh0omcPqbbXeyA+oQ+Wcl3xPYKZwafPxE+Oh4UV6rwr0+KH3JZvy5w0hVvwndsgB NkYpA3mNxjJ54KkA+zWkBBmYvBj6rtE8YJ/QGwa7u1QZXThCFb8FRA+LJqO/veIzXV D2CJC/QSCa5kU/Gr/0Q4T65izfeuN7HQtmxkr9yszrsWxMVW+HjkoZoeTYMH2ufisv QZh/lGcblxGHg== 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 V2 1/6] shmem: make shmem_inode_acct_block() return error Date: Thu, 20 Apr 2023 10:03:54 +0200 Message-Id: <20230420080359.2551150-2-cem@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230420080359.2551150-1-cem@kernel.org> References: <20230420080359.2551150-1-cem@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: E8D551C0024 X-Stat-Signature: imjs4b81bnxp3efd8fbg8hbs1dg8m7og X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1681977847-811057 X-HE-Meta: U2FsdGVkX1/RxN25q/OCZsB2upkE+5v9vFBPviGUYojkBrNVpOlHcrAfPI+KWEwZvCKmdrmPwc+jGTgM+JFEDHjYJFG5ruOVNSY0eNzVjn6RPJ4iIymILPH5fjt1CL+WnsA6wAq46QRQwdP+HndvumUW0XDMS+/78K9K0V4e2raUxRumgYsFAybkfdNlVg/zfEz3AImCn8gyfaVbAbrgd5uk9wxAxRDXvOwONehzWi0qWUcxrs9X+WKQ2/fDX9oo9F4ZNK5PG+dJHpu3HRy8zWUqmryrvJHV7DU4L6V104dv2LTb6f7vCB9k54lqz5rTqMLO0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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 --- V2: - remove unused variable initialization on shmem_alloc_and_acct_folio 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