Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp4589963pja; Thu, 21 Nov 2019 22:25:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwU4afTgIzsunyijJ3en9aCGHTA04+V/JIBiX4GSjSfSnsanaxWR8ossLEmFu/lTRNVbNhj X-Received: by 2002:a17:906:6b01:: with SMTP id q1mr19754006ejr.162.1574403920648; Thu, 21 Nov 2019 22:25:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574403920; cv=none; d=google.com; s=arc-20160816; b=Xi9S2SbpVagEveKIlgZ2W4fQxjQ9rOVoockUkF5sLLRuHEwjfHXT/CI8dIeSHtYEpo vAGaszmSq6Ui5xmZ5+h2gOPyboh8R73xIjGqsNnLyaFYpwUX0Du3t56m57nXF5yrE1FE qlN9MY3kbAuZDCmicDedABc8YRZWoqbVQrq15++TNWBJxiwfx/yVwuwwJHOye3r9zSXi sKyA2JDZbX8i5SalCMhrr1lR95YSBkb1PyHMg69JegZS0zQhF1yY4YDRu34yB0sIuJ7j eZEc3gEhb7povnjxtYPOqFnx+BbH6UMarARAEkt14Irk5hlxN2gGw0SqvAq0X/LblK8Q UPrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t1V0d7BFyyt7R8IoVR0DFx9ITmyLsgW1DdY08IBqNE8=; b=v7sB0MxGmjyte7WI18LxpdvTRb49awuli4fOyy40w67r3C3zbDqzai75gFTXvL5rMu kyCjITeLuAb77IUwrDsbHZRxV2m4HL2LsLDqSRvbIN7PFWQwcjCZ+5IKrEoGbU0FxFFj MiqDIQ18z0GB35wxGRalI0jyN0AxsvCkKHo77nxEz4YbG6ROGTqXNb/9suo9KXO6mLnU hHEtSocCfVsS4OACnhyAHhYuXiLXV6fCkRaM04QHfv/NelgVYkwsw78oj567clahy9lG mdBnkKPMpMWeaXB8JNvsOXlB23CZ6h9+VsVVJsvpPIQzyTzypVDakDKy7wySEyQ4QgzF ZvIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=szSHzuqW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h17si3335880ejy.239.2019.11.21.22.24.56; Thu, 21 Nov 2019 22:25:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=szSHzuqW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728445AbfKVFwN (ORCPT + 99 others); Fri, 22 Nov 2019 00:52:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:57624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728419AbfKVFwJ (ORCPT ); Fri, 22 Nov 2019 00:52:09 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 115272071B; Fri, 22 Nov 2019 05:52:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574401928; bh=KG6ooScHarpxP6/uZ0p1fKUiCMRXaGr7NhSoKbbuXzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=szSHzuqWymcR5A0LWClU6i1hforFTJVWo2mSPgnEVVqj1SBPUaX55tcX9gbf8zCiX rZEFKmq0uSUVfVA+/lDNYdi2NTJa9VM0cCexN7AcrY7lLPaVHwKayIoEi+wVmGh0B0 vH5hWD4pn0hTCUzf0ckHvopmVLrE4jhSOVeJ+OpU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Aaron Lu , Vlastimil Babka , Alexander Duyck , Ilias Apalodimas , Jesper Dangaard Brouer , Mel Gorman , Pankaj gupta , Pawel Staszewski , Tariq Toukan , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.19 155/219] mm/page_alloc.c: use a single function to free page Date: Fri, 22 Nov 2019 00:48:07 -0500 Message-Id: <20191122054911.1750-148-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122054911.1750-1-sashal@kernel.org> References: <20191122054911.1750-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aaron Lu [ Upstream commit 742aa7fb52c56fb3b307e704f93e67b698959cc2 ] There are multiple places of freeing a page, they all do the same things so a common function can be used to reduce code duplicate. It also avoids bug fixed in one function but left in another. Link: http://lkml.kernel.org/r/20181119134834.17765-3-aaron.lu@intel.com Signed-off-by: Aaron Lu Acked-by: Vlastimil Babka Cc: Alexander Duyck Cc: Ilias Apalodimas Cc: Jesper Dangaard Brouer Cc: Mel Gorman Cc: Pankaj gupta Cc: Pawel Staszewski Cc: Tariq Toukan Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/page_alloc.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index dcc46d955df2e..74fb5c338e8fb 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4451,16 +4451,19 @@ unsigned long get_zeroed_page(gfp_t gfp_mask) } EXPORT_SYMBOL(get_zeroed_page); -void __free_pages(struct page *page, unsigned int order) +static inline void free_the_page(struct page *page, unsigned int order) { - if (put_page_testzero(page)) { - if (order == 0) - free_unref_page(page); - else - __free_pages_ok(page, order); - } + if (order == 0) /* Via pcp? */ + free_unref_page(page); + else + __free_pages_ok(page, order); } +void __free_pages(struct page *page, unsigned int order) +{ + if (put_page_testzero(page)) + free_the_page(page, order); +} EXPORT_SYMBOL(__free_pages); void free_pages(unsigned long addr, unsigned int order) @@ -4509,14 +4512,8 @@ void __page_frag_cache_drain(struct page *page, unsigned int count) { VM_BUG_ON_PAGE(page_ref_count(page) == 0, page); - if (page_ref_sub_and_test(page, count)) { - unsigned int order = compound_order(page); - - if (order == 0) - free_unref_page(page); - else - __free_pages_ok(page, order); - } + if (page_ref_sub_and_test(page, count)) + free_the_page(page, compound_order(page)); } EXPORT_SYMBOL(__page_frag_cache_drain); @@ -4581,14 +4578,8 @@ void page_frag_free(void *addr) { struct page *page = virt_to_head_page(addr); - if (unlikely(put_page_testzero(page))) { - unsigned int order = compound_order(page); - - if (order == 0) /* Via pcp? */ - free_unref_page(page); - else - __free_pages_ok(page, order); - } + if (unlikely(put_page_testzero(page))) + free_the_page(page, compound_order(page)); } EXPORT_SYMBOL(page_frag_free); -- 2.20.1