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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97506C433EF for ; Tue, 15 Mar 2022 03:33:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=M9FJdMdYu/O9ismIwi/vBgUsgivW5IsqG3oO9RMhJiw=; b=eavcdp2ihcgWPE TzvWcL1n8iXSjMKsMazFlflnguRklynnZZNIfREofmBWob5PSuUvqQyHbtRoPEOXzNGLSvU8O4YGs sept+OU0MY1um0hdFI/smC+Ef89y4oDduh+y0NJ5wo8xPPRqBTEolFZsujrK2iur6gmk40lhursKs kQoNHMJkXSAhY2RC9M7OK7AockgpXmNrZ6mVKmoOkdPexXPet0OWSt6LSwI2tFFN54F+qfYFbtMME HCqhb6US2f7Y6fAsplPAIw4wLDevtz7EYZgK94hTGAwSFR1KQWHbiNbfmggXqXd025ZmzmYMhvDVf 6L8Roww7ceFL4mp17Y3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTxv9-007eH0-Ce; Tue, 15 Mar 2022 03:32:27 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTxv6-007eG8-6z; Tue, 15 Mar 2022 03:32:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=LX0E2les13YpXYBTKiKwQRB41rW+42lYHTDGzHdEAYU=; b=AJtxFRchW7D27kGcK6oYZmF5sA XonPIJLddVIcOM02rq5l+CPZAvswzV8R0vLGibH1n7vDtNBi+gm0lpOHdTI8nd6bcE/Ek6ASTfm24 yiJ0EYKcNa7cX75sXm10TtJOKSou5cdiBjj4gA5LMqyPZyDJ1ZRU7fhIIyqyAjT5EWxdPJCil+RKd W5ZQnQj1V5z0lzKNjpi2q6oZ2+UCkhn6CX2vevQTuW3ooFUnhiwRikZDoYpLgqwr+CaELRGcUl7dj DuRyLHWcQU2iD+7P2DJilra4pXNGTl+F+1IqVcgdzEeKgkte+s1UX9rzFVrKVR4pRAlvNMyY4m+r+ RirbJIMg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTxuy-004e5z-Dd; Tue, 15 Mar 2022 03:32:16 +0000 Date: Tue, 15 Mar 2022 03:32:16 +0000 From: Matthew Wilcox To: Andrew Yang Cc: Andrew Morton , Matthias Brugger , Vlastimil Babka , David Howells , William Kucharski , David Hildenbrand , Yang Shi , Marc Zyngier , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com, Nicholas Tang , Kuan-Ying Lee Subject: Re: [PATCH] mm/migrate: fix race between lock page and clear PG_Isolated Message-ID: References: <20220315030515.20263-1-andrew.yang@mediatek.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220315030515.20263-1-andrew.yang@mediatek.com> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Mar 15, 2022 at 11:05:15AM +0800, Andrew Yang wrote: > When memory is tight, system may start to compact memory for large > continuous memory demands. If one process tries to lock a memory page > that is being locked and isolated for compaction, it may wait a long time > or even forever. This is because compaction will perform non-atomic > PG_Isolated clear while holding page lock, this may overwrite PG_waiters > set by the process that can't obtain the page lock and add itself to the > waiting queue to wait for the lock to be unlocked. > > CPU1 CPU2 > lock_page(page); (successful) > lock_page(); (failed) > __ClearPageIsolated(page); SetPageWaiters(page) (may be overwritten) > unlock_page(page); > > The solution is to not perform non-atomic operation on page flags while > holding page lock. > > Signed-off-by: andrew.yang > --- > include/linux/page-flags.h | 2 +- > mm/migrate.c | 12 ++++++------ > 2 files changed, 7 insertions(+), 7 deletions(-) > > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > index 1c3b6e5c8bfd..64a84a9835cb 100644 > --- a/include/linux/page-flags.h > +++ b/include/linux/page-flags.h > @@ -918,7 +918,7 @@ PAGE_TYPE_OPS(Guard, guard) > > extern bool is_free_buddy_page(struct page *page); > > -__PAGEFLAG(Isolated, isolated, PF_ANY); > +PAGEFLAG(Isolated, isolated, PF_ANY); Agreed. Further, page cannot be a tail page (this is implied by the get_page_unless_zero() as tailpages have a zero refcount, and it is assumed by __PageMovable() as page->mapping is undefined for tail pages). So this can actually be: +PAGEFLAG(Isolated, isolated, PF_NO_TAIL); I considered PF_ONLY_HEAD, but there are a lot more places that _check_ PageIsolated() and I don't want to prove that they're all definitely working on head pages. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel