From patchwork Thu Jun 20 17:27: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: 11007523 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 00E6076 for ; Thu, 20 Jun 2019 17:28:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E50491FFBD for ; Thu, 20 Jun 2019 17:28:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4D3728710; Thu, 20 Jun 2019 17:28: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 6C64E1FFBD for ; Thu, 20 Jun 2019 17:28:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0AD476B0007; Thu, 20 Jun 2019 13:28:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 011168E0002; Thu, 20 Jun 2019 13:28:12 -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 DCE348E0001; Thu, 20 Jun 2019 13:28:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f69.google.com (mail-yw1-f69.google.com [209.85.161.69]) by kanga.kvack.org (Postfix) with ESMTP id B19056B0007 for ; Thu, 20 Jun 2019 13:28:12 -0400 (EDT) Received: by mail-yw1-f69.google.com with SMTP id o135so3621456ywo.16 for ; Thu, 20 Jun 2019 10:28:12 -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=p96op37WrfEV+OVQe7FHjSG2knRLYf3E94bNHd0vAIoINphJ6zvF3I3UkxrvOfZbLh 1kQvMbMvH4nCop/1ZtvYZxhOwTVk/OCuCZNV1Tr7ScpU/O5ZoqdJXDYs5w2jJ7ahoMUP hgBFO7E43WoFR2T3sH+WnghpES4eV9t3c77ot5gwj9rEXtVCZr+i4naVEiAEUWtPluNn LCwcPI6sChxasVnVUy9NxHYR6lvNrU9eIgaPl8H7p2iEz3ZEH7hSIF5IaeDoZd4xhBXi lNIVjCupSzStj+geXgtnzc10jHx7C2XUntipY0DvqQisAeIHNrNlWSl9fAdW84nnanRn wQBg== X-Gm-Message-State: APjAAAXrYxrzE3hdJBaN3dNhUjC6Z2BT+zhC0cny/yeDfLFpRAPyBMFh xedaC/hoo2Mi52Uo4hfgh1DQhWeGcmxmEpmT9ylThpU2wkb2/5MKGVL6J+SY+hpS8MKaCCed0Xt lX/1hH+RnClpMSuHGmT+F5UUaaN1s9CawbW7H41sltckZx5dlzr6OeAnbPw8UPiy/Hg== X-Received: by 2002:a25:38ce:: with SMTP id f197mr58318073yba.300.1561051692485; Thu, 20 Jun 2019 10:28:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHR9oWXdXWak8i+hJXGbL/s3l4F5FqbdOaH2XdmBltvVKT2usj3jXUhhSRr6FSsbPFomew X-Received: by 2002:a25:38ce:: with SMTP id f197mr58318060yba.300.1561051692003; Thu, 20 Jun 2019 10:28:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561051691; cv=none; d=google.com; s=arc-20160816; b=bmKz722Qte3Iv/tFs1OTkidCz4ESA/VCh9KDGvLPndULgBATNBMKJ3h3Fc2EmarSxd Go0CNCdZQJUJP9t80iUCP+NtNCpVbMZuefZ0eOdcfymPIuozE3aVrUwjPr0JlWAKEmEK f9GTtfH8Tiejgn39eU44MFwflxWNNV/QL86sFAfgskmmVVhpLYX+KVcdTFYg7WZ8loGq iisgh5cfFolOHig9PZkMf7En2W6xSadG5FeyE+47BcKQPLle+VQd5l1Qvb6wbnsmNGDn 4ab5bTWeF0wN9iMZ3G98wbKi/HTlFuGkfr18c5tjnE9fh0ENXWPtE335O4t/rwhEHXvK Ma8Q== 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=uunFY1wNU9KdsoDoH+9rjgO9u4UhXPlg/aP7Lpo1gZiGA7yG+CcpNmk05TL5PIz7AZ YUG+Gq4qUugpKdrw97sdT+pduWTN4nWfYlgPFl3A1Q9ry07tFHGd3fmYVi56PGYII7+g 3XbOVynDwFQzNZJeaRAxa7pDvOFYDNKJ15r1vTm3b+pxYr6qq+hTyS27AVD2SLv8CLBb 7AwOxwG7bNkTx9XTiL9ABumQYuPA8GVnAd6rn9uQCKTYwNa4bVtT9OiCeJup7kNFTyLA qqPizMPh+Uswt3k7aciAmAzkKN8zba4TWzUEOQvAlYWd58DXavhXZK9NVEa5Sv2uo1Hf yhOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=WtVAiSL4; spf=pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=107476d203=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com. [67.231.153.30]) by mx.google.com with ESMTPS id j64si34544ybb.150.2019.06.20.10.28.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 10:28:11 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.153.30 as permitted sender) client-ip=67.231.153.30; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=WtVAiSL4; spf=pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=107476d203=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0001255.ppops.net [127.0.0.1]) by mx0b-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5KHJiEV021867 for ; Thu, 20 Jun 2019 10:28:11 -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=WtVAiSL4pkv5AjfkhFLdw/fL37uvBfV7B+EkD4ddcNFBFJ7XMDUe/dOAdTFyx0zJCoBV sKDERts9lAuagNccRtxrTSKyqSJXY8n/b1GmBIQgMBoExqn59o5Z9k2aWCS+MdBBNy3T CRqvw4Gu6Ov1NuidnapPV9xDlfmID5F+Z1A= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by mx0b-00082601.pphosted.com with ESMTP id 2t8aj98ykt-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 20 Jun 2019 10:28:11 -0700 Received: from mx-out.facebook.com (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5; Thu, 20 Jun 2019 10:28:09 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 7FD8F62E2004; Thu, 20 Jun 2019 10:28:05 -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 v4 1/6] filemap: check compound_head(page)->mapping in filemap_fault() Date: Thu, 20 Jun 2019 10:27:47 -0700 Message-ID: <20190620172752.3300742-2-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190620172752.3300742-1-songliubraving@fb.com> References: <20190620172752.3300742-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-20_12:,, 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=926 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906200124 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 Thu Jun 20 17:27: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: 11007521 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 DCB3376 for ; Thu, 20 Jun 2019 17:28:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF0EC1FFBD for ; Thu, 20 Jun 2019 17:28:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2E8428710; Thu, 20 Jun 2019 17:28:13 +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 2D1261FFBD for ; Thu, 20 Jun 2019 17:28:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 259C76B0006; Thu, 20 Jun 2019 13:28:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1E45C8E0002; Thu, 20 Jun 2019 13:28:12 -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 0D3BC8E0001; Thu, 20 Jun 2019 13:28:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id CCA936B0006 for ; Thu, 20 Jun 2019 13:28:11 -0400 (EDT) Received: by mail-pf1-f199.google.com with SMTP id q14so769704pff.8 for ; Thu, 20 Jun 2019 10:28:11 -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=t4WP0ysVCAWfCLs/z5oz2yIS2tXOX7fKqzTXHhkUjsDhraUvbrXd/4iOMH90y4RK4c 7kE9l9Vryz+A8JclnN8Ud8R/4CTw1LAYpJFbFh1WvF7VqKM3vAstccDwSmstFSSFBHCH RkmWE+ngl44L3fvpAp3kJT5or4XLIKtq/BRqGdSJoDOg+rifv6tOwyTV3Rq0PGM1J8iV VsZ40u46KhddodwFT177YeW+VVK3Xe9evnT8Ui9EtrC0+nvXuAfqsEI3hY5dIREXD9dh C7IW/3J1MbC0IbLA/0e9RtlgOaHXJqd7PxfilSUjNygaaNI6gAImaNztmHZI+ROvHUGQ jgmg== X-Gm-Message-State: APjAAAXzR8xRCEj7Cb3Pwuj5EwCWKlLujHdjrzsy9PdylBDLPlc8iVWp ywOtXv4PIz3bFfC+ghWKt4QMmC49Cf34/U//Eyv+Z1KGbKJcqNltQ4CmFLHuQdue7h4rP5YZYKD Q9UYyvSKUxMYIJdgkL0FKEaKBEstZQSQFr8SOQJ8HCjEJG63x01+N5agUqsO9qIFwPg== X-Received: by 2002:a17:90a:32ec:: with SMTP id l99mr819202pjb.44.1561051691499; Thu, 20 Jun 2019 10:28:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3EPC7s1OSoZnDYjae4Gnt4U4lplBFM07DZCVMDcNJydCrLxtqICVJBW3Knnocfqqpjafb X-Received: by 2002:a17:90a:32ec:: with SMTP id l99mr819152pjb.44.1561051690940; Thu, 20 Jun 2019 10:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561051690; cv=none; d=google.com; s=arc-20160816; b=xw3XfoaRq8OO0rZHqhceJ5cDNwgLDHyE6TFFY5PyA5vq34fh3ui3ZKS6XV+1yL04nv 1+/RBPgk7C29olJP6/mIPZ6EmiJP4GEGsMMF0hvZQyYWlqRcpKd+P/JqQ/jc0wwIsodQ 5lfKKw+82uB4JB2wtECsyY6buBkdvetoDADOL5vkC3PZBdSzHS+SukuhvNxv7opTrbHw W4xrPGsvs9aIAKIvZ/7GHPWOBN59nJGlXWlzz0ilkSODlw1v0447/vHWYx+VDvwVo9GI 5ZMz7flUCpeG19gtg87PSIhUg8MozPXt2QCJy7YSgPEzZV4ePfwKx7hkEfbdhaOrzY2D tWag== 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=A1fU+O+3pmlsjI/G7D/0whG9z6EAwg5iuo7YRcKWdj3wug63BREYlJOFhH58Q3e8/t 637oaiPj5RQsrMva6qr5H5/P5OQM8mNOSxo0abF9ZXcAD+PYVyLgj5WXwe9N26HXVkzR eJvnZexccT7YN6zG0Ci/PrcTcf9Z97ISZKtSb+bgkAGVlFqhjsrS2jd9hDYOPVVEe0/i aaVpzy5pzFnsNt4lO4TtgD8+t+N9mslpFT5ryotcQL+pMSq7sAfs614ptFIzKEbZQs/4 4zbRXLffh7PEVOq/Oc91h2bP6+uwDmiAVsu4APx9H4SCGsF66021fsngJlFw1R85n+l5 sIUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b="mNhc/hpX"; spf=pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=107476d203=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 d31si260043pla.393.2019.06.20.10.28.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 10:28:10 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=107476d203=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="mNhc/hpX"; spf=pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=107476d203=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 x5KHJx5W008103 for ; Thu, 20 Jun 2019 10:28:10 -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=mNhc/hpX80vHQg9u1eg66tZ1YAkihKLtnrLdS9akUfCSDf3mAo2t9I8+6iKvzcaYbn4d vtenrW+VwtMHK0eiP7mAQ+1pGOHXf8rUFN61PepQBZWXnc84HnHgHUoU/qsmHv3SOBVw yd19T7EPogSnkyo5Zc852usFjK6wP00kdp4= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2t85v8hthb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 20 Jun 2019 10:28:10 -0700 Received: from mx-out.facebook.com (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5; Thu, 20 Jun 2019 10:28:09 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id AC6B762E2004; Thu, 20 Jun 2019 10:28:08 -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 v4 2/6] filemap: update offset check in filemap_fault() Date: Thu, 20 Jun 2019 10:27:48 -0700 Message-ID: <20190620172752.3300742-3-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190620172752.3300742-1-songliubraving@fb.com> References: <20190620172752.3300742-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-20_12:,, 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=804 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906200124 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 Thu Jun 20 17:27: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: 11007527 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 39A7314E5 for ; Thu, 20 Jun 2019 17:28:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AF9E1FFBD for ; Thu, 20 Jun 2019 17:28:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F8E828710; Thu, 20 Jun 2019 17:28:23 +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 A21FC1FFBD for ; Thu, 20 Jun 2019 17:28:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3BAAB6B000A; Thu, 20 Jun 2019 13:28:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 36D928E0002; Thu, 20 Jun 2019 13:28:19 -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 198498E0001; Thu, 20 Jun 2019 13:28:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f71.google.com (mail-yw1-f71.google.com [209.85.161.71]) by kanga.kvack.org (Postfix) with ESMTP id ECF136B000A for ; Thu, 20 Jun 2019 13:28:18 -0400 (EDT) Received: by mail-yw1-f71.google.com with SMTP id f11so3687672ywc.4 for ; Thu, 20 Jun 2019 10:28:18 -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=iFz1RdjWCbrw1b7w4eZ5iGWyb2zDfKg3QSt6me6ZtqE=; b=SkHITzS2mKkMJkoUi4xNLmQIhW9SCtar4JsUiZp5wkSykA9eOL08TioA1bB1QRvXB2 nBWGV7iz/2tewrFJ5BBgG9lHTrTi2yz9rNJ0J48spwxbIEKG5T4xnMsse7YUrrVZt4Rw ovIeVCsMIovfLvFtTgXkycRgYK7r+Zddu2piet82cWmU9SBigIW9UMTFw14gvTa5G5lg IVQ6otdmRPzuG6XXwiGJRgIdUhLPBpX7NivG00BJ8i2uAW43+175yBsvpbnU8PayLFcj OJuRytLe+Bvxl11gk7Yq7QZ+bxC/joEht7z7aB6yhYiyDRixYi+S8mFWcFaWj0rjJ3bu ohGw== X-Gm-Message-State: APjAAAWwvmoAsGUNgul3thOvzKJe7g/dfpmKwQIWuWulMZsLEYDNWXAC jr4n2l9XdejaLQU1xhikJpweRCp53mJmUGmMbkFokEsB6AMG39//m0Rgn6i3xkVpatCcAVPfxYM KKDUcDVM5od5FAHcKiKcfx5dGR+9Xas3IrCbgGZJ0J87zZx94CZVFwBV/owwV/qy9NA== X-Received: by 2002:a25:bd91:: with SMTP id f17mr66195604ybh.509.1561051698738; Thu, 20 Jun 2019 10:28:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQWO4oCzGfR6l7kHahpZFdkbc58lW4qeQNtA0B+blZCiDE65yRxQqUtvGRLHaZsVQaeXjg X-Received: by 2002:a25:bd91:: with SMTP id f17mr66195573ybh.509.1561051697991; Thu, 20 Jun 2019 10:28:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561051697; cv=none; d=google.com; s=arc-20160816; b=nh8qcKqnBcS81QOJIXUeJSzjpQ6KxOPvDe37cYE0kWVLaJ6t/KcM59yZZVhisE+688 kYyAPLKjCnEXoBZoG/oZtOIRsAKWUO8Q8nJwcCPkWNv6Eo6xGhDCNS86fX277Z7RRXXt /7cC5C2Tta1o+BVdjqToW8qFP9v1HZxIyRLtv76zx9//waRWyiPVKdBdLlpy4K3uDy0F PU4tlgR0OBNU9KzTVQEXR331apYCb0+Ztiw3NxfCp/hRhtwqedv3XgHwF4P7LFSidzAn pjYUBqNhSkQBYluZrNEwHBKUJCRYYVS7RAnxN/O2I4km/TmBQYgngFysFojEd72k0qWo Mkqw== 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=iFz1RdjWCbrw1b7w4eZ5iGWyb2zDfKg3QSt6me6ZtqE=; b=ef7OXXYKi+pE6yul03GyIWlTQ3L7JCmk+UGnA0g6Ce5WyrzOezyRzRMouzJsANWpNn 8AyH7EGFumLomaNsu6NJgbNS9BAFlGTp+lu3cbSLYyrjvmEA4PFICtJgu7+KKOIy4Ix0 LeqRy1kGFleFUqedJIYRqznFITpm0Uh/f3LFwvrsNlYC4z9srsgduwaEk+EDWyqTQksx +vNsWEMaOWM/6SRAxwRrDuvp/IJ+awHxxBHdrw2U/MLzdR5L9ujEak/h9qXKMwMx243E MGBKN8mociVN7Fne3rMJDtVpbGi57vIFJYPx9LKShcLu3leYPJJtYQUpHIAHCryq9RRK 3dKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=G9H7o7hR; spf=pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=107476d203=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com. [67.231.153.30]) by mx.google.com with ESMTPS id 187si28265ybt.401.2019.06.20.10.28.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 10:28:17 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.153.30 as permitted sender) client-ip=67.231.153.30; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=G9H7o7hR; spf=pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=107476d203=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5KHJt5N023614 for ; Thu, 20 Jun 2019 10:28:17 -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=iFz1RdjWCbrw1b7w4eZ5iGWyb2zDfKg3QSt6me6ZtqE=; b=G9H7o7hRRDhToLUjiPC/9weezLUab7QuK3QTMtXgsg9vrzVqnCDbKhxv2O/DIU02paLi 2TpfVbB7HWcJjKVQRtAAIEFpcx6M3hkd5lRUkTTpirzoYnRbK+cjeHAj4lKQorJoq7dT igpKuTPymnTsZ1nU4z0RxZDtoZ72UeUc1Pw= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2t8aj310br-8 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 20 Jun 2019 10:28:17 -0700 Received: from mx-out.facebook.com (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::129) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5; Thu, 20 Jun 2019 10:28:13 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id E4F3762E2004; Thu, 20 Jun 2019 10:28:11 -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 v4 3/6] mm,thp: stats for file backed THP Date: Thu, 20 Jun 2019 10:27:49 -0700 Message-ID: <20190620172752.3300742-4-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190620172752.3300742-1-songliubraving@fb.com> References: <20190620172752.3300742-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-20_12:,, 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-1906200124 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 two stats and exposes them in /proc/meminfo Acked-by: Rik van Riel Signed-off-by: Song Liu --- fs/proc/meminfo.c | 4 ++++ include/linux/mmzone.h | 2 ++ mm/vmstat.c | 2 ++ 3 files changed, 8 insertions(+) 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/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 Thu Jun 20 17:27:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11007525 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 1EF4D14E5 for ; Thu, 20 Jun 2019 17:28:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10A6A1FFBD for ; Thu, 20 Jun 2019 17:28:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04B8528710; Thu, 20 Jun 2019 17:28:20 +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 83D061FFBD for ; Thu, 20 Jun 2019 17:28:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62C296B0008; Thu, 20 Jun 2019 13:28:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5DC6D8E0002; Thu, 20 Jun 2019 13:28:18 -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 47C4D8E0001; Thu, 20 Jun 2019 13:28:18 -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 0FAD16B0008 for ; Thu, 20 Jun 2019 13:28:18 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id z10so2200277pgf.15 for ; Thu, 20 Jun 2019 10:28:18 -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=n2snFM7QmmPTPpShlBhEnsGKC2i2/uKCmCMTseCu52k=; b=paT8FBn0keMvk0GJ/BbH3sc/wGkGtSkmG+SobticI9SR38o1is4tVT4ZavK2Q6tUlV sR22XH8VIF8PUayDtiyhF78WsxaxUfkSipu3LkQV66qXrzFmDPGo/MNc3bQQ9G5LK+oX MqC/1id2hNi7s7OTyAlj2GsgfTHm0FHpz0LH2vCT2uAhY1Qc8d7ia+ArJ7+W0y2ZvsaS 4sbQYYCJZAyNvtIjT5dQjx/RvzpOMXuGxjQVAYhS3WTo1NtdvY8ROWFWqobTftjuDIux Wvmt0TxBWwLH0aVOCizzb7cpunlXH2uEC3RrMeHmANkvbJ7iN6Fmu6ZeWdMwo84dg3If D73A== X-Gm-Message-State: APjAAAXyiugtR8DJNyKEqppQbPmwco76xJrgDazYDANOlrtnvaAHlj5L XZeOIrXS6ygjt47Kap9If1n18uOhbW0QFCkg0nfBEuu7jjVbL91t+zRZrCLbjhzqNrOwUL+u004 1eRDX329YNFxwv9IF82fCNIODkY6FT8GedMsqyFJwKNHxe9LwBWGcdQ8iAQIuiXJUkA== X-Received: by 2002:a17:902:b7c1:: with SMTP id v1mr33194838plz.85.1561051697688; Thu, 20 Jun 2019 10:28:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqzNKQ79Pn0KuQ/tNWSxl9dnHKRFNQxgVQSb1sKGKA1gOk58QTn97BipQWiqtJfuWPmWAVs0 X-Received: by 2002:a17:902:b7c1:: with SMTP id v1mr33194791plz.85.1561051697043; Thu, 20 Jun 2019 10:28:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561051697; cv=none; d=google.com; s=arc-20160816; b=ZAhTb9+JFN9sHNY8K8wkFIrn8rSVSxtM2y/0cAHVioWrNl3moOel8WIxapLM/tynmZ N+jq1INxQU5N57i0IiFG1G1+WCQPGtybkN+jwyDs39MOkFVc5f85YmwLWxmfz/xRq63k 22VrMYI7FaHosDEo6AaeIIbP3r9WiXkAa9G1et8rUtkx0ue/N/oLjMvsG8+wmpWWGYF4 VcKJqE79V+v+6JaPBMmGYy5hCHKFxjOluBAHht0XlLS5nSZH1v81ct+tJDfArmQZcISf kRyeX9BOFMLjnsxQZYKIunBRFaCga6od40Ep7nsy/J4DWPgMpA/7J3uLAVZ3xmPaYZcQ IWSA== 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=n2snFM7QmmPTPpShlBhEnsGKC2i2/uKCmCMTseCu52k=; b=EEBzvARewC8aisJDg3LanykFR9LnEaDItPQGvQcLdU5PiIIst9dMDVxNuFKXP46728 r0MdF5MWJ5O+UiZ6w8DzHJNk1F73CGYStQYYQfrXdUi0qArZnD2cW1ObWEk4VNp7IYlE Hr4FouAKuz4PoO42D7KVBlyHHzObJ1wntMXuL+Ld722l+dffn6Mr42yH9MEcQgpqeop+ 38h0IaBiwLrrDKIK+7K9pt6qw4L9CuRc750TyJDYAlSwngkbBovoDn8u3dCy/mmQK4Pu MELL5wUX/caPrZdP7hH4kD0z0E6VQtX2/QM0X7vMUM/4gec+bgQN9HD+99rj91JWjFrd 0qCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=c3uhS5dv; spf=pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=107476d203=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 x3si276276plv.26.2019.06.20.10.28.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 10:28:17 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=107476d203=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=c3uhS5dv; spf=pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=107476d203=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5KHKK21021503 for ; Thu, 20 Jun 2019 10:28:16 -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=n2snFM7QmmPTPpShlBhEnsGKC2i2/uKCmCMTseCu52k=; b=c3uhS5dv+i1TaGkWXy4jxAx8EgvqHJeArMxxJXK1A2gC9DEhwbjC9rTkoHSHJStPZ/7x GGwY3MNdkh462FJ7vQzguq+h3Hj8ZMXvPbOhJFCDjZTranrnwk0tf3TPHksf8l8WkZoc 2Eodc4phEC+6YIQ3P8hIadXuYucvgWgiGNM= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2t7wrj36sg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 20 Jun 2019 10:28:16 -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; Thu, 20 Jun 2019 10:28:15 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id C1F4B62E2004; Thu, 20 Jun 2019 10:28:14 -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 v4 4/6] khugepaged: rename collapse_shmem() and khugepaged_scan_shmem() Date: Thu, 20 Jun 2019 10:27:50 -0700 Message-ID: <20190620172752.3300742-5-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190620172752.3300742-1-songliubraving@fb.com> References: <20190620172752.3300742-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-20_12:,, 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=567 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906200124 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() Acked-by: Rik van Riel Signed-off-by: Song Liu --- mm/khugepaged.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 0f7419938008..dde8e45552b3 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, +static void collapse_file(struct vm_area_struct *vma, struct address_space *mapping, pgoff_t start, struct page **hpage, int node) { + struct mm_struct *mm = vma->vm_mm; gfp_t gfp; struct page *new_page; struct mem_cgroup *memcg; @@ -1563,7 +1564,7 @@ static void collapse_shmem(struct mm_struct *mm, /* TODO: tracepoints */ } -static void khugepaged_scan_shmem(struct mm_struct *mm, +static void khugepaged_scan_file(struct vm_area_struct *vma, struct address_space *mapping, pgoff_t start, struct page **hpage) { @@ -1631,14 +1632,14 @@ 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(vma, mapping, start, hpage, node); } } /* TODO: tracepoints */ } #else -static void khugepaged_scan_shmem(struct mm_struct *mm, +static void khugepaged_scan_file(struct vm_area_struct *vma, struct address_space *mapping, pgoff_t start, struct page **hpage) { @@ -1722,7 +1723,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, + khugepaged_scan_file(vma, file->f_mapping, pgoff, hpage); fput(file); } else { From patchwork Thu Jun 20 17:27:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11007533 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 8143E76 for ; Thu, 20 Jun 2019 17:28:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 743561FFBD for ; Thu, 20 Jun 2019 17:28:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6849128710; Thu, 20 Jun 2019 17:28:26 +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 9A6041FFBD for ; Thu, 20 Jun 2019 17:28:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F3356B000C; Thu, 20 Jun 2019 13:28:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 47DAB8E0002; Thu, 20 Jun 2019 13:28:20 -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 2F8F38E0001; Thu, 20 Jun 2019 13:28:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f198.google.com (mail-yb1-f198.google.com [209.85.219.198]) by kanga.kvack.org (Postfix) with ESMTP id 081136B000C for ; Thu, 20 Jun 2019 13:28:20 -0400 (EDT) Received: by mail-yb1-f198.google.com with SMTP id e7so3194474ybk.22 for ; Thu, 20 Jun 2019 10:28:20 -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=6FlH20KsDCELbe7kvIBY8oKv4X0OwAVrMOno5QaQ+28=; b=APUtX1kTHM+WpBMkBrU8l2vT0XcGVyryJ4vD+25efOCpnXDngyLJaA4FCwe64PzIHM CdpusVSDeDd7CXBcKxADVsNNtdLu17D/52kvKXpqpRzyMOfdy51hSvIFWqEI5OvghroA seBL29UGJigNbGip32gVYErw3JhsUNw5SOdtl3ybYPqjJHFG1xC2Yl/FTVtOYmuRJVuY QUIg+bcxVYfwbifnFBzPRbLGn5yt95+XPcKPQ8SAbnWMMiRxMmnkZ0A2EZml2i3m+Dw+ XtG9FvvMmtBL1ybHSev2VzqHsKhzDJN5T59tunohZPr3wuvJvh1p1Vr8ip2NNx+I+RkK FFLQ== X-Gm-Message-State: APjAAAVzOAkDBo3PW3K+OJQxLz/dhMkkuaqMLY1izgOBOCzFFU5nNaqC Pd3EclkKFmJocla6/cfBHY/aBJtYwPGV1aDwQB7oxRC/J07h/QqlNJQauEiBEjjUWyixW/h/prp 2QrBAnRuqmTWNyiA9hEmtzhrRdi7rVJXmxX99Hfx44FkNX7A3uOUyfTyeIM/dc7TjJQ== X-Received: by 2002:a25:7413:: with SMTP id p19mr61792125ybc.310.1561051699710; Thu, 20 Jun 2019 10:28:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyb+rTLvvLwt1Q1/gGp2hN1cvCMsfX0DzkOzLTsto8M9tGFosAqggt1UHuYAG8P8+KPN4oU X-Received: by 2002:a25:7413:: with SMTP id p19mr61792088ybc.310.1561051698708; Thu, 20 Jun 2019 10:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561051698; cv=none; d=google.com; s=arc-20160816; b=wbbiLzZyZiPQPZmD39VRTA7MP4QjyZaRpK9FiVq6ylnKuWbQsYfhZG/kc/qK1k2YRW MMcN4XzNWeuv4G+JqP2j/Hk8KDGxvAZnha5hampxkqj0G4KbLMxru451B6ZuMrI7m7cn 4E2+RcD91mO8KvA1ABZHA4yE2z3/g2bx+scYs3Cslj+uNDIq0dLmCP55+qkW00J1DmjI UgQpviJXSi7KiQrQcDl0zjFH4gYpf9YtQtFHp2o/uScrcgq5nGNmBoUtx/PMkOhFQ6qt FTyqqpEIMTrXb4w9eK6vKjahZe/ptF4sImliBemYJRPwHfYwQ6tBYA2mJYlnG8+fDNFU 3LkQ== 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=6FlH20KsDCELbe7kvIBY8oKv4X0OwAVrMOno5QaQ+28=; b=biqrdm1L0pmgI1BVyq4G9HfDNt9Ax4+vW+tZ43FmIfzfftseNvKwqd7/w4hWTLmYdl d+BP3ZVfefz+mghMi8R9DfGNUgSNnC+2NTrGX92v3B2kC6bSZwhqaMTkxU0Co6DXQ7iw wfD9y+4FdPf/Gofrorm5ftvcXvWF0YpSN5cnWw/L4+i5mIc6KWuXvjmPAXub0G0V8FF/ DaQsUzVbmZ/H16jkMMFBUGKVWfMOym7TPNkmM0uNOsOr14Kg+WVjbf8vMh1BZq1zNQ+m x6DOwgWmdzCp77xnqc6oidoklz1PPkN07uSzeTD0K3TbjO0/Uzc7pWt3uNa4UQdb7LX7 KK2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=bC8XViEo; spf=pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=107476d203=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com. [67.231.153.30]) by mx.google.com with ESMTPS id b18si24236yba.411.2019.06.20.10.28.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 10:28:18 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.153.30 as permitted sender) client-ip=67.231.153.30; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=bC8XViEo; spf=pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=107476d203=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.27/8.16.0.27) with SMTP id x5KHJiIG014667 for ; Thu, 20 Jun 2019 10:28:18 -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=6FlH20KsDCELbe7kvIBY8oKv4X0OwAVrMOno5QaQ+28=; b=bC8XViEo5t73tNxkLH1pyUz8wMiBgMmHVyKt3Sjql20qI5dlrkVMmL7YPw+hvdQRnxaG kEk/r0AH8xKZrdb63Mta6T0mtFUy+ohrxvqwX1ibv9wVF/BnBQ27Sf+Gtoh6D4yTODJi 9eWGZBoooEihcMTi4rXz3ibMy1rd9itnRn4= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net with ESMTP id 2t8dffr8y6-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 20 Jun 2019 10:28:18 -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; Thu, 20 Jun 2019 10:28:18 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id AC3E862E2004; Thu, 20 Jun 2019 10:28:17 -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 v4 5/6] mm,thp: add read-only THP support for (non-shmem) FS Date: Thu, 20 Jun 2019 10:27:51 -0700 Message-ID: <20190620172752.3300742-6-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190620172752.3300742-1-songliubraving@fb.com> References: <20190620172752.3300742-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-20_12:,, 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-1906200124 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. Signed-off-by: Song Liu Acked-by: Rik van Riel --- mm/Kconfig | 11 ++++++ mm/filemap.c | 4 +-- mm/khugepaged.c | 91 +++++++++++++++++++++++++++++++++++++++++-------- mm/rmap.c | 12 ++++--- 4 files changed, 97 insertions(+), 21 deletions(-) diff --git a/mm/Kconfig b/mm/Kconfig index f0c76ba47695..546d45d9bdab 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 makes files with thp in + the page cache read-only. To overwrite the file, it need to be + truncated or removed first. + 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 dde8e45552b3..fbcff5a1d65a 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 vm_area_struct *vma, 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(vma->vm_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 vm_area_struct *vma, } 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 vm_area_struct *vma, 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 vm_area_struct *vma, 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,24 @@ static void collapse_file(struct vm_area_struct *vma, result = SCAN_FAIL; goto xa_unlocked; } + } else if (!page || xa_is_value(page)) { + unsigned long vaddr; + + VM_BUG_ON(is_shmem); + + vaddr = vma->vm_start + + ((index - vma->vm_pgoff) << PAGE_SHIFT); + xas_unlock_irq(&xas); + if (get_user_pages_remote(NULL, mm, vaddr, 1, + FOLL_FORCE, &page, NULL, NULL) != 1) { + result = SCAN_FAIL; + goto xa_unlocked; + } + lru_add_drain(); + lock_page(page); + } else if (!PageUptodate(page) || PageDirty(page)) { + result = SCAN_FAIL; + goto xa_locked; } else if (trylock_page(page)) { get_page(page); xas_unlock_irq(&xas); @@ -1426,6 +1455,12 @@ static void collapse_file(struct vm_area_struct *vma, 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 +1498,18 @@ static void collapse_file(struct vm_area_struct *vma, 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 +1547,15 @@ static void collapse_file(struct vm_area_struct *vma, 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 +1570,9 @@ static void collapse_file(struct vm_area_struct *vma, /* 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 +1655,17 @@ static void khugepaged_scan_file(struct vm_area_struct *vma, 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; @@ -1714,11 +1773,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 Thu Jun 20 17:27:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11007535 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 E214C76 for ; Thu, 20 Jun 2019 17:28:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D17B91FFBD for ; Thu, 20 Jun 2019 17:28:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C57CF28710; Thu, 20 Jun 2019 17:28:29 +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 966BE1FFBD for ; Thu, 20 Jun 2019 17:28:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D7166B000D; Thu, 20 Jun 2019 13:28:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F2B888E0002; Thu, 20 Jun 2019 13:28:23 -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 DF3518E0001; Thu, 20 Jun 2019 13:28:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) by kanga.kvack.org (Postfix) with ESMTP id BDC8B6B000D for ; Thu, 20 Jun 2019 13:28:23 -0400 (EDT) Received: by mail-yb1-f199.google.com with SMTP id v83so3209495ybv.17 for ; Thu, 20 Jun 2019 10:28:23 -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=hD2kmpWpjDtZ0Sd5qjALN5Ckzd1PVypTF/Ew4nsBLJo=; b=Rx3AIerdXf6Bw+8uaMBGsoWyFENeVlyzR20Z8j20O9zaJgVFjS80pjF5HrIQ/14U72 QMhKBmT4G28oFyoJ8C0R6Su47us9+uvtVEwfTiZ80eNopy1z7QFtf7Kz+ai1fGPQVWI8 nFFoFrqhUPOIx4Z+2/mOd3k61wADa4gLlkl9YG6dtH5scwt6D43gMoQlyiuJXAszz1MQ 5/UVh1/KrqRdzohFlIT4An4i5VbwS1xNahkha7JF9ny9KYnMHsUPDXusfYfk4Dfpl55d uHMbibaI0Tnz4bgEedkXxiuqvp/eQKx3nHniKtWmUQ/j/HfrVia11As3NumSpxZYW+zc 4UXw== X-Gm-Message-State: APjAAAWUhp2/vk+CPkxoJ0FtxFkrGBhM6KURqjS9GkwFtloKYyyZpE0t NyMe9wD2vhR4zbaTdJo/A4FSlRv/4qxr5ygbLEALNMYLCLE3A93AGcXEaNuZitX/VGacJXDn+9g ZrDj4zdYGAFcPGuFXrB2DOqukPHz7yJqXGMmhQPFw03OAXxR7OGkOFHsZcyBVAfFIhQ== X-Received: by 2002:a25:bb0e:: with SMTP id z14mr38358381ybg.82.1561051703456; Thu, 20 Jun 2019 10:28:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPslqJRhNnp/8CfCHtARon3BaOvjNdAy39QEs5eQuAQOX73dNQONJrW1BOQy1DoMGpGsra X-Received: by 2002:a25:bb0e:: with SMTP id z14mr38358343ybg.82.1561051702722; Thu, 20 Jun 2019 10:28:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561051702; cv=none; d=google.com; s=arc-20160816; b=GHQqN3s+CcN/y9lxLXzgTAoLwBnYhfSF8mTFc2Aq68/l278TJbW3R9nkSWJUP2r9oM aVGHxEf3KfC56uVktyflBelGPUoWjfwGpmJNleLNeRjNQ4gHG2vRthpwAOKybWW/4diZ 5UxS5mpYYxM2JqcntwCK5Qc/R3zpIx4jZAEdXWZDAEHTZm1LCrhy3dRBhVq/sDCRywVq 1E+GOvIqmceDcwGsDWG1En60g6iHw1Gt6UOLzhOYG3OgtTKlG3nQtqJhWcqLSnLZBX+r UcXD1k9hh+9J7LDXS502fAzWF+zmGmQlGKU8bJATGFjF+UAj/wMFxqVPK5z+tZU1V+d3 CecA== 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=hD2kmpWpjDtZ0Sd5qjALN5Ckzd1PVypTF/Ew4nsBLJo=; b=WbMXpSCrEgcijFtqGWt8MF2K4J1OHyXmmPntO+rgKByI8DvYeggXNIhZLcIOiy8Ixw 1jJgS+L8y4UlpdFUW1GF1KIuzmkUSBmjIFhZ585yEoeDZahyBxitfG0xQ8pa0ywHn8rZ YhULHImfDkk5RoJurb2azVMVcT1LnHi7fqwqs06Z53Zufg/9B2Y3k9xXm5XjZ1OJcYQh pUSS4rdksWzy1RwhG6Q5WDIP/DEM3QRvRutvnMC5HAqRX++bXIb12X3Alfr9Nt5Xg+Au bPsGniVNkuMDkMweSRCMMHbfXyASOh+u5RIp9bREcQ/CF8jJgcmZiApp488S6vigJsHa 59XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=kTITvPU+; spf=pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=107476d203=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com. [67.231.153.30]) by mx.google.com with ESMTPS id 134si25945ybd.375.2019.06.20.10.28.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 10:28:22 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.153.30 as permitted sender) client-ip=67.231.153.30; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=kTITvPU+; spf=pass (google.com: domain of prvs=107476d203=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=107476d203=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.27/8.16.0.27) with SMTP id x5KHJimr014684 for ; Thu, 20 Jun 2019 10:28:22 -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=hD2kmpWpjDtZ0Sd5qjALN5Ckzd1PVypTF/Ew4nsBLJo=; b=kTITvPU+VLMLvfdbMFDyZifEq4QY77unhvF7ZNsPRIYRVmsaTTAczOkMqjQbrW4KkNyx WRfB20b5+cNT/Nla5uSLnfp54+53I10+wQTxJ6BmSDrwxxjWvi59igHtflD1vYawgI+G 1bHjUCkL41VroygCaOla9CU8Q2cjtAL1Z0U= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net with ESMTP id 2t8dffr8yf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 20 Jun 2019 10:28:22 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 20 Jun 2019 10:28:21 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 51AB362E2004; Thu, 20 Jun 2019 10:28:20 -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 v4 6/6] mm,thp: avoid writes to file with THP in pagecache Date: Thu, 20 Jun 2019 10:27:52 -0700 Message-ID: <20190620172752.3300742-7-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190620172752.3300742-1-songliubraving@fb.com> References: <20190620172752.3300742-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-20_12:,, 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=789 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906200124 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 last vma with VM_DENYWRITE is removed. A new counter nr_thps is added to struct address_space. In exit_mmap(), if nr_thps is non-zero, we drop page cache for the whole file. Signed-off-by: Song Liu --- fs/inode.c | 3 +++ include/linux/fs.h | 31 +++++++++++++++++++++++++++++++ mm/filemap.c | 1 + mm/khugepaged.c | 4 +++- mm/mmap.c | 14 ++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) 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/include/linux/fs.h b/include/linux/fs.h index f7fdfe93e25d..3edf4ee42eee 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -444,6 +444,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 +2794,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 fbcff5a1d65a..17ebe9da56ce 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1500,8 +1500,10 @@ static void collapse_file(struct vm_area_struct *vma, 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); diff --git a/mm/mmap.c b/mm/mmap.c index 7e8c3e8ae75f..8094ce028d74 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3088,6 +3088,18 @@ int vm_brk(unsigned long addr, unsigned long len) } EXPORT_SYMBOL(vm_brk); +static inline void release_file_thp(struct vm_area_struct *vma) +{ +#ifdef CONFIG_READ_ONLY_THP_FOR_FS + struct file *file = vma->vm_file; + + if (file && (vma->vm_flags & VM_DENYWRITE) && + atomic_read(&file_inode(file)->i_writecount) == 0 && + filemap_nr_thps(file_inode(file)->i_mapping)) + truncate_pagecache(file_inode(file), 0); +#endif +} + /* Release all mmaps. */ void exit_mmap(struct mm_struct *mm) { @@ -3153,6 +3165,8 @@ void exit_mmap(struct mm_struct *mm) while (vma) { if (vma->vm_flags & VM_ACCOUNT) nr_accounted += vma_pages(vma); + + release_file_thp(vma); vma = remove_vma(vma); } vm_unacct_memory(nr_accounted);