Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756731Ab3H3NYJ (ORCPT ); Fri, 30 Aug 2013 09:24:09 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:47568 "EHLO e9.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755424Ab3H3NYD (ORCPT ); Fri, 30 Aug 2013 09:24:03 -0400 From: "Srivatsa S. Bhat" Subject: [RFC PATCH v3 20/35] mm: Provide a mechanism to delete pages from buddy freelists in bulk To: akpm@linux-foundation.org, mgorman@suse.de, hannes@cmpxchg.org, tony.luck@intel.com, matthew.garrett@nebula.com, dave@sr71.net, riel@redhat.com, arjan@linux.intel.com, srinivas.pandruvada@linux.intel.com, willy@linux.intel.com, kamezawa.hiroyu@jp.fujitsu.com, lenb@kernel.org, rjw@sisk.pl Cc: gargankita@gmail.com, paulmck@linux.vnet.ibm.com, svaidy@linux.vnet.ibm.com, andi@firstfloor.org, isimatu.yasuaki@jp.fujitsu.com, santosh.shilimkar@ti.com, kosaki.motohiro@gmail.com, srivatsa.bhat@linux.vnet.ibm.com, linux-pm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Fri, 30 Aug 2013 18:50:01 +0530 Message-ID: <20130830131959.4947.91045.stgit@srivatsabhat.in.ibm.com> In-Reply-To: <20130830131221.4947.99764.stgit@srivatsabhat.in.ibm.com> References: <20130830131221.4947.99764.stgit@srivatsabhat.in.ibm.com> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13083013-7182-0000-0000-0000084105A2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2739 Lines: 85 When the buddy allocator releases excess free memory to the region allocator, it does it at a region granularity - that is, it releases all the freepages of that region to the region allocator, at once. So, in order to make this efficient, we need a way to delete all those pages from the buddy freelists in one shot. Add this support, and also take care to update the nr-free statistics properly. Signed-off-by: Srivatsa S. Bhat --- mm/page_alloc.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b66ddff..5227ac3 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -853,6 +853,61 @@ page_found: } } +/* + * Delete all freepages belonging to the region 'region_id' from 'free_list' + * and move them to 'list'. Using suitable list-manipulation tricks, we move + * the pages between the lists in one shot. + */ +static void del_from_freelist_bulk(struct list_head *list, + struct free_list *free_list, int order, + int region_id) +{ + struct mem_region_list *region, *prev_region; + unsigned long nr_pages = 0; + struct free_area *area; + struct list_head *cur; + struct page *page; + int prev_region_id; + + region = &free_list->mr_list[region_id]; + + /* + * Perform bulk movement of all pages of the region to the new list, + * except the page pointed to by region->pageblock. + */ + prev_region_id = find_prev_region(region_id, free_list); + if (prev_region_id < 0) { + /* This is the first region on the list */ + list_cut_position(list, &free_list->list, + region->page_block->prev); + } else { + prev_region = &free_list->mr_list[prev_region_id]; + list_cut_position(list, prev_region->page_block, + region->page_block->prev); + } + + list_for_each(cur, list) + nr_pages++; + + region->nr_free -= nr_pages; + + /* + * Now delete the page pointed to by region->page_block using + * del_from_freelist(), so that it sets up the region related + * data-structures of the freelist properly. + */ + page = list_entry(region->page_block, struct page, lru); + del_from_freelist(page, free_list, order); + + list_add_tail(&page->lru, list); + + area = &(page_zone(page)->free_area[order]); + area->nr_free -= nr_pages + 1; + + /* Fix up the zone region stats, since del_from_freelist() altered it */ + region->zone_region->nr_free += 1 << order; +} + /** * Move a given page from one freelist to another. */ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/