From patchwork Thu Apr 28 15:42:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 567763 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4195C433F5 for ; Thu, 28 Apr 2022 15:42:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347707AbiD1PqG (ORCPT ); Thu, 28 Apr 2022 11:46:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348013AbiD1PqB (ORCPT ); Thu, 28 Apr 2022 11:46:01 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54C7FAC061; Thu, 28 Apr 2022 08:42:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 902A6B82E5F; Thu, 28 Apr 2022 15:42:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E84EDC385A9; Thu, 28 Apr 2022 15:42:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651160563; bh=L2Rcj50kHvipfO9WA+wNHp0G73eGU8osDpLt0jRoNjc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YonJc2ne8OrwzooS6kMzRv6f+Sm0KBqC7ar0P8yzF7Ga18ceL7Rd4xBJKxJ9xNb2X yTXiPVXzQX6Blk9TRuslvvgJVPtUFKPQHZjEnHZqz+SAsPPFvMNmNRkyLRyNHrg+N1 z4CuZUCqrR+YqJP4dcLNPJC4rEgz2Qh9FWNano7E= From: Greg Kroah-Hartman To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Hugh Dickins , Yang Shi , "Kirill A. Shutemov" , Andrew Morton , Linus Torvalds , Greg Kroah-Hartman Subject: [PATCH AUTOSEL 13/14] mm/thp: ClearPageDoubleMap in first page_add_file_rmap() Date: Thu, 28 Apr 2022 17:42:21 +0200 Message-Id: <20220428154222.1230793-13-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220428154222.1230793-1-gregkh@linuxfoundation.org> References: <20220428154222.1230793-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1929; i=gregkh@linuxfoundation.org; h=from:subject; bh=t020Ye3UZged8UWdaHnaf2vQNl0s0QD+/We8io6+w0s=; b=owGbwMvMwCRo6H6F97bub03G02pJDElZW+9lFBZvbBGY9XOlT7oth9Uhx3V687STop7c3xy5/jLX hDWSHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRMzYMc2Wnic4UOGbrV8cwT/F3xN wk0QdHghgWrPSOWTLpWXxzRcjLhAernpwMPXrYEgA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Hugh Dickins commit bd55b0c2d64e84a75575f548a33a3dfecc135b65 upstream. PageDoubleMap is maintained differently for anon and for shmem+file: the shmem+file one was never cleared, because a safe place to do so could not be found; so it would blight future use of the cached hugepage until evicted. See https://lore.kernel.org/lkml/1571938066-29031-1-git-send-email-yang.shi@linux.alibaba.com/ But page_add_file_rmap() does provide a safe place to do so (though later than one might wish): allowing testing to return to an initial state without a damaging drop_caches. Link: https://lkml.kernel.org/r/61c5cf99-a962-9a25-597a-53ab1bd8fbc0@google.com Fixes: 9a73f61bdb8a ("thp, mlock: do not mlock PTE-mapped file huge pages") Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi Cc: "Kirill A. Shutemov" Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/rmap.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/rmap.c b/mm/rmap.c index 9e27f9f038d3..444d0d958aff 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1252,6 +1252,17 @@ void page_add_file_rmap(struct page *page, bool compound) } if (!atomic_inc_and_test(compound_mapcount_ptr(page))) goto out; + + /* + * It is racy to ClearPageDoubleMap in page_remove_file_rmap(); + * but page lock is held by all page_add_file_rmap() compound + * callers, and SetPageDoubleMap below warns if !PageLocked: + * so here is a place that DoubleMap can be safely cleared. + */ + VM_WARN_ON_ONCE(!PageLocked(page)); + if (nr == nr_pages && PageDoubleMap(page)) + ClearPageDoubleMap(page); + if (PageSwapBacked(page)) __mod_lruvec_page_state(page, NR_SHMEM_PMDMAPPED, nr_pages);