From patchwork Wed Jun 19 06:24:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11003517 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 C111C76 for ; Wed, 19 Jun 2019 06:24:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2AA028A59 for ; Wed, 19 Jun 2019 06:24:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A694328A69; Wed, 19 Jun 2019 06:24:39 +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 AA29D28A59 for ; Wed, 19 Jun 2019 06:24:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B43748E0008; Wed, 19 Jun 2019 02:24:34 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AF3278E0003; Wed, 19 Jun 2019 02:24:34 -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 944A08E0009; Wed, 19 Jun 2019 02:24:34 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by kanga.kvack.org (Postfix) with ESMTP id 6DF798E0008 for ; Wed, 19 Jun 2019 02:24:34 -0400 (EDT) Received: by mail-yb1-f200.google.com with SMTP id a13so16501616ybm.5 for ; Tue, 18 Jun 2019 23:24:34 -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=dhUKP3pweBve5jEl9pyVN6bP2b9W9cQjo4xYKr65fIFogGygEOWlaBcbhnMepnF12V VBnjLHTfji1soHHRbyJ6pdJUuyISLy1kOTrvkF3ITJRJuTYB33V4N8ZBgrM7rmvux2CH tlz3TPcCqp1U0OyRmbzrqMI8Z/TTZt0UXG/dgvOTnXSJeAv9/bkWvMFiY2b+Ep/cBgF9 IO4uSWmTPDueb1meKaxcv16c+3Kb07Qfl6Z9NJ9+qtNURQEAxSM76NPbUq9Sv49brQXP 9n1W+ZlZmW6xbkMHyDLiUhxiAENEh/EWdVrhXcd2o9ihqsAUSdb9oj/2g6kQac0NlKGt 2pCA== X-Gm-Message-State: APjAAAX2d5eZDDurnjuzn10x6n/wbw+9JEg8lEytEHD4Ad0g1pdWur9i umOqkXbRMGDqa2VYBeR3Jc26brJRQIJSwQ7JJyfesGFj4gqed8/VNK39z0P1jDWYZJW58ZVom9C zNq430HC+66H+VWhPzNxsVE25G6bvfqqCEKd2eYnKdlmqKYbkzekKMES0WbVAR+kAJg== X-Received: by 2002:a81:638a:: with SMTP id x132mr4377255ywb.463.1560925474192; Tue, 18 Jun 2019 23:24:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4/YvRhjli/vnvYCU1IyfgBWY+SC1R5jZs2hlNdjlG1LKt76E45DRrGs1kN09rE68lsJA+ X-Received: by 2002:a81:638a:: with SMTP id x132mr4377239ywb.463.1560925473710; Tue, 18 Jun 2019 23:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560925473; cv=none; d=google.com; s=arc-20160816; b=oJu4bRPSnbGpxSuDqw5Oi7rOLzui2Eicy1zQ33D1vlA3K5710hY+mvyzpAe5yUGTuO g5qFKY5DpUdsJPWNhd6Dd089xJrGfwBYKElricDK9KQPjdehvNLmeKiNC37ETx9hJQ72 kMx0rQuF47h1EYjhrbqVvMMpcmNpOrFC+Ir+vIzueDol+lTkoDnLkZ+GpO2waj73fQYl CWoXU+VeqjRTt1WwoiMWLKGKRFgp/BKcpSuTBntKUHI3TRksyQEsAeuAMea0L+PJeD+V BbWIhbRZawD/LHDqgAF4/pySxLGKssIWWLa8Vn/BEgS3MEX+fuQd0SlGYlLQiGnB4oA5 WSng== 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=Lrk3755YBYNKXFB1KxytYcaMli764/PdHX+tnsiqSFbdJFzPoMIcpa7APvmJm6UfV7 N4gLtuP35BbpWxEGm7PpsyLM7GyJNBIfQH7q+pesCca0DYKDiAUZ0ozu2VytrScYDkVh SlJdXdY/bfuu/UQuA2kNTZnOU+JPF/dWMBXjAbXm8aVlMrgap/GQkfiYLLzjnayDUJgR ZwsYBebPQSq6Q1lcxjQsT2tOhBVVWSE7bn4zCy3+1CLO2Xt9CpZ7U9bwjCDFq0lVPL2p kYfBqeGSKQ7t8E6UjouD6ISFyfix/072yFauGylnMpcDeXEYrq+JT3LdHWfVDVNbaZLS DjFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=ID5ajaKM; spf=pass (google.com: domain of prvs=1073bc1fa3=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=1073bc1fa3=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 d64si2116582ybb.259.2019.06.18.23.24.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jun 2019 23:24:33 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=1073bc1fa3=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=ID5ajaKM; spf=pass (google.com: domain of prvs=1073bc1fa3=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=1073bc1fa3=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.27/8.16.0.27) with SMTP id x5J6LNfk025885 for ; Tue, 18 Jun 2019 23:24:33 -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=ID5ajaKMn4YJkmbkush1oz0lfEupmjXRHK5U5hR0MieBzthFF1YAYiVfcvcf8x/fijZa 3Hs87+5dHuKkai1QaU0paRiQSKWBcjR1/kyga0/1ijehRFooZTQOmmkhuDajl72+dHss w8y1oC01uMIZwLdkWzO005bg2pAB3XUZleo= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net with ESMTP id 2t77yfhbr1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 18 Jun 2019 23:24:33 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 18 Jun 2019 23:24:32 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 4A58762E30AA; Tue, 18 Jun 2019 23:24:32 -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 v3 1/6] filemap: check compound_head(page)->mapping in filemap_fault() Date: Tue, 18 Jun 2019 23:24:19 -0700 Message-ID: <20190619062424.3486524-2-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190619062424.3486524-1-songliubraving@fb.com> References: <20190619062424.3486524-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-19_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=845 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906190052 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 Wed Jun 19 06:24:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11003519 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 83A4576 for ; Wed, 19 Jun 2019 06:24:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 743BE28A59 for ; Wed, 19 Jun 2019 06:24:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6873528A69; Wed, 19 Jun 2019 06:24:41 +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 0400428A59 for ; Wed, 19 Jun 2019 06:24:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E01BD8E0009; Wed, 19 Jun 2019 02:24:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DB1C78E0003; Wed, 19 Jun 2019 02:24:39 -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 CC7AE8E0009; Wed, 19 Jun 2019 02:24:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f72.google.com (mail-yw1-f72.google.com [209.85.161.72]) by kanga.kvack.org (Postfix) with ESMTP id A353F8E0003 for ; Wed, 19 Jun 2019 02:24:39 -0400 (EDT) Received: by mail-yw1-f72.google.com with SMTP id p76so18064547ywg.5 for ; Tue, 18 Jun 2019 23:24:39 -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=GT7rjxgO438+mq79t++266fcjefGPY2yMpYsgoogFZE=; b=AmSiJtGk/7WhJAXSf/ox4xZhb1Y1UNl7sUfNtuZOHy3dpcfKOgkuPU257mv0/FJlY7 WxJkFDYmmpK3ufO99kB4UeeMg6AXej3TTaD7OfvXYund1zlqb+Ib73K0FqX1YmV4wihP MVM/FzEcSe9LJP6cF+D6eV6xFvz1L9dLCfYNWiF+Po9FEatBkMU+gpO59/ygMe53A9wH bIKSQEg2D2Tj1qIHfs/+kyJl6hsBNzoFhBnoSlUgb9hT4pPsNhg4+7UBmg0jSqzPSHWU Wu4y34iBHfJuAPdO9dcLI0hwkr9mjKA6qdcuVBz51VzlofUacXz5OQHofm9J5r++aa93 PH0Q== X-Gm-Message-State: APjAAAUwj+SOD1pCzVnOF70y0uTy8F5m+YKa7WQiAugNlCVM6uKQbaHv WosyyEHHmU93BqQ9lHcuois4Efr+flyYVWISFW5rO88tjyZ/aoBf92LflUrzAjWGzKJdvGnmKz3 U2Y2gxmXIeyM0mtVMqjFlgxKYrimL7oIol7VEgQ7TOTsCL8PrSntDCQLlpkwhpPs8fw== X-Received: by 2002:a25:ade3:: with SMTP id d35mr19192531ybe.371.1560925479300; Tue, 18 Jun 2019 23:24:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqWYAbbL4Gx3385JApZmfrKBDL3+PbAmAeGxc+E6xnZXKD2c28ep29zc1JleAh9hMKpP7Y X-Received: by 2002:a25:ade3:: with SMTP id d35mr19192513ybe.371.1560925478789; Tue, 18 Jun 2019 23:24:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560925478; cv=none; d=google.com; s=arc-20160816; b=VvWs8/FUPMFNGPQo/vSXtse2fXwIXMR0ZDvMM0igzioDzJKRcgcCYbiEnlJ5TcKOR9 sUGcmSEbrV4jjOZ7y7IKGeWLZUyWMZ/Lsxk3J1yFRMVHQMY0eMjyD3ynXn4GwE1B1G/C iN0fvunCu476WN652SZspAgIAhUvZx2MC6rycYMMypfeK9/U3YgxtWIxIR2IIeBuwy74 wbowhk/fR1FOOHOkOGJmIeBdAdkm14ITu3bOtluzu7Z44uurrXxreCQltAML126FkS6t xsLytTzzVf9sYGxPfKEWAgz7D+GSDeB07alFWmCfVd7dZI2OyjBbW0vishlBI0YDbcD+ umFQ== 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=GT7rjxgO438+mq79t++266fcjefGPY2yMpYsgoogFZE=; b=NRVYoyFxQLRA60h56r2YftwAsupJrpJT23U2kyaYKg5DY1Jyq1g/ocRJ6Rw7GRQ1Fx 5zQDi45jcCp57PEN1fflQOJKWNLFw339DlFyfokJKxu5FLB8cBCABmeuBdaQdYPKzPLu 5ox910+rpz/Yei0bR6YagBi+fioiexhQuQNK/wLX+C1J7XPSc5cU4uo0UCdLaEsnF0kM gG8MqjjHK+BYNojBV7ocjzIH0PIrKOR8kB9lNGlUGT2dWEhc1WPyNs6MxEWwN2M2RZ+c 43piJcpS4LeVhGmOGBG8bR3fFAkLFjnSp7sB7NaMfj53UQ57oG9dzLCbSW8aAzmgv2hN aiRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=dqiJHgwk; spf=pass (google.com: domain of prvs=1073bc1fa3=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=1073bc1fa3=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 q78si5725402ywg.138.2019.06.18.23.24.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jun 2019 23:24:38 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=1073bc1fa3=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=dqiJHgwk; spf=pass (google.com: domain of prvs=1073bc1fa3=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=1073bc1fa3=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.27/8.16.0.27) with SMTP id x5J6LSeP025894 for ; Tue, 18 Jun 2019 23:24:38 -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=GT7rjxgO438+mq79t++266fcjefGPY2yMpYsgoogFZE=; b=dqiJHgwkvzOBTMWTjSGed7XavOFK1kzLVqFkeZQUHqleMOfyRJEjg7p1pW0/Y9L0AsT9 rMGb0ZeiF7WnF2k8eeZsQ4vMvTQftTg8XkcvMGjYKVyYYWuLPfA+ehp2FZAKod16xxl9 66/T2e9tTffg/7L0ZywcDFCS7X3o288J9D4= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by m0001303.ppops.net with ESMTP id 2t77yfhbr5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 18 Jun 2019 23:24:38 -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; Tue, 18 Jun 2019 23:24:37 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 9868562E30AA; Tue, 18 Jun 2019 23:24:36 -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 v3 2/6] filemap: update offset check in filemap_fault() Date: Tue, 18 Jun 2019 23:24:20 -0700 Message-ID: <20190619062424.3486524-3-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190619062424.3486524-1-songliubraving@fb.com> References: <20190619062424.3486524-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-19_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=729 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906190052 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); Signed-off-by: Song Liu Acked-by: Rik van Riel --- 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 Wed Jun 19 06:24:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11003521 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 8FC7176 for ; Wed, 19 Jun 2019 06:24:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FAAD28A59 for ; Wed, 19 Jun 2019 06:24:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7240F28A69; Wed, 19 Jun 2019 06:24:44 +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 E1C4328A59 for ; Wed, 19 Jun 2019 06:24:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7502D8E000A; Wed, 19 Jun 2019 02:24:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6FBD98E0003; Wed, 19 Jun 2019 02:24:42 -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 5C2428E000A; Wed, 19 Jun 2019 02:24:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f72.google.com (mail-yw1-f72.google.com [209.85.161.72]) by kanga.kvack.org (Postfix) with ESMTP id 2BC708E0003 for ; Wed, 19 Jun 2019 02:24:42 -0400 (EDT) Received: by mail-yw1-f72.google.com with SMTP id 77so18061909ywp.14 for ; Tue, 18 Jun 2019 23:24:42 -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=eF7TFIs9TCx8ANjmXiC0/WGsf3NbdhMtYrcRxsYcbKhzJUtPTRNqrnN6s889F/2etO bIgQIwUa91IiiCPJC6FJI/J46JSHkQ1oCG4IQEYCL5VNMuz8PDxjrN3GrN9/wMhoRlBA 3zKxRc1LrPO6qQhNMKN234D4xZtCtjZ+pou5Ey9FhGnW4zizFcG+tiA8S36yeO6XZvnn 4aveJzP73vUfI53MlIL4lRsQThwRSlAEjejmAJ0zQRwAdQBgRTM4X/C7Qy2cBN+gyOsb k84Lf+y9kQgmX5h56EVfh1M/ozgYns03ShKdqC0cK43GB5x6135Mez18IZx51UDJtR/u VQDQ== X-Gm-Message-State: APjAAAV33iM9rlna+bMT+rh9kDH6EIgsciFOSxBB8T9Hyc4ksvM82378 IX9J1eB/JmA4/ccZxsDbNZBqJRnQ0ct3Wyg8TcwN5DvReWruWZePPFu9RoAzwajSrtJy4PVKnf5 6ojW0DfZNuBA0Nx2F0iFjFO93TA0wemxtOO8U+MBvw1scaFqWvnVV0Ne5olhIkDYblQ== X-Received: by 2002:a0d:d6ce:: with SMTP id y197mr619799ywd.329.1560925481935; Tue, 18 Jun 2019 23:24:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqz307hkH2rkoB32N6kqnwIlMx/t3hfcAvIEnB4V06aBNyjGQI5MDj7BVOVrHpMuuYn5gb7B X-Received: by 2002:a0d:d6ce:: with SMTP id y197mr619786ywd.329.1560925481451; Tue, 18 Jun 2019 23:24:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560925481; cv=none; d=google.com; s=arc-20160816; b=v9ezVBN2dlrWP7VJL1KSzEAM3RiVjOF+uQrBFPyi3jfefvM2t2ThjrPhgaQb6uNqkp HB6bcGZ6p6mlQYCFo/DXdDhaarKGfRc/KBBCcD57ooloY3k77p3h8iYL0CqysCYsZzHu 2OUzLY/+wyq+eQ8nMVECmUviG7mnF799eDfIAvMtt0M9yMKqr7dN19mL2zBY0cFjSyBT ojUijQP7wdBnSo6Ple2jFhf6myUcdSAZBX4T/9gmpSjruHYcbXL2ci9LbXz64Avrdkoq lreYeuSwbJBlEKtk4Uc/Md00eqUuuO8OqVnShQ/s6193cAFTgxaUNGPi7zQlSYTcVgT5 Owjw== 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=WijFVqzMZ9Fw2rl03VdQNdXLG2/2NFHiVxLm+YW/UfO/Ulwp0gWCP5nWFg2tZ7jIbk S2Ughpq5oKH+TrNsy9ubpD+w3WGpNZ7pdaelFEP1SNPlm73W3xHlXWj/bNxTaDYWuKdo BOOTzGqOxzkN6TOU7YmLJWMmJICxGUzT7Dv6PPY6nYX07CU+JeTJS3cMevVdTOMvzn6l 3QjU6/tLFbsLkwpZaRyKzh31ExiNvMquT6c/9DIkDmH6tIUryRmOEaXFDypkvhJsDL8B Y8Bca4putteeyW5VgAC1vQIeuvPKJvBKh+PTKGq5K2bpKkO4Sa0sbNucuPYtrBWRQTGs KaWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=CVCpvvmr; spf=pass (google.com: domain of prvs=1073bc1fa3=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=1073bc1fa3=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 f132si6290615ybf.483.2019.06.18.23.24.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jun 2019 23:24:41 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=1073bc1fa3=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=CVCpvvmr; spf=pass (google.com: domain of prvs=1073bc1fa3=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=1073bc1fa3=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 x5J6OcD7011458 for ; Tue, 18 Jun 2019 23:24:41 -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=CVCpvvmrty2+BmU8R61TTEjty064z3cQqZ//jbIofM1juXWXIdjB1yJInN2QpQjUQzan 9H9A7a7RgQsLxPy+v7Btkc7zepdtdiKEXUlXnUqdkqCYrlC4IfaY6LyF/jJDXkY9PTBl 5oDPADIQ/yoQpAdClpHeevLd2aD+ylblhjk= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net with ESMTP id 2t77yyhbnu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 18 Jun 2019 23:24:41 -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; Tue, 18 Jun 2019 23:24:39 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 9B1B962E30AA; Tue, 18 Jun 2019 23:24:39 -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 v3 3/6] mm,thp: stats for file backed THP Date: Tue, 18 Jun 2019 23:24:21 -0700 Message-ID: <20190619062424.3486524-4-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190619062424.3486524-1-songliubraving@fb.com> References: <20190619062424.3486524-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-19_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 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-1906190052 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 Wed Jun 19 06:24:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11003529 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 97DCB924 for ; Wed, 19 Jun 2019 06:24:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8459B28A59 for ; Wed, 19 Jun 2019 06:24:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7617A28A69; Wed, 19 Jun 2019 06:24:57 +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 F21E228A59 for ; Wed, 19 Jun 2019 06:24:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 74AD68E000D; Wed, 19 Jun 2019 02:24:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 723C98E0003; Wed, 19 Jun 2019 02:24:51 -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 59C0A8E000D; Wed, 19 Jun 2019 02:24:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 203178E0003 for ; Wed, 19 Jun 2019 02:24:51 -0400 (EDT) Received: by mail-pl1-f198.google.com with SMTP id y9so9243230plp.12 for ; Tue, 18 Jun 2019 23:24:51 -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=UcBQx3V3cM3XT9Fzx7VrthaHanV1PsrKo4nQSd3ehcM=; b=sPDp21Byyqjgg7AOTBGIXfqB5fVr9aNybz5jdFsa0veON505A+HLsnUB+sfW9Zivwg I62M44GqHuvcFlgDK8L0VU4U8iyjMWzA3nzsqafiF2ZdMmImpHAlYZhMSeO8W672few1 ZaxWPsQckCrHbMxJgY+1BszKygtoBFblpi7va0Ev12tN3PX7p997lZNRycDaF36c9Ke6 rMNDH/Tq721QkSqABCJbW7gBEVWjYbtACdaGQ7+68A44hmHGvJKOK2KnEMtIFsEMUPyJ GLbxpwNfYeB4JIcpiCYfuQeoJN0koni1mXIHX31MUJPnJCmxPdpOSj4LL3P2laJI+L3F 5adg== X-Gm-Message-State: APjAAAUN/eHJAXkIHyJYwS/ArIiQXC2baiktfAgioRMAwhKJi434jtsM g8ECuw+qHTeh+d03VBn0SEIDtbab75on4z7jCraTD4BqDYz0zsSRMzatIqYWSIkamDxYFG+hxS5 J+X/jcH2nKiHy1TlwdEredzyNjZyDdXmUDf6cBDVGs/IpMzls33RIMbrse+3re2sQwA== X-Received: by 2002:a17:90a:cb15:: with SMTP id z21mr5580297pjt.87.1560925490713; Tue, 18 Jun 2019 23:24:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8/y1eVlcpUK5J0xNgCIhIw6wQIzrRbl4EWK8Le5ofLC41jnTYr2kRcI8rk3siKnK+RImC X-Received: by 2002:a17:90a:cb15:: with SMTP id z21mr5580253pjt.87.1560925490067; Tue, 18 Jun 2019 23:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560925490; cv=none; d=google.com; s=arc-20160816; b=NwYBERMvlcJOxRF1ULAgA1zJIjexX/AfpvpXLsxD1IP+g6w+6mPHsDs8JKogvT0ZN4 ufu73ESC/TLbajsGAiwUpBlfU9uzras2oi4G/XICiT/+o80WtduNV2uoZmyunrOKoVQg DThyQE6KrMpyHBdguUCxjQzvxRRSvHijZxcpS7UV58bqCBYnMLSlOcHuqrs3wwnWXlW2 zJHw5M6oWSZZtodPXLhnmxrGLycfKFDaiLJ/ThdZwUj2asjDUOW3/LJ/QkLwp3qH3VB8 mI2uiRD6DKLX4Gzzz1aYqTYABts+4u29+jH+L6NLscDhBx1VvzqoWBWRshv7M5oXtmCv 7Vdw== 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=UcBQx3V3cM3XT9Fzx7VrthaHanV1PsrKo4nQSd3ehcM=; b=rOgccFFuxRCiLQPsk2oXoKmaFSudipDupqwj4xYibWSP89RyYF2PKY5lpoyTSJmQqG +yM8L2kIjPlxGMOy6P07l2pBpEZ70oaRuPz5wC+teuLGcQZpgsm0qUvgOjNpUmbdBBQN we2ge/58Cd+V0pgTsl9fap4YDTVXhaUo9aXnJE1tjcow69TNZ9xoMKCK63FNwxhrYTwd bGVYcA+7ZCv9a2+yOzAdjY1AcYoZP5W8svcjKEXxFdspC0HHF5tRPcViMD/VSL7+uTJg /GTqxyzZjKDupEnmNw2+Q/Y4wQxDYOD1rXah73HJInpBEj3szWPiUsMYuolnd+poxt9j FPuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=io6Ul3MA; spf=pass (google.com: domain of prvs=1073bc1fa3=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1073bc1fa3=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 u2si2304691pgc.87.2019.06.18.23.24.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jun 2019 23:24:50 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=1073bc1fa3=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=io6Ul3MA; spf=pass (google.com: domain of prvs=1073bc1fa3=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1073bc1fa3=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5J6OniT014215 for ; Tue, 18 Jun 2019 23:24:49 -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=UcBQx3V3cM3XT9Fzx7VrthaHanV1PsrKo4nQSd3ehcM=; b=io6Ul3MA8HC/k5AERHzQ1h6EMRVFblG2QKDHlpT2COIFF1L3+j3aJ2O2fQ/JjSbkUMLF LaIkgd7fh11ZH4Dfduqcy8B+KqzdNkhkTXruSIL1Xy7Wt+t36fCzHjhK6NnID0ZdDJDX 2VNobPbyrQLzbI1p/Wr7QhNMRVYj9sOAbPM= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2t77yusdtj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 18 Jun 2019 23:24:49 -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; Tue, 18 Jun 2019 23:24:42 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 603D562E30AA; Tue, 18 Jun 2019 23:24:42 -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 v3 4/6] khugepaged: rename collapse_shmem() and khugepaged_scan_shmem() Date: Tue, 18 Jun 2019 23:24:22 -0700 Message-ID: <20190619062424.3486524-5-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190619062424.3486524-1-songliubraving@fb.com> References: <20190619062424.3486524-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-19_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=492 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906190052 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 Acked-by: Rik van Riel --- 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 Wed Jun 19 06:24:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11003527 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 2FC2776 for ; Wed, 19 Jun 2019 06:24:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F83628A59 for ; Wed, 19 Jun 2019 06:24:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1412F28A69; Wed, 19 Jun 2019 06:24:55 +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 314A428A59 for ; Wed, 19 Jun 2019 06:24:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C4B58E000B; Wed, 19 Jun 2019 02:24:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 576FB8E0003; Wed, 19 Jun 2019 02:24:50 -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 39EC28E000D; Wed, 19 Jun 2019 02:24:50 -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 DF2F98E000B for ; Wed, 19 Jun 2019 02:24:49 -0400 (EDT) Received: by mail-pf1-f199.google.com with SMTP id 140so10985904pfa.23 for ; Tue, 18 Jun 2019 23:24:49 -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=J49iqFo/ILagWkKhxiPkPYjA1lU6zzhFlRBSKgB72h4Xb52uHz/bySwhZ55PpUK3fo /vJOTW1aqVR+kNzl+6z4YlFn3GLWLqwwPjDyG3OGqZI0pQuCE7Jf9d0L7MaS2HYhtHMa wzFBALynpxDJja7kJRAyW66LE5pkYg8114N1N7dTM3H5TWnkNaEZCylTuFXhmQ9Vxkcx bVvorZBuWEbburgy4CFOlm9ZPDynPE3gTIoz0W00D3CRJ2d1jzE3JqPy8kSnmGwkV58l Lg5K8j9S/4HWWnL52bWPCPNiVd+sP9tqGceXMqzEUztW0C+fpdmetm2fj1a2rneL4/oy Dpdw== X-Gm-Message-State: APjAAAUMDtpO0W9IgsrNDznSYpEJmUIZkGHD8iA78Bpsl4n6ygRCzZ72 gjUGwKWttNp96XfQM27CXzc1tui5R5Gkz4svLgduJTyfU2KLLDur0arGBsWeqEvhSC+Cm0eMVLl uZ/SLXnKWVFfI8ZHZEoj1bzziG7AV1IAQV56D/s6rQuGP5XXfXwNwNt6FM5nkMD+xNQ== X-Received: by 2002:a17:90a:360b:: with SMTP id s11mr9314927pjb.51.1560925489552; Tue, 18 Jun 2019 23:24:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/eoj6IG3VvYrOaF4013PnLYjn6PEVACki2xdfrYyTt9uaMqxinG7MzFmww20z96WFAXld X-Received: by 2002:a17:90a:360b:: with SMTP id s11mr9314862pjb.51.1560925488585; Tue, 18 Jun 2019 23:24:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560925488; cv=none; d=google.com; s=arc-20160816; b=m9iz0sL7ewSjWBuXvqWQI/PhGnLpbbevHOFykuU9nlQO/qYePsGShvAzBPHEFkqo23 TPAF9yO5jUguqbnR2JWo/JhdQV5iQ00+AAWCbqk3N5rRFo3pWyHI07aAN4nYKv+ghL8Z MY5fLsXsfw7Pxu9Cs54Q/rtlnzApE78D6nO990LPtMULW9PIlQvOi1NQ7RJ/pI51ecch rz6zsoN713VuaGKBClRAdtO+1KGpPpV4tn8NWlfFbCNq9O3IgvmzEqHoFhsEJf3jMKjx gyAuMQLKJjHplhcS5Tgj9YwuQqmCTXi8hia1LVF2Y2lgg+Lf4V/8JUp1oe9+sOScVLzv 2sHA== 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=yyrSA+ZFEVbemzP/zfMlzYq+VcMGdk3pI6/6t6lV4TySw01mYM1kF6rfR0u71SaBoH weEjPJFRo4XUMeMLby8R2N8iBqMscqBc/ZXfHLSPmFGw6AnaN/d0PsPefq5ZbtS4e5+T DSX1kdjqg5nPzEBmhvJbb0NgBEwAekp3xaUa2YR7LPFQQZBJ3OerUPFrEnCOtmnCqdXz L2tTCliDfd8lyJvgr0XKZA8ZGFLQDypJ7hZtWcXzwotrEQvWfe6uCs8RyFVrEq0CF7Lm 4z1fLIoTF2zK1OidjLo4UHG8N657QXpWN0t3UgxgKLSOqRqSMiiwa4tlFEJ2RD5H81VO 0GbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=KhlUIygz; spf=pass (google.com: domain of prvs=1073bc1fa3=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1073bc1fa3=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 c3si15419211pfr.27.2019.06.18.23.24.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jun 2019 23:24:48 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=1073bc1fa3=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=KhlUIygz; spf=pass (google.com: domain of prvs=1073bc1fa3=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=1073bc1fa3=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 x5J6OmsB029563 for ; Tue, 18 Jun 2019 23:24:48 -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=KhlUIygzA/VpDyodFbrRzxxJoZfGT+zac4U61Rv4urFyI0J9JQNicjHFsmMZwu2xu02g keq6Pi2j7RcaCbOx/d7NGU8/2NDey5Qy5ntAyNqEwg1WPUAHzC0vRvFEDte+7eNNXxUy xo228sPlp/lYAhigklxS+/nyYulRma66FRk= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2t77yy1dxt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 18 Jun 2019 23:24:48 -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; Tue, 18 Jun 2019 23:24:46 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id E0E5862E30AA; Tue, 18 Jun 2019 23:24:44 -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 v3 5/6] mm,thp: add read-only THP support for (non-shmem) FS Date: Tue, 18 Jun 2019 23:24:23 -0700 Message-ID: <20190619062424.3486524-6-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190619062424.3486524-1-songliubraving@fb.com> References: <20190619062424.3486524-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-19_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 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-1906190052 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 --- 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 Wed Jun 19 06:24:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11003525 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 DE5C4924 for ; Wed, 19 Jun 2019 06:24:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD55928A59 for ; Wed, 19 Jun 2019 06:24:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1DA228A69; Wed, 19 Jun 2019 06:24:51 +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 3598128A59 for ; Wed, 19 Jun 2019 06:24:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A6648E000C; Wed, 19 Jun 2019 02:24:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 17F278E0003; Wed, 19 Jun 2019 02:24:50 -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 045708E000C; Wed, 19 Jun 2019 02:24:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f70.google.com (mail-yw1-f70.google.com [209.85.161.70]) by kanga.kvack.org (Postfix) with ESMTP id D18848E0003 for ; Wed, 19 Jun 2019 02:24:49 -0400 (EDT) Received: by mail-yw1-f70.google.com with SMTP id o135so17948053ywo.16 for ; Tue, 18 Jun 2019 23:24:49 -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=6cpDwB9/DOqvYGBieqT3GM6rp8s/fUHfF1+MzgzUlLc=; b=lt/9ePIYZOm0agktJi6WbUXBWedfcNn6UpL94pTidkTEYEUaIQGkwpu1Y8Flqoo1xA p4+MAf6HTFrVf2LRGcSPui80zz0fXM8n5WuDbGZ9UYdjk8+1OjNPQi5DPG/hWeE5KGG3 6DIa2eM91YwpBGOUAxSnFHefwhVyuLf62Qan9YojvYN+dHIycPJUS8SLupbExM/3G52Q 8GIL7K+U6Is3tkor32reKY21dvE+iC5WLw42L1SNU+ciuVMmSrdMuXsUPT97q5oN+S3n rmoFV8H9LFhyL5tTNcBb4MsDI+i5KghS0ccYeWEt/eiMkPwe7ZYpPQ0Srmphc9qPgr5k N8Ew== X-Gm-Message-State: APjAAAXzp7MCHUH6D/4QSmFyxFnMCGURxqkHwwM44QguFPM/BxetaseM OaSmx838c8Aj41L7rpWOCpSKj/x7l1lqYafkP7OimgZI5EFVumZXS7UNZ3Zy31WAa59jOhav5sS G8GDne4vMBAvv09nvdYZ2OBhUK10qLfvfzSe8LymNFLdCvP/zUPBnDxOJckdwLIVs6Q== X-Received: by 2002:a0d:edc1:: with SMTP id w184mr53169498ywe.174.1560925489618; Tue, 18 Jun 2019 23:24:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1NhBM/JtLp7p4FBT13hK/mIy3vRmHFFAZp7WSYRCeAfRfqlHz85Uhpf6vwusZugpuCNVo X-Received: by 2002:a0d:edc1:: with SMTP id w184mr53169472ywe.174.1560925488860; Tue, 18 Jun 2019 23:24:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560925488; cv=none; d=google.com; s=arc-20160816; b=0YrybQtVx1s7NcP62i6pEcTnNokXnSu9s1FP4GIs4I1aDZq5e/W/HV56Apm0pdR7J6 JYw7GJu46MqFZACuhA3u2HiD9ncUQOqkwBE1siAGsW8eyoypPLdNcToRxIlS95axNHqO pn0IYttM493yC+tg0LJZLZDcsIGfaAJnANnTqwwWlYLVmtkCRG3McZzEtFNaeUh//9hG Y/mkAOn68gKhtFTToDsSMgSwQ8/t8RA8OYGcUk43+RejyIxYsgJoXhzU6a5qc9w2+ghB ZT3RQmUlRB1N0MQkIZvyz+KZG4OvO+lAjtDsViL4QWyiMmijUAYJUfh89+FE5DMN3ZoT FOAQ== 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=6cpDwB9/DOqvYGBieqT3GM6rp8s/fUHfF1+MzgzUlLc=; b=V4qev88WNkp0Oy2mGsqQWLkx4l715FK5I5U7dIl3TXRlU2xuGOMNdgMEAHyvP2UGLk vAEcUw3Fstp004x0M09FpcDJbnWLixiFmJncbb4fhj0qgQc/icy1FAfX9JFoxjNCeHn2 i8N9f+MPvuJtvwPB3H6i+9iOwmkeFzXXisVZ+Wwhe6uR2U01Yv/RL81yZQK8kX5FD0wi b80iuVziFWbCYgN6ufdv/AZvWKF54wIGmNClKof3RDNkGVOqxaKdLmx51WKv5SJcBDf+ UT05vX8I82nbqZnAdkQCIiTN7x4Bff0Rcz2DciRY2tjVmkws97zpKMkofENYaCMIj/AA s4zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=RKuPaAkt; spf=pass (google.com: domain of prvs=1073bc1fa3=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=1073bc1fa3=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 r127si6149132ywr.312.2019.06.18.23.24.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jun 2019 23:24:48 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=1073bc1fa3=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=RKuPaAkt; spf=pass (google.com: domain of prvs=1073bc1fa3=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=1073bc1fa3=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.27/8.16.0.27) with SMTP id x5J6LM8H025877 for ; Tue, 18 Jun 2019 23:24:48 -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=6cpDwB9/DOqvYGBieqT3GM6rp8s/fUHfF1+MzgzUlLc=; b=RKuPaAkt4RwZsGKXPNeyJrxfkUzDBKl33bpXVgEdf7+g1fqNA1Kqr2L3y4V8CLFAmiw7 yOrDjpjRRGw+geEXyerRYWa2Z1eoEfCMl59JfURaV9qg/W64vJ+ureGZlR1X8tTfiS92 es/deAqTiMI+gNcA2uUSYAqQ/4ZIlnFEQWw= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net with ESMTP id 2t77yfhbrk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 18 Jun 2019 23:24:48 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 18 Jun 2019 23:24:48 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 7183062E30AA; Tue, 18 Jun 2019 23:24:47 -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 v3 6/6] mm,thp: handle writes to file with THP in pagecache Date: Tue, 18 Jun 2019 23:24:24 -0700 Message-ID: <20190619062424.3486524-7-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190619062424.3486524-1-songliubraving@fb.com> References: <20190619062424.3486524-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-19_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=759 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906190052 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 briefly handles such writes by truncate the whole file in sys_open(). A new counter nr_thps is added to struct address_space. in truncate_pagecache(), if nr_thps is not zero, we force truncate of 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/truncate.c | 7 ++++++- 5 files changed, 44 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/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/truncate.c b/mm/truncate.c index 8563339041f6..bab8d9eef46c 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -790,7 +790,11 @@ EXPORT_SYMBOL_GPL(invalidate_inode_pages2); void truncate_pagecache(struct inode *inode, loff_t newsize) { struct address_space *mapping = inode->i_mapping; - loff_t holebegin = round_up(newsize, PAGE_SIZE); + loff_t holebegin; + + /* if non-shmem file has thp, truncate the whole file */ + if (filemap_nr_thps(mapping)) + newsize = 0; /* * unmap_mapping_range is called twice, first simply for @@ -801,6 +805,7 @@ void truncate_pagecache(struct inode *inode, loff_t newsize) * truncate_inode_pages finishes, hence the second * unmap_mapping_range call must be made for correctness. */ + holebegin = round_up(newsize, PAGE_SIZE); unmap_mapping_range(mapping, holebegin, 0, 1); truncate_inode_pages(mapping, newsize); unmap_mapping_range(mapping, holebegin, 0, 1);