From patchwork Thu Oct 24 17:27:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11210543 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F070139A for ; Thu, 24 Oct 2019 17:28:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D93CF205F4 for ; Thu, 24 Oct 2019 17:27:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D93CF205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E766B6B0003; Thu, 24 Oct 2019 13:27:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E00386B0006; Thu, 24 Oct 2019 13:27:58 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CED936B0007; Thu, 24 Oct 2019 13:27:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0001.hostedemail.com [216.40.44.1]) by kanga.kvack.org (Postfix) with ESMTP id A7F216B0003 for ; Thu, 24 Oct 2019 13:27:58 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 436751801BB95 for ; Thu, 24 Oct 2019 17:27:58 +0000 (UTC) X-FDA: 76079361036.06.map22_b45ad768d625 X-Spam-Summary: 50,0,0,3c9b3524df81f65c,d41d8cd98f00b204,yang.shi@linux.alibaba.com,:hughd@google.com:kirill.shutemov@linux.intel.com:aarcange@redhat.com:akpm@linux-foundation.org:yang.shi@linux.alibaba.com::linux-kernel@vger.kernel.org,RULES_HIT:41:355:379:541:800:960:966:967:968:973:988:989:1260:1261:1345:1431:1437:1534:1541:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2525:2553:2560:2563:2682:2685:2736:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3352:3865:3867:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4385:5007:6119:6120:6261:7901:8957:9025:10004:11026:11232:11473:11638:11658:11914:12043:12048:12296:12297:12438:12555:12740:12895:13069:13161:13184:13229:13311:13357:14096:14181:14384:14394:14721:21060:21080:21451:21627:21788:30045:30054:30070:30090,0,RBL:115.124.30.130:@linux.alibaba.com:.lbl8.mailshell.net-62.20.2.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk ,SPF:fp, X-HE-Tag: map22_b45ad768d625 X-Filterd-Recvd-Size: 2564 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Oct 2019 17:27:57 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04391;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0Tg58mS4_1571938066; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0Tg58mS4_1571938066) by smtp.aliyun-inc.com(127.0.0.1); Fri, 25 Oct 2019 01:27:53 +0800 From: Yang Shi To: hughd@google.com, kirill.shutemov@linux.intel.com, aarcange@redhat.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: thp: clear PageDoubleMap flag when the last PMD map gone Date: Fri, 25 Oct 2019 01:27:46 +0800 Message-Id: <1571938066-29031-1-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 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: File THP sets PageDoubleMap flag when the first it gets PTE mapped, but the flag is never cleared until the THP is freed. This result in unbalanced state although it is not a big deal. Clear the flag when the last compound_mapcount is gone. It should be cleared when all the PTE maps are gone (become PMD mapped only) as well, but this needs check all subpage's _mapcount every time any subpage's rmap is removed, the overhead may be not worth. The anonymous THP also just clears PageDoubleMap flag when the last PMD map is gone. Cc: Hugh Dickins Cc: Kirill A. Shutemov Cc: Andrea Arcangeli Signed-off-by: Yang Shi Acked-by: Song Liu --- Hugh thought it is unnecessary to fix it completely due to the overhead (https://lkml.org/lkml/2019/10/22/1011), but it sounds simple to achieve the similar balance as anonymous THP. mm/rmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/rmap.c b/mm/rmap.c index 0c7b2a9..d17cbf3 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1236,6 +1236,9 @@ static void page_remove_file_rmap(struct page *page, bool compound) __dec_node_page_state(page, NR_SHMEM_PMDMAPPED); else __dec_node_page_state(page, NR_FILE_PMDMAPPED); + + /* The last PMD map is gone */ + ClearPageDoubleMap(compound_head(page)); } else { if (!atomic_add_negative(-1, &page->_mapcount)) goto out;