From patchwork Tue Nov 6 11:31:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 10670145 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 38B8F15A6 for ; Tue, 6 Nov 2018 11:31:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2385429C16 for ; Tue, 6 Nov 2018 11:31:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12BB429C49; Tue, 6 Nov 2018 11:31:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A54829C16 for ; Tue, 6 Nov 2018 11:31:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EA306B030E; Tue, 6 Nov 2018 06:31:54 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7993B6B0310; Tue, 6 Nov 2018 06:31:54 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AE766B0311; Tue, 6 Nov 2018 06:31:54 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 2D92F6B030E for ; Tue, 6 Nov 2018 06:31:54 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id j13-v6so12274073pff.0 for ; Tue, 06 Nov 2018 03:31:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:message-id:references:mime-version:content-disposition :in-reply-to:user-agent; bh=nooXuvKyhrXoM0mH7x9dhIX7ZgTpfgfIEvVfYWQ280A=; b=Y8icm6UBNGU0xS79Eg19aiz+vS3XxlsGy6tY+RpmJ9gpdA1k0V6Sodpu/CxJe87B3p UPu/f+t0Zz7k0aFoBCmYj7f8ZcMoLXe05CgMgCu7am2Y328SddmtdfSDaGQTmQCMxJ1c FFJRc0b2PX8DhWxAUDGCGN42+YRIb9FEKQ6ziiAKKpymgQzDXrB4niTbnx8eMcuo4rNh n338itbnJUOIxsqJNPzY6k3TLlYILLRx11QEDRinhpDyER7ffw9QgVT/Hk4SBXJiaxYk 60+b29TwTEL7Dj4VDR04tMPijWSZUFcKqphWNkSeorpZ6eb6VV9nsribr3IkFFGV+98B /TKg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AGRZ1gIjLQi1op5gIZF5F2qy4zXI3iNqX4w9f2t+qLMxOXR8TMUaSUIv X/SInkEZMD5ZnmPx4DXD2Rbdi06/gcvdtQK0Bmnq9x4D0H4fIh8B2l6MQnwpjulr9P3AxqB9uC8 OBavnPl/KFmVoeHCXcAHOLfqBj875B/7mHe5YK8TGxBdh1WiBJFuVdhb6Hbaa159epA== X-Received: by 2002:a62:120b:: with SMTP id a11-v6mr25687691pfj.165.1541503913795; Tue, 06 Nov 2018 03:31:53 -0800 (PST) X-Google-Smtp-Source: AJdET5euOIYEHm4nnj1UkBsb0UGVWDbRG3quiQxwGtPDxvGtMOmaxoHPQjz1FaHpA0cUsdjUwY+1 X-Received: by 2002:a62:120b:: with SMTP id a11-v6mr25687618pfj.165.1541503912984; Tue, 06 Nov 2018 03:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541503912; cv=none; d=google.com; s=arc-20160816; b=0QQ5GE8zRpHAv3JzfSX2zWRX4UQiwgWQ4rGoCo7BWNKEC2F+pV60DV0NB7GItNe/rQ Um0IT4jVb0wbbly2blj+EGEHyoKdbyIYAR0dzLKY5kdXg/EdcFL613UNA9jUHzkoBFiO MYmBdFzRUhDrmUwX3qusyraGdTt7OIaG1eOxLE+FyMzzZGSLSPu3AdI1eb0qyOQ9Khew 9dzQ8Bnrpga4A07A7C2ySGF1v0gn8RzKAGaAR7eQaoKUg87XFywlxeQDO1QNXZjcQL3/ QKrCdvsMFQ8mzeaOKtjLFFHbyyWI0/odmciIO9hHjM78fpPlNP91WV+yRVDuGZu3JUG4 D3jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date; bh=nooXuvKyhrXoM0mH7x9dhIX7ZgTpfgfIEvVfYWQ280A=; b=VcQidga+kJj1Zi/3Rgz4iNBKt+fCXSevFxhJdhsO8k1V906rG83hPvTvmZw6Ma1KQI iXx/hnxNG/YMozWiaqWZC2/0OsAD7zgnEGDUNnDxYt3AfaJfTTNrQJN8xknSYmj2UGRE B+JHXHMTRcqAQF+349AhOLIwoh9gLrqPb9atog0dAq1Y5+9nHc9GbO/jQDTg5iV5A6IO 0tVccyuPRfySxh4c1mlIQ7dMSeCYJULj0ne/9ow4sMnOywlKHLQzuVYtQeKvdIobkPH7 tIMKSDwFq3dR1l5BLla0bww5M10Nt58PP8G9DuFF/8y8CHqesBnfgH6VeKO2z/m2Nut8 v7gg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga03.intel.com (mga03.intel.com. [134.134.136.65]) by mx.google.com with ESMTPS id b3-v6si47754312plc.103.2018.11.06.03.31.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 03:31:52 -0800 (PST) Received-SPF: pass (google.com: domain of aaron.lu@intel.com designates 134.134.136.65 as permitted sender) client-ip=134.134.136.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Nov 2018 03:31:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,471,1534834800"; d="scan'208";a="247384839" Received: from aaronlu.sh.intel.com (HELO intel.com) ([10.239.159.44]) by orsmga004.jf.intel.com with ESMTP; 06 Nov 2018 03:31:49 -0800 Date: Tue, 6 Nov 2018 19:31:49 +0800 From: Aaron Lu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Andrew Morton , =?utf-8?b?UGF3ZcWC?= Staszewski , Jesper Dangaard Brouer , Eric Dumazet , Tariq Toukan , Ilias Apalodimas , Yoel Caspersen , Mel Gorman , Saeed Mahameed , Michal Hocko , Vlastimil Babka , Dave Hansen , Alexander Duyck Subject: [PATCH v3 2/2] mm/page_alloc: use a single function to free page Message-ID: <20181106113149.GC24198@intel.com> References: <20181105085820.6341-1-aaron.lu@intel.com> <20181105085820.6341-2-aaron.lu@intel.com> <20181106053037.GD6203@intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20181106053037.GD6203@intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) 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: X-Virus-Scanned: ClamAV using ClamSMTP We have multiple places of freeing a page, most of them doing similar things and a common function can be used to reduce code duplicate. It also avoids bug fixed in one function but left in another. Signed-off-by: Aaron Lu Acked-by: Vlastimil Babka --- v3: Vlastimil mentioned the possible performance loss by using page_ref_sub_and_test(page, 1) for put_page_testzero(page), since we aren't sure so be safe by keeping page ref decreasing code as is, only move freeing page part to a common function. 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 91a9a6af41a2..431a03aa96f8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4425,16 +4425,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) + 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) @@ -4483,14 +4486,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); @@ -4555,14 +4552,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) - 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);