From patchwork Fri Jun 29 18:17:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 10497189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0A51B60325 for ; Fri, 29 Jun 2018 18:18:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0AC6297A0 for ; Fri, 29 Jun 2018 18:18:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4385297BE; Fri, 29 Jun 2018 18:18:25 +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 C0E4F297A0 for ; Fri, 29 Jun 2018 18:18:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA3D16B0269; Fri, 29 Jun 2018 14:18:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B78C46B026A; Fri, 29 Jun 2018 14:18:20 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3FE36B026B; Fri, 29 Jun 2018 14:18:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr0-f197.google.com (mail-wr0-f197.google.com [209.85.128.197]) by kanga.kvack.org (Postfix) with ESMTP id 4524D6B0269 for ; Fri, 29 Jun 2018 14:18:20 -0400 (EDT) Received: by mail-wr0-f197.google.com with SMTP id x6-v6so4957214wrl.6 for ; Fri, 29 Jun 2018 11:18:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:smtp-origin-hostprefix:from :smtp-origin-hostname:to:cc:smtp-origin-cluster:subject:date :message-id:mime-version; bh=AoJhkxsmByGfntAH5HYsiDrr0c7SBsDhX9SKVpaqciw=; b=CDVxIXaYLp7pqFXb9m85AkmqQKGI2J2C4LenFfxeLDSzS8bkYc7X6lB5RqaE+Obl3V iI1ZUS/yhRK6iy8CZF5mwV3a1HuVPj2v+TN8SrcDM5gsy42lDebwgxu8abjbjajAYXD5 rrcFVk1FaOdMwrLSPQhdwBbxERoaN2FqLZAp9xjJmapD0sqK3HlfB3FhO0FoQaFH9d+b x1wl7cU7o/ymPAiui4jzlUq7A9icA8mZ1t3k97ge2qUa2JJeD9aowbfBETTr+ZXsAYcH xpAOgUR/MkAp66HlytaEIDGulNhnCUDU4HEJQ+GTheKLYeleEXlMVwqMYRU3BVD3wKh1 3vew== X-Gm-Message-State: APt69E21cjKASyT4obpGZV+lsTwQ/LVeBsVG3Ef5fdzcIxrhwU2NVRzD asep5gWW5lPmZ1Tllj9K6y6bYSJGIHIYzOf3lOwfEm1fgUSAQv1d2OrwPS+hWfws2k6efU8RhKp SbYNgI6fYwB0AupehZ7ryfrZo2LC8NXImqBc5ym9DSEVjxTJ/QGKRMo3DKMXrWT/Srw== X-Received: by 2002:a1c:b18a:: with SMTP id a132-v6mr2330448wmf.18.1530296299782; Fri, 29 Jun 2018 11:18:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeg8n6y15+aFCKG7P+Ev6buOmB5kgkenDdMhAUSgF5ytVZ9le/3G1STx1Usp0I+7JO5+n+m X-Received: by 2002:a1c:b18a:: with SMTP id a132-v6mr2330423wmf.18.1530296299078; Fri, 29 Jun 2018 11:18:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530296299; cv=none; d=google.com; s=arc-20160816; b=hP5G04zHvBHF9hpcwkXPh3i09J7sBTUyWcNPqxlZx7vYKkSDHCnDDPF8O8xJIvmmWV qLhQW35jolcmULlycfO7HE3MZFndzEL/GZHqeeflOXqi3L+9+k7JYlq/X79ffNCFVWTC CTksKfEUpAcjna8FYLV1l//fEh3v7Sw8L123weyd4LzzqlZuMN+O2cfCVu4JLfS15KGV /FzX6dUz2ceglwMFcPa67CiEttz/DY/1mIfAfYZ8huD2u073kc31uI0KL30IilvR+Gq0 Bxhdkhsa87GD41SK82agKjVbs3zXtgTOvC6rA6PEE6pYGAWUTN7gf5gtJORrkVW/2Zay Y/Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:message-id:date:subject:smtp-origin-cluster:cc:to :smtp-origin-hostname:from:smtp-origin-hostprefix:dkim-signature :arc-authentication-results; bh=AoJhkxsmByGfntAH5HYsiDrr0c7SBsDhX9SKVpaqciw=; b=Iur599UXDSN/oroulJzto3sulD7+LByHctMWuYB6Bwj0qWQcq6T7u3mBRbAauwk1eA 2cqyZZSR4nDIcq6JY25n/64xCSnU3NGWL9J175r8kiD9jRbRpi1USuvLeLe61BaiqJhA ga36fIBmOgU/tf+K82K1WMdnxWYXGiejBGU63jHqFmFJmM0oj8arxexC0CSWeouQPNEi +b/ux/Wlr/sugJyY0slpf5aC3n7TQDfxloVECbxhjOZ9Fdq/cPAkuRMesgpmsTHUL/EM PV0vL0se1wbJ3Alr3k0ZYNHw1ujcUQu2r/vi+fwz4vRVjfDLhg6ERVVkL1RKy84zzfxF d/cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=NqNZzSwW; spf=pass (google.com: domain of prvs=0718b942a4=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=0718b942a4=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com. [67.231.153.30]) by mx.google.com with ESMTPS id s7-v6si4646207wrq.151.2018.06.29.11.18.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Jun 2018 11:18:19 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=0718b942a4=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=NqNZzSwW; spf=pass (google.com: domain of prvs=0718b942a4=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=0718b942a4=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w5TIDNej029085 for ; Fri, 29 Jun 2018 11:18:17 -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=AoJhkxsmByGfntAH5HYsiDrr0c7SBsDhX9SKVpaqciw=; b=NqNZzSwWnjt7uIgKMcRnwwjqA+0BRRRMP36VNXabGAi4GoC+KdFdW7dEwkKNwPJGCh4k GLDvsP17xZY242va83AJXAwitE10WDl3gK8iPiR5pXdPV7M9WkatSWa2PvF08vtUxvH9 WBcXutSu33SpG1QBYAd+dbo7iIlSdpdDJv0= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2jwsdj0318-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 29 Jun 2018 11:18:17 -0700 Received: from mx-out.facebook.com (192.168.52.123) by mail.thefacebook.com (192.168.16.15) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 29 Jun 2018 11:18:16 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id CFE5762E13CF; Fri, 29 Jun 2018 11:18:14 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: CC: , Song Liu , Yang Shi , "Kirill A . Shutemov" , Hugh Dickins , Vlastimil Babka , Andrew Morton , Rik van Riel Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH] mm: thp: passing correct vm_flags to hugepage_vma_check Date: Fri, 29 Jun 2018 11:17:52 -0700 Message-ID: <20180629181752.792831-1-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-06-29_08:, , signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe 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 Back in May, I sent patch similar to 02b75dc8160d: https://patchwork.kernel.org/patch/10416233/ (v1) This patch got positive feedback. However, I realized there is a problem, that vma->vm_flags in khugepaged_enter_vma_merge() is stale. The separate argument vm_flags contains the latest value. Therefore, it is necessary to pass this vm_flags into hugepage_vma_check(). To fix this problem, I resent v2 and v3 of the work: https://patchwork.kernel.org/patch/10419527/ (v2) https://patchwork.kernel.org/patch/10433937/ (v3) To my surprise, after I thought we all agreed on v3 of the work. Yang's patch, which is similar to correct looking (but wrong) v1, got applied. So we still have the issue of stale vma->vm_flags. This patch fixes this issue. Please apply. Fixes: 02b75dc8160d ("mm: thp: register mm for khugepaged when merging vma for shmem") Cc: Yang Shi Cc: Kirill A. Shutemov Cc: Hugh Dickins Cc: Vlastimil Babka Cc: Andrew Morton Cc: Rik van Riel Signed-off-by: Song Liu Reviewed-by: Rik van Riel Reviewed-by: Yang Shi --- mm/khugepaged.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index b2c328030aa2..38b7db1933a3 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -397,10 +397,11 @@ static inline int khugepaged_test_exit(struct mm_struct *mm) return atomic_read(&mm->mm_users) == 0; } -static bool hugepage_vma_check(struct vm_area_struct *vma) +static bool hugepage_vma_check(struct vm_area_struct *vma, + unsigned long vm_flags) { - if ((!(vma->vm_flags & VM_HUGEPAGE) && !khugepaged_always()) || - (vma->vm_flags & VM_NOHUGEPAGE) || + if ((!(vm_flags & VM_HUGEPAGE) && !khugepaged_always()) || + (vm_flags & VM_NOHUGEPAGE) || test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) return false; if (shmem_file(vma->vm_file)) { @@ -413,7 +414,7 @@ static bool hugepage_vma_check(struct vm_area_struct *vma) return false; if (is_vma_temporary_stack(vma)) return false; - return !(vma->vm_flags & VM_NO_KHUGEPAGED); + return !(vm_flags & VM_NO_KHUGEPAGED); } int __khugepaged_enter(struct mm_struct *mm) @@ -458,7 +459,7 @@ int khugepaged_enter_vma_merge(struct vm_area_struct *vma, * khugepaged does not yet work on non-shmem files or special * mappings. And file-private shmem THP is not supported. */ - if (!hugepage_vma_check(vma)) + if (!hugepage_vma_check(vma, vm_flags)) return 0; hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; @@ -861,7 +862,7 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, hend = vma->vm_end & HPAGE_PMD_MASK; if (address < hstart || address + HPAGE_PMD_SIZE > hend) return SCAN_ADDRESS_RANGE; - if (!hugepage_vma_check(vma)) + if (!hugepage_vma_check(vma, vma->vm_flags)) return SCAN_VMA_CHECK; return 0; } @@ -1660,7 +1661,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, progress++; break; } - if (!hugepage_vma_check(vma)) { + if (!hugepage_vma_check(vma, vma->vm_flags)) { skip: progress++; continue;