From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E333C433B4 for ; Mon, 12 Apr 2021 10:59:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A445761074 for ; Mon, 12 Apr 2021 10:59:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A445761074 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=techsingularity.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4226C6B006C; Mon, 12 Apr 2021 06:59:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F9146B006E; Mon, 12 Apr 2021 06:59:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30F446B0070; Mon, 12 Apr 2021 06:59:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id 14D7C6B006C for ; Mon, 12 Apr 2021 06:59:44 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id CB5701803978A for ; Mon, 12 Apr 2021 10:59:43 +0000 (UTC) X-FDA: 78023419446.39.58AEB18 Received: from outbound-smtp56.blacknight.com (outbound-smtp56.blacknight.com [46.22.136.240]) by imf14.hostedemail.com (Postfix) with ESMTP id 0725EC0007D4 for ; Mon, 12 Apr 2021 10:59:35 +0000 (UTC) Received: from mail.blacknight.com (pemlinmail02.blacknight.ie [81.17.254.11]) by outbound-smtp56.blacknight.com (Postfix) with ESMTPS id C9AB9FB858 for ; Mon, 12 Apr 2021 11:59:39 +0100 (IST) Received: (qmail 8089 invoked from network); 12 Apr 2021 10:59:39 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.22.4]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 12 Apr 2021 10:59:39 -0000 Date: Mon, 12 Apr 2021 11:59:38 +0100 From: Mel Gorman To: Vlastimil Babka Cc: Andrew Morton , Chuck Lever , Jesper Dangaard Brouer , Christoph Hellwig , Alexander Duyck , Matthew Wilcox , Ilias Apalodimas , LKML , Linux-Net , Linux-MM , Linux-NFS Subject: Re: [PATCH 2/9] mm/page_alloc: Add a bulk page allocator Message-ID: <20210412105938.GU3697@techsingularity.net> References: <20210325114228.27719-1-mgorman@techsingularity.net> <20210325114228.27719-3-mgorman@techsingularity.net> <28729c76-4e09-f860-0db1-9c79c8220683@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <28729c76-4e09-f860-0db1-9c79c8220683@suse.cz> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0725EC0007D4 X-Stat-Signature: a17gh9yeenhbm5egdsjskwdft5zaqe1e Received-SPF: none (techsingularity.net>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from=""; helo=outbound-smtp56.blacknight.com; client-ip=46.22.136.240 X-HE-DKIM-Result: none/none X-HE-Tag: 1618225175-18032 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: On Mon, Apr 12, 2021 at 12:21:42PM +0200, Vlastimil Babka wrote: > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index 8a3e13277e22..eb547470a7e4 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -4965,6 +4965,124 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, > > return true; > > } > > > > +/* > > + * __alloc_pages_bulk - Allocate a number of order-0 pages to a list > > + * @gfp: GFP flags for the allocation > > + * @preferred_nid: The preferred NUMA node ID to allocate from > > + * @nodemask: Set of nodes to allocate from, may be NULL > > + * @nr_pages: The number of pages desired on the list > > + * @page_list: List to store the allocated pages > > + * > > + * This is a batched version of the page allocator that attempts to > > + * allocate nr_pages quickly and add them to a list. > > + * > > + * Returns the number of pages on the list. > > + */ > > +int __alloc_pages_bulk(gfp_t gfp, int preferred_nid, > > + nodemask_t *nodemask, int nr_pages, > > + struct list_head *page_list) > > +{ > > + struct page *page; > > + unsigned long flags; > > + struct zone *zone; > > + struct zoneref *z; > > + struct per_cpu_pages *pcp; > > + struct list_head *pcp_list; > > + struct alloc_context ac; > > + gfp_t alloc_gfp; > > + unsigned int alloc_flags; > > Was going to complain that this is not set to ALLOC_WMARK_LOW. Must be faster > next time... > Good that you caught it anyway! > > + int allocated = 0; > > + > > + if (WARN_ON_ONCE(nr_pages <= 0)) > > + return 0; > > + > > + /* Use the single page allocator for one page. */ > > + if (nr_pages == 1) > > + goto failed; > > + > > + /* May set ALLOC_NOFRAGMENT, fragmentation will return 1 page. */ > > I don't understand this comment. Only alloc_flags_nofragment() sets this flag > and we don't use it here? > It's there as a reminder that there are non-obvious consequences to ALLOC_NOFRAGMENT that may affect the bulk allocation success rate. __rmqueue_fallback will only select pageblock_order pages and if that fails, we fall into the slow path that allocates a single page. I didn't deal with it because it was not obvious that it's even relevant but I bet in 6 months time, I'll forget that ALLOC_NOFRAGMENT may affect success rates without the comment. I'm waiting for a bug that can trivially trigger a case with a meaningful workload where the success rate is poor enough to affect latency before adding complexity. Ideally by then, the allocation paths would be unified a bit better. > > + gfp &= gfp_allowed_mask; > > + alloc_gfp = gfp; > > + if (!prepare_alloc_pages(gfp, 0, preferred_nid, nodemask, &ac, &alloc_gfp, &alloc_flags)) > > + return 0; > > + gfp = alloc_gfp; > > + > > + /* Find an allowed local zone that meets the high watermark. */ > > Should it say "low watermark"? > Yeah, that's leftover from an earlier prototype :( -- Mel Gorman SUSE Labs