From patchwork Thu Mar 17 23:48:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12784676 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C95DC433F5 for ; Thu, 17 Mar 2022 23:48:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FA0F8D0006; Thu, 17 Mar 2022 19:48:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A9FA8D0001; Thu, 17 Mar 2022 19:48:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 025808D0006; Thu, 17 Mar 2022 19:48:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0083.hostedemail.com [216.40.44.83]) by kanga.kvack.org (Postfix) with ESMTP id E680B8D0001 for ; Thu, 17 Mar 2022 19:48:40 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 958B3182751C8 for ; Thu, 17 Mar 2022 23:48:40 +0000 (UTC) X-FDA: 79255520400.25.8600839 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf04.hostedemail.com (Postfix) with ESMTP id 29EA74000A for ; Thu, 17 Mar 2022 23:48:40 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id p17so5734086plo.9 for ; Thu, 17 Mar 2022 16:48:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XKQspk4LAoVq0Cn8x51eh1PH1jIoAPLYMSrh0f750IY=; b=jFpvMyu8Lmr30lvoJVeQyn6l2I3hQx7c4LidmLWMeHE4pc9vJJjEZWCIvkxKg+angN IKSwRoWtxS2l+HwIpyduOicwl2cPw8BId1H8G1v857wETnyNwbCcD8rxkYN7IHnbM2jv 2yh1znyUjEMD/yp7wB5tzUGvQ9qmp4T31S+grwxSZv1lsoZwjngjtovgzZVDcZokHo3g LyHy8HqznKKYKNlcp7xXBV9YLMUT+CNXT7N/eUh+CGOJJPl1dryMvjJ7YiSeiYh+gS7/ IzlJm8QRKIDVl5EKLTbQIgRQyqa0RoX0GyQyIGZWYNQWnC1C1SUsLE+Vii5kQf4cSfrj vv9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XKQspk4LAoVq0Cn8x51eh1PH1jIoAPLYMSrh0f750IY=; b=qBBEClAPwdNtFLmYA3d5XNmxfZTRBJfr0K8o8y2oB8EDWMP1dKiM3qimTgApJe69/K vk5iqjeN12p2sAc+gYl9eWwbcEBlpjtuL55skHlZd3+1DPoS17uAiuYK06738Jw48bZZ eqnMsMhJFObqV0/muzhbyf85omGAJKP3hNcpLYDQsH+2kyP+gX1VqkixBtLgXUmFmtzr YCvQF/oskHZlKYHbg4tK74rxnOhbdzvTzP1dPS9Dp7BhjcykoTwMMrzthgNZfUroy7Yk Dzy8R2aaf0e5E0nIJ4InFTbA5xuv924eQpL6Jwn8x3lDwqEmOq4OfuMNmFZaVRDjEgwy 4aRA== X-Gm-Message-State: AOAM530knzSDobPm46tbJvlkHS7asypswshNqDDEaxlYQcNlDf5s/HjT NdqmdSjUq/aM/PCqsF1g2c8= X-Google-Smtp-Source: ABdhPJydZul27UYLlzwCg5wysvPkxxFiprMv7eHU1Yr/csXpk/Erca9BMe2mrozIbghvD/AKSU+PgQ== X-Received: by 2002:a17:90a:aa83:b0:1b9:7c62:61e5 with SMTP id l3-20020a17090aaa8300b001b97c6261e5mr8263237pjq.118.1647560919231; Thu, 17 Mar 2022 16:48:39 -0700 (PDT) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id o7-20020aa79787000000b004f8e44a02e2sm8581329pfp.45.2022.03.17.16.48.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 16:48:38 -0700 (PDT) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, songliubraving@fb.com, riel@surriel.com, willy@infradead.org, ziy@nvidia.com, akpm@linux-foundation.org, tytso@mit.edu, adilger.kernel@dilger.ca, darrick.wong@oracle.com Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v2 PATCH 2/8] mm: khugepaged: remove redundant check for VM_NO_KHUGEPAGED Date: Thu, 17 Mar 2022 16:48:21 -0700 Message-Id: <20220317234827.447799-3-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220317234827.447799-1-shy828301@gmail.com> References: <20220317234827.447799-1-shy828301@gmail.com> MIME-Version: 1.0 X-Stat-Signature: b3yb5dsce7a16iadtfr16x4z4mg453cz Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jFpvMyu8; spf=pass (imf04.hostedemail.com: domain of shy828301@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 29EA74000A X-HE-Tag: 1647560920-680314 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: The hugepage_vma_check() called by khugepaged_enter_vma_merge() does check VM_NO_KHUGEPAGED. Remove the check from caller and move the check in hugepage_vma_check() up. More checks may be run for VM_NO_KHUGEPAGED vmas, but MADV_HUGEPAGE is definitely not a hot path, so cleaner code does outweigh. Reviewed-by: Miaohe Lin Signed-off-by: Yang Shi --- mm/khugepaged.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 131492fd1148..82c71c6da9ce 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -366,8 +366,7 @@ int hugepage_madvise(struct vm_area_struct *vma, * register it here without waiting a page fault that * may not happen any time soon. */ - if (!(*vm_flags & VM_NO_KHUGEPAGED) && - khugepaged_enter_vma_merge(vma, *vm_flags)) + if (khugepaged_enter_vma_merge(vma, *vm_flags)) return -ENOMEM; break; case MADV_NOHUGEPAGE: @@ -446,6 +445,9 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, if (!transhuge_vma_enabled(vma, vm_flags)) return false; + if (vm_flags & VM_NO_KHUGEPAGED) + return false; + if (vma->vm_file && !IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff, HPAGE_PMD_NR)) return false; @@ -471,7 +473,8 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, return false; if (vma_is_temporary_stack(vma)) return false; - return !(vm_flags & VM_NO_KHUGEPAGED); + + return true; } int __khugepaged_enter(struct mm_struct *mm)