Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1441996imu; Mon, 5 Nov 2018 21:31:20 -0800 (PST) X-Google-Smtp-Source: AJdET5fGIppcxCfspxMo6/N2/HnozZqsSnaAZehx4H7FaqZ5poeIRVlSVKkojqiOhgDv7fKanVlL X-Received: by 2002:a63:1b1f:: with SMTP id b31mr22322155pgb.66.1541482280139; Mon, 05 Nov 2018 21:31:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541482280; cv=none; d=google.com; s=arc-20160816; b=xXeKfFqXK92WBTGOTVQTmjhU0/KWDaKLAwNPwY+31srdJJr34BDE2vlkYXwZVnukxO iNVlGQ+QVFIy3gwSdMOPSn1sZpffDydxkWgy4aJbSwDVXX7CpkoLF1EXXKVOEnE6E5Wo ksC8wcBPMEUVAOYxr8IWKn5Vjdt8dYwpf+0dU8tpKAtFANg3H04Q5oOIDnT2uaVu2SFP UIA8/hvg+BkR4pEX0btPQkY6X5+d1IxG9W5y/q1tnqtdm+HdKzZqTWVNzUVNf0evLwKl KaflYOO7MyLW2pps/fp9maEI3K0TT1K7fnUJ3kjfBrf3Tmmala4VmYCH3j3j7SksUjAx PuBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=sSuknSTLb0hDdou0FgsYW6Ek6e5AAneTrJySEshBoyc=; b=mZ+cKpnWUct3bnwjqwF+TgkoLrijy8pqGFHPcQPfkvk2yIcOu8jE0WR048yw2y7qMT WmV1HnoUpWOXR3NypZOoOf8lplsZ1P5nFGDReeq5r0IjhvUs2v+C8ReVtWjSIyncl4V5 GHHGqLW6sE8wv4kVChFzLZeUBhOHX4HEaJlxHbjQnw8MUo+gRQuBYoBMI9kqbZ2D4PGe KbhtApQSSRyo0LOX5A2A9863dLo+/AKLPFbo1i9R9gmXHLqf6RWuQ8VqZmtwnEZSD97V myv5ItzgklB7FgjSDp9f3uu+t8JYHOo1kPB4N/4UMWhUxsAA4cOdbtcZt6LqtGJVM/9T 4DrQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d31-v6si47422131pla.27.2018.11.05.21.31.04; Mon, 05 Nov 2018 21:31: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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729712AbeKFOyI (ORCPT + 99 others); Tue, 6 Nov 2018 09:54:08 -0500 Received: from mga07.intel.com ([134.134.136.100]:2531 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729016AbeKFOyH (ORCPT ); Tue, 6 Nov 2018 09:54:07 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2018 21:30:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,470,1534834800"; d="scan'208";a="88880351" Received: from aaronlu.sh.intel.com (HELO intel.com) ([10.239.159.44]) by orsmga006.jf.intel.com with ESMTP; 05 Nov 2018 21:30:36 -0800 Date: Tue, 6 Nov 2018 13:30:37 +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 v2 2/2] mm/page_alloc: use a single function to free page Message-ID: <20181106053037.GD6203@intel.com> References: <20181105085820.6341-1-aaron.lu@intel.com> <20181105085820.6341-2-aaron.lu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181105085820.6341-2-aaron.lu@intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- v2: move comments close to code as suggested by Dave. mm/page_alloc.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 91a9a6af41a2..4faf6b7bf225 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4425,9 +4425,17 @@ 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, int nr) { - if (put_page_testzero(page)) { + VM_BUG_ON_PAGE(page_ref_count(page) == 0, page); + + /* + * Free a page by reducing its ref count by @nr. + * If its refcount reaches 0, then according to its order: + * order0: send to PCP; + * high order: directly send to Buddy. + */ + if (page_ref_sub_and_test(page, nr)) { if (order == 0) free_unref_page(page); else @@ -4435,6 +4443,10 @@ void __free_pages(struct page *page, unsigned int order) } } +void __free_pages(struct page *page, unsigned int order) +{ + free_the_page(page, order, 1); +} EXPORT_SYMBOL(__free_pages); void free_pages(unsigned long addr, unsigned int order) @@ -4481,16 +4493,7 @@ static struct page *__page_frag_cache_refill(struct page_frag_cache *nc, 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); - } + free_the_page(page, compound_order(page), count); } EXPORT_SYMBOL(__page_frag_cache_drain); @@ -4555,14 +4558,7 @@ 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); - } + free_the_page(page, compound_order(page), 1); } EXPORT_SYMBOL(page_frag_free); -- 2.17.2