From patchwork Sun Jun 23 05:47:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11011561 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5605014B6 for ; Sun, 23 Jun 2019 05:48:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4617728B2A for ; Sun, 23 Jun 2019 05:48:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A6BE28B2C; Sun, 23 Jun 2019 05:48:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAEC028B2A for ; Sun, 23 Jun 2019 05:48:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6ED48E0001; Sun, 23 Jun 2019 01:48:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CF6FD6B0008; Sun, 23 Jun 2019 01:48:02 -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 B20A98E0001; Sun, 23 Jun 2019 01:48:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 765E26B0007 for ; Sun, 23 Jun 2019 01:48:02 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id k136so173727pgc.10 for ; Sat, 22 Jun 2019 22:48:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:smtp-origin-hostprefix:from :smtp-origin-hostname:to:cc:smtp-origin-cluster:subject:date :message-id:in-reply-to:references:mime-version; bh=EqtD9pgjSn3RpeCA8R1A7DD1Wom8eSWCEiXrtl71yV4=; b=HCh2NjGTGQBCVfp/d7EvCScVN12/b1b++WiE94r0r87Gb0M8U0W6KaINsOpRNoimWp LOwf1TzAukUR24vKAj30HS5rXI05rS8k3xC4EWmNN7FSSi7YQTbgVMtJEZhqr+Y/A2L2 H607n6SR6WjEMuFMnGDrYf+4acw3ByqJ1W4LI+FD9WZCWh9cx78HYZonMvNLkum+xOZT TtGc3DI07lZOKk8lhITnvwGe0fQQNod6NmPyW3ErjZ7NIxCGbYEh+P7WhOf/qP4UW9ZA 64ZwBgcZmz0K27n64e8X0pfayi7Uh2YoLwxN6Zh1AdMraATlP8IpEA9Cb62VbtCtY1ZO QXsQ== X-Gm-Message-State: APjAAAW0o4kTF5omD0AAL+pdNovafpGYHOZbIliIpUlyDRLe37RQTQkL djQT8g5D7vBBBYRoUzM546bsVqYOXSbanxgdlluJYYQyJ35M7BI/i2HeoVI26aCrR7UXCcMM003 bWYSM9tKYtXmRIqpNqRnVPn35E01CxzGFYrz3U6lspLZ6Ppp35oWTsuVITQiqGb40vw== X-Received: by 2002:a63:f50d:: with SMTP id w13mr26555187pgh.411.1561268882048; Sat, 22 Jun 2019 22:48:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxp5U48YvypJg1wuwJ7IQGJanw4pJ1EKZGeds7ZvEDsA6E+YLDIpqqGd7tZJ9ORfF6CV0SK X-Received: by 2002:a63:f50d:: with SMTP id w13mr26555158pgh.411.1561268881349; Sat, 22 Jun 2019 22:48:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561268881; cv=none; d=google.com; s=arc-20160816; b=w9yDnJjSGyF7svjOwHFxyC5ASbssEMFaKEf4mWcPjWPepHMjRvkHU/ba0YSSmh5FGL PnBMXcE4kOndz9Tl/wiNuHEhxLVtAYrCnINJkk+xQkFqg0pSBREBipYXLvNthO1DX7w3 +lGu6osg+M4mlQXGii4ONpPrFuPjhji6sSeG+cLp+kDx2bNqDZ28bakzqCYUfpI8799+ mCJMnmzFBjZrCNZmNBJiPEHIY6FUrjT7gl5YAcI1D0paYHfyP2Os7OkWMyrmzVROX9nd W1+bzac+8Fy+wCntKTbiem5Rd3escxjDm0jNo8iUno25S8isJCHOsNCU39Vi3pWJi+Ap anfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=EqtD9pgjSn3RpeCA8R1A7DD1Wom8eSWCEiXrtl71yV4=; b=wFrerTufHKhK+TH2hLKbAZeAusehkHhlPNb47SwkyKSwD25mI3fibPQP1w4/aKpugv W2d42q8N4uZsAk08wAJVongyCi+V+fiXUNyP+5hPUqv+aIdqa22AiBL9HcTZt4Bb4u3x vCl7oYw0sf1iPWTQdZ0v/suJpfB5O8LFwCLBZXOg98NCltZHl8S0VbUBGBjnDauALyPg 30mYvXnyarHIN2cLNLfxj3Y7uMPlN3kVbLq9cuogJ5LBrudeRh7bKYkdi/KTZ77WlxQp chl7ewZFbjHCvQ8j0VFBJQz/VKpbuz3MoGZ+upaSaxHoFT/awzeZsyq+5gEaL3yVDoxb 5OZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=d5JMGC4A; spf=pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1077171f80=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com. [67.231.145.42]) by mx.google.com with ESMTPS id p62si7434307pjp.66.2019.06.22.22.48.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Jun 2019 22:48:01 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) client-ip=67.231.145.42; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=d5JMGC4A; spf=pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1077171f80=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5N5gtC1018659 for ; Sat, 22 Jun 2019 22:48:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=EqtD9pgjSn3RpeCA8R1A7DD1Wom8eSWCEiXrtl71yV4=; b=d5JMGC4AXGRT9DlNcP+QLU5cCQgnYo+oGcoi38z++C7ol4h64qzmUCFUo4x/vkC5s7AU fjJV185z5j+ZtriexMGle7aMOi+taWO7hPog5i+KJZg6cDW+RBQEazgQVVFE6gsYgzDi MpIiNAqySQfdOca/2K37f3aA7Qac+xinXUU= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2t9kmja0xr-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sat, 22 Jun 2019 22:48:00 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Sat, 22 Jun 2019 22:47:59 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 472D662E2CFB; Sat, 22 Jun 2019 22:47:56 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v7 1/6] filemap: check compound_head(page)->mapping in filemap_fault() Date: Sat, 22 Jun 2019 22:47:44 -0700 Message-ID: <20190623054749.4016638-2-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190623054749.4016638-1-songliubraving@fb.com> References: <20190623054749.4016638-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-23_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=925 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906230050 X-FB-Internal: deliver 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: X-Virus-Scanned: ClamAV using ClamSMTP Currently, filemap_fault() avoids trace condition with truncate by checking page->mapping == mapping. This does not work for compound pages. This patch let it check compound_head(page)->mapping instead. Acked-by: Rik van Riel Signed-off-by: Song Liu --- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index df2006ba0cfa..f5b79a43946d 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2517,7 +2517,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) goto out_retry; /* Did it get truncated? */ - if (unlikely(page->mapping != mapping)) { + if (unlikely(compound_head(page)->mapping != mapping)) { unlock_page(page); put_page(page); goto retry_find; From patchwork Sun Jun 23 05:47:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11011559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5EE661398 for ; Sun, 23 Jun 2019 05:48:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DE2928B2A for ; Sun, 23 Jun 2019 05:48:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4194D28B2C; Sun, 23 Jun 2019 05:48:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 090A728B2A for ; Sun, 23 Jun 2019 05:48:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 185EA6B0006; Sun, 23 Jun 2019 01:48:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 10FEE8E0002; Sun, 23 Jun 2019 01:48:02 -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 EA5168E0001; Sun, 23 Jun 2019 01:48:01 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id ADC796B0006 for ; Sun, 23 Jun 2019 01:48:01 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id k136so173716pgc.10 for ; Sat, 22 Jun 2019 22:48:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:smtp-origin-hostprefix:from :smtp-origin-hostname:to:cc:smtp-origin-cluster:subject:date :message-id:in-reply-to:references:mime-version; bh=z7orUW1w2AFawDH57ZTLvYALJSDsMI3HPUuppHQ+jCM=; b=iRj7q6HjSvGP+FFXO9kK02rWbLxt30EzSimsM4GbPmKm0qk+G0CgLjA69pEqKODNKU zaKrXgPJ6Xy6U/D+RIwonb2ouFSZKRWc4orGghJL3OgNHUa4Qc+FRuZ3qTz53RvgfLqr SBuVVAviid0PUzJwXIODuw+xCVwDEKtqsA7kMFXVYuPb29ZY/BJal/lr9xvvU8kpDGuO iHEF5quEDo1Ku7W5eL4l+57woP0x791VxHR/Gd7szLjHzbqkT6IlBE2P8IHnW30p+jIL ELamYHoyJ2APsYwT6k1iDjTvGXJCcTQRQXCJkw5zXX2+ApPds3wTP0PwVcRU6MemYljF 4y9A== X-Gm-Message-State: APjAAAUESfY+zPawcD6bW9WlsdTF7xNLCNcNdxM8TaZYL60U/Qprgx3B 3fVRohjv+mT7kbqLJA0QnNEc0A2LEqNSPE15fBbUEf6wgtgbfxLww9hGTFIb7YQwtMQPy6eu57E V+IeIdUYrUhAH8uTEM8nFbWEpLnOgIEpqCWqnm2Fw3/6UCw5v5TK5+RmJSxLu6YYqjA== X-Received: by 2002:a17:90a:2446:: with SMTP id h64mr17697202pje.0.1561268881278; Sat, 22 Jun 2019 22:48:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwlrS8LMuomlNq4rfU1D8wxnfhhYWlSZw1+f5Tgev46a65BTizgJ1khyGein2uoy8A0iN+ X-Received: by 2002:a17:90a:2446:: with SMTP id h64mr17697163pje.0.1561268880711; Sat, 22 Jun 2019 22:48:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561268880; cv=none; d=google.com; s=arc-20160816; b=ir8KBdOgIXh9XZ00YGQyED9Au5nyWFiRg1/Fs3VmhoET0ACHqghQni2tJLgjO49srK 47wYGlEtMEkTIdDZ6Y93nWAQxzxlcwkudnD2yKumDUqaOveG0j7+cwkB51z+X+Pdg/Zg RWXQkWiOjKHlHHpjPBkPqqIfMlux770AzfckyWbYK/6Mmb22JmWGcwOQJEO9ZkYBjVBK sVEyDJGIJ8SgbN1FJr2UmSYzm5BBfFzNID5tX/FFcX7hjxtjFNhOcjCGXj6JwlJmKPde zOJogZwkaTv0xUKEklFMict4KkcvFl9ib+S63jIsw3qY9KMbRgGVujk7CnRjiqMWIMqO L3DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=z7orUW1w2AFawDH57ZTLvYALJSDsMI3HPUuppHQ+jCM=; b=cs5tigbiFa9LVHqEfFJyBmuh0Wk4ChjIuC1FjqT7+2Ixon+usVe+0rDF1levBU3Pqk gO8K2DZ5BgaEbZZV7+MiQowhVjTlmSEFxV00m/3w6dnq55SacI3SBXJQtlHvffCMsfXw pzfc2B5V/uHsli9MOxqSycNeCV3Z/JvKCAOny6R79kGTRkyXyu4u5OmPHGYoa8fcUjkB CLNuiAWRdy2zCRHsg76akxsQUXAS8xsvRFa6NBUNixKUccriUXwe7gT/EGejQJ+IayQz MSwaLXYpZcmO8Uz0Ghok3cujuddP+VnfrPsbSUwGfGskJ0dY07MJYSC4/e8M0wehvvJr Y7Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=DQH6Z5J1; spf=pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1077171f80=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com. [67.231.145.42]) by mx.google.com with ESMTPS id 31si2650681pld.245.2019.06.22.22.48.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Jun 2019 22:48:00 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) client-ip=67.231.145.42; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=DQH6Z5J1; spf=pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1077171f80=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5N5gg64018602 for ; Sat, 22 Jun 2019 22:48:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=z7orUW1w2AFawDH57ZTLvYALJSDsMI3HPUuppHQ+jCM=; b=DQH6Z5J1ftaDDjyPugAGXH8mrN4pGG+P0POCXuezd2+btjU0ZmyPv3fxqwXt474rDpmN Q5RWGFCat0V9LnDwrjwR6zYCSZT9+WyArOkNcGiupUH1KzeRSTGPivyhEo0ZTIMBbzr6 RWAWn9ar2sFekaFl4aAO4TZLL7+mRg3uMqE= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2t9kmja0xp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sat, 22 Jun 2019 22:48:00 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Sat, 22 Jun 2019 22:47:58 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 1599262E2D94; Sat, 22 Jun 2019 22:47:58 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v7 2/6] filemap: update offset check in filemap_fault() Date: Sat, 22 Jun 2019 22:47:45 -0700 Message-ID: <20190623054749.4016638-3-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190623054749.4016638-1-songliubraving@fb.com> References: <20190623054749.4016638-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-23_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=803 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906230050 X-FB-Internal: deliver 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: X-Virus-Scanned: ClamAV using ClamSMTP With THP, current check of offset: VM_BUG_ON_PAGE(page->index != offset, page); is no longer accurate. Update it to: VM_BUG_ON_PAGE(page_to_pgoff(page) != offset, page); Acked-by: Rik van Riel Signed-off-by: Song Liu --- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index f5b79a43946d..5f072a113535 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2522,7 +2522,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) put_page(page); goto retry_find; } - VM_BUG_ON_PAGE(page->index != offset, page); + VM_BUG_ON_PAGE(page_to_pgoff(page) != offset, page); /* * We have a locked page in the page cache, now we need to check From patchwork Sun Jun 23 05:47:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11011563 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF9BA14B6 for ; Sun, 23 Jun 2019 05:48:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEAB428B2A for ; Sun, 23 Jun 2019 05:48:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D307628B2C; Sun, 23 Jun 2019 05:48:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45EC828B2A for ; Sun, 23 Jun 2019 05:48:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE7728E0002; Sun, 23 Jun 2019 01:48:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B71396B0008; Sun, 23 Jun 2019 01:48:05 -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 974F98E0002; Sun, 23 Jun 2019 01:48:05 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 5D0096B0007 for ; Sun, 23 Jun 2019 01:48:05 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id g21so1116300pfb.13 for ; Sat, 22 Jun 2019 22:48:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:smtp-origin-hostprefix:from :smtp-origin-hostname:to:cc:smtp-origin-cluster:subject:date :message-id:in-reply-to:references:mime-version; bh=DNX0Ai841ZgyA6yG9XH0uRWq8DS0N63a6b+fvROsjjM=; b=HGgWVB2NLdCQMQifdxZPOP1y2gqlCkWjID2BmegO+RmswNnz8QSSdg7baRbjj2Y3kD vXG7kzzBE1z+WkhLD/LwrNiHNmzxzk0com4YkCYJoJtXHJ1Pk5ONBiiDKaxdfXKpwD6M Y5jWJZESdEHaMJ82rrz238GGk8TdNQKuPjMy822qAweRkVQXzhGETtRo2tsiMtmBOlBP PlKZCpbAo1SyhccMqid1ECJg982ThuzZLgXklONIDXX7Fv1lLlw9E+fEZSVBn6kJgZMP bJE7/2swBpbVZqYI1I6nHUFBY2o8kSBBLqPY006NetXFa0C3o9yGHvYAmASBLpDNKQq/ 27Xw== X-Gm-Message-State: APjAAAUNPA/lxeEgkR8QLdB7DRgpV7BPNI5PvPw1/2ZySDLUpEn+egeB Hkmm2HJgeKfNHrsZWVouoPd14ZUkYnzGKQ2+ObgCkLu3qTiUkDRy3ifbKGS+ZmuksDPaV0tGMCM HwCOcmn5jV9A8rnGmuadZ4HLiyvQk/8MpGDaRNB6IEq/7xB2jfrK3jbZZeaUgjy27Lw== X-Received: by 2002:a63:e14c:: with SMTP id h12mr25472479pgk.87.1561268884375; Sat, 22 Jun 2019 22:48:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzcVrOBTTqsFsHCIKhW5VNQ4sOUQ0PIWQXYrk1ztQ5WW32d41ZEpLBSegF4Kblm4BW9IkVr X-Received: by 2002:a63:e14c:: with SMTP id h12mr25472444pgk.87.1561268883627; Sat, 22 Jun 2019 22:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561268883; cv=none; d=google.com; s=arc-20160816; b=rEnXeCTVBicfCYNh8GVfXD57WdrncxubfmPTjSxxDrxm0UhJJ06OJPZz5c3skgcuKI yjL1OMMqXPWzYA5XExgdDCH6qHiWpBiEJdPuHqe+PWVstiVRZW+5hV4BwswTD2h0g2Wd qsnxH4fC3tAklDH2T9Ez9DtugtkgYKubi2ku/ON4RQVVuHzl+zS5pOWTEKe8LmTHzBv7 YbyJ8Dem/EFP3l9du+9M1ED/4qUrmMNuuHOeex5ZliKaTJnUjQc0HxjRdd+KwS9AsoJt gLpUU8G9bKBoZgA2PXKkbt4PxWJ30pHn3Y04zJxevOg6NugiOrGSD6G/hvYmuWnaV4TS DbLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=DNX0Ai841ZgyA6yG9XH0uRWq8DS0N63a6b+fvROsjjM=; b=vlCzjUN29Sz5FsqVMUl7qg7nuvRDyCnOV+3dVyuTUhw8CVOYyNVXCgMZC+SvR6gTYa ZHxRY9Eqrb3mB0M5qE/2jZcg+KEZbKVXSN/WihVVu1YBNVP6Ws3LDatJdlVUbh2y6vj1 3eU9OvLON/v1phE2HiVtdChhL55woRYbyusZxHUc7sBW+VgoCoRyv9sqtM5ftPG6Jxjq svpZoRrSvDEeRvCTwbQFCcvoYi9smN3Yn+yQ1AzErHqeQppZAOdRLr6NQNaPln9U1kid w/IRYGLVzQdcaebqYQ7aK3qDK90zjuAZdeIEOBcLJgu4Uwfw0oKXJj3b7fKPObMJ6dRa 77Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b="NH/YvZ3A"; spf=pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1077171f80=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com. [67.231.145.42]) by mx.google.com with ESMTPS id u13si6488959pgp.478.2019.06.22.22.48.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Jun 2019 22:48:03 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) client-ip=67.231.145.42; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b="NH/YvZ3A"; spf=pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1077171f80=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5N5j1aQ008141 for ; Sat, 22 Jun 2019 22:48:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=DNX0Ai841ZgyA6yG9XH0uRWq8DS0N63a6b+fvROsjjM=; b=NH/YvZ3A9KYYikbaXGSCR+tX0cwr+D9Chp5GcViw8hlPikEsX3+fHG262Aj1RKIOQO1y RMvw1/XiFKdn6YBEJDE71g9zSyL6shxagudVY6N8mnm5czXVJjctI3bSIyGwdMJEYJzG QO1P496Jx/B66gviXL93Zw3cZaj7vWNYeY0= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2t9fn2ag9x-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sat, 22 Jun 2019 22:48:03 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Sat, 22 Jun 2019 22:48:00 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 3B48462E2CFB; Sat, 22 Jun 2019 22:48:00 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v7 3/6] mm,thp: stats for file backed THP Date: Sat, 22 Jun 2019 22:47:46 -0700 Message-ID: <20190623054749.4016638-4-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190623054749.4016638-1-songliubraving@fb.com> References: <20190623054749.4016638-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-23_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906230050 X-FB-Internal: deliver 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: X-Virus-Scanned: ClamAV using ClamSMTP In preparation for non-shmem THP, this patch adds a few stats and exposes them in /proc/meminfo, /sys/bus/node/devices//meminfo, and /proc//task//smaps. This patch is mostly a rewrite of Kirill A. Shutemov's earlier version: https://lkml.org/lkml/2017/1/26/284. Acked-by: Rik van Riel Signed-off-by: Song Liu --- drivers/base/node.c | 6 ++++++ fs/proc/meminfo.c | 4 ++++ fs/proc/task_mmu.c | 4 +++- include/linux/mmzone.h | 2 ++ mm/vmstat.c | 2 ++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index 8598fcbd2a17..71ae2dc93489 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -426,6 +426,8 @@ static ssize_t node_read_meminfo(struct device *dev, "Node %d AnonHugePages: %8lu kB\n" "Node %d ShmemHugePages: %8lu kB\n" "Node %d ShmemPmdMapped: %8lu kB\n" + "Node %d FileHugePages: %8lu kB\n" + "Node %d FilePmdMapped: %8lu kB\n" #endif , nid, K(node_page_state(pgdat, NR_FILE_DIRTY)), @@ -451,6 +453,10 @@ static ssize_t node_read_meminfo(struct device *dev, nid, K(node_page_state(pgdat, NR_SHMEM_THPS) * HPAGE_PMD_NR), nid, K(node_page_state(pgdat, NR_SHMEM_PMDMAPPED) * + HPAGE_PMD_NR), + nid, K(node_page_state(pgdat, NR_FILE_THPS) * + HPAGE_PMD_NR), + nid, K(node_page_state(pgdat, NR_FILE_PMDMAPPED) * HPAGE_PMD_NR) #endif ); diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index 568d90e17c17..bac395fc11f9 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -136,6 +136,10 @@ static int meminfo_proc_show(struct seq_file *m, void *v) global_node_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR); show_val_kb(m, "ShmemPmdMapped: ", global_node_page_state(NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR); + show_val_kb(m, "FileHugePages: ", + global_node_page_state(NR_FILE_THPS) * HPAGE_PMD_NR); + show_val_kb(m, "FilePmdMapped: ", + global_node_page_state(NR_FILE_PMDMAPPED) * HPAGE_PMD_NR); #endif #ifdef CONFIG_CMA diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 01d4eb0e6bd1..0360e3b2ba89 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -413,6 +413,7 @@ struct mem_size_stats { unsigned long lazyfree; unsigned long anonymous_thp; unsigned long shmem_thp; + unsigned long file_thp; unsigned long swap; unsigned long shared_hugetlb; unsigned long private_hugetlb; @@ -563,7 +564,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, else if (is_zone_device_page(page)) /* pass */; else - VM_BUG_ON_PAGE(1, page); + mss->file_thp += HPAGE_PMD_SIZE; smaps_account(mss, page, true, pmd_young(*pmd), pmd_dirty(*pmd), locked); } #else @@ -767,6 +768,7 @@ static void __show_smap(struct seq_file *m, const struct mem_size_stats *mss) SEQ_PUT_DEC(" kB\nLazyFree: ", mss->lazyfree); SEQ_PUT_DEC(" kB\nAnonHugePages: ", mss->anonymous_thp); SEQ_PUT_DEC(" kB\nShmemPmdMapped: ", mss->shmem_thp); + SEQ_PUT_DEC(" kB\nFilePmdMapped: ", mss->file_thp); SEQ_PUT_DEC(" kB\nShared_Hugetlb: ", mss->shared_hugetlb); seq_put_decimal_ull_width(m, " kB\nPrivate_Hugetlb: ", mss->private_hugetlb >> 10, 7); diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 70394cabaf4e..827f9b777938 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -234,6 +234,8 @@ enum node_stat_item { NR_SHMEM, /* shmem pages (included tmpfs/GEM pages) */ NR_SHMEM_THPS, NR_SHMEM_PMDMAPPED, + NR_FILE_THPS, + NR_FILE_PMDMAPPED, NR_ANON_THPS, NR_UNSTABLE_NFS, /* NFS unstable pages */ NR_VMSCAN_WRITE, diff --git a/mm/vmstat.c b/mm/vmstat.c index fd7e16ca6996..6afc892a148a 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1158,6 +1158,8 @@ const char * const vmstat_text[] = { "nr_shmem", "nr_shmem_hugepages", "nr_shmem_pmdmapped", + "nr_file_hugepages", + "nr_file_pmdmapped", "nr_anon_transparent_hugepages", "nr_unstable", "nr_vmscan_write", From patchwork Sun Jun 23 05:47:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11011595 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FA0C13AF for ; Sun, 23 Jun 2019 06:30:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FADA28AE3 for ; Sun, 23 Jun 2019 06:30:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DE6228B2C; Sun, 23 Jun 2019 06:30:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F3F528AE3 for ; Sun, 23 Jun 2019 06:30:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 783496B0003; Sun, 23 Jun 2019 02:30:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6BE8E8E0002; Sun, 23 Jun 2019 02:30:02 -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 4005F8E0001; Sun, 23 Jun 2019 02:30:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 05BB76B0003 for ; Sun, 23 Jun 2019 02:30:02 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id 30so6911290pgk.16 for ; Sat, 22 Jun 2019 23:30:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:smtp-origin-hostprefix:from :smtp-origin-hostname:to:cc:smtp-origin-cluster:subject:date :message-id:in-reply-to:references:mime-version; bh=Kr37aYRy2KacRNeWnEOl8WIgUYHSnWgZ3fV+borBCvY=; b=Yd/Q3MJ/GxONgxm4VxztR6Dlwfv8UVSqLx553ojdlk37llIg8cDBnm9qY9zezQxpNq JJXTfv/CtHl4JZkRgRbkYiQfaEvLJsSjYbWAj4movpio3EfFOlKwljyxJS0QExIKSyPz zxi+s9hp0kLlKdlePYpxunLsG4Vd6rZpATLdPl+eU9RmBfs5RbtQTQ+vLShDiG1YHGd9 6E8oSFgaIogupY5ImGdScNL3q71hLcXlGEPZg1mtpxIn+7t53I4j+3geqflQp3key0rq 4obOj3c3hKulC+lywFaYWvfpNqtorioMFY5PQuO4zsEP43p73j2QVkSRqNpLas0uEYl5 HseQ== X-Gm-Message-State: APjAAAUsbla4uE1V8aSBIy9JF+Nhndh8udkFSrFooNvuxjeRaccYaCFA Ls1C3G5iBVd8cWkixRNAnLA4TP4mnC0s2wEHzJ/OSFDQ8yIYVU/5yAF51h+aPO26slV2g1dB313 4YPIL/LCqFM/Mc9ThHrI/cM4EZ5MkQjgJsn1WflccdDvppSgIUzhwjfozfY5IOWT4MQ== X-Received: by 2002:a63:2985:: with SMTP id p127mr25130257pgp.400.1561271401568; Sat, 22 Jun 2019 23:30:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2+ge3rN+CgQnimZbpebE82G5AahAzI7rfLoSjnKVMIPvfEpWGkdSunA7m3/RuTJuHxJhw X-Received: by 2002:a63:2985:: with SMTP id p127mr25130216pgp.400.1561271400695; Sat, 22 Jun 2019 23:30:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561271400; cv=none; d=google.com; s=arc-20160816; b=YBZGlIt9eAd0JaOJcD9pLC3C1643+pvFrrwzhzorrTKWTx6gpOuyT1ksn3mleoIJ5s 23LDqso0q2BqtegYR/9L9goAzx6pAHQLuS1ArPWEH6ewrIBTUnHsGB9q1mUZZKX8Db0b g4KkHA1oUuUvv0kLuW7zsjUriy0fdQ7eaYyrBqC2q0t86exNCQdXJ9xLhNkwm6jxd4w6 KqDxinD8vkYRL31FlBffWRbvZPXVSUMYYBTGovoib104FEGvfcG35EVEmuB6STQ0boGN 6lw9XFXcnogv5sBZrktEtujGcIAbI/de4AqRxbL5mqAB+y3q/Jrv7kQjzEbbahP53bU0 JBlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=Kr37aYRy2KacRNeWnEOl8WIgUYHSnWgZ3fV+borBCvY=; b=ybF2oYFAhEU1zjkqVuTeEmIGiEVrXrtgGbPK28/YsjSeU9J/CElIv3pfeFbOAYbVB1 F1Cuvr4Bm2uGC9jBfDuqolGfMY9tBxwQ3lNHSRycSMnBplXOPnGw5kQideKaWcUZfQLu gPszh/xa6JvG60cjY8ptiLAAeThaZ8o6B+GAVOnPVecEXphgRcZazbD1S3Ox0Kri3ITc KgLrxXm3ZSqFxwuSM0LijwX6dGwprlgWlcvK9jVcKVjCblOc0LPo2bE1b26NS4fmAmuy vFdxXCB9JMUAj94Gg0qx+TnhakxBbMJV2FsnQiEDojacZQ5KeiJ7tIfELXmZ+dCxm+GG s7Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=aZXkBDUW; spf=pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1077171f80=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com. [67.231.145.42]) by mx.google.com with ESMTPS id m1si7082323pjr.47.2019.06.22.23.30.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Jun 2019 23:30:00 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) client-ip=67.231.145.42; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=aZXkBDUW; spf=pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1077171f80=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5N6Ro97018427 for ; Sat, 22 Jun 2019 23:30:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=Kr37aYRy2KacRNeWnEOl8WIgUYHSnWgZ3fV+borBCvY=; b=aZXkBDUWBAxL6VM2VUmr2HhxlWoVql7hYob6GSLvl5bca4qxkLshU/ThbTI2qq8C0Zdl hYLatvDXMiRKVOA23zOhJz0n7mYr8EbPs7aVkeEFv/M0mn0/afxvtD7ZMtRlTsDLnOzg D+P+vBel+RxasIlfbOKqC1Qm4wgLJsdOxBE= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2t9kmja3gf-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sat, 22 Jun 2019 23:30:00 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Sat, 22 Jun 2019 22:36:48 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 34DE762E2CFB; Sat, 22 Jun 2019 22:48:02 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v7 4/6] khugepaged: rename collapse_shmem() and khugepaged_scan_shmem() Date: Sat, 22 Jun 2019 22:47:47 -0700 Message-ID: <20190623054749.4016638-5-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190623054749.4016638-1-songliubraving@fb.com> References: <20190623054749.4016638-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-23_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=628 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906230055 X-FB-Internal: deliver 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: X-Virus-Scanned: ClamAV using ClamSMTP Next patch will add khugepaged support of non-shmem files. This patch renames these two functions to reflect the new functionality: collapse_shmem() => collapse_file() khugepaged_scan_shmem() => khugepaged_scan_file() Signed-off-by: Song Liu --- mm/khugepaged.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 0f7419938008..158cad542627 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1287,7 +1287,7 @@ static void retract_page_tables(struct address_space *mapping, pgoff_t pgoff) } /** - * collapse_shmem - collapse small tmpfs/shmem pages into huge one. + * collapse_file - collapse small tmpfs/shmem pages into huge one. * * Basic scheme is simple, details are more complex: * - allocate and lock a new huge page; @@ -1304,10 +1304,11 @@ static void retract_page_tables(struct address_space *mapping, pgoff_t pgoff) * + restore gaps in the page cache; * + unlock and free huge page; */ -static void collapse_shmem(struct mm_struct *mm, - struct address_space *mapping, pgoff_t start, +static void collapse_file(struct mm_struct *mm, + struct file *file, pgoff_t start, struct page **hpage, int node) { + struct address_space *mapping = file->f_mapping; gfp_t gfp; struct page *new_page; struct mem_cgroup *memcg; @@ -1563,11 +1564,11 @@ static void collapse_shmem(struct mm_struct *mm, /* TODO: tracepoints */ } -static void khugepaged_scan_shmem(struct mm_struct *mm, - struct address_space *mapping, - pgoff_t start, struct page **hpage) +static void khugepaged_scan_file(struct mm_struct *mm, + struct file *file, pgoff_t start, struct page **hpage) { struct page *page = NULL; + struct address_space *mapping = file->f_mapping; XA_STATE(xas, &mapping->i_pages, start); int present, swap; int node = NUMA_NO_NODE; @@ -1631,16 +1632,15 @@ static void khugepaged_scan_shmem(struct mm_struct *mm, result = SCAN_EXCEED_NONE_PTE; } else { node = khugepaged_find_target_node(); - collapse_shmem(mm, mapping, start, hpage, node); + collapse_file(mm, file, start, hpage, node); } } /* TODO: tracepoints */ } #else -static void khugepaged_scan_shmem(struct mm_struct *mm, - struct address_space *mapping, - pgoff_t start, struct page **hpage) +static void khugepaged_scan_file(struct mm_struct *mm, + struct file *file, pgoff_t start, struct page **hpage) { BUILD_BUG(); } @@ -1722,8 +1722,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, file = get_file(vma->vm_file); up_read(&mm->mmap_sem); ret = 1; - khugepaged_scan_shmem(mm, file->f_mapping, - pgoff, hpage); + khugepaged_scan_file(mm, file, pgoff, hpage); fput(file); } else { ret = khugepaged_scan_pmd(mm, vma, From patchwork Sun Jun 23 05:47:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11011571 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D113A14B6 for ; Sun, 23 Jun 2019 05:48:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCF7328B2A for ; Sun, 23 Jun 2019 05:48:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B186228B47; Sun, 23 Jun 2019 05:48:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C92B928B2A for ; Sun, 23 Jun 2019 05:48:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 383D88E0005; Sun, 23 Jun 2019 01:48:14 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2E4C96B0008; Sun, 23 Jun 2019 01:48:14 -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 099E68E0005; Sun, 23 Jun 2019 01:48:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id C58656B0007 for ; Sun, 23 Jun 2019 01:48:13 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id d3so6885454pgc.9 for ; Sat, 22 Jun 2019 22:48:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:smtp-origin-hostprefix:from :smtp-origin-hostname:to:cc:smtp-origin-cluster:subject:date :message-id:in-reply-to:references:mime-version; bh=O+6EE6cOoTCUvHE2RvQJnTHHVGzJsPDThSyZpQ9T/s8=; b=kIyXVnNUKc7u6q6GXvtAbxOUUI+BTZ6qrYeDyg1OqGY2L1tMXVwMTHei4lqceb3Nia hDG5X0CjYPZCSVtq3NJlkgGM1rDjg9RNyNX/E+fonfLFwYOrU+Q+CmplbQfR3MA9qTf8 +aAeRruS/CWjWNd58tZh2IRK0Ozy68EeM15wJ1T4cxw06REc605y4FzBp6KzWJL+I9Qt WPZAg64sr6pXQ7W3DqNJLu7PQL/4zPbKIvnYG/H8uNDUe6j418hY1dZsO1JbqPvuq7Su Pa6solmgda84ksSSb8h55dcWY39X0XKy0iLNCcXd4XSEhBygFJY2PEk4Ct4SGk8aYwlc 2urQ== X-Gm-Message-State: APjAAAVvU+2DgjmKWdy35JZ7c6c7AZyephtdsSezX7+t2JPWgT7md+M6 6jU+iIb7EiL0XU3cifq0J23Zibxr8Zi/frXlbYLAbX4cK8GI1tlZgZakKvcbIhMlhM3cis0hZXM Huhb1PV+U16BsGlefW8YxP+YnEVuhi9/4i5nUbAfuTHU8DGkkJbOHrzsX752FGc3X6Q== X-Received: by 2002:a17:90a:2343:: with SMTP id f61mr17068856pje.130.1561268893380; Sat, 22 Jun 2019 22:48:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPg3qlNZ+Dr2ibYobgYlzqM+CDOqfd6s85KMgN03erls1iGx33YZJCwtOA4p7tEWBQCU+o X-Received: by 2002:a17:90a:2343:: with SMTP id f61mr17068798pje.130.1561268892408; Sat, 22 Jun 2019 22:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561268892; cv=none; d=google.com; s=arc-20160816; b=FOkXvhxSxwutUXyazzI8wEc16myPNXsPPQldeA6l2GmIUWuu4vui7c5IMWuwtWU4MT IzRAo7SNEzRTPpdY/vl9LGQe5A2HPTt/wkUO0cLY0Q6RRQEg3kMMHjjqql7rDqZJaL4t okED+c0D0enMnQRb1x1jI0c4pQ4pKp2IwVNqj8xpPf/4BbZeotNouIFVZ/Jpgvj1+Mk4 F453EqnYtGQGOjcHw7QgwTsVyUhB+nQ0UTDehdaLTsgR5bJS/Kbjvq4Fzk9xlyAEEC2o S0YHPn7VQW4u/C886kl5t+Or4fSXH3GCskr/mQSXmwmYCrAnvMVBhSIBJfBxTD1fI7AD 0mBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=O+6EE6cOoTCUvHE2RvQJnTHHVGzJsPDThSyZpQ9T/s8=; b=qgm1WqQi/C2leaz22IjrVBWnZ2R9MHACUtN/zWPnNTksH02nUME+K2mQnl4SAlHK1D s9E+zfGQWHZWofjX48IokviOyDtVSQK3yH7jBQForsOJPftZzWuOQ77PhllwY7mLcWn8 MPgq60G19jDA8/udNAdqXeXrzN9Xpmq0gSWv0Eal6uuvv2EtshcFkRo9UTwxjz1glUW6 3yrzA4gK7pHCybpKS7P/oYeVxQ9Km2T7srIn78jQSfGvO63i71IXTAPtDeDgc567Oiu2 IgNGegd8BpyxQ99EYIvzQmnDzIiOFVHX+VHQ75OiD5BGXb/+nEt0IwN+5tNIJepG2fR7 Adwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=fbsbu114; spf=pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1077171f80=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com. [67.231.145.42]) by mx.google.com with ESMTPS id 19si7412758pfi.81.2019.06.22.22.48.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Jun 2019 22:48:12 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) client-ip=67.231.145.42; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=fbsbu114; spf=pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1077171f80=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5N5gI7n016031 for ; Sat, 22 Jun 2019 22:48:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=O+6EE6cOoTCUvHE2RvQJnTHHVGzJsPDThSyZpQ9T/s8=; b=fbsbu114wSE2afUgjlqBjmlldW/o7GFZ0ngNP8riEVrvqXjTiRCNTaGmSwkKCLQMDXzK W2yktwEoObYmoWUF+NJ5jTbp4PgjsIkIYPMo7QM3c98WUw9E/E2+CRSKAWdWqzTHiXzB 0OTcj28R7RRFBkjetPNE1JyQjp+ZD0oE2aY= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2t9he9j8qw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sat, 22 Jun 2019 22:48:11 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Sat, 22 Jun 2019 22:48:10 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id EC52462E2CFB; Sat, 22 Jun 2019 22:48:03 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v7 5/6] mm,thp: add read-only THP support for (non-shmem) FS Date: Sat, 22 Jun 2019 22:47:48 -0700 Message-ID: <20190623054749.4016638-6-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190623054749.4016638-1-songliubraving@fb.com> References: <20190623054749.4016638-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-23_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906230050 X-FB-Internal: deliver 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: X-Virus-Scanned: ClamAV using ClamSMTP This patch is (hopefully) the first step to enable THP for non-shmem filesystems. This patch enables an application to put part of its text sections to THP via madvise, for example: madvise((void *)0x600000, 0x200000, MADV_HUGEPAGE); We tried to reuse the logic for THP on tmpfs. Currently, write is not supported for non-shmem THP. khugepaged will only process vma with VM_DENYWRITE. The next patch will handle writes, which would only happen when the vma with VM_DENYWRITE is unmapped. An EXPERIMENTAL config, READ_ONLY_THP_FOR_FS, is added to gate this feature. Acked-by: Rik van Riel Signed-off-by: Song Liu --- mm/Kconfig | 11 ++++++ mm/filemap.c | 4 +-- mm/khugepaged.c | 90 ++++++++++++++++++++++++++++++++++++++++--------- mm/rmap.c | 12 ++++--- 4 files changed, 96 insertions(+), 21 deletions(-) diff --git a/mm/Kconfig b/mm/Kconfig index f0c76ba47695..0a8fd589406d 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -762,6 +762,17 @@ config GUP_BENCHMARK See tools/testing/selftests/vm/gup_benchmark.c +config READ_ONLY_THP_FOR_FS + bool "Read-only THP for filesystems (EXPERIMENTAL)" + depends on TRANSPARENT_HUGE_PAGECACHE && SHMEM + + help + Allow khugepaged to put read-only file-backed pages in THP. + + This is marked experimental because it is a new feature. Write + support of file THPs will be developed in the next few release + cycles. + config ARCH_HAS_PTE_SPECIAL bool diff --git a/mm/filemap.c b/mm/filemap.c index 5f072a113535..e79ceccdc6df 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -203,8 +203,8 @@ static void unaccount_page_cache_page(struct address_space *mapping, __mod_node_page_state(page_pgdat(page), NR_SHMEM, -nr); if (PageTransHuge(page)) __dec_node_page_state(page, NR_SHMEM_THPS); - } else { - VM_BUG_ON_PAGE(PageTransHuge(page), page); + } else if (PageTransHuge(page)) { + __dec_node_page_state(page, NR_FILE_THPS); } /* diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 158cad542627..090127e4e185 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -48,6 +48,7 @@ enum scan_result { SCAN_CGROUP_CHARGE_FAIL, SCAN_EXCEED_SWAP_PTE, SCAN_TRUNCATED, + SCAN_PAGE_HAS_PRIVATE, }; #define CREATE_TRACE_POINTS @@ -404,7 +405,11 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, (vm_flags & VM_NOHUGEPAGE) || test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) return false; - if (shmem_file(vma->vm_file)) { + + if (shmem_file(vma->vm_file) || + (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && + vma->vm_file && + (vm_flags & VM_DENYWRITE))) { if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGE_PAGECACHE)) return false; return IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff, @@ -456,8 +461,9 @@ int khugepaged_enter_vma_merge(struct vm_area_struct *vma, unsigned long hstart, hend; /* - * khugepaged does not yet work on non-shmem files or special - * mappings. And file-private shmem THP is not supported. + * khugepaged only supports read-only files for non-shmem files. + * khugepaged does not yet work on special mappings. And + * file-private shmem THP is not supported. */ if (!hugepage_vma_check(vma, vm_flags)) return 0; @@ -1287,12 +1293,12 @@ static void retract_page_tables(struct address_space *mapping, pgoff_t pgoff) } /** - * collapse_file - collapse small tmpfs/shmem pages into huge one. + * collapse_file - collapse filemap/tmpfs/shmem pages into huge one. * * Basic scheme is simple, details are more complex: * - allocate and lock a new huge page; * - scan page cache replacing old pages with the new one - * + swap in pages if necessary; + * + swap/gup in pages if necessary; * + fill in gaps; * + keep old pages around in case rollback is required; * - if replacing succeeds: @@ -1316,7 +1322,11 @@ static void collapse_file(struct mm_struct *mm, LIST_HEAD(pagelist); XA_STATE_ORDER(xas, &mapping->i_pages, start, HPAGE_PMD_ORDER); int nr_none = 0, result = SCAN_SUCCEED; + bool is_shmem = shmem_file(file); +#ifndef CONFIG_READ_ONLY_THP_FOR_FS + VM_BUG_ON(!is_shmem); +#endif VM_BUG_ON(start & (HPAGE_PMD_NR - 1)); /* Only allocate from the target node */ @@ -1348,7 +1358,8 @@ static void collapse_file(struct mm_struct *mm, } while (1); __SetPageLocked(new_page); - __SetPageSwapBacked(new_page); + if (is_shmem) + __SetPageSwapBacked(new_page); new_page->index = start; new_page->mapping = mapping; @@ -1363,7 +1374,7 @@ static void collapse_file(struct mm_struct *mm, struct page *page = xas_next(&xas); VM_BUG_ON(index != xas.xa_index); - if (!page) { + if (is_shmem && !page) { /* * Stop if extent has been truncated or hole-punched, * and is now completely empty. @@ -1384,7 +1395,7 @@ static void collapse_file(struct mm_struct *mm, continue; } - if (xa_is_value(page) || !PageUptodate(page)) { + if (is_shmem && (xa_is_value(page) || !PageUptodate(page))) { xas_unlock_irq(&xas); /* swap in or instantiate fallocated page */ if (shmem_getpage(mapping->host, index, &page, @@ -1392,6 +1403,23 @@ static void collapse_file(struct mm_struct *mm, result = SCAN_FAIL; goto xa_unlocked; } + } else if (!page || xa_is_value(page)) { + xas_unlock_irq(&xas); + page_cache_sync_readahead(mapping, &file->f_ra, file, + index, PAGE_SIZE); + lru_add_drain(); + page = find_lock_page(mapping, index); + if (unlikely(page == NULL)) { + result = SCAN_FAIL; + goto xa_unlocked; + } + } else if (!PageUptodate(page)) { + VM_BUG_ON(is_shmem); + result = SCAN_FAIL; + goto xa_locked; + } else if (!is_shmem && PageDirty(page)) { + result = SCAN_FAIL; + goto xa_locked; } else if (trylock_page(page)) { get_page(page); xas_unlock_irq(&xas); @@ -1426,6 +1454,12 @@ static void collapse_file(struct mm_struct *mm, goto out_unlock; } + if (page_has_private(page) && + !try_to_release_page(page, GFP_KERNEL)) { + result = SCAN_PAGE_HAS_PRIVATE; + break; + } + if (page_mapped(page)) unmap_mapping_pages(mapping, index, 1, false); @@ -1463,12 +1497,18 @@ static void collapse_file(struct mm_struct *mm, goto xa_unlocked; } - __inc_node_page_state(new_page, NR_SHMEM_THPS); + if (is_shmem) + __inc_node_page_state(new_page, NR_SHMEM_THPS); + else + __inc_node_page_state(new_page, NR_FILE_THPS); + if (nr_none) { struct zone *zone = page_zone(new_page); __mod_node_page_state(zone->zone_pgdat, NR_FILE_PAGES, nr_none); - __mod_node_page_state(zone->zone_pgdat, NR_SHMEM, nr_none); + if (is_shmem) + __mod_node_page_state(zone->zone_pgdat, + NR_SHMEM, nr_none); } xa_locked: @@ -1506,10 +1546,15 @@ static void collapse_file(struct mm_struct *mm, SetPageUptodate(new_page); page_ref_add(new_page, HPAGE_PMD_NR - 1); - set_page_dirty(new_page); mem_cgroup_commit_charge(new_page, memcg, false, true); + + if (is_shmem) { + set_page_dirty(new_page); + lru_cache_add_anon(new_page); + } else { + lru_cache_add_file(new_page); + } count_memcg_events(memcg, THP_COLLAPSE_ALLOC, 1); - lru_cache_add_anon(new_page); /* * Remove pte page tables, so we can re-fault the page as huge. @@ -1524,7 +1569,9 @@ static void collapse_file(struct mm_struct *mm, /* Something went wrong: roll back page cache changes */ xas_lock_irq(&xas); mapping->nrpages -= nr_none; - shmem_uncharge(mapping->host, nr_none); + + if (is_shmem) + shmem_uncharge(mapping->host, nr_none); xas_set(&xas, start); xas_for_each(&xas, page, end - 1) { @@ -1607,6 +1654,17 @@ static void khugepaged_scan_file(struct mm_struct *mm, break; } + if (page_has_private(page) && trylock_page(page)) { + int ret; + + ret = try_to_release_page(page, GFP_KERNEL); + unlock_page(page); + if (!ret) { + result = SCAN_PAGE_HAS_PRIVATE; + break; + } + } + if (page_count(page) != 1 + page_mapcount(page)) { result = SCAN_PAGE_COUNT; break; @@ -1713,11 +1771,13 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, VM_BUG_ON(khugepaged_scan.address < hstart || khugepaged_scan.address + HPAGE_PMD_SIZE > hend); - if (shmem_file(vma->vm_file)) { + if (vma->vm_file) { struct file *file; pgoff_t pgoff = linear_page_index(vma, khugepaged_scan.address); - if (!shmem_huge_enabled(vma)) + + if (shmem_file(vma->vm_file) + && !shmem_huge_enabled(vma)) goto skip; file = get_file(vma->vm_file); up_read(&mm->mmap_sem); diff --git a/mm/rmap.c b/mm/rmap.c index e5dfe2ae6b0d..87cfa2c19eda 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1192,8 +1192,10 @@ void page_add_file_rmap(struct page *page, bool compound) } if (!atomic_inc_and_test(compound_mapcount_ptr(page))) goto out; - VM_BUG_ON_PAGE(!PageSwapBacked(page), page); - __inc_node_page_state(page, NR_SHMEM_PMDMAPPED); + if (PageSwapBacked(page)) + __inc_node_page_state(page, NR_SHMEM_PMDMAPPED); + else + __inc_node_page_state(page, NR_FILE_PMDMAPPED); } else { if (PageTransCompound(page) && page_mapping(page)) { VM_WARN_ON_ONCE(!PageLocked(page)); @@ -1232,8 +1234,10 @@ static void page_remove_file_rmap(struct page *page, bool compound) } if (!atomic_add_negative(-1, compound_mapcount_ptr(page))) goto out; - VM_BUG_ON_PAGE(!PageSwapBacked(page), page); - __dec_node_page_state(page, NR_SHMEM_PMDMAPPED); + if (PageSwapBacked(page)) + __dec_node_page_state(page, NR_SHMEM_PMDMAPPED); + else + __dec_node_page_state(page, NR_FILE_PMDMAPPED); } else { if (!atomic_add_negative(-1, &page->_mapcount)) goto out; From patchwork Sun Jun 23 05:47:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11011565 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D15601398 for ; Sun, 23 Jun 2019 05:48:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF37F28B2A for ; Sun, 23 Jun 2019 05:48:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B210F28B2C; Sun, 23 Jun 2019 05:48:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D316D28B2A for ; Sun, 23 Jun 2019 05:48:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 137BB8E0003; Sun, 23 Jun 2019 01:48:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 09B476B0008; Sun, 23 Jun 2019 01:48:10 -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 E07FA8E0003; Sun, 23 Jun 2019 01:48:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id A3AA86B0007 for ; Sun, 23 Jun 2019 01:48:09 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id i11so4062746pgt.7 for ; Sat, 22 Jun 2019 22:48:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:smtp-origin-hostprefix:from :smtp-origin-hostname:to:cc:smtp-origin-cluster:subject:date :message-id:in-reply-to:references:mime-version; bh=OCLrqfSXcpxK+1VOccrQtP7qai4h6E5adUP8VenR0FM=; b=a+73xbgpCnHnRBLulafMLd9/TaSGfhu8PUAH1vGwBd5qSEYin6rppLB05lRKblz/sX D+IR+rpdkZdi9EBZzye1V/tdVXhXRYBbBAyD9CC/OkaVu3G29RTcU7GAmALSUGt20/U+ 1hN7G/Bn6n7xgV9BMhCqbKNCLX2KoGipyrVfXp1nNHOlWJDddJc1eEdE8b6thNE3ov0b fbD8nkd6EqS+mefnH9IwREkPZa9meqhH9eGYMMR5evMqTHp/F3RmJrckGfimBwzQ+f8b z0hKWi8XALsr53wO6an+1OsN9YZJSW6npJF/AglGbqF0yogkct9+8A3ubEp4wLRRCWoX vrUg== X-Gm-Message-State: APjAAAXVMihXKIkAylYMkcSogjpc0jp4WFUvngB8FvVfUTkqWNbFOeFk QQo25JvPrC6KKTFcUWGd0WUKw80oZZWo7Hm1g7eKykTZl2afU8cE3EshVrhvKiwsYpVIE31KFMf wb8p4H//RI4ulFnBE6pxOxjmnRJhp3ZyYlEu7cuwNTOh4Nwu3SsTyHy61N2iRYkWKpw== X-Received: by 2002:a17:902:403:: with SMTP id 3mr138404894ple.66.1561268889341; Sat, 22 Jun 2019 22:48:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUd8WeQE7gFCLJZm8C0QsWl0ZU3xzx2aehJKIJDTaxWU9aIQ4ayFoDg+/eOGTuyNe5qdQY X-Received: by 2002:a17:902:403:: with SMTP id 3mr138404858ple.66.1561268888535; Sat, 22 Jun 2019 22:48:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561268888; cv=none; d=google.com; s=arc-20160816; b=0VjR+KNlWy4YvVtBSZ4CJFiVm9TojSRYSMF6qXtS/NnEyyirRSKK+XHBswzE0PzkZT gGV33z4B2fSAJqAJpr0BWeWgkqXYLYjVB/OWPBkaL8pssQIpiFNJHgKaN2bPdNZZwglH oGophTdT7xTHBxj2qbGpHYhjWHgyGzvp0ReOAuCUFicWCmtEtOhwBCrmrtsRsjqkuRuM TPjUzynWBNZsTsL7SNveYyCRtYb++0NIpzgGiID1RY11iZTDyHXawKg0lWqSLFLKDxq7 L/TK+nKIM3veHg4WGJZBSTYMuJ1+8UxE6YnMg8X4UxuUwiQ2X/Dv7HjLR2WKNAgXfZpo 0R5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=OCLrqfSXcpxK+1VOccrQtP7qai4h6E5adUP8VenR0FM=; b=VARe9JXJ4lnM0aFUuMESQZz/cDCgaH7tcI8NM5gsY2cZCpNVGCD1M+UB6fnO8/vNFa m53rM8T56LKT+OLP2ChwX5HxkaJvf9yZ87YDGGlVTcKLpyUT/CButfy4DVr/SY8MOyMu xZWfaAW3v5N1RDUtYnQ2oCAzhDEokFWCPHn/0NSLqkCosEOWPwstPoFexPZIkRbeKjUO D6K6hQeq08HqSOu/kN4WlLH1Q+bi9itSF+wla7SXY0cH/gXYnszKkq3psyPgc3krgO6i 16Q2eJ1Zj6RUltp+dNFs5PFSdUevaIkdKTSqiQWH5Cb0TeJH2lNQ5bUgdVuWLGZeIOtY /ZpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=XACg37lK; spf=pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1077171f80=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com. [67.231.145.42]) by mx.google.com with ESMTPS id d67si6897946pgc.62.2019.06.22.22.48.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Jun 2019 22:48:08 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) client-ip=67.231.145.42; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=XACg37lK; spf=pass (google.com: domain of prvs=1077171f80=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1077171f80=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0044008.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5N5iEvB015402 for ; Sat, 22 Jun 2019 22:48:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=OCLrqfSXcpxK+1VOccrQtP7qai4h6E5adUP8VenR0FM=; b=XACg37lKEV90/F5mriDHnYNQrSoMA73T2pJ1EfyNCjj0mnKpdojTvsQUJLFebiS8eshZ RughF7uKEfJhTDjYho2hW+eZsIX3xaKPxsqfd9J8PD2o5HOezvj3GNp5qN+u5p8BACKl 2vlKjgnvmueW56iXHP5M5NCxaQRQX1oRPFA= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2t9fmjjfmm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sat, 22 Jun 2019 22:48:07 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Sat, 22 Jun 2019 22:48:06 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 2EA2C62E2CFB; Sat, 22 Jun 2019 22:48:06 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v7 6/6] mm,thp: avoid writes to file with THP in pagecache Date: Sat, 22 Jun 2019 22:47:49 -0700 Message-ID: <20190623054749.4016638-7-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190623054749.4016638-1-songliubraving@fb.com> References: <20190623054749.4016638-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-23_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=765 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906230050 X-FB-Internal: deliver 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: X-Virus-Scanned: ClamAV using ClamSMTP In previous patch, an application could put part of its text section in THP via madvise(). These THPs will be protected from writes when the application is still running (TXTBSY). However, after the application exits, the file is available for writes. This patch avoids writes to file THP by dropping page cache for the file when the file is open for write. A new counter nr_thps is added to struct address_space. In do_last(), if the file is open for write and nr_thps is non-zero, we drop page cache for the whole file. Reported-by: kbuild test robot Signed-off-by: Song Liu --- fs/inode.c | 3 +++ fs/namei.c | 22 +++++++++++++++++++++- include/linux/fs.h | 32 ++++++++++++++++++++++++++++++++ mm/filemap.c | 1 + mm/khugepaged.c | 4 +++- 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index df6542ec3b88..518113a4e219 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -181,6 +181,9 @@ int inode_init_always(struct super_block *sb, struct inode *inode) mapping->flags = 0; mapping->wb_err = 0; atomic_set(&mapping->i_mmap_writable, 0); +#ifdef CONFIG_READ_ONLY_THP_FOR_FS + atomic_set(&mapping->nr_thps, 0); +#endif mapping_set_gfp_mask(mapping, GFP_HIGHUSER_MOVABLE); mapping->private_data = NULL; mapping->writeback_index = 0; diff --git a/fs/namei.c b/fs/namei.c index 20831c2fbb34..de64f24b58e9 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3249,6 +3249,22 @@ static int lookup_open(struct nameidata *nd, struct path *path, return error; } +/* + * The file is open for write, so it is not mmapped with VM_DENYWRITE. If + * it still has THP in page cache, drop the whole file from pagecache + * before processing writes. This helps us avoid handling write back of + * THP for now. + */ +static inline void release_file_thp(struct file *file) +{ +#ifdef CONFIG_READ_ONLY_THP_FOR_FS + struct inode *inode = file_inode(file); + + if (inode_is_open_for_write(inode) && filemap_nr_thps(inode->i_mapping)) + truncate_pagecache(inode, 0); +#endif +} + /* * Handle the last step of open() */ @@ -3418,7 +3434,11 @@ static int do_last(struct nameidata *nd, goto out; opened: error = ima_file_check(file, op->acc_mode); - if (!error && will_truncate) + if (error) + goto out; + + release_file_thp(file); + if (will_truncate) error = handle_truncate(file); out: if (unlikely(error > 0)) { diff --git a/include/linux/fs.h b/include/linux/fs.h index f7fdfe93e25d..082fc581c7fc 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -427,6 +427,7 @@ int pagecache_write_end(struct file *, struct address_space *mapping, * @i_pages: Cached pages. * @gfp_mask: Memory allocation flags to use for allocating pages. * @i_mmap_writable: Number of VM_SHARED mappings. + * @nr_thps: Number of THPs in the pagecache (non-shmem only). * @i_mmap: Tree of private and shared mappings. * @i_mmap_rwsem: Protects @i_mmap and @i_mmap_writable. * @nrpages: Number of page entries, protected by the i_pages lock. @@ -444,6 +445,10 @@ struct address_space { struct xarray i_pages; gfp_t gfp_mask; atomic_t i_mmap_writable; +#ifdef CONFIG_READ_ONLY_THP_FOR_FS + /* number of thp, only for non-shmem files */ + atomic_t nr_thps; +#endif struct rb_root_cached i_mmap; struct rw_semaphore i_mmap_rwsem; unsigned long nrpages; @@ -2790,6 +2795,33 @@ static inline errseq_t filemap_sample_wb_err(struct address_space *mapping) return errseq_sample(&mapping->wb_err); } +static inline int filemap_nr_thps(struct address_space *mapping) +{ +#ifdef CONFIG_READ_ONLY_THP_FOR_FS + return atomic_read(&mapping->nr_thps); +#else + return 0; +#endif +} + +static inline void filemap_nr_thps_inc(struct address_space *mapping) +{ +#ifdef CONFIG_READ_ONLY_THP_FOR_FS + atomic_inc(&mapping->nr_thps); +#else + WARN_ON_ONCE(1); +#endif +} + +static inline void filemap_nr_thps_dec(struct address_space *mapping) +{ +#ifdef CONFIG_READ_ONLY_THP_FOR_FS + atomic_dec(&mapping->nr_thps); +#else + WARN_ON_ONCE(1); +#endif +} + extern int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync); extern int vfs_fsync(struct file *file, int datasync); diff --git a/mm/filemap.c b/mm/filemap.c index e79ceccdc6df..a8e86c136381 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -205,6 +205,7 @@ static void unaccount_page_cache_page(struct address_space *mapping, __dec_node_page_state(page, NR_SHMEM_THPS); } else if (PageTransHuge(page)) { __dec_node_page_state(page, NR_FILE_THPS); + filemap_nr_thps_dec(mapping); } /* diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 090127e4e185..a4f90a1b06f5 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1499,8 +1499,10 @@ static void collapse_file(struct mm_struct *mm, if (is_shmem) __inc_node_page_state(new_page, NR_SHMEM_THPS); - else + else { __inc_node_page_state(new_page, NR_FILE_THPS); + filemap_nr_thps_inc(mapping); + } if (nr_none) { struct zone *zone = page_zone(new_page);