From patchwork Thu Mar 3 01:50:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12766960 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B246AC433F5 for ; Thu, 3 Mar 2022 01:50:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F8DD8D0002; Wed, 2 Mar 2022 20:50:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 280228D0001; Wed, 2 Mar 2022 20:50:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FA9B8D0002; Wed, 2 Mar 2022 20:50:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id EDF068D0001 for ; Wed, 2 Mar 2022 20:50:51 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A2D5B18200A11 for ; Thu, 3 Mar 2022 01:50:51 +0000 (UTC) X-FDA: 79201396302.23.0B98E04 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) by imf02.hostedemail.com (Postfix) with ESMTP id 3900480010 for ; Thu, 3 Mar 2022 01:50:51 +0000 (UTC) Received: by mail-oo1-f47.google.com with SMTP id r41-20020a4a966c000000b0031bf85a4124so4228807ooi.0 for ; Wed, 02 Mar 2022 17:50:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:mime-version; bh=WLZHWiYfsav+TK/RC6MOIHPotleUyTDNef71iAWH83s=; b=haqBoSpzcULkCdwm3OY68wDxPssQDwkueKAhc8ywZtwo3AhtURCVS+X++VAyk8hNqu sGajtVStNdtWeXBWvyOalU2UExs8g2CKWZpsmgEBz+zZdw+PqtIjrn9NidHOc6XombMc zad9VSRcqqIG+JdRSbe5IQdsbXS6VVN/iznaAhq9kg/0aQif2FIwEI48H9trq5H8A1Vt lyvfoSjgjXqgNBl+G3j3utaAh5NcfELXn/xv+Jl3Vqu6+p9AfB6CUyj1Wqx3nrbFiPBH jIvAX5p2ZYHhOopRNaazWRdy7d9HGmA4ETv5+TMtkl70tNAcCXqj3e/clPNkgniwAyiz P6gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version; bh=WLZHWiYfsav+TK/RC6MOIHPotleUyTDNef71iAWH83s=; b=33g73DK/KYisA+dXo0Ko8et4x9/iORl5/+nhctpDSkp16lwmFTHjdCHBmIE3d+g/SL WhbbX4qx1UzTJVfLl54T2cPIWIiPiUlei9gbPbu8W2jmcHYRD7zEkVXfu1jCEt1wulwJ at26+r852BCJUzZ+aNpsLajexWljXcEHNby+jKIwf+zPHFdIO6tLuJ9eg4MNtB9wEhZl +U2i+XnvHqOVijKnaX5gDP8DkakOUUz7E0ouG2q7n1zf7UvXmnZZVRicFkrSeCXQg2Ja yvphoma/JLsefKZ1WrlILiceN1X3vJR01zE0oURNeUD+GZM7u3xFejF/Bb1vWb4/+El3 hl1A== X-Gm-Message-State: AOAM531raURDHH5TWo1F+EqnT0Bsa3qwZK+EUxKdB1/x6gUtFjdzN0oM p2MOeHiNYdjdaMFFZRR1kGABaQ== X-Google-Smtp-Source: ABdhPJwxxfUl0pGVTd8mU4wHLFPUcsOH6iKB7NBPXgjbZmJiEex6cQS96okXwy+xSlqqmdQ3yZr9Dw== X-Received: by 2002:a05:6870:2054:b0:d7:2a0:8b97 with SMTP id l20-20020a056870205400b000d702a08b97mr2324000oad.56.1646272250164; Wed, 02 Mar 2022 17:50:50 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id l10-20020a9d708a000000b005af3e65ce95sm287765otj.70.2022.03.02.17.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 17:50:49 -0800 (PST) Date: Wed, 2 Mar 2022 17:50:48 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: "Kirill A. Shutemov" , Yang Shi , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH mmotm] mm/thp: ClearPageDoubleMap in first page_add_file_rmap() Message-ID: <61c5cf99-a962-9a25-597a-53ab1bd8fbc0@google.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3900480010 X-Stat-Signature: 3yjdp6sfui9bicbzka8tzb1womtngny9 X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=haqBoSpz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of hughd@google.com designates 209.85.161.47 as permitted sender) smtp.mailfrom=hughd@google.com X-Rspamd-Server: rspam03 X-HE-Tag: 1646272251-598251 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: 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. Fixes: 9a73f61bdb8a ("thp, mlock: do not mlock PTE-mapped file huge pages") Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi --- mm/rmap.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1251,6 +1251,17 @@ void page_add_file_rmap(struct page *page, } 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);