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=-8.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 AA44EC388F9 for ; Thu, 22 Oct 2020 12:52:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 139C02462E for ; Thu, 22 Oct 2020 12:52:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 139C02462E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1CEE06B005D; Thu, 22 Oct 2020 08:52:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 159916B0062; Thu, 22 Oct 2020 08:52:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01EFD6B0068; Thu, 22 Oct 2020 08:52:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id C0C546B005D for ; Thu, 22 Oct 2020 08:52:11 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 46788181AEF07 for ; Thu, 22 Oct 2020 12:52:11 +0000 (UTC) X-FDA: 77399549262.08.camp87_2310ad927251 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 1F9F81819E766 for ; Thu, 22 Oct 2020 12:52:11 +0000 (UTC) X-HE-Tag: camp87_2310ad927251 X-Filterd-Recvd-Size: 3936 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Thu, 22 Oct 2020 12:52:10 +0000 (UTC) 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 A4F2CAECD; Thu, 22 Oct 2020 12:52:08 +0000 (UTC) Date: Thu, 22 Oct 2020 14:52:00 +0200 From: Oscar Salvador To: Vlastimil Babka Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Michal Hocko , Pavel Tatashin , David Hildenbrand , Joonsoo Kim , Michal Hocko Subject: Re: [PATCH v2 7/7] mm, page_alloc: disable pcplists during memory offline Message-ID: <20201022125159.GE26121@linux> References: <20201008114201.18824-1-vbabka@suse.cz> <20201008114201.18824-8-vbabka@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201008114201.18824-8-vbabka@suse.cz> User-Agent: Mutt/1.10.1 (2018-07-13) 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 Thu, Oct 08, 2020 at 01:42:01PM +0200, Vlastimil Babka wrote: > Memory offline relies on page isolation can race with process freeing pages to > pcplists in a way that a page from isolated pageblock can end up on pcplist. > This can be worked around by repeated draining of pcplists, as done by commit > 968318261221 ("mm/memory_hotplug: drain per-cpu pages again during memory > offline"). > > David and Michal would prefer that this race was closed in a way that callers > of page isolation who need stronger guarantees don't need to repeatedly drain. > David suggested disabling pcplists usage completely during page isolation, > instead of repeatedly draining them. > > To achieve this without adding special cases in alloc/free fastpath, we can use > the same approach as boot pagesets - when pcp->high is 0, any pcplist addition > will be immediately flushed. > > The race can thus be closed by setting pcp->high to 0 and draining pcplists > once, before calling start_isolate_page_range(). The draining will serialize > after processes that already disabled interrupts and read the old value of > pcp->high in free_unref_page_commit(), and processes that have not yet disabled > interrupts, will observe pcp->high == 0 when they are rescheduled, and skip > pcplists. This guarantees no stray pages on pcplists in zones where isolation > happens. > > This patch thus adds zone_pcp_disable() and zone_pcp_enable() functions that > page isolation users can call before start_isolate_page_range() and after > unisolating (or offlining) the isolated pages. > > Also, drain_all_pages() is optimized to only execute on cpus where pcplists are > not empty. The check can however race with a free to pcplist that has not yet > increased the pcp->count from 0 to 1. Thus make the drain optionally skip the > racy check and drain on all cpus, and use this option in zone_pcp_disable(). > > As we have to avoid external updates to high and batch while pcplists are > disabled, we take pcp_batch_high_lock in zone_pcp_disable() and release it in > zone_pcp_enable(). This also synchronizes multiple users of > zone_pcp_disable()/enable(). > > Currently the only user of this functionality is offline_pages(). > > Suggested-by: David Hildenbrand > Suggested-by: Michal Hocko > Signed-off-by: Vlastimil Babka I definitely like this one, and the implemantion looks smoth. As Michal said in another thread, Hwposion code will also benefit from this, since now we have a drain_all_pages dance that might be suboptimal and not accurate. I will get back to that once this gets merged. Reviewed-by: Oscar Salvador Thanks! -- Oscar Salvador SUSE L3