Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1233308ybz; Wed, 29 Apr 2020 17:45:47 -0700 (PDT) X-Google-Smtp-Source: APiQypJRpsOQXooVJDNSXv5T5+HnJTyjUznQUKTWKAYkiVX1eV/ZXL8yQbmGhMAoTr6JaE18TCVN X-Received: by 2002:a50:f0dc:: with SMTP id a28mr499988edm.87.1588207547180; Wed, 29 Apr 2020 17:45:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588207547; cv=none; d=google.com; s=arc-20160816; b=tpAFZhI6MkWSux03R11Q6r03M63ktdPoNSQYKxQ1VXpRnLY1zsa0ooltukbY0yVNod pvzMRmg2cC8Wzw+KqpegL4qbo53Mqh2YiS9zd1MsmF7boQYWfsuSojlcXEyqS076LXvS 30anqQTXYyhHqXTdu02+1R+U90+yX4qYaK4Yb47+gD1I2Hc0N+b1k4qMfyuKr8TAX7df 4KaKVyDmyCN4v400q/y0xPvymbsk/ILD/oLuhLsWi4loyfw2WtjxMb0tJ/zo/kF3DjoC Ri+ZiAOX9X2Il+7B3dafUWVfdJC8P4dVlpHCLRrtgJO9brOMX5jkeBfwJdEWIiDugM92 FkQg== 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:from:references:cc:to:subject; bh=yCMD4zOZLsjGKhwttUoUL+bh9OGjwRcWMg55lubmzf8=; b=Z68cUva0+M2p8XoZobhi5uJKPLHUioy9i8+c2sA4P3iXMSx4VYRZjAIOMZcTm9mm21 iNyEz3ohCm9+DRYsUPZ0e/eaFnB+UOGmGY2q82kLpGAZDNeKPGm8au5FlKIUDI7rueEc sQ4zwAnaSBgcz0mhdsSk4utfU/gd8NEJ5ZyPGw4mOoWvxLxBg381xnLrzWMt4bG2J3+M /z5+Dgw2tpEmpP9Lh/HfGUwCl+dmp9RVXu9AVurb0drLsSA2VbR8KbN2iecI4vTKEEUy lOxDZoXHC7IEA56W74WqGFJC2frYHX5vWV/wc0GjhuaDR4SYqdwUqoa+sjBCQ3dNl/uE vx2g== 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 by8si4976576ejb.525.2020.04.29.17.45.24; Wed, 29 Apr 2020 17:45:47 -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 S1726431AbgD3AmD (ORCPT + 99 others); Wed, 29 Apr 2020 20:42:03 -0400 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:47598 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726309AbgD3AmC (ORCPT ); Wed, 29 Apr 2020 20:42:02 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04428;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0Tx31E2F_1588207304; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0Tx31E2F_1588207304) by smtp.aliyun-inc.com(127.0.0.1); Thu, 30 Apr 2020 08:41:58 +0800 Subject: Re: [linux-next PATCH 2/2] mm: khugepaged: don't have to put being freed page back to lru 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> From: Yang Shi Message-ID: Date: Wed, 29 Apr 2020 17:41:40 -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: <1588200982-69492-2-git-send-email-yang.shi@linux.alibaba.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 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. 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); > } > } >