Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3990828ybg; Fri, 25 Oct 2019 11:46:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdGBW/MzNP2pC/14z4QNY2mfqSydYSzGdsdfPiHioDQzuX1kmcwBUfbhU+Wmqz/hBQyNm8 X-Received: by 2002:a17:906:a2d1:: with SMTP id by17mr4948536ejb.206.1572029178808; Fri, 25 Oct 2019 11:46:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572029178; cv=none; d=google.com; s=arc-20160816; b=Klqr8RyIZEqcbFpKPjjPdwEKUmjEL92lvQ4FDNP7TTUKtB9FAzQevweUNOJdP7DzzQ oP2k7wZOVetQ+UHgK/z8xpJbEklSDAcg0lwEWo2b8P5+cpNIhq3jvoLZbGEhWgZnPPm5 LhQEDED6c7SvjnTxEFPgmmo+0GkgqLt9LjF4AwN7wNHI7/Fo3Cw/7/aHDzNAVJrFUcjo zabINGPoqBJA1izqjMDYb76kMxBAmuKvIErx3mfbFYpMJl6j2wz1Mnu3m+HiLorncv9m 8IYrwlmxKrTpKEMKA2gz/XFJ/8T5+kbeMDj4AEtaa/c8OBGPUKK0+WFXl3aQW6GSF/uA +OfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=0wY1F55+Ip8y/1DIYJHxsyHK+DtaKwpjT9P33ATdE1U=; b=j3kP0d1ix0L1LnRWROYDlqHpgpV/VLiBdBV7xbQ5BjB7Jr77xUfMSxvhCbTCb9qc/Q m5bmb+1blfjygBMpCUttXfbIr5L634wH8AIKBALqYQkj+AKxAVMLyyxv/bfScRbOfBa+ 9rrvj92AgEGSUfhgXzkJZjRS9EAeu2NmMo3s4zw3kDm3Bko0LUiaMJ02UzyTtnqESgpJ 5Gzo4HsHzxeO30i3cGAVoNBqu+DLOv5IY1k1Ebgpq8gmVQ83PS1c3Gra4hPM7TQpGLON jSiAoX5brbU4lrS2AA6wUmqBuKuAzzzKUFBYjxBdPJubQkhpoetvpmUwLvcrfln3JsUD PHbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id qc16si1709308ejb.12.2019.10.25.11.45.55; Fri, 25 Oct 2019 11:46:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S2440041AbfJXR2Q (ORCPT + 99 others); Thu, 24 Oct 2019 13:28:16 -0400 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]:32805 "EHLO out30-43.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394016AbfJXR2Q (ORCPT ); Thu, 24 Oct 2019 13:28:16 -0400 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; -- 1.8.3.1