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=-8.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 33823ECE58E for ; Thu, 17 Oct 2019 16:12:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EC24420872 for ; Thu, 17 Oct 2019 16:12:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="pPFZz0wa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC24420872 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 80D268E0005; Thu, 17 Oct 2019 12:12:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BCA68E0003; Thu, 17 Oct 2019 12:12:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DD338E0005; Thu, 17 Oct 2019 12:12:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0233.hostedemail.com [216.40.44.233]) by kanga.kvack.org (Postfix) with ESMTP id 4BB158E0003 for ; Thu, 17 Oct 2019 12:12:52 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id E3ABD181AEF10 for ; Thu, 17 Oct 2019 16:12:51 +0000 (UTC) X-FDA: 76053770142.09.wood36_703d5e4d6f407 X-HE-Tag: wood36_703d5e4d6f407 X-Filterd-Recvd-Size: 4685 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Thu, 17 Oct 2019 16:12:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/ASj5BAjjmZ0b4T5e4J6N07bBbYhOsugrzCLbymRK5I=; b=pPFZz0waJ/OX/rwoWc6LMzRoQ qcoGMAdH6vGR15HWdCfUe5RsnqsjB7A3bZdUdCXllT5q/HQmJlIf39K70K+prBRGL/IBdPUMCMKeT MU3VqOfzZVIB4kVc1+YLhVAdmZczn6SfvsY4j81bCpgraiWbov2iGz3HmiVKAnOL3IWpYT1ZUjYN+ SPAow4cD6j6Sn8DaW55HYVPQO2Q+QyfdUb9Tfo8MUXGXnXjYl84voelmPX4ni3AHGYge1ts8wh8NR 6d3y+B/Cv8uw7JhhOGyVPPrVLsjCG/jJYQVeMSdCxANYDgnRJHA8wGFAeU4LSn4G4wqG+5muHEa2X I6P31uoxQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1iL8ON-0001hl-Da; Thu, 17 Oct 2019 16:12:47 +0000 Date: Thu, 17 Oct 2019 09:12:47 -0700 From: Matthew Wilcox To: Song Liu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, matthew.wilcox@oracle.com, kernel-team@fb.com, william.kucharski@oracle.com, "Kirill A. Shutemov" Subject: Re: [PATCH 3/4] mm/thp: allow drop THP from page cache Message-ID: <20191017161247.GK32665@bombadil.infradead.org> References: <20191016073731.4076725-1-songliubraving@fb.com> <20191016073731.4076725-4-songliubraving@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191016073731.4076725-4-songliubraving@fb.com> User-Agent: Mutt/1.12.1 (2019-06-15) 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 Wed, Oct 16, 2019 at 12:37:30AM -0700, Song Liu wrote: > From: "Kirill A. Shutemov" > > Once a THP is added to the page cache, it cannot be dropped via > /proc/sys/vm/drop_caches. Fix this issue with proper handling in > invalidate_mapping_pages() and __remove_mapping(). > > Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS") > Signed-off-by: Kirill A. Shutemov > Tested-by: Song Liu > Signed-off-by: Song Liu > --- > mm/truncate.c | 12 ++++++++++++ > mm/vmscan.c | 3 ++- > 2 files changed, 14 insertions(+), 1 deletion(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index c6659bb758a4..1d80a188ad4a 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -932,7 +932,8 @@ static int __remove_mapping(struct address_space *mapping, struct page *page, > * Note that if SetPageDirty is always performed via set_page_dirty, > * and thus under the i_pages lock, then this ordering is not required. > */ > - if (unlikely(PageTransHuge(page)) && PageSwapCache(page)) > + if (unlikely(PageTransHuge(page)) && > + (PageSwapCache(page) || !PageSwapBacked(page))) > refcount = 1 + HPAGE_PMD_NR; > else > refcount = 2; Kirill suggests that this patch would be better (for this part of the patch; the part in truncate.c should remain as it is) commit ddcee327f96d57cb9d5310486d21e43892b7a368 Author: William Kucharski Date: Fri Sep 20 16:14:51 2019 -0400 mm: Support removing arbitrary sized pages from mapping __remove_mapping() assumes that pages can only be either base pages or HPAGE_PMD_SIZE. Further, it assumes that large pages are swap-backed. Support all kinds of pages by unconditionally asking how many pages this page references. Signed-off-by: William Kucharski Signed-off-by: Matthew Wilcox (Oracle) diff --git a/mm/vmscan.c b/mm/vmscan.c index c6659bb758a4..f870da1f4bb7 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -932,10 +932,7 @@ static int __remove_mapping(struct address_space *mapping, struct page *page, * Note that if SetPageDirty is always performed via set_page_dirty, * and thus under the i_pages lock, then this ordering is not required. */ - if (unlikely(PageTransHuge(page)) && PageSwapCache(page)) - refcount = 1 + HPAGE_PMD_NR; - else - refcount = 2; + refcount = 1 + compound_nr(page); if (!page_ref_freeze(page, refcount)) goto cannot_free; /* note: atomic_cmpxchg in page_ref_freeze provides the smp_rmb */