Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2366958ybi; Thu, 20 Jun 2019 13:54:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaIZMN2TzcmYygGpZHNHGri9lhBD1RwIT3ya6r63jjcH3ZzDjFmLPeWaq60duILJpc6SvS X-Received: by 2002:a63:1d10:: with SMTP id d16mr14325600pgd.446.1561064082692; Thu, 20 Jun 2019 13:54:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561064082; cv=none; d=google.com; s=arc-20160816; b=oiUR2Bh14pkvELOoGuFM3FOhqI9xj4ilCMKhxKMdXq7Tx10xZdyuPBdA66toqHaTHN /VJSpS668yRLlkacRUg3S7e/sg7VMoIR+JWxmtFp0s9s/Zk8JXHf+XksxxsONLh1lwqN qrsPfD0/C08kHIbePbx2I1jnZKar8RafBYdSK32QtuWBMFPhbcwcKtqsiGIlyHqOXsnV 1QXpweCjBq339mqPEiw1p1z3ODNp7cHeGV65QOWy3hKxvp6H05fCy3y7HihNJ2NKZ9z3 8q9bh4Gfb1OYXCGZfvkmyCQIZ5IfGz3G84zIcA12eMAvMQSfHxO5+WpGMBE3Vt70O/RK UYjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=Rd2surzaIHpsaXLZZ+uUyTgCfzwHrwQk/kkn9z9rfxg=; b=vDN9qA9qzSePlDQ+0YJ5dUzyinZjB3jIN/wzMcXvCJpBbqunXwgiZAX5vs0BQI1AP+ 2v/nBD7YcCYE3Sh9kWb3Q5Z7hRHnSGm1lATOZoqduWCu4P3gIzcHlhWVA+KiTP+OFsdL V9czmXWZ3f1iYmbyqnreCUMbrRSNsIDFUwEKiKwKY+wjwd5brTnAzHhA+8lPhjpOGCC4 8mDJVOCo0h+y4Cgql4waxA+YsVjqcsN4JX5b3cgOWV3hLLn366r4qKeFoR8+uQt5gOSS AEFiDgAxCUUQVeYK5UcAG/WTbMR50B1puT7uyp/XaMwxq5CRSW19LhPIt6Jf68Tk62d3 uijA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=bmnEUWpp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 21si520864pfo.138.2019.06.20.13.54.26; Thu, 20 Jun 2019 13:54:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=bmnEUWpp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726912AbfFTUyM (ORCPT + 99 others); Thu, 20 Jun 2019 16:54:12 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:7364 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726761AbfFTUyJ (ORCPT ); Thu, 20 Jun 2019 16:54:09 -0400 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 x5KKs22Y010777 for ; Thu, 20 Jun 2019 13:54:07 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=Rd2surzaIHpsaXLZZ+uUyTgCfzwHrwQk/kkn9z9rfxg=; b=bmnEUWpp8Y8WJH7dw7bmchR2wyhNRQUERSe+Zg6nd5c39AHPWdSFJpF+Ky6w48V4pwA3 qMjVqvcEns9twS1FqAZeYVdzUfiSwRHkXtvUUpc3IR4eQ8w6EZONYHRKK2baFtmd9OI/ wngv+NAW04YT2hZzMN91BEvskAUFRzlODFQ= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2t8aj31pkm-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 20 Jun 2019 13:54:03 -0700 Received: from mx-out.facebook.com (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::128) 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 13:53:53 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id C847B62E2A35; Thu, 20 Jun 2019 13:53:52 -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 v5 0/6] Enable THP for text section of non-shmem files Date: Thu, 20 Jun 2019 13:53:42 -0700 Message-ID: <20190620205348.3980213-1-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-20_14:,, 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-1906200150 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Changes v4 => v5: 1. Move the logic to drop THP from pagecache to open() path (Rik). 2. Revise description of CONFIG_READ_ONLY_THP_FOR_FS. Changes v3 => v4: 1. Put the logic to drop THP from pagecache in a separate function (Rik). 2. Move the function to drop THP from pagecache to exit_mmap(). 3. Revise confusing commit log 6/6. Changes v2 => v3: 1. Removed the limitation (cannot write to file with THP) by truncating whole file during sys_open (see 6/6); 2. Fixed a VM_BUG_ON_PAGE() in filemap_fault() (see 2/6); 3. Split function rename to a separate patch (Rik); 4. Updated condition in hugepage_vma_check() (Rik). Changes v1 => v2: 1. Fixed a missing mem_cgroup_commit_charge() for non-shmem case. This set follows up discussion at LSF/MM 2019. The motivation is to put text section of an application in THP, and thus reduces iTLB miss rate and improves performance. Both Facebook and Oracle showed strong interests to this feature. To make reviews easier, this set aims a mininal valid product. Current version of the work does not have any changes to file system specific code. This comes with some limitations (discussed later). This set enables an application to "hugify" its text section by simply running something like: madvise(0x600000, 0x80000, MADV_HUGEPAGE); Before this call, the /proc//maps looks like: 00400000-074d0000 r-xp 00000000 00:27 2006927 app After this call, part of the text section is split out and mapped to THP: 00400000-00425000 r-xp 00000000 00:27 2006927 app 00600000-00e00000 r-xp 00200000 00:27 2006927 app <<< on THP 00e00000-074d0000 r-xp 00a00000 00:27 2006927 app Limitations: 1. This only works for text section (vma with VM_DENYWRITE). 2. Original limitation #2 is removed in v3. We gated this feature with an experimental config, READ_ONLY_THP_FOR_FS. Once we get better support on the write path, we can remove the config and enable it by default. Tested cases: 1. Tested with btrfs and ext4. 2. Tested with real work application (memcache like caching service). 3. Tested with "THP aware uprobe": https://patchwork.kernel.org/project/linux-mm/list/?series=131339 Please share your comments and suggestions on this. Thanks! Song Liu (6): filemap: check compound_head(page)->mapping in filemap_fault() filemap: update offset check in filemap_fault() mm,thp: stats for file backed THP khugepaged: rename collapse_shmem() and khugepaged_scan_shmem() mm,thp: add read-only THP support for (non-shmem) FS mm,thp: avoid writes to file with THP in pagecache fs/inode.c | 3 ++ fs/namei.c | 22 ++++++++- fs/proc/meminfo.c | 4 ++ include/linux/fs.h | 31 ++++++++++++ include/linux/mmzone.h | 2 + mm/Kconfig | 11 +++++ mm/filemap.c | 9 ++-- mm/khugepaged.c | 104 +++++++++++++++++++++++++++++++++-------- mm/rmap.c | 12 +++-- mm/vmstat.c | 2 + 10 files changed, 171 insertions(+), 29 deletions(-) -- 2.17.1