From mboxrd@z Thu Jan 1 00:00:00 1970 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 8BB70C43334 for ; Sat, 11 Jun 2022 00:28:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94B366B00A7; Fri, 10 Jun 2022 20:28:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FA526B00A8; Fri, 10 Jun 2022 20:28:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79B196B00A9; Fri, 10 Jun 2022 20:28:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6B8C16B00A7 for ; Fri, 10 Jun 2022 20:28:31 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 30D82120307 for ; Sat, 11 Jun 2022 00:28:31 +0000 (UTC) X-FDA: 79564068822.05.4B45684 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by imf13.hostedemail.com (Postfix) with ESMTP id 9921E2006E for ; Sat, 11 Jun 2022 00:28:30 +0000 (UTC) Received: by mail-lf1-f45.google.com with SMTP id y32so860474lfa.6 for ; Fri, 10 Jun 2022 17:28:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zwlnuv7EIAz5vX1ar0mQBEL2DsqcUV9zFmlfRt4dEpQ=; b=HWkmG+GxSfTVVpNBHrzpod1cQ9Gfkz7mAnPjHA5tZA+I27Gp8SysZtcuaXql4fjZD7 AZ9vSlsswLNqBAEpqBVRqcGbtDXuXPqkGT/DFb1wPtNldb+O1oDKEvurghO8FLzrhcTP UuHJ7KntEIfq7Dfb+duYuRHrsihqb9haG3KoFpLfZ3DrLg8eux5cnX0akA661ohemWfC vaenhEWIWKmm3jV3mDkb/MR8C4k331hwX3amypn48ZTWJRhTJXol2bEM5MZgcB/vrpg5 sqchCnNrdi6FaM5Mn54HVMga6nR7JHBcAzPS8YVJG2uc336x+ux7hYYUfdvm/Tj98pPs Oe/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zwlnuv7EIAz5vX1ar0mQBEL2DsqcUV9zFmlfRt4dEpQ=; b=yctkckaubg8d/7oHa7Ac+9sq4Dzopm+WTgO/ZwbkS4Dn9UqH6e7ctSOo7C+9SAsHdo 1sQTypQWA7SoodZXgeRfcEx5zD3aR3bPk+F4ip3D0HzHf0WMxtdQ6guTnLzgrdwmwWmV WUzrWCV4XiDUZBsvmMsQTjQqXo2/47q1iKRsh/7OYCB341ptFgAr7BEJEckoHHv2KJ8V xTt4dpSFT51iK4oViAsdJWfL5hWbqCxP1zZ7Ingl4oZ4OK8UPA0gstS/hBIJgWY9mUM6 ZWUyxBJFEd6FOZGlaASGsQTgmO/mxOyKQ8gm6brljC11LcIbJ31PIUt+bE7DezsDoLPk nSBg== X-Gm-Message-State: AOAM532Ip6+yLJHWBYwxmT9PiKCOD4CXzZ64YQGQEp40tJn/kvmTNYBG leGr/bNynhUHDL6WNzRpttXCjlLC2tj20Z4RKs1aRg== X-Google-Smtp-Source: ABdhPJxOfDAnHfVNyokmeSEifDSC/DsxsMpIf/vkKH2wLwgABKE5etARtTKUGen5GoZQVXp/xjsedj84B/MQZoCp7NA= X-Received: by 2002:ac2:55b1:0:b0:478:ec0b:b784 with SMTP id y17-20020ac255b1000000b00478ec0bb784mr28751679lfg.60.1654907308511; Fri, 10 Jun 2022 17:28:28 -0700 (PDT) MIME-Version: 1.0 References: <20220606214414.736109-1-shy828301@gmail.com> <20220606214414.736109-5-shy828301@gmail.com> In-Reply-To: From: "Zach O'Keefe" Date: Fri, 10 Jun 2022 17:27:51 -0700 Message-ID: Subject: Re: [v3 PATCH 4/7] mm: khugepaged: use transhuge_vma_suitable replace open-code To: Yang Shi Cc: Vlastimil Babka , "Kirill A. Shutemov" , Matthew Wilcox , Andrew Morton , Linux MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654907310; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zwlnuv7EIAz5vX1ar0mQBEL2DsqcUV9zFmlfRt4dEpQ=; b=0fB3zZCubgB99ZN1XEpgWtkqolUOAFeVWYlLzzfK0RHmGUvDrHBG3xw9+vqvIHAIbAS+N+ oSa2fZcykZtbCR26QNKhyBJwjIzERGxkA0vQHH6ppa4Ol4/ePnDddh/nbhvQArs/gaKUex tfvKqMm74MYDp/5EoIhQHpCa/F0BYew= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654907310; a=rsa-sha256; cv=none; b=yLd7y058w8OkryqYx8ahM+KjSQePzeTBz5y7IPabXpKTPc4y6z2JVeevlFNDSPN6wDo1iL nZiHxFg3e1D7TpN3vdIBybWp89UhqrgkInYzfC5V7WNwRyQrc8T73MTMsqFlfgAdvWPx7V U2i6b1IpGpDp30P1YUjPBNEwo2gtcPc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=HWkmG+Gx; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of zokeefe@google.com designates 209.85.167.45 as permitted sender) smtp.mailfrom=zokeefe@google.com X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=HWkmG+Gx; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of zokeefe@google.com designates 209.85.167.45 as permitted sender) smtp.mailfrom=zokeefe@google.com X-Rspamd-Server: rspam03 X-Stat-Signature: y13eiadfe8go5qfkht4p9a76f1jthob1 X-Rspamd-Queue-Id: 9921E2006E X-HE-Tag: 1654907310-389053 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: On Fri, Jun 10, 2022 at 3:04 PM Yang Shi wrote: > > On Fri, Jun 10, 2022 at 9:59 AM Yang Shi wrote: > > > > On Thu, Jun 9, 2022 at 6:52 PM Zach O'Keefe wrote: > > > > > > On Mon, Jun 6, 2022 at 2:44 PM Yang Shi wrote: > > > > > > > > The hugepage_vma_revalidate() needs to check if the address is still in > > > > the aligned HPAGE_PMD_SIZE area of the vma when reacquiring mmap_lock, > > > > but it was open-coded, use transhuge_vma_suitable() to do the job. And > > > > add proper comments for transhuge_vma_suitable(). > > > > > > > > Signed-off-by: Yang Shi > > > > --- > > > > include/linux/huge_mm.h | 6 ++++++ > > > > mm/khugepaged.c | 5 +---- > > > > 2 files changed, 7 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h > > > > index a8f61db47f2a..79d5919beb83 100644 > > > > --- a/include/linux/huge_mm.h > > > > +++ b/include/linux/huge_mm.h > > > > @@ -128,6 +128,12 @@ static inline bool transhuge_vma_size_ok(struct vm_area_struct *vma) > > > > return false; > > > > } > > > > > > > > +/* > > > > + * Do the below checks: > > > > + * - For non-anon vma, check if the vm_pgoff is HPAGE_PMD_NR aligned. > > > > + * - For all vmas, check if the haddr is in an aligned HPAGE_PMD_SIZE > > > > + * area. > > > > + */ > > > > > > AFAIK we aren't checking if vm_pgoff is HPAGE_PMD_NR aligned, but > > > rather that linear_page_index(vma, round_up(vma->vm_start, > > > HPAGE_PMD_SIZE)) is HPAGE_PMD_NR aligned within vma->vm_file. I was > > > > Yeah, you are right. > > > > > pretty confused about this (hopefully I have it right now - if not - > > > case and point :) ), so it might be a good opportunity to add some > > > extra commentary to help future travelers understand why this > > > constraint exists. > > > > I'm not fully sure I understand this 100%. I think this is related to > > how page cache is structured. I will try to add more comments. > > How's about "The underlying THP is always properly aligned in page > cache, but it may be across the boundary of VMA if the VMA is > misaligned, so the THP can't be PMD mapped for this case." I could certainly still be wrong / am learning here - but I *thought* the reason for this check was to make sure that the hugepage to-be-collapsed is naturally aligned within the file (since, AFAIK, without this constraint, different mm's might have different ideas about where hugepages in the file should be). > > > > > > > > Also I wonder while we're at it if we can rename this to > > > transhuge_addr_aligned() or transhuge_addr_suitable() or something. > > > > I think it is still actually used to check vma. > > > > > > > > Otherwise I think the change is a nice cleanup. > > > > > > > static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, > > > > unsigned long addr) > > > > { > > > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > > > > index 7a5d1c1a1833..ca1754d3a827 100644 > > > > --- a/mm/khugepaged.c > > > > +++ b/mm/khugepaged.c > > > > @@ -951,7 +951,6 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, > > > > struct vm_area_struct **vmap) > > > > { > > > > struct vm_area_struct *vma; > > > > - unsigned long hstart, hend; > > > > > > > > if (unlikely(khugepaged_test_exit(mm))) > > > > return SCAN_ANY_PROCESS; > > > > @@ -960,9 +959,7 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, > > > > if (!vma) > > > > return SCAN_VMA_NULL; > > > > > > > > - hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; > > > > - hend = vma->vm_end & HPAGE_PMD_MASK; > > > > - if (address < hstart || address + HPAGE_PMD_SIZE > hend) > > > > + if (!transhuge_vma_suitable(vma, address)) > > > > return SCAN_ADDRESS_RANGE; > > > > if (!hugepage_vma_check(vma, vma->vm_flags)) > > > > return SCAN_VMA_CHECK; > > > > -- > > > > 2.26.3 > > > > > > > >