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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 7C8C5C433E0 for ; Wed, 3 Mar 2021 12:49:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EF01464ED4 for ; Wed, 3 Mar 2021 12:49:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF01464ED4 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 49F288D0161; Wed, 3 Mar 2021 07:49:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 44FCE8D0157; Wed, 3 Mar 2021 07:49:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F03F8D0161; Wed, 3 Mar 2021 07:49:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id 103D28D0157 for ; Wed, 3 Mar 2021 07:49:40 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C19F81DEC for ; Wed, 3 Mar 2021 12:49:39 +0000 (UTC) X-FDA: 77878544478.01.50E0803 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf27.hostedemail.com (Postfix) with ESMTP id 4A13380192E2 for ; Wed, 3 Mar 2021 12:49:38 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1614775777; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BQssk3EVhR0e4qDrxXX/wywKQ0WwpPCIYl69HQscnfM=; b=BMTmdNky2gbKO1P0DmVGENevbyUFIr500AaV/XDrlVVF50OPVswWkMN5GBhHN0M1BKdNJy VfiQ2CSJAnm7KWRRb0hdy81w6Zfry39cU8DnZ+RMtdJ8+tTdBOlx1DoqD0yIWFQMSIZ3Vd p2+qHNYsyje0bIlY0JDfQcAZ2b/APxs= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A1759AC24; Wed, 3 Mar 2021 12:49:37 +0000 (UTC) Date: Wed, 3 Mar 2021 13:49:36 +0100 From: Michal Hocko To: Minchan Kim Cc: Andrew Morton , linux-mm , LKML , joaodias@google.com, surenb@google.com, cgoldswo@codeaurora.org, willy@infradead.org, david@redhat.com, vbabka@suse.cz, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 1/2] mm: disable LRU pagevec during the migration temporarily Message-ID: References: <20210302210949.2440120-1-minchan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210302210949.2440120-1-minchan@kernel.org> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 4A13380192E2 X-Stat-Signature: juybdee9xitegipt347b9wtrpw54arwa Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf27; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614775778-131704 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 Tue 02-03-21 13:09:48, Minchan Kim wrote: > LRU pagevec holds refcount of pages until the pagevec are drained. > It could prevent migration since the refcount of the page is greater > than the expection in migration logic. To mitigate the issue, > callers of migrate_pages drains LRU pagevec via migrate_prep or > lru_add_drain_all before migrate_pages call. > > However, it's not enough because pages coming into pagevec after the > draining call still could stay at the pagevec so it could keep > preventing page migration. Since some callers of migrate_pages have > retrial logic with LRU draining, the page would migrate at next trail > but it is still fragile in that it doesn't close the fundamental race > between upcoming LRU pages into pagvec and migration so the migration > failure could cause contiguous memory allocation failure in the end. > > To close the race, this patch disables lru caches(i.e, pagevec) > during ongoing migration until migrate is done. > > Since it's really hard to reproduce, I measured how many times > migrate_pages retried with force mode below debug code. > > int migrate_pages(struct list_head *from, new_page_t get_new_page, > .. > .. > > if (rc && reason == MR_CONTIG_RANGE && pass > 2) { > printk(KERN_ERR, "pfn 0x%lx reason %d\n", page_to_pfn(page), rc); > dump_page(page, "fail to migrate"); > } > > The test was repeating android apps launching with cma allocation > in background every five seconds. Total cma allocation count was > about 500 during the testing. With this patch, the dump_page count > was reduced from 400 to 30. Have you seen any improvement on the CMA allocation success rate? > Signed-off-by: Minchan Kim > --- > * from RFC - http://lore.kernel.org/linux-mm/20210216170348.1513483-1-minchan@kernel.org > * use atomic and lru_add_drain_all for strict ordering - mhocko > * lru_cache_disable/enable - mhocko > > fs/block_dev.c | 2 +- > include/linux/migrate.h | 6 +++-- > include/linux/swap.h | 4 ++- > mm/compaction.c | 4 +-- > mm/fadvise.c | 2 +- > mm/gup.c | 2 +- > mm/khugepaged.c | 2 +- > mm/ksm.c | 2 +- > mm/memcontrol.c | 4 +-- > mm/memfd.c | 2 +- > mm/memory-failure.c | 2 +- > mm/memory_hotplug.c | 2 +- > mm/mempolicy.c | 6 +++++ > mm/migrate.c | 15 ++++++----- > mm/page_alloc.c | 5 +++- > mm/swap.c | 55 +++++++++++++++++++++++++++++++++++------ > 16 files changed, 85 insertions(+), 30 deletions(-) The churn seems to be quite big for something that should have been a very small change. Have you considered not changing lru_add_drain_all but rather introduce __lru_add_dain_all that would implement the enforced flushing? [...] > +static atomic_t lru_disable_count = ATOMIC_INIT(0); > + > +bool lru_cache_disabled(void) > +{ > + return atomic_read(&lru_disable_count); > +} > + > +void lru_cache_disable(void) > +{ > + /* > + * lru_add_drain_all's IPI will make sure no new pages are added > + * to the pcp lists and drain them all. > + */ > + atomic_inc(&lru_disable_count); As already mentioned in the last review. The IPI reference is more cryptic than useful. I would go with something like this instead /* * lru_add_drain_all in the force mode will schedule draining on * all online CPUs so any calls of lru_cache_disabled wrapped by * local_lock or preemption disabled would be ordered by that. * The atomic operation doesn't need to have stronger ordering * requirements because that is enforece by the scheduling * guarantees. */ > + > + /* > + * Clear the LRU lists so pages can be isolated. > + */ > + lru_add_drain_all(true); > +} -- Michal Hocko SUSE Labs