Received: by 10.223.176.46 with SMTP id f43csp173250wra; Tue, 23 Jan 2018 18:31:12 -0800 (PST) X-Google-Smtp-Source: AH8x225+u9om5OjiR+l0QUFrWSDj/155qtKuPOwB2Qp0w10jHxG+G064XsZX5sWfOfzc2gVIukic X-Received: by 10.99.96.201 with SMTP id u192mr9600418pgb.234.1516761072560; Tue, 23 Jan 2018 18:31:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516761072; cv=none; d=google.com; s=arc-20160816; b=IZVCiAuz5LXKRdURcbap0Fb9NP+9IbFsOvG5veM3RHWjn4FGG1B4AtAOgUI2cxAeUR AIUWN8uiQ68t2/cHPE2XdHTwpvPL72ZQjBKyPvN587ESIBeSTHz8dkS3S1ULbr5G2rnB +B408iEi1wN+hnrsxB7PZMQZbaYVOPe0IiFFmDB55h/NcZAuS4FlaSUGMmc7nxkyhvIk gFx4DBK5FvyqoyDDjaoh8jx8iFqZy+rFSEnmKp5WnasSaGMDPIzrfa4Mirl7t1IIcwYX rVZ2GYwoIFWnIaGB+sw5/upZT0zjnbHzYYtbFxKpIBZBUhzbR3PlFHklVqFB6kenzQia ALZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=vnYA2qj6o4uNTlMfkOysjGktDk8+gZVIT9Tiq+7Ucms=; b=m4QL5Ps7G+U2ARYpl6MJCvAZoui6MlxU+tYyQYDRWgo5u8KxHwRbYtsd03EEt+5rA7 huVNfQPq/V8GFMhAGgrFloV0zE6cx9ORYT08rZaohjJ62psRVq/2DYO5fmieWMp8BJui 4sL0Gv8pfC6py0zDeuKcmlPCL9TXMDa3fouieWbcKTN/mYbx7jQyhfyOb4mXUxjs0ajA 21r7OhWJITilRx2+zflXE7VhNCxc6JuKu82L2WkWITU6MvtDtatPX3n1tyJVgmcA/Rxd OzZ1qxycQjgUmN58a83HpaCrZiAbGdmEYsK88UXTEX0FKgbYMF7FJnNpo1siN0D8Qkms cXpQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t14si12534655pgn.157.2018.01.23.18.30.57; Tue, 23 Jan 2018 18:31:12 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752079AbeAXCac (ORCPT + 99 others); Tue, 23 Jan 2018 21:30:32 -0500 Received: from mga01.intel.com ([192.55.52.88]:43977 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751937AbeAXCaa (ORCPT ); Tue, 23 Jan 2018 21:30:30 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Jan 2018 18:30:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,404,1511856000"; d="scan'208";a="21846883" Received: from aaronlu.sh.intel.com ([10.239.159.135]) by orsmga003.jf.intel.com with ESMTP; 23 Jan 2018 18:30:28 -0800 From: Aaron Lu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Huang Ying , Dave Hansen , Kemi Wang , Tim Chen , Andi Kleen , Michal Hocko , Vlastimil Babka , Mel Gorman Subject: [PATCH 1/2] free_pcppages_bulk: do not hold lock when picking pages to free Date: Wed, 24 Jan 2018 10:30:49 +0800 Message-Id: <20180124023050.20097-1-aaron.lu@intel.com> X-Mailer: git-send-email 2.14.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When freeing a batch of pages from Per-CPU-Pages(PCP) back to buddy, the zone->lock is held and then pages are chosen from PCP's migratetype list. While there is actually no need to do this 'choose part' under lock since it's PCP pages, the only CPU that can touch them is us and irq is also disabled. Moving this part outside could reduce lock held time and improve performance. Test with will-it-scale/page_fault1 full load: kernel Broadwell(2S) Skylake(2S) Broadwell(4S) Skylake(4S) v4.15-rc4 9037332 8000124 13642741 15728686 this patch 9608786 +6.3% 8368915 +4.6% 14042169 +2.9% 17433559 +10.8% What the test does is: starts $nr_cpu processes and each will repeated do the following for 5 minutes: 1 mmap 128M anonymouse space; 2 write access to that space; 3 munmap. The score is the aggregated iteration. https://github.com/antonblanchard/will-it-scale/blob/master/tests/page_fault1.c Signed-off-by: Aaron Lu --- mm/page_alloc.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 4093728f292e..a076f754dac1 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1113,12 +1113,12 @@ static void free_pcppages_bulk(struct zone *zone, int count, int migratetype = 0; int batch_free = 0; bool isolated_pageblocks; + struct list_head head; + struct page *page, *tmp; - spin_lock(&zone->lock); - isolated_pageblocks = has_isolate_pageblock(zone); + INIT_LIST_HEAD(&head); while (count) { - struct page *page; struct list_head *list; /* @@ -1140,26 +1140,31 @@ static void free_pcppages_bulk(struct zone *zone, int count, batch_free = count; do { - int mt; /* migratetype of the to-be-freed page */ - page = list_last_entry(list, struct page, lru); /* must delete as __free_one_page list manipulates */ list_del(&page->lru); - mt = get_pcppage_migratetype(page); - /* MIGRATE_ISOLATE page should not go to pcplists */ - VM_BUG_ON_PAGE(is_migrate_isolate(mt), page); - /* Pageblock could have been isolated meanwhile */ - if (unlikely(isolated_pageblocks)) - mt = get_pageblock_migratetype(page); - if (bulkfree_pcp_prepare(page)) continue; - __free_one_page(page, page_to_pfn(page), zone, 0, mt); - trace_mm_page_pcpu_drain(page, 0, mt); + list_add_tail(&page->lru, &head); } while (--count && --batch_free && !list_empty(list)); } + + spin_lock(&zone->lock); + isolated_pageblocks = has_isolate_pageblock(zone); + + list_for_each_entry_safe(page, tmp, &head, lru) { + int mt = get_pcppage_migratetype(page); + /* MIGRATE_ISOLATE page should not go to pcplists */ + VM_BUG_ON_PAGE(is_migrate_isolate(mt), page); + /* Pageblock could have been isolated meanwhile */ + if (unlikely(isolated_pageblocks)) + mt = get_pageblock_migratetype(page); + + __free_one_page(page, page_to_pfn(page), zone, 0, mt); + trace_mm_page_pcpu_drain(page, 0, mt); + } spin_unlock(&zone->lock); } -- 2.14.3