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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55812C433F5 for ; Mon, 14 Mar 2022 09:34:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7FA48D0003; Mon, 14 Mar 2022 05:34:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2FC08D0001; Mon, 14 Mar 2022 05:34:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF6FF8D0003; Mon, 14 Mar 2022 05:34:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id A06258D0001 for ; Mon, 14 Mar 2022 05:34:04 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 63ECE237D2 for ; Mon, 14 Mar 2022 09:34:04 +0000 (UTC) X-FDA: 79242480408.13.D125906 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf26.hostedemail.com (Postfix) with ESMTP id 9478814002B for ; Mon, 14 Mar 2022 09:34:03 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6FADC210FE; Mon, 14 Mar 2022 09:34:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1647250442; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hrhvns3eJJSZbbPJB+GUKs5Vp1t21GpqMnW5wv4sJQ8=; b=Y25w2WPOH3cK6txjIYtc49Po4O1/afIyXuOozDA34MwximIDz+N2cmbar4kSB5EYpzkrJk bODVrAA9bozP9LHMeq2RXmoYbfT1j/H3TtejnVbud0rlZXzzTW/1nNQK3sJ7mhyKva6UPi cOepCvvAzYumSLU8QtlsWV6+PopStGs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1647250442; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hrhvns3eJJSZbbPJB+GUKs5Vp1t21GpqMnW5wv4sJQ8=; b=/wIFhhkF1b+HQseLdC724tUXvjOGsEMoH8Bz86vUlo0aZ2HZ6VT6gu1JBvHEQjQlq+mCL0 nm6kqi1rM3wr+eCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3F3ED13B2B; Mon, 14 Mar 2022 09:34:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iqa5DgoML2KUbQAAMHmgww (envelope-from ); Mon, 14 Mar 2022 09:34:02 +0000 Message-ID: Date: Mon, 14 Mar 2022 10:34:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 Content-Language: en-US To: Eric Dumazet , Andrew Morton Cc: linux-kernel , linux-mm , Eric Dumazet , Mel Gorman , Matthew Wilcox , Shakeel Butt , David Rientjes , Michal Hocko , Wei Xu , Greg Thelen , Hugh Dickins References: <20220313232547.3843690-1-eric.dumazet@gmail.com> From: Vlastimil Babka Subject: Re: [PATCH] mm/page_alloc: call check_pcp_refill() while zone spinlock is not held In-Reply-To: <20220313232547.3843690-1-eric.dumazet@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9478814002B X-Stat-Signature: cwd6scr5cpf6tb593jmcq9ey1nby9ypu Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Y25w2WPO; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="/wIFhhkF"; spf=pass (imf26.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-HE-Tag: 1647250443-343721 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 3/14/22 00:25, Eric Dumazet wrote: > From: Eric Dumazet > > check_pcp_refill() is used from rmqueue_bulk() while zone spinlock > is held. > > This used to be fine because check_pcp_refill() was testing only the > head page, while its 'struct page' was very hot in the cpu caches. > > With ("mm/page_alloc: check high-order pages for corruption during PCP > operations") check_pcp_refill() will add latencies for high order pages. > > We can defer the calls to check_pcp_refill() after the zone > spinlock has been released. > > Signed-off-by: Eric Dumazet > Cc: Mel Gorman > Cc: Matthew Wilcox > Cc: Shakeel Butt > Cc: David Rientjes > Cc: Vlastimil Babka > Cc: Michal Hocko > Cc: Wei Xu > Cc: Greg Thelen > Cc: Hugh Dickins > --- > mm/page_alloc.c | 21 +++++++++++++-------- > 1 file changed, 13 insertions(+), 8 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index c9ebf0635d592c6f58df9793ce9fa213371a9a7f..5f0531c11ad668b1c4426ebddc17821aca824783 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -3024,7 +3024,9 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order, > unsigned long count, struct list_head *list, > int migratetype, unsigned int alloc_flags) > { > + struct page *page, *tmp; > int i, allocated = 0; > + int free_cma_pages = 0; > > /* > * local_lock_irq held so equivalent to spin_lock_irqsave for Right so this should be AFAIU enough for __mod_zone_page_state(NR_FREE_CMA_PAGES) at the end to be OK outside of zone->lock. > @@ -3032,14 +3034,10 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order, > */ > spin_lock(&zone->lock); > for (i = 0; i < count; ++i) { > - struct page *page = __rmqueue(zone, order, migratetype, > - alloc_flags); > + page = __rmqueue(zone, order, migratetype, alloc_flags); > if (unlikely(page == NULL)) > break; > > - if (unlikely(check_pcp_refill(page))) > - continue; > - > /* > * Split buddy pages returned by expand() are received here in > * physical page order. The page is added to the tail of > @@ -3052,9 +3050,6 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order, > */ > list_add_tail(&page->lru, list); > allocated++; > - if (is_migrate_cma(get_pcppage_migratetype(page))) > - __mod_zone_page_state(zone, NR_FREE_CMA_PAGES, > - -(1 << order)); > } > > /* > @@ -3065,6 +3060,16 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order, > */ > __mod_zone_page_state(zone, NR_FREE_PAGES, -(i << order)); > spin_unlock(&zone->lock); You could maybe even exchange those two lines as well? > + list_for_each_entry_safe(page, tmp, list, lru) { > + if (unlikely(check_pcp_refill(page))) { > + list_del(&page->lru); > + allocated--; > + } else if (is_migrate_cma(get_pcppage_migratetype(page))) { > + free_cma_pages++; I think in line with the (IMHO correct) decreasing NR_FREE_CMA_PAGES regardless of the check result, we should also count free_cma_pages here unconditionally before doing check_pcp_refill(). > + } > + } > + if (free_cma_pages) > + __mod_zone_page_state(zone, NR_FREE_CMA_PAGES, -(free_cma_pages << order)); > return allocated; > } >