From patchwork Sun Jan 16 12:18:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 12714543 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 4D10CC4332F for ; Sun, 16 Jan 2022 12:18:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 818596B007E; Sun, 16 Jan 2022 07:18:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A5ED6B0078; Sun, 16 Jan 2022 07:18:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41FC86B0071; Sun, 16 Jan 2022 07:18:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay039.a.hostedemail.com [64.99.140.39]) by kanga.kvack.org (Postfix) with ESMTP id 20C556B0074 for ; Sun, 16 Jan 2022 07:18:29 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CDA002499B for ; Sun, 16 Jan 2022 12:18:28 +0000 (UTC) X-FDA: 79036053096.02.92FF8EA Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id 110871C0002 for ; Sun, 16 Jan 2022 12:18:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=3MIQy1Z2cREUy+AYirD8/hbvJvQAYl4W5xf1lrR8/fc=; b=Z4YcmDRUqYP1PmRMV4Cq/T/YCL 44F6kIQbZPnImDlMxhiRXRfXke9wm9hnu+ycUToDuWrmdiSzq6DrycKO9fRyKn23vfwRPie7hKmFT t8G5pmM1qEGBc6n4yYjxnyEKwjKDLSHpegALqtoNUVdK5pkCQ44E+ynfeBm2El5JuqmJBLHATpwfv HOxCuIHnwdqiqlmHlWZpxi0c8XjlhXMvvaztXsb9FuPOTGBU2HA1ABEV+mQv2vARDRj37RSDE/dLL rIwMojoZJ22p76EGYNRn2w9ts+hFFa0LgSsr3i/aXjS4a7g2g7aMP0TLL3ju09B7URdCnvX/aGM2G jx0e5u7w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n94UM-007FUD-8P; Sun, 16 Jan 2022 12:18:26 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 02/12] filemap: Use folio_put_refs() in filemap_free_folio() Date: Sun, 16 Jan 2022 12:18:12 +0000 Message-Id: <20220116121822.1727633-3-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220116121822.1727633-1-willy@infradead.org> References: <20220116121822.1727633-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 110871C0002 X-Stat-Signature: t3d7jejgrgofsi6d68i997uypat8a7n7 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Z4YcmDRU; spf=none (imf20.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1642335507-80181 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: This shrinks filemap_free_folio() by 55 bytes in my .config; 24 bytes from removing the VM_BUG_ON_FOLIO() and 31 bytes from unifying the small/large folio paths. We could just use folio_ref_sub() here since the caller should hold a reference (as the VM_BUG_ON_FOLIO() was asserting), but that's fragile. Signed-off-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 2fd9b2f24025..afc8f5ca85ac 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -231,17 +231,15 @@ void __filemap_remove_folio(struct folio *folio, void *shadow) void filemap_free_folio(struct address_space *mapping, struct folio *folio) { void (*freepage)(struct page *); + int refs = 1; freepage = mapping->a_ops->freepage; if (freepage) freepage(&folio->page); - if (folio_test_large(folio) && !folio_test_hugetlb(folio)) { - folio_ref_sub(folio, folio_nr_pages(folio)); - VM_BUG_ON_FOLIO(folio_ref_count(folio) <= 0, folio); - } else { - folio_put(folio); - } + if (folio_test_large(folio) && !folio_test_hugetlb(folio)) + refs = folio_nr_pages(folio); + folio_put_refs(folio, refs); } /**