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 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 C4180CA9EC0 for ; Mon, 28 Oct 2019 18:48:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6D14220862 for ; Mon, 28 Oct 2019 18:48:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eftxoBuO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6D14220862 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 B63646B0005; Mon, 28 Oct 2019 14:48:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B13256B0006; Mon, 28 Oct 2019 14:48:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A00B66B0007; Mon, 28 Oct 2019 14:48:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id 7648A6B0005 for ; Mon, 28 Oct 2019 14:48:10 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 029A2181AEF32 for ; Mon, 28 Oct 2019 18:48:10 +0000 (UTC) X-FDA: 76094078340.22.nose80_473778389f605 X-HE-Tag: nose80_473778389f605 X-Filterd-Recvd-Size: 7241 Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Mon, 28 Oct 2019 18:48:09 +0000 (UTC) Received: by mail-ed1-f65.google.com with SMTP id b18so2206411edr.11 for ; Mon, 28 Oct 2019 11:48:09 -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=EHyhzaUcHuFSPNZjQTvfVFBDTJcXH6fFFTg6Ug5vl/w=; b=eftxoBuOK0m51kqednJ0vJ5uhvZ6lnRq2Mp4ilL7+41wss1fQzaqjH9Og513WjUPGB WCzJbmfRNSHigl74zg5rpnO641tW7pIww7pdkwmPu1ZjVgdvleOIMdcT3PvDaM2fzB0L gHcdDsf/dhluKboUwMZkE/z274JYQB1zlOP3+8rRbHIv0BNix72w4VG5ODoIHb2FBqHq HosoHCCr8L+gbHgrOYJGckZTUeVXSJ60CkHp3KBz3Xae1icRDQAmZxviqme1+dea7bKg roqwFmkwsuCfFYn5s1nbGbkj4KJqhcY0fMkhAu+8uWFQ1eQeLQYq86+1f3hi0Kv08tau 3gqg== 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=EHyhzaUcHuFSPNZjQTvfVFBDTJcXH6fFFTg6Ug5vl/w=; b=cgZnFUmA8w8VHY+kmf01tpVIfiDi1hqZFSKn1D/jBCU1DfJFlIfVa7HK+VcaFr9I6q KOPfKODLHRbY8Zu60oXeJ/4pM57XPmVreH1cbTeOOpX+7poTGGp9gTzxn85gdpKf4XTl 0qtI3QywbKUKxkYXVyrGA30Iq0CZCKbdnyNLe5rWkwvhZvioFZgd6ABryzxzvXU8RLr0 2BKZ0/T4kIk+fA8R6K6+mhhoui0ZmRP8K/l2sZJ5GRH2kCKkzuSNgNDW85l6JoZp6fMR K3zDqkBBCqYtbXzLnSJz26iZ2gVYi2AlRomhMQ0CBzHbx5OMD/BBjkhyy75vtYWi9wLD SbWg== X-Gm-Message-State: APjAAAVjmq9vXMXv7bBUhqlPfHHPZktZvmghusZGSUWQXQFBXX3fUfsD 31XT2zrkpDfazvXTephY11LXJa8SBpqUw32Rth8= X-Google-Smtp-Source: APXvYqyY9tzObogsVwsExPv2puG5zkXcYtqaRE8JtURRebZRsFf/wgsWqUpSdSAIQlybiTFsP1aKQJp9Hys911h8NKE= X-Received: by 2002:a17:906:b347:: with SMTP id cd7mr18723654ejb.105.1572288488048; Mon, 28 Oct 2019 11:48:08 -0700 (PDT) MIME-Version: 1.0 References: <1572269624-60283-1-git-send-email-zhongjiang@huawei.com> In-Reply-To: <1572269624-60283-1-git-send-email-zhongjiang@huawei.com> From: Yang Shi Date: Mon, 28 Oct 2019 11:47:56 -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 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 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 > >