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=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 A7099CA9EC3 for ; Tue, 29 Oct 2019 04:12:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3FADC217D6 for ; Tue, 29 Oct 2019 04:12:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kYI1pRph" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3FADC217D6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 997866B0005; Tue, 29 Oct 2019 00:12:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 91FD56B0006; Tue, 29 Oct 2019 00:12:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E7906B0007; Tue, 29 Oct 2019 00:12:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com [216.40.44.221]) by kanga.kvack.org (Postfix) with ESMTP id 5251E6B0005 for ; Tue, 29 Oct 2019 00:12:38 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id CCF686D8F for ; Tue, 29 Oct 2019 04:12:37 +0000 (UTC) X-FDA: 76095500754.28.war10_33fd63660d112 X-HE-Tag: war10_33fd63660d112 X-Filterd-Recvd-Size: 7972 Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Oct 2019 04:12:37 +0000 (UTC) Received: by mail-ed1-f67.google.com with SMTP id c4so9699462edl.0 for ; Mon, 28 Oct 2019 21:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ND3o1HWYje8s8FQQXxJoL4kVewu2aXOJB0GAwomlWJw=; b=kYI1pRphIiX9Jl0bc107b+glDg4IY7pEK2bnxrr4EYV8ZT2M1g/rLgGfIXqayEazzX /JIiqbe9HbtQsUf6T2+gJmG8nGuqDcJFFpqxXblC5c6V6o9g71Isd/jxFkrkRoWRPfLr BxCeDajFEZ5Q3QU8CCon8LPLP+Y0Y70rXJbovMhiDm23Z6yB6Fs9kH/kD/eK23Y5KHxF IBM3A1syBl9y0P7C69sF3X4Z97yMqMYP3XAvn5BnhRWztBcG/8rdF+1MTzgxevFOaXQA Q/iWBY7cdHRx1vHiG9dc41dnAvfonXEJY34i8iW4wUcF80Qs1nWZJUC7MvfzoO85ubyf g9tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ND3o1HWYje8s8FQQXxJoL4kVewu2aXOJB0GAwomlWJw=; b=LOFbNZlT7XQHN7nke/ljhwEWoaRItzr7l/eDaRZSWHej2+jQ/ClVLosYL1isnu1c6s NNbHpK4i5AYOMoscT9lqCfdBAPx7Lsqqn/cGb1rOG9S5/j+UQwlSubbaJEPAy+pTY+E8 95Ix+YTpYTYLgHY5u+UvQ8Ub0KOPJZbDnKa6F3L7/hUDH1NFb/3TsrDO9uAO49Q5iEg3 61dHzLkUxmvMHUYGE/GIebLmRdhqSK5eot7RILBAGZYMZPAMf6RI0ZzlssPosXGkqup7 nZMt92foO2FwAf75x3/OStXfo9jSXReaF6gsiCswXivvsGjNOesTfbc14C5MGDsAGKoL UMug== X-Gm-Message-State: APjAAAUNbZ8QI4GZJyuXCFyo63+vHPC1S2TAlSWGS9TLiBm9P4kAi8b7 f9XxP6gzj+MipAdhHuF2tDfrgUrcgAYS4LtxtnM= X-Google-Smtp-Source: APXvYqxRi17rtznAhTUqN3u/NohsOkuXAlZcJslRxVBOvFDWg3H7cbr8TCuQcactGA+MDE+tY13q0RC955V1C8Q40S4= X-Received: by 2002:a17:906:76c9:: with SMTP id q9mr1212858ejn.53.1572322355791; Mon, 28 Oct 2019 21:12:35 -0700 (PDT) MIME-Version: 1.0 References: <1572269624-60283-1-git-send-email-zhongjiang@huawei.com> <5DB7A96B.8090104@huawei.com> In-Reply-To: <5DB7A96B.8090104@huawei.com> From: Yang Shi Date: Mon, 28 Oct 2019 21:12:23 -0700 Message-ID: Subject: Re: [PATCH] mm: put the page into the correct list when shrink_page_list fails to reclaim. To: zhong jiang Cc: Andrew Morton , ira.weiny@intel.com, John Hubbard , "Kirill A. Shutemov" , rppt@linux.ibm.com, Linux MM Content-Type: text/plain; charset="UTF-8" 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 Mon, Oct 28, 2019 at 7:52 PM zhong jiang wrote: > > On 2019/10/29 2:47, Yang Shi wrote: > > On Mon, Oct 28, 2019 at 6:37 AM zhong jiang wrote: > >> Recently, I notice an race case between mlock syscall and shrink_page_list. > >> > >> one cpu run mlock syscall to make an range of the vma locked in memory. And > >> The specified pages will escaped from evictable list from unevictable. > >> Meanwhile, another cpu scan and isolate the specified pages to reclaim. > >> shrink_page_list hold the page lock to shrink the page and follow_page_pte > >> will fails to get the page lock, hence we fails to mlock the page to make > >> it Unevictabled. > >> > >> shrink_page_list fails to reclaim the page due to some reason. it will putback > >> the page to evictable lru. But the page actually belongs to an locked range of > >> the vma. it is unreasonable to do that. It is better to put the page to unevictable > >> lru. > > Yes, there is definitely race between mlock() and vmscan, and in the > > above case it might stay in evictable LRUs one more round, but it > > should be not harmful since try_to_unmap() would move the page to > > unevictable list eventually. > The key is how to make sure try_to_unmap alway will be called before the page is freed. > It is possibility page_mapped(page) is false due to some condition. Is it a problem? The gup just needs to refault the page in. > > Thanks, > zhong jiang > >> The patch set PageMlocked when mlock fails to get the page locked. shrink_page_list > >> fails to reclaim the page will putback to the correct list. if it success to reclaim > >> the page, we should ClearPageMlocked in time to prevent the warning from free_pages_prepare. > >> > >> Signed-off-by: zhong jiang > >> --- > >> mm/gup.c | 28 ++++++++++++++++++---------- > >> mm/vmscan.c | 9 ++++++++- > >> 2 files changed, 26 insertions(+), 11 deletions(-) > >> > >> diff --git a/mm/gup.c b/mm/gup.c > >> index c2b3e11..c26d28c 100644 > >> --- a/mm/gup.c > >> +++ b/mm/gup.c > >> @@ -283,16 +283,24 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, > >> * handle it now - vmscan will handle it later if and > >> * when it attempts to reclaim the page. > >> */ > >> - if (page->mapping && trylock_page(page)) { > >> - lru_add_drain(); /* push cached pages to LRU */ > >> - /* > >> - * Because we lock page here, and migration is > >> - * blocked by the pte's page reference, and we > >> - * know the page is still mapped, we don't even > >> - * need to check for file-cache page truncation. > >> - */ > >> - mlock_vma_page(page); > >> - unlock_page(page); > >> + if (page->mapping) { > >> + if (trylock_page(page)) { > >> + lru_add_drain(); /* push cached pages to LRU */ > >> + /* > >> + * Because we lock page here, and migration is > >> + * blocked by the pte's page reference, and we > >> + * know the page is still mapped, we don't even > >> + * need to check for file-cache page truncation. > >> + */ > >> + mlock_vma_page(page); > >> + unlock_page(page); > >> + } else { > >> + /* > >> + * Avoid putback the page to evictable list when > >> + * the page is in the locked vma. > >> + */ > >> + SetPageMlocked(page); > >> + } > >> } > >> } > >> out: > >> diff --git a/mm/vmscan.c b/mm/vmscan.c > >> index 1154b3a..f7d1301 100644 > >> --- a/mm/vmscan.c > >> +++ b/mm/vmscan.c > >> @@ -1488,8 +1488,15 @@ static unsigned long shrink_page_list(struct list_head *page_list, > >> */ > >> if (unlikely(PageTransHuge(page))) > >> (*get_compound_page_dtor(page))(page); > >> - else > >> + else { > >> + /* > >> + * There is an race between mlock and shrink_page_list > >> + * when mlock fails to get the PageLocked(). > >> + */ > >> + if (unlikely(PageMlocked(page))) > >> + ClearPageMlocked(page); > >> list_add(&page->lru, &free_pages); > >> + } > >> continue; > >> > >> activate_locked_split: > >> -- > >> 1.7.12.4 > >> > >> > > . > > > >