Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1237645ybz; Wed, 29 Apr 2020 17:51:39 -0700 (PDT) X-Google-Smtp-Source: APiQypJWV4xYUA8wdymh34cj/rdmG5OGDgg6ziT66GqSjH40KPFt7rj2seh8SURpWNP/TKWpx0oR X-Received: by 2002:a05:6402:b82:: with SMTP id cf2mr522767edb.49.1588207898947; Wed, 29 Apr 2020 17:51:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588207898; cv=none; d=google.com; s=arc-20160816; b=xu+JHaIIi70J9zzszs1JJiVRDbKhW3PA7RgZhsNw6QeIAkiKg6hW8gBqw+ZZrNBdoP 26D1H2cHaOATmcYqDgULIGm5sR8jWkv3m68m2cEEyCL3Wy12vHniAs3EtSbrhrzR0Z7q MBdRwm0clAMv/oeZ6227qxEQbG/lu7+TvkwmSTjqgEYIAnAqYvIaAkkvH1rxIOWFjTFC 8nt3EdnIv78VO+R6UW6Rzf7pv+FiDt4EbqW4Xp08W03nO7Mbe5niYFPiBVHOUxyT0XAP KsqxqlmGtkF2ZoC7V6EemzdRNPNSUnmihoduvged9hfr3jVQ3a+ExyJ7g4wzjV3Irq8L oBfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=pMONp5cKH111PiC5Trn1LjUYczWa/GRKGKGyIwPl4GI=; b=hWRoxYC91awfRswaG1ixDCfw87226+ZI8a4uTn4bN1T+Ml4jGYpMXo8YtYzZWwe26j 9PFkN/RL0psIdIhphoBN4/Oq3hpVl1sFgordDtVKNO8D+kHiroldwIRFDe9uvVXao0Gw eWB4ouJx/ItciEnJss15X9AwzwHXkDJRCozFuM3hu2o2oCwSEbMSBgUsCfXdnYJVMyza FX+tsczYS/c+r/Jrz916IcD6zQ2AaN9S58h5pLamk59o1dg8+pSDe0uS9PLguFE5OG9o nH/GUIkR4/NnUHk+Bawd5lPxPvM4Uv0uRbmWxAno8SD0KwOLlirjyYJ8kJYyOI+zAwRy Hk0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g24si4486723edu.104.2020.04.29.17.51.16; Wed, 29 Apr 2020 17:51:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726431AbgD3Arp (ORCPT + 99 others); Wed, 29 Apr 2020 20:47:45 -0400 Received: from out30-54.freemail.mail.aliyun.com ([115.124.30.54]:45470 "EHLO out30-54.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbgD3Arp (ORCPT ); Wed, 29 Apr 2020 20:47:45 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07484;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0Tx3-FoL_1588207658; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0Tx3-FoL_1588207658) by smtp.aliyun-inc.com(127.0.0.1); Thu, 30 Apr 2020 08:47:40 +0800 Subject: Re: [linux-next PATCH 2/2] mm: khugepaged: don't have to put being freed page back to lru From: Yang Shi To: kirill.shutemov@linux.intel.com, hughd@google.com, aarcange@redhat.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1588200982-69492-1-git-send-email-yang.shi@linux.alibaba.com> <1588200982-69492-2-git-send-email-yang.shi@linux.alibaba.com> Message-ID: <1d7c1fdd-3589-da46-716f-7767eecb87a4@linux.alibaba.com> Date: Wed, 29 Apr 2020 17:47:34 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/29/20 5:41 PM, Yang Shi wrote: > > > On 4/29/20 3:56 PM, Yang Shi wrote: >> When khugepaged successfully isolated and copied data from base page to >> collapsed THP, the base page is about to be freed.  So putting the page >> back to lru sounds not that productive since the page might be isolated >> by vmscan but it can't be reclaimed by vmscan since it can't be unmapped >> by try_to_unmap() at all. >> >> Actually khugepaged is the last user of this page so it can be freed >> directly.  So, clearing active and unevictable flags, unlocking and >> dropping refcount from isolate instead of calling putback_lru_page(). > > Please disregard the patch. I just remembered Kirill added collapse > shared pages support. If the pages are shared then they have to be put > back to lru since they may be still mapped by other processes. So we > need check the mapcount if we would like to skip lru. > > And I spotted the other issue. The release_pte_page() calls > mod_node_page_state() unconditionally, it was fine before. But, due to > the support for collapsing shared pages we need check if the last > mapcount is gone or not. Hmm... this is false. I mixed up NR_ISOLATED_ANON and NR_ANON_MAPPED. > > Andrew, would you please remove this patch from -mm tree? I will send > one or two rectified patches. Sorry for the inconvenience. > >> >> Cc: Kirill A. Shutemov >> Cc: Hugh Dickins >> Cc: Andrea Arcangeli >> Signed-off-by: Yang Shi >> --- >>   mm/khugepaged.c | 15 +++++++++++++-- >>   1 file changed, 13 insertions(+), 2 deletions(-) >> >> diff --git a/mm/khugepaged.c b/mm/khugepaged.c >> index 0c8d30b..c131a90 100644 >> --- a/mm/khugepaged.c >> +++ b/mm/khugepaged.c >> @@ -559,6 +559,17 @@ void __khugepaged_exit(struct mm_struct *mm) >>   static void release_pte_page(struct page *page) >>   { >>       mod_node_page_state(page_pgdat(page), >> +        NR_ISOLATED_ANON + page_is_file_lru(page), -compound_nr(page)); >> +    ClearPageActive(page); >> +    ClearPageUnevictable(page); >> +    unlock_page(page); >> +    /* Drop refcount from isolate */ >> +    put_page(page); >> +} >> + >> +static void release_pte_page_to_lru(struct page *page) >> +{ >> +    mod_node_page_state(page_pgdat(page), >>               NR_ISOLATED_ANON + page_is_file_lru(page), >>               -compound_nr(page)); >>       unlock_page(page); >> @@ -576,12 +587,12 @@ static void release_pte_pages(pte_t *pte, pte_t >> *_pte, >>           page = pte_page(pteval); >>           if (!pte_none(pteval) && !is_zero_pfn(pte_pfn(pteval)) && >>                   !PageCompound(page)) >> -            release_pte_page(page); >> +            release_pte_page_to_lru(page); >>       } >>         list_for_each_entry_safe(page, tmp, compound_pagelist, lru) { >>           list_del(&page->lru); >> -        release_pte_page(page); >> +        release_pte_page_to_lru(page); >>       } >>   } >