Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp213130pxb; Wed, 11 Nov 2020 01:32:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRpNd/Jlj4s3kaSq8Uce4TSbXE1bgSarkrWbeL0Wo9J298a/NmbQ+pTRdPtThWH3/soY0C X-Received: by 2002:a05:6402:43:: with SMTP id f3mr24972696edu.373.1605087152257; Wed, 11 Nov 2020 01:32:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605087152; cv=none; d=google.com; s=arc-20160816; b=LgkPvO3+ay78st4ezB9uZuC7dsA2WwVNJnrEy7HKJz5pz+XzthsAW8drTkkvMEg2zH MvufCrr87xewpZATSNiEF9dQBc5OgbG+8mTYnXCnP0EMZN9ejjqJ0exlhs5X8uKJAI5U HaJsNJDtG0nh5uMPnWgIUfzl9xL72z6Nt2yockUjABTQY+jfmDq3Y4kfw/b/KpFdFuTh 949pulomsk/I5QlIdnn/yRuiK50tY5XbpFJ0lqM6GlGk6DrLFj4kQ4yUnRYV+/Lw6Nyf TveGgDmO4/2vcMM/PvBLRRary/7ZpRywUUIlvYudlcGSqVxo50a774MWj/AY1BtZ+P+e 30sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gC27YbQ+Cxwp45Vllq2iFQrj2FSxSOnpETTlDt3zN9g=; b=Ascj3O3ROXdisEAHC3tVroas++gs/CoEWaNYKibda5pFsKU1GLudQfiQxMhyfgGGKC WFC8khjWz8IBEoHTVZDG+WHQUE6+P89aliB+NtsgUfSj+4PnSKcWQl3oJEQhwGcSq1hU KuyePtt71Jgpq3doLf2XJoeCDbOBzu6+eoKVUi4iB1eXOU22o1fmvjUM/2GC/d8mT3Tv nGpBjRgC1VaLvAaP+/NBbpyBmuecJh0bPxz8Jrlm1ZdYN3ZK2caCbcMoFDE1OJuzCv9T 9xN7OR/G3ixuBeDDarqgGxVioJVpikE4jq/lnSByJ0VMtJLZq2W5f//M6oubh464K0uF 36qQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bh4si1159569ejb.421.2020.11.11.01.32.08; Wed, 11 Nov 2020 01:32:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727255AbgKKJ2j (ORCPT + 99 others); Wed, 11 Nov 2020 04:28:39 -0500 Received: from mx2.suse.de ([195.135.220.15]:37752 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727215AbgKKJ20 (ORCPT ); Wed, 11 Nov 2020 04:28:26 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CAF00AD29; Wed, 11 Nov 2020 09:28:22 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Michal Hocko , Pavel Tatashin , David Hildenbrand , Oscar Salvador , Joonsoo Kim , Vlastimil Babka , Michal Hocko Subject: [PATCH v3 6/7] mm, page_alloc: move draining pcplists to page isolation users Date: Wed, 11 Nov 2020 10:28:11 +0100 Message-Id: <20201111092812.11329-7-vbabka@suse.cz> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201111092812.11329-1-vbabka@suse.cz> References: <20201111092812.11329-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, pcplists are drained during set_migratetype_isolate() which means once per pageblock processed start_isolate_page_range(). This is somewhat wasteful. Moreover, the callers might need different guarantees, and the draining is currently prone to races and does not guarantee that no page from isolated pageblock will end up on the pcplist after the drain. Better guarantees are added by later patches and require explicit actions by page isolation users that need them. Thus it makes sense to move the current imperfect draining to the callers also as a preparation step. Suggested-by: David Hildenbrand Suggested-by: Pavel Tatashin Signed-off-by: Vlastimil Babka Reviewed-by: David Hildenbrand Reviewed-by: Oscar Salvador Acked-by: Michal Hocko --- mm/memory_hotplug.c | 11 ++++++----- mm/page_alloc.c | 2 ++ mm/page_isolation.c | 10 +++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 41c62295292b..3c494ab0d075 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1500,6 +1500,8 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages) goto failed_removal; } + drain_all_pages(zone); + arg.start_pfn = start_pfn; arg.nr_pages = nr_pages; node_states_check_changes_offline(nr_pages, zone, &arg); @@ -1550,11 +1552,10 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages) } /* - * per-cpu pages are drained in start_isolate_page_range, but if - * there are still pages that are not free, make sure that we - * drain again, because when we isolated range we might - * have raced with another thread that was adding pages to pcp - * list. + * per-cpu pages are drained after start_isolate_page_range, but + * if there are still pages that are not free, make sure that we + * drain again, because when we isolated range we might have + * raced with another thread that was adding pages to pcp list. * * Forward progress should be still guaranteed because * pages on the pcp list can only belong to MOVABLE_ZONE diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 25bc9bb77696..2ec3e1e27169 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8539,6 +8539,8 @@ int alloc_contig_range(unsigned long start, unsigned long end, if (ret) return ret; + drain_all_pages(cc.zone); + /* * In case of -EBUSY, we'd like to know which page causes problem. * So, just fall through. test_pages_isolated() has a tracepoint diff --git a/mm/page_isolation.c b/mm/page_isolation.c index abbf42214485..feab446d1982 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -49,7 +49,6 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ __mod_zone_freepage_state(zone, -nr_pages, mt); spin_unlock_irqrestore(&zone->lock, flags); - drain_all_pages(zone); return 0; } @@ -172,11 +171,12 @@ __first_valid_page(unsigned long pfn, unsigned long nr_pages) * * Please note that there is no strong synchronization with the page allocator * either. Pages might be freed while their page blocks are marked ISOLATED. - * In some cases pages might still end up on pcp lists and that would allow + * A call to drain_all_pages() after isolation can flush most of them. However + * in some cases pages might still end up on pcp lists and that would allow * for their allocation even when they are in fact isolated already. Depending - * on how strong of a guarantee the caller needs drain_all_pages might be needed - * (e.g. __offline_pages will need to call it after check for isolated range for - * a next retry). + * on how strong of a guarantee the caller needs, further drain_all_pages() + * might be needed (e.g. __offline_pages will need to call it after check for + * isolated range for a next retry). * * Return: 0 on success and -EBUSY if any part of range cannot be isolated. */ -- 2.29.1