Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3853854pxf; Tue, 6 Apr 2021 01:46:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwHKGDOSNwuVmcFfshBGw5TDu47Z+vHtWmqoydow5QmcaqdDfNhXp0r0OV97OrMzm7+Q/R X-Received: by 2002:aa7:c804:: with SMTP id a4mr35812982edt.251.1617698759975; Tue, 06 Apr 2021 01:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617698759; cv=none; d=google.com; s=arc-20160816; b=l1q9ajb/Hp/kyfWb4AyUd0sIuyQKdOZAM/25r70IfIVl6pMXNoR+CdDCUe8llMeyxG bMShs9DUBBcqoNwjGS+VpIOscoqJnQ2SCt11n9a61dAPuS3VPZnwI5Vax6QlY2fRvIib cn3UEYJ2MkkTt+oqa7Nbbapkc1He63kwVF4P+yruILyYHKjDx/PI5FSO28BrtsA4b3VA jzabZO3U8z1ntQl5+YI+Gd4dyqMcwpy3Vx6E9/mto//076Y8U9fI9q9hXlQVufTA3JFQ pMdwg7EUnb7P4jiDQ3sD0p9dTP2o9tawID7wVMaq6/1s24oSY79snUhqvkgdCb8hwecU f7hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ar3GZrsZAoxiwaAKwrinVn8bd57MclGABFFkui0oZ7I=; b=h+bYLuu4hg7rLvSFZA6Sc3dEUvgr/jNgQh0qc3bwv+svlkEqNp+c68tA+z7AQFSYM3 ulJCbjVFC3SiX1UZPk5fVXKR7CLlltHjm18St0BO54sfmxGbtjo73+jeyRDtiVhvAQqK taHE8J86aezxp+kVVgetg+1Zl7UxR9q0S84nZd8s8Uz9F7qO/vz1sKNKd9T21YTWYOM6 96fivXwVwPXGsaK7pPlH2idYyArinc1krXbVN2v2Aqj9LG/G7rfnvuT7Mj7KGHNHjw1r CnInPVZzuKyl6aaoF02Bm5zAA+IOjWYuhbZ3LDjdedUnzc91aIKD4dCBOcTETw6fNCpD V3dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G0UX1D8Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dj16si2667995edb.368.2021.04.06.01.45.31; Tue, 06 Apr 2021 01:45:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G0UX1D8Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235045AbhDESVI (ORCPT + 99 others); Mon, 5 Apr 2021 14:21:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234552AbhDESVI (ORCPT ); Mon, 5 Apr 2021 14:21:08 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7603DC061756 for ; Mon, 5 Apr 2021 11:21:00 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id r22so1016423edq.9 for ; Mon, 05 Apr 2021 11:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ar3GZrsZAoxiwaAKwrinVn8bd57MclGABFFkui0oZ7I=; b=G0UX1D8YfamriSLn3tfIkyF1l768/z4Xvh1tKbjmEG1uLpzn1fx/8gSAJlyUta81or ruksmpskDrHNltCP+Q30iit0IzFAbdMRql6dB/3OOj047Lu2RLpkzkQTdQY4TKLjTjvE jj/H5F+n5ItEubcI5J/cr+W6LimqipbYprxlP+zTWVCOwbbjJMPb35fNoFZqlE3HQ1Yw rwRdq+vcPtf2CKnRBHcvEnXXtiSQBwdi11oRuM68qebKhKawmELORybovjV+kda2RuBj BSs2rnokh73Q73EhJFbrlOQZdDhZvjm9ZwIEkqxbQKk1dcz4DPjbyM4ezEFAePIQ3/ll frmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ar3GZrsZAoxiwaAKwrinVn8bd57MclGABFFkui0oZ7I=; b=ul3+QUhagmvmaA4fpWRdma5LzHmYD7cjUrKABieqEwCP7yWeBz6cAZHKkVGOlV7Tbm VQ8pVI6xiTzqLL3fgpUI/DyDtrr1ZEJQ6GhZzeW/gX3AmvIRSIOV23Y9wVrb42o1UOWC oKGMuc5agmMuKOITKOyjKXMJ0i3bdvgHDUvchvx5nOfGk/sVcDE6TZj6/Qo83zIht/Of +YkzvUjJDxcgj1uiAribXKLrWe63PmYmcwsfE3B8pU4aiMLxbxaQZlrKLYg9Eebkj56s kuP8FdPdsHtrlZLvz4anqMhxy6UZWmqNb1iJz2iy95HY8alPQObIdi9LlmJF+E3NQiGb Laog== X-Gm-Message-State: AOAM533soJkSZSJWOWWJA0IexTa+UcyyBFo9gdf/U/+V7qGr8tprHkVC mY+502z4S7+JyMq3fjwwiPiu5hPP0+8j0dCRDpg= X-Received: by 2002:a05:6402:518d:: with SMTP id q13mr33195428edd.313.1617646859199; Mon, 05 Apr 2021 11:20:59 -0700 (PDT) MIME-Version: 1.0 References: <20210404153311.1460106-1-yanfei.xu@windriver.com> <20210404153311.1460106-3-yanfei.xu@windriver.com> In-Reply-To: <20210404153311.1460106-3-yanfei.xu@windriver.com> From: Yang Shi Date: Mon, 5 Apr 2021 11:20:47 -0700 Message-ID: Subject: Re: [PATCH 2/2] mm: khugepaged: check MMF_DISABLE_THP ahead of iterating over vmas To: yanfei.xu@windriver.com Cc: Linux MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 4, 2021 at 8:33 AM wrote: > > From: Yanfei Xu > > We could check MMF_DISABLE_THP ahead of iterating over all of vma. > Otherwise if some mm_struct contain a large number of vma, there will > be amounts meaningless cpu cycles cost. > > BTW, drop an unnecessary cond_resched(), because there is a another > cond_resched() followed it and no consumed invocation between them. > > Signed-off-by: Yanfei Xu > --- > mm/khugepaged.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 2efe1d0c92ed..c293ec4a94ea 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -2094,6 +2094,8 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, > */ > if (unlikely(!mmap_read_trylock(mm))) > goto breakouterloop_mmap_lock; > + if (test_bit(MMF_DISABLE_THP, &mm->flags)) > + goto breakouterloop_mmap_lock; It is fine to check this flag. But mmap_lock has been acquired so you should jump to breakouterloop. > if (likely(!khugepaged_test_exit(mm))) > vma = find_vma(mm, khugepaged_scan.address); > > @@ -2101,7 +2103,6 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, > for (; vma; vma = vma->vm_next) { > unsigned long hstart, hend; > > - cond_resched(); I don't have a strong opinion for removing this cond_resched(). But IIUC khugepaged is a best effort job there is no harm to keep it IMHO. > if (unlikely(khugepaged_test_exit(mm))) { > progress++; > break; > -- > 2.27.0 > >