From patchwork Tue May 2 23:56:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13229395 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 431C7C77B78 for ; Tue, 2 May 2023 23:56:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6B8E6B0075; Tue, 2 May 2023 19:56:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D1B956B0078; Tue, 2 May 2023 19:56:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0AD36B007B; Tue, 2 May 2023 19:56:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by kanga.kvack.org (Postfix) with ESMTP id A44C16B0075 for ; Tue, 2 May 2023 19:56:32 -0400 (EDT) Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-b922aa3725fso8837984276.0 for ; Tue, 02 May 2023 16:56:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683071792; x=1685663792; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=VTfG7F65o0oFg67+X6WxPMuxEdDT/M2lH43dZvx+e04=; b=c02k0bI/rvnso3tOW89PkXkbHVcOqnqtz/00RV+zglFTuL3AV5vA/JoKSNHXrhMxG9 +LZbpUPZXFVoVQSziSRHpEdmft/gnRjoj88wWvi7L3QqqtQLPo/bTT9KlqUe7FEZrkmT kGRk8qzYo+aZdpDYL+VamZFw9iAGIVJRiPI6zv15Q2xrkqDjBi8jP9NS7Dbu8bdZK2F7 KEJ2wKk3UtPulyyjlsZpP3fIL2NFuQldZ2lmIa+b3C2DxvEaMQUrhg17UOZSdvvjzx+B ZPjjwHFYiiaZmKrHPUjRp9V+c1NbfhSytafwBjb3vd+XSDdVfZYD8U0Yn4pTZyIRQ4R/ 2xUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683071792; x=1685663792; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=VTfG7F65o0oFg67+X6WxPMuxEdDT/M2lH43dZvx+e04=; b=OreH1vss4C64JS3f6dS6ANvBy3aqI19XAqSHWXZzntBqQGFzM3hSd0Xvu1tQf0zL0C wzLYvb5tT0ymF3fy4ERoh29H8px+ntqBa43NwypqDb2fZYM8MFlwRzpT9/36DnDsPoi4 B7pnEuJImTC8r2OFPGq4vL6uV8+ZNsIcPRuNtwB1XptEwlCniZz19RpY83ys9C65/ZE/ lVZB0QLi5ssLH+KpBId86l1kRGMc3O2LYfQXkzU6TZs4aeSn9ffZpaSyqWwwseMLa3zo h6bRpN2D4hpJ0g8lbyPRyCFIHFqfSzKR9Ke5h4ZdU/RwbX8nY4a/it/t+J8Yp+ctKxwB JAwA== X-Gm-Message-State: AC+VfDzfF6s0rEIqR1kCLkV822o8axkwBCk9rTVqzVyHiwnwK5bEXNl5 1rFFwQwO8mf0J4ayloX8l0uBPsYuoxV+qLC/JA== X-Google-Smtp-Source: ACHHUZ48PCyKBqXvRaNrp+9TLDB21cvKYwuAMRuGxA5xQuupd0isU49vzdMgfnH965aUyYs8rAuSZBdYGckJj4CLgw== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a25:50c1:0:b0:b9d:94eb:fa4c with SMTP id e184-20020a2550c1000000b00b9d94ebfa4cmr7441408ybb.6.1683071792300; Tue, 02 May 2023 16:56:32 -0700 (PDT) Date: Tue, 2 May 2023 23:56:22 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230502235622.3652586-1-ackerleytng@google.com> Subject: [PATCH] fs: hugetlbfs: Set vma policy only when needed for allocating folio From: Ackerley Tng To: akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mike.kravetz@oracle.com, muchun.song@linux.dev, willy@infradead.org, sidhartha.kumar@oracle.com, jhubbard@nvidia.com Cc: vannapurve@google.com, erdemaktas@google.com, Ackerley Tng 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: Calling hugetlb_set_vma_policy() later avoids setting the vma policy and then dropping it on a page cache hit. Signed-off-by: Ackerley Tng Reviewed-by: Mike Kravetz --- fs/hugetlbfs/inode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index f640cff1bbce..380b1cd6c93f 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -833,9 +833,6 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, break; } - /* Set numa allocation policy based on index */ - hugetlb_set_vma_policy(&pseudo_vma, inode, index); - /* addr is the offset within the file (zero based) */ addr = index * hpage_size; @@ -846,7 +843,6 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, /* See if already present in mapping to avoid alloc/free */ if (filemap_has_folio(mapping, index)) { mutex_unlock(&hugetlb_fault_mutex_table[hash]); - hugetlb_drop_vma_policy(&pseudo_vma); continue; } @@ -858,6 +854,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, * folios in these areas, we need to consume the reserves * to keep reservation accounting consistent. */ + hugetlb_set_vma_policy(&pseudo_vma, inode, index); folio = alloc_hugetlb_folio(&pseudo_vma, addr, 0); hugetlb_drop_vma_policy(&pseudo_vma); if (IS_ERR(folio)) {