From patchwork Thu Jun 13 04:44:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10991097 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 ED32C14E5 for ; Thu, 13 Jun 2019 04:44:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBF0328A7E for ; Thu, 13 Jun 2019 04:44:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BECD628B08; Thu, 13 Jun 2019 04:44:36 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY 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 27FC728A7E for ; Thu, 13 Jun 2019 04:44:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C8016B0005; Thu, 13 Jun 2019 00:44:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 177E76B0006; Thu, 13 Jun 2019 00:44:35 -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 066FD6B0007; Thu, 13 Jun 2019 00:44:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id C52DE6B0005 for ; Thu, 13 Jun 2019 00:44:34 -0400 (EDT) Received: by mail-pf1-f198.google.com with SMTP id b127so13592768pfb.8 for ; Wed, 12 Jun 2019 21:44:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=j5MbCLhVNCmEPDQlr1rpYtmPkjYr3dRGdvMWKjAKhpQ=; b=SpFkuns6YE9W8o23+LB/0lPZTXqw5xvnhJv0N3dUFDNVI3FmikZm0tw5tgX04IvY4p jrtw30SDd474DpPeVnJT6e5iZh2HxZAhRcY7slmbCTWfi6kJm/k2zvMip35/OR552Nru E3pDxnMaGOU+Mif+UFyH8E3dYicoJ0gU6Rxp57ylWs5eVWHuHQVjl28laXYN2T8JV/ER Jbxth+tmj9Op5KGl4F+yO6AhxHif+ExXTFqlCMoIUmDGs7vWFVE5kvu25IS83Gff5rVF vY+ExzKJnWYvGKlsiFUFhdHrBBMXr+RJWXNSWdJ77CE9Hjf3SQeMv82AIp32BnElDw+M o1Zw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: APjAAAUp2SYW/9PMxgHSfZ0pm7l9ur2QOhLa64+IvDF9htQfTbJOufIH +GwbYv7WxeKnc3zrUTR/YpmxNwAqiCpX2c++rKQyv4IooJ58F5/il1u9m/L6LnkSaL970xjji3F hVWReNm/vsU4h9yd74L3ahWQ0nsHnGDVyY7wV0H6nBVgeWwAHzXIkqL0oXqr3O0raYg== X-Received: by 2002:a17:90a:24ac:: with SMTP id i41mr2946515pje.124.1560401074431; Wed, 12 Jun 2019 21:44:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqztGVBpoecT25cVHR/6RucPouBOhgTx2A7iTHZbEBbdjAlo83yitW+gIfZ9Sz7+nT9qIQ9C X-Received: by 2002:a17:90a:24ac:: with SMTP id i41mr2946374pje.124.1560401073098; Wed, 12 Jun 2019 21:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560401073; cv=none; d=google.com; s=arc-20160816; b=BJyPGOS17nsyiVyxCdiKndO0v4p9k45lF1TltKuzaPNZKmEhJmufIuiKhArT22cLH7 a2DELC7Xx9fM4iHs2VxelnsaCRIl3IpK1OKkwxibbt/HL56Rw8CWNSRJmoPFgf76KMoR j4wjBXUNtXmgzkgDFceCnWd5V/ki8SaqMsTkVU5d7V3K0ksMEQNUlc4xMklmUzyELMGf TXaiLhrirTG/VElMJpDgrSF5+NZxth3FGLiBqF26TngtCSF52hNsrzAg46uvi176UqL6 Tup6tPF/Av+yw7OkVTOmAFPfdELvmzle9ruFQFHCbHO9ptE6qAzyfVte6chTEDDPkDKr ywDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=j5MbCLhVNCmEPDQlr1rpYtmPkjYr3dRGdvMWKjAKhpQ=; b=PT96d0Nu9TC28594VjEim/teoQrEmbRs2tpUJKSplYjD0al+cWqQyqWP7TY1qwYfH+ Oz/8slTc7s3x1xSx+JYxNBYo90GQjM5xsfIX2U0emghZhmIbm31Q7pkcFCmT/UNOeRD5 otPlhHxLKMYAdhDARZt1g7+6nPD+8r2LjhA9tcB/n0oxwOQCW+v1v/ZYUV3ZhNv/7jea FB1AlGstHOpVaJN4cloZyEkSaVysYd8NyDiiz4Yw0dv2fq2hmOjr+uOBu2jVaRTWsbbc sx/zO84tAcJJt/Om6n3ucQ0tCLju8Wdzo2tWeX4aDzixHpGcWPlOABZVjMFVODVk1SLT dpDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com. [47.88.44.36]) by mx.google.com with ESMTPS id a22si1853945pgb.292.2019.06.12.21.44.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2019 21:44:33 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) client-ip=47.88.44.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R291e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04391;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0TU25N7U_1560401051; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TU25N7U_1560401051) by smtp.aliyun-inc.com(127.0.0.1); Thu, 13 Jun 2019 12:44:19 +0800 From: Yang Shi To: hughd@google.com, kirill.shutemov@linux.intel.com, mhocko@suse.com, vbabka@suse.cz, rientjes@google.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 1/2] mm: thp: make transhuge_vma_suitable available for anonymous THP Date: Thu, 13 Jun 2019 12:44:00 +0800 Message-Id: <1560401041-32207-2-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1560401041-32207-1-git-send-email-yang.shi@linux.alibaba.com> References: <1560401041-32207-1-git-send-email-yang.shi@linux.alibaba.com> 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 The transhuge_vma_suitable() was only available for shmem THP, but anonymous THP has the same check except pgoff check. And, it will be used for THP eligible check in the later patch, so make it available for all kind of THPs. This also helps reduce code duplication slightly. Since anonymous THP doesn't have to check pgoff, so make pgoff check shmem vma only. Cc: Hugh Dickins Cc: Kirill A. Shutemov Cc: Michal Hocko Cc: Vlastimil Babka Cc: David Rientjes Signed-off-by: Yang Shi --- mm/huge_memory.c | 2 +- mm/internal.h | 25 +++++++++++++++++++++++++ mm/memory.c | 13 ------------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9f8bce9..4bc2552 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -691,7 +691,7 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf) struct page *page; unsigned long haddr = vmf->address & HPAGE_PMD_MASK; - if (haddr < vma->vm_start || haddr + HPAGE_PMD_SIZE > vma->vm_end) + if (!transhuge_vma_suitable(vma, haddr)) return VM_FAULT_FALLBACK; if (unlikely(anon_vma_prepare(vma))) return VM_FAULT_OOM; diff --git a/mm/internal.h b/mm/internal.h index 9eeaf2b..7f096ba 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -555,4 +555,29 @@ static inline bool is_migrate_highatomic_page(struct page *page) void setup_zone_pageset(struct zone *zone); extern struct page *alloc_new_node_page(struct page *page, unsigned long node); + +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#define HPAGE_CACHE_INDEX_MASK (HPAGE_PMD_NR - 1) +static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, + unsigned long haddr) +{ + /* Don't have to check pgoff for anonymous vma */ + if (!vma_is_anonymous(vma)) { + if (((vma->vm_start >> PAGE_SHIFT) & HPAGE_CACHE_INDEX_MASK) != + (vma->vm_pgoff & HPAGE_CACHE_INDEX_MASK)) + return false; + } + + if (haddr < vma->vm_start || haddr + HPAGE_PMD_SIZE > vma->vm_end) + return false; + return true; +} +#else +static inline bool transhuge_vma_suitable(struct vma_area_struct *vma, + unsigned long haddr) +{ + return false; +} +#endif + #endif /* __MM_INTERNAL_H */ diff --git a/mm/memory.c b/mm/memory.c index 96f1d47..2286424 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3205,19 +3205,6 @@ static vm_fault_t pte_alloc_one_map(struct vm_fault *vmf) } #ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE - -#define HPAGE_CACHE_INDEX_MASK (HPAGE_PMD_NR - 1) -static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, - unsigned long haddr) -{ - if (((vma->vm_start >> PAGE_SHIFT) & HPAGE_CACHE_INDEX_MASK) != - (vma->vm_pgoff & HPAGE_CACHE_INDEX_MASK)) - return false; - if (haddr < vma->vm_start || haddr + HPAGE_PMD_SIZE > vma->vm_end) - return false; - return true; -} - static void deposit_prealloc_pte(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; From patchwork Thu Jun 13 04:44:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10991101 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 417F114E5 for ; Thu, 13 Jun 2019 04:45:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BA5028875 for ; Thu, 13 Jun 2019 04:45:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08D252890F; Thu, 13 Jun 2019 04:45:33 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY 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 5D2A328875 for ; Thu, 13 Jun 2019 04:45:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 521AE6B000A; Thu, 13 Jun 2019 00:45:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4D1E56B000C; Thu, 13 Jun 2019 00:45:31 -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 3EB106B000D; Thu, 13 Jun 2019 00:45:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 06C316B000A for ; Thu, 13 Jun 2019 00:45:31 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id y187so12974482pgd.1 for ; Wed, 12 Jun 2019 21:45:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=b++5wQT5X+2HL7ydJLKxd3UTgelDknQq5vbNdqzzGcE=; b=d2biULrmfohkN7cT3X0s52n4TwPMAtaXXHQdZpQgkdJWcgOuvQsyLsEXiDX5t6awd4 W9NwVTH4knSfnB8hk1qIHFIXmh9JKcAS2aUU7tNzZoXue9iMo/kOC0fgoTCGb8yh4jMg XaMRlTYhwEk32PzpD95DPi+ZVOcHac8b8Oe52LzkhEhUr+wAuQ8kiKOho9Uih6Ras6KP oC1iTgd7Jaa9WdlqJoiJwN5X4KmKbmpDgCzdq46eTeDmihje3EnPWtRsnT6pVjfr9/Kg w0eN8mhSiJi+itmcSPs0O67v6HfnMJQQRv5RZZDPhux1jUX9HEnDKqMueb6O7WYLiMOB 68xA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.37 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: APjAAAX4lKDLNETpVA7cTk+KiE9B5zxA+eHbcpvIyFOZnyx0voLjLTk2 lPSImr2d9IjhGYJM7agDC2kHJuCCnx6Mb6ZbTPX99DuFh0HyyZAphcrUxbv2yCU1l8PXfGh4YYv E3XoOTKKmjF8snHWeiXlel6XwGqlYXjAVGyqy4X5CFPPt+fgH349eMQF7Na+Fhi+HuA== X-Received: by 2002:a17:90a:9f93:: with SMTP id o19mr3043927pjp.70.1560401130638; Wed, 12 Jun 2019 21:45:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLiZC12tCx1Nl2q0GuV+EwKltobTAE3x7NTqBMlxZxfDy4RVULfbgG9Nb3oNLh8uGYUino X-Received: by 2002:a17:90a:9f93:: with SMTP id o19mr3043821pjp.70.1560401129310; Wed, 12 Jun 2019 21:45:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560401129; cv=none; d=google.com; s=arc-20160816; b=GtK2AHdTW0GGPT7rW+DiZSS2dv20KKG54BGNDmROf/OPc6zhXZL3Dje/zBk2E6cqU3 II42bS7T3iqVnYc+tmEgcUrWBnusp7A4juy1VMdI/1YjW+biIjrdl4Cv9jIOMDNwhXBg 8uUEB/+13fwzfzwk5EB8FcvQfV7PEsxSshBVqjl/aNCywVCJTNvu4FD3oaGYXUDLW6Ip TcmoPQk8Qr4w3pd1UePVVdJz9IWa+sSwc7coA8JrarI9zLIn6pj1SuVjNrbT1xpl6fuL G5ShJceiOChADDfrwX6/llEviJ1QxYM4o2F3oqUUIq2FdYdAV/Tbcg4nhPqeyo+bMgIJ peyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=b++5wQT5X+2HL7ydJLKxd3UTgelDknQq5vbNdqzzGcE=; b=cYp1TkKZoRp3XmSwPMvU76G6r/rFFabumTZUTWW64PwxTn+tO1aOp2EZQfBxNduJxF qwjGZEFL4z6c7sKYzRaomfXDKSbBJfcOfULjh8qgRTcVxPB3/95lnDKaT68FTtKFIrrY lD08vRQiXjjsmxG7fi49OdD4CuEEVHipYS4pUMdbUS7gqUHbJicF/3OhJ+GiJ+ATY/ji FF+9qInZFFndisq6oQmQ60wVOwNo1IPRSHqhb78/l+y3LDbCxp7WVrEgaaLInJAhMVpP S151mLzPl9erg3mEGWVqtynq1ncH7CA4k1ikmA2NyAZucKvV4XMjInuBO4kM8eEpklfj TpEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.37 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4437.biz.mail.alibaba.com (out4437.biz.mail.alibaba.com. [47.88.44.37]) by mx.google.com with ESMTPS id m143si1926289pfd.224.2019.06.12.21.45.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2019 21:45:29 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.37 as permitted sender) client-ip=47.88.44.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.37 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0TU25N7U_1560401051; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TU25N7U_1560401051) by smtp.aliyun-inc.com(127.0.0.1); Thu, 13 Jun 2019 12:44:19 +0800 From: Yang Shi To: hughd@google.com, kirill.shutemov@linux.intel.com, mhocko@suse.com, vbabka@suse.cz, rientjes@google.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 2/2] mm: thp: fix false negative of shmem vma's THP eligibility Date: Thu, 13 Jun 2019 12:44:01 +0800 Message-Id: <1560401041-32207-3-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1560401041-32207-1-git-send-email-yang.shi@linux.alibaba.com> References: <1560401041-32207-1-git-send-email-yang.shi@linux.alibaba.com> 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 The commit 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma, __transparent_hugepage_enabled() is called to override the result from shmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show: 7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764 /dev/shm/test Size: 4096 kB ... [snip] ... ShmemPmdMapped: 4096 kB ... [snip] ... THPeligible: 0 And, /proc/meminfo does show THP allocated and PMD mapped too: ShmemHugePages: 4096 kB ShmemPmdMapped: 4096 kB This doesn't make too much sense. The shmem objects should be treated separately from anonymous THP. Calling shmem_huge_enabled() with checking MMF_DISABLE_THP sounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already. Also check if vma is suitable for THP by calling transhuge_vma_suitable(). And minor fix to smaps output format and documentation. Fixes: 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma") Cc: Hugh Dickins Cc: Kirill A. Shutemov Cc: Michal Hocko Cc: Vlastimil Babka Cc: David Rientjes Signed-off-by: Yang Shi Acked-by: Hugh Dickins --- Documentation/filesystems/proc.txt | 4 ++-- fs/proc/task_mmu.c | 3 ++- mm/huge_memory.c | 9 +++++++-- mm/shmem.c | 3 +++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt index 66cad5c..b0ded06 100644 --- a/Documentation/filesystems/proc.txt +++ b/Documentation/filesystems/proc.txt @@ -477,8 +477,8 @@ replaced by copy-on-write) part of the underlying shmem object out on swap. "SwapPss" shows proportional swap share of this mapping. Unlike "Swap", this does not take into account swapped out page of underlying shmem objects. "Locked" indicates whether the mapping is locked in memory or not. -"THPeligible" indicates whether the mapping is eligible for THP pages - 1 if -true, 0 otherwise. +"THPeligible" indicates whether the mapping is eligible for allocating THP +pages - 1 if true, 0 otherwise. It just shows the current status. "VmFlags" field deserves a separate description. This member represents the kernel flags associated with the particular virtual memory area in two letter encoded diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 01d4eb0..6a13882 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -796,7 +796,8 @@ static int show_smap(struct seq_file *m, void *v) __show_smap(m, &mss); - seq_printf(m, "THPeligible: %d\n", transparent_hugepage_enabled(vma)); + seq_printf(m, "THPeligible: %d\n", + transparent_hugepage_enabled(vma)); if (arch_pkeys_enabled()) seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 4bc2552..36f0225 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -65,10 +65,15 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) { + /* The addr is used to check if the vma size fits */ + unsigned long addr = (vma->vm_end & HPAGE_PMD_MASK) - HPAGE_PMD_SIZE; + + if (!transhuge_vma_suitable(vma, addr)) + return false; if (vma_is_anonymous(vma)) return __transparent_hugepage_enabled(vma); - if (vma_is_shmem(vma) && shmem_huge_enabled(vma)) - return __transparent_hugepage_enabled(vma); + if (vma_is_shmem(vma)) + return shmem_huge_enabled(vma); return false; } diff --git a/mm/shmem.c b/mm/shmem.c index 1bb3b8d..a807712 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3872,6 +3872,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma) loff_t i_size; pgoff_t off; + if ((vma->vm_flags & VM_NOHUGEPAGE) || + test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) + return false; if (shmem_huge == SHMEM_HUGE_FORCE) return true; if (shmem_huge == SHMEM_HUGE_DENY)