Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3362244pxp; Mon, 14 Mar 2022 17:49:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylS33TaJmksDPwjaMcBQucaR0O90WHmXGpIbFM0hsMpGo2b8ZDVEqB/Drbfst9oDguv4DB X-Received: by 2002:a05:6a00:2448:b0:4f7:a138:29c7 with SMTP id d8-20020a056a00244800b004f7a13829c7mr15006678pfj.32.1647305365964; Mon, 14 Mar 2022 17:49:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647305365; cv=none; d=google.com; s=arc-20160816; b=Cmi7kNVcoSgYDbwmVq8yhWMs/2R86X+mx3jNSIyQc1nFpXTKk2URzYPVP/odbXdwwu lmmU7QY33ryPVpc41GB4UWMlUgiSsKZ2p0b2ybLvZL5iMGWsW2UpUrvRBn9F9KYtj3RS 99PAdCFG7qystj1IGSIVIEDPLuBwW/FPpUxI0+sbVmNetGXtSRwLcp5MZ2B/Hdty5VY8 aZVsQ5s9c4k2N+FrYpv46bRQZJh0MHMltYm2ltipYJhWfw5ZQ5ikzvAslsdMez2yZN2S N507JiZmtN110BuQ0Fkfy9cjHJISeuJIgfM0Cn9SsENRWEuIwWM4fL7aHnWHD/VWMX2v LdNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=hrhvns3eJJSZbbPJB+GUKs5Vp1t21GpqMnW5wv4sJQ8=; b=PCVMZUACoiRSeaiqVydmJQd/KeZkJNEFWFfNZdCxzjHCZ59nwi/Lfz+9s34aoZT6aT KeCasp/cIcdq702hsKqmPNMuQl2X+vua4MXXVM8VpnsEcA1OkXVe56h1QxEtJ663aHd0 D1O6i++6MA89PhtDWUFqqh0HpOhaHvgl/Wy7QIlbJtJsRhOre3/hGnQkmqW2IPn/5a8x RPRi+tybSkxsY/Sh1qlt7ZJttBOc2yxaOdMpOtnP/iUYnbX6Gm5xT1oMLjwJghnSHxTT CIBPuZiC688G1tu9OqA9h3NWQtmR/bxnY0uUPwuLyGJBT6sQKL54Y+CBMNeLa5G+nQt9 V/Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Y25w2WPO; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l1-20020a63da41000000b0037434232a7fsi16298992pgj.113.2022.03.14.17.49.02; Mon, 14 Mar 2022 17:49:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Y25w2WPO; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233081AbiCNJfO (ORCPT + 99 others); Mon, 14 Mar 2022 05:35:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229821AbiCNJfN (ORCPT ); Mon, 14 Mar 2022 05:35:13 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB4B87649 for ; Mon, 14 Mar 2022 02:34:03 -0700 (PDT) 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; > } >