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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=no 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 327D2C433DB for ; Thu, 18 Mar 2021 00:13:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7242464F24 for ; Thu, 18 Mar 2021 00:13:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7242464F24 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D08C86B0070; Wed, 17 Mar 2021 20:13:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB8C06B0071; Wed, 17 Mar 2021 20:13:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5A276B0072; Wed, 17 Mar 2021 20:13:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id 98ACB6B0070 for ; Wed, 17 Mar 2021 20:13:20 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4BA6F6D7F for ; Thu, 18 Mar 2021 00:13:20 +0000 (UTC) X-FDA: 77931070560.05.7B28A04 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf23.hostedemail.com (Postfix) with ESMTP id 9E50FA0009CE for ; Thu, 18 Mar 2021 00:13:19 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id AC41964F0F; Thu, 18 Mar 2021 00:13:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1616026398; bh=fSIIYD4Bqq9DjOcJ00I7RmGxvGVeisJfg5itiZrWuHk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dx2142MJ4udauam6sy8vYa+l2BrMlHhDtLm82C5w2FxZOH+zh5poMNLBuOfjTH9PY YrH34VWJ6SNWpYYGs9v72EsDYsYYQnuXboQFKGsbIAwB9ciSYAOYU8G7sG2QLCW0Ch cWgTie2g1YKTddJEH6EuGC3OKB/UiaSCNKBGLdWA= Date: Wed, 17 Mar 2021 17:13:16 -0700 From: Andrew Morton To: Minchan Kim Cc: linux-mm , LKML , joaodias@google.com, surenb@google.com, cgoldswo@codeaurora.org, willy@infradead.org, mhocko@suse.com, david@redhat.com, vbabka@suse.cz, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v3 2/3] mm: disable LRU pagevec during the migration temporarily Message-Id: <20210317171316.d261de806203d8d99c6bf0ef@linux-foundation.org> In-Reply-To: <20210310161429.399432-2-minchan@kernel.org> References: <20210310161429.399432-1-minchan@kernel.org> <20210310161429.399432-2-minchan@kernel.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Stat-Signature: ej65djmdwsjj1jn8ng9o3ukwgsxxacga X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9E50FA0009CE Received-SPF: none (linux-foundation.org>: No applicable sender policy available) receiver=imf23; identity=mailfrom; envelope-from=""; helo=mail.kernel.org; client-ip=198.145.29.99 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616026399-377414 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 Wed, 10 Mar 2021 08:14:28 -0800 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(it is about a fallback to a > sync migration) with 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. > > The new interface is also useful for memory hotplug which currently > drains lru pcp caches after each migration failure. This is rather > suboptimal as it has to disrupt others running during the operation. > With the new interface the operation happens only once. This is also in > line with pcp allocator cache which are disabled for the offlining as > well. > This is really a rather ugly thing, particularly from a maintainability point of view. Are you sure you found all the sites which need the enable/disable? How do we prevent new ones from creeping in which need the same treatment? Is there some way of adding a runtime check which will trip if a conversion was missed? > ... > > +bool lru_cache_disabled(void) > +{ > + return atomic_read(&lru_disable_count); > +} > + > +void lru_cache_enable(void) > +{ > + atomic_dec(&lru_disable_count); > +} > + > +/* > + * lru_cache_disable() needs to be called before we start compiling > + * a list of pages to be migrated using isolate_lru_page(). > + * It drains pages on LRU cache and then disable on all cpus until > + * lru_cache_enable is called. > + * > + * Must be paired with a call to lru_cache_enable(). > + */ > +void lru_cache_disable(void) > +{ > + atomic_inc(&lru_disable_count); > +#ifdef CONFIG_SMP > + /* > + * 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 enforeced by the scheduling > + * guarantees. > + */ > + __lru_add_drain_all(true); > +#else > + lru_add_drain(); > +#endif > +} I guess at least the first two of these functions should be inlined.