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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 ADD5CC433DB for ; Wed, 17 Feb 2021 08:59:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EB96364E28 for ; Wed, 17 Feb 2021 08:59:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB96364E28 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 29A348D002A; Wed, 17 Feb 2021 03:59:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 24A1F8D0019; Wed, 17 Feb 2021 03:59:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1616B8D002A; Wed, 17 Feb 2021 03:59:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0054.hostedemail.com [216.40.44.54]) by kanga.kvack.org (Postfix) with ESMTP id 00BE18D0019 for ; Wed, 17 Feb 2021 03:59:57 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B176C4405 for ; Wed, 17 Feb 2021 08:59:57 +0000 (UTC) X-FDA: 77827162434.22.32BCDAC Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf09.hostedemail.com (Postfix) with ESMTP id 586DD6002496 for ; Wed, 17 Feb 2021 08:59:54 +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=1613552395; 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=l9ZjUGZRskkZ0NzAW6UUH7ZF+ZkwTXUSHR0haHlwa+Y=; b=DGkoj1xr1pVVIdtvc1btoSO4zxqq1Jd5ow+34vyReiJF0smOdHRWzua1E+hcBUJAcqmhGF 21kRdXV8V/d7ttjtb11zizK/bo+9gCMz3Bw5+RShP4BcEe4Sdi67Rn1VnqBdA1bzoYofB1 lNUrZGoUO1MdNd5cc1LqWoMhT9jqaYs= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 863F9B030; Wed, 17 Feb 2021 08:59:55 +0000 (UTC) Date: Wed, 17 Feb 2021 09:59:54 +0100 From: Michal Hocko To: Minchan Kim Cc: Andrew Morton , linux-mm , LKML , cgoldswo@codeaurora.org, linux-fsdevel@vger.kernel.org, willy@infradead.org, david@redhat.com, vbabka@suse.cz, viro@zeniv.linux.org.uk, joaodias@google.com Subject: Re: [RFC 1/2] mm: disable LRU pagevec during the migration temporarily Message-ID: References: <20210216170348.1513483-1-minchan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210216170348.1513483-1-minchan@kernel.org> X-Stat-Signature: gwd9ztnqwq45ewu86rcgq4r8uo4zurrc X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 586DD6002496 Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf09; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613552394-815735 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 16-02-21 09:03:47, 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. Please put some numbers on how often this happens here. > The other concern is migration keeps retrying until pages in pagevec > are drained. During the time, migration repeatedly allocates target > page, unmap source page from page table of processes and then get to > know the failure, restore the original page to pagetable of processes, > free target page, which is also not good. This is not good for performance you mean, rigth? > To solve the issue, this patch tries to close the race rather than > relying on retrial and luck. The idea is to introduce > migration-in-progress tracking count with introducing IPI barrier > after atomic updating the count to minimize read-side overhead. > > The migrate_prep increases migrate_pending_count under the lock > and IPI call to guarantee every CPU see the uptodate value > of migrate_pending_count. Then, drain pagevec via lru_add_drain_all. > >From now on, no LRU pages could reach pagevec since LRU handling > functions skips the batching if migration is in progress with checking > migrate_pedning(IOW, pagevec should be empty until migration is done). > Every migrate_prep's caller should call migrate_finish in pair to > decrease the migration tracking count. migrate_prep already does schedule draining on each cpu which has pages queued. Why isn't it enough to disable pcp lru caches right before draining in migrate_prep? More on IPI side below [...] > +static DEFINE_SPINLOCK(migrate_pending_lock); > +static unsigned long migrate_pending_count; > +static DEFINE_PER_CPU(struct work_struct, migrate_pending_work); > + > +static void read_migrate_pending(struct work_struct *work) > +{ > + /* TODO : not sure it's needed */ > + unsigned long dummy = __READ_ONCE(migrate_pending_count); > + (void)dummy; What are you trying to achieve here? Are you just trying to enforce read memory barrier here? > +} > + > +bool migrate_pending(void) > +{ > + return migrate_pending_count; > +} > + > /* > * migrate_prep() needs to be called before we start compiling a list of pages > * to be migrated using isolate_lru_page(). If scheduling work on other CPUs is > @@ -64,11 +80,27 @@ > */ > void migrate_prep(void) > { > + unsigned int cpu; > + > + spin_lock(&migrate_pending_lock); > + migrate_pending_count++; > + spin_unlock(&migrate_pending_lock); I suspect you do not want to add atomic_read inside hot paths, right? Is this really something that we have to microoptimize for? atomic_read is a simple READ_ONCE on many archs. > + > + for_each_online_cpu(cpu) { > + struct work_struct *work = &per_cpu(migrate_pending_work, cpu); > + > + INIT_WORK(work, read_migrate_pending); > + queue_work_on(cpu, mm_percpu_wq, work); > + } > + > + for_each_online_cpu(cpu) > + flush_work(&per_cpu(migrate_pending_work, cpu)); I also do not follow this scheme. Where is the IPI you are mentioning above? > + /* > + * From now on, every online cpu will see uptodate > + * migarte_pending_work. > + */ > /* > * Clear the LRU lists so pages can be isolated. > - * Note that pages may be moved off the LRU after we have > - * drained them. Those pages will fail to migrate like other > - * pages that may be busy. > */ > lru_add_drain_all(); Overall, this looks rather heavy weight to my taste. Have you tried to play with a simple atomic counter approach? atomic_read when adding to the cache and atomic_inc inside migrate_prep followed by lrdu_add_drain. -- Michal Hocko SUSE Labs