From patchwork Tue Nov 6 05:30:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 10669665 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 D4A7014BD for ; Tue, 6 Nov 2018 05:30:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0E6F2A02F for ; Tue, 6 Nov 2018 05:30:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B00012A045; Tue, 6 Nov 2018 05:30:44 +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 3A7D52A02F for ; Tue, 6 Nov 2018 05:30:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43C366B02B3; Tue, 6 Nov 2018 00:30:43 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3C40E6B02B4; Tue, 6 Nov 2018 00:30:43 -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 2685F6B02B5; Tue, 6 Nov 2018 00:30:43 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id D34316B02B3 for ; Tue, 6 Nov 2018 00:30:42 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id 33-v6so12331041pld.19 for ; Mon, 05 Nov 2018 21:30:42 -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=sSuknSTLb0hDdou0FgsYW6Ek6e5AAneTrJySEshBoyc=; b=oPRmpzgYIS0lJbNfHNMXlkeVMsCqai6kfRRo+8HHEYmdTTaMmEo67eiNm7Fus683Bw yblTWsseM0LAljykVA52RtVBX3yklfamWWL4ng4QE/Vuo2qr/mnQg7X1G3sZdVNybzeo AvEdD5hodrq/sHnRRbXKGDKHiwuwmtXPELPpCkHZZenMlhiVnHNEMdH6eXj1+Yk76SiE Uxxw0BtLKvWYU7gcFcWYSizSb9gSsA70AZZ6XpSrdirx2pfmTqCm2sJ7M/yCw1NN0ZUa nmBUBhPeWhdsj2hCH+KE8ExAojNMp4PuQpQRhVQo1zGDjB+C4ifYsAtOQAT1XsRPpde1 y8Mw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 192.55.52.88 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: AGRZ1gI7WRTLa7QezSBn1UntuGiA7OIm4aJL21tPG08CtMe2AtUZxesr ZHE7JMXfdfd9d/9x//AuQybEXhC0YkNhzRWA7skj55F8iCtPm4+WvsXDlkvOf1C2CWCNe1ZRTVX zpGqNJDHzus6zOBvPNd0WzdWCsu4nKIw3vcWnFAYx9ESqswYvtXONUYjo6Ru7W/SqNA== X-Received: by 2002:a17:902:9009:: with SMTP id a9-v6mr25139733plp.134.1541482242503; Mon, 05 Nov 2018 21:30:42 -0800 (PST) X-Google-Smtp-Source: AJdET5d3ylafPaVfh6K90IIbS8RwiwwvJyepm8ruD9jliojBSl+R7NMqV+4tLpylegn5FhmXQAAO X-Received: by 2002:a17:902:9009:: with SMTP id a9-v6mr25139694plp.134.1541482241880; Mon, 05 Nov 2018 21:30:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541482241; cv=none; d=google.com; s=arc-20160816; b=x071u3c/p4+XFo5ae0wGHIIewSfTgSrdCcx6b3aqzdo0OXxzptLcDwsAQwZYAiacgh NJz3wH1158OS9rsHKYLFDvKzh8c9ZIS/l+d17O+lnNN5GpvuSpqYrv/zJxJRdZMS2jQF AUY2gqs5ekR3ztFW1Xi2pjiaXAzDRt6pgzhahhRygib/NNFVgIIhxkKUpi0+MkoSoh2l n/7SMclYkDQQtkPxob1QS+WKxht2Knpw7ttORmS+4GbXyUdADcJHRHsT6dkA7/QjQ3iS zLo1cHlnA/3igP8JSLDGzg4tGFDQ0xQvmdvC+KcZfdyZi9Jt7FT0ztOSBTYWjzI9UVrO gzaA== 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=sSuknSTLb0hDdou0FgsYW6Ek6e5AAneTrJySEshBoyc=; b=ixaBa028u+NO5J4VrB/wnubMNaczdZJwDcDDIMV0Eb188JCX5BcDSQIaGYGZPP2fFo pL6ghNMyiy+4TYZ/QDW7IzSPYDyXnPBzsbPAVZS3U1nvPkViW4iN4KxyYkXCkYhrwr5x U02Lss2hWeBciDQGv0+x3aaal658z4WIVSAturf4NyvisPaPqyvWT+lBxJIBskeEVDoB MpV7Wk5At1vuVz/9+C/tPT4C74RAK37uNViMCk8Mwkc5Pg9lzQFl3moZweDSZSHiLYIt oblLQu1YnrYPOeUMDDbeIW+RAGWf9GM245x9TS8xCWPnRwcQKmX/QbqMujI5GhMeVj+A 3euQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga01.intel.com (mga01.intel.com. [192.55.52.88]) by mx.google.com with ESMTPS id v24-v6si44421949ply.158.2018.11.05.21.30.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 21:30:41 -0800 (PST) Received-SPF: pass (google.com: domain of aaron.lu@intel.com designates 192.55.52.88 as permitted sender) client-ip=192.55.52.88; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2018 21:30:41 -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-Disposition: inline In-Reply-To: <20181105085820.6341-2-aaron.lu@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 --- 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);