From patchwork Fri Jan 13 02:30:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Stevens X-Patchwork-Id: 13099666 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 BD1F0C54EBD for ; Fri, 13 Jan 2023 02:30:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D8D38E0002; Thu, 12 Jan 2023 21:30:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 061388E0001; Thu, 12 Jan 2023 21:30:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1C938E0002; Thu, 12 Jan 2023 21:30:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CCA598E0001 for ; Thu, 12 Jan 2023 21:30:27 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A056880A65 for ; Fri, 13 Jan 2023 02:30:27 +0000 (UTC) X-FDA: 80348196894.19.5360440 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf07.hostedemail.com (Postfix) with ESMTP id 024BE4000C for ; Fri, 13 Jan 2023 02:30:25 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=BAJ1luVg; spf=pass (imf07.hostedemail.com: domain of stevensd@chromium.org designates 209.85.214.177 as permitted sender) smtp.mailfrom=stevensd@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673577026; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=QQfFNObX23nRFgvMolgS2BLErvEkHc3/pg8u1wb3WfA=; b=4t/asvxAIRbUVvMdwzgV3Jya+pAZBfkZdCbmh4GOBiiEvti+tGmhYr9CoCHOlUb47wmNC+ EZ23opEAvpuR/WSPN70pWvHecKEiQcMW44BFfaZPcAHPAaJMC/HHFF52W6o/Dz85zUlv1d plU+10jyo9LcGvtAsNv/ynJUfA6TFbw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=BAJ1luVg; spf=pass (imf07.hostedemail.com: domain of stevensd@chromium.org designates 209.85.214.177 as permitted sender) smtp.mailfrom=stevensd@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673577026; a=rsa-sha256; cv=none; b=zHoRLf1yXVq2FvUkMpaPsRj+lcOTzotHHGmznWkKUEIrTSZ68dCoJzz6orIxn0PmR9n0xb ju6YN/9xcSjJPDSj+kslM3tBHUaLphezLtYCFf2vSz1gJYL3bEt3QSY8QOCKsdmUjh5It9 uKpSgK+tRlyvE+reqefdiN+S0sKjLDc= Received: by mail-pl1-f177.google.com with SMTP id w3so22088412ply.3 for ; Thu, 12 Jan 2023 18:30:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QQfFNObX23nRFgvMolgS2BLErvEkHc3/pg8u1wb3WfA=; b=BAJ1luVg89O7aQsrrfyrax3G1mJpE7vfoxwJhRKFblxcsG0wjjfmfYUop26Yz6jVAZ AOHm2vRIrqkYh4PVuaRhUMPDEXHJ1p+EkUfcjVOZ7j/FCG3w+x6uKN5Amc9nOyMdCDId Y7/H0nxdJeaM4vn9UnWo3LNO9/nG8tP+nz/cs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QQfFNObX23nRFgvMolgS2BLErvEkHc3/pg8u1wb3WfA=; b=HKDCMkNtMTxbKApeJQnVDX95NK1KArdL2C8C0FrC94YfPxB7PHzxMCa0VnvJXp4blZ pBgkf1BVb4ECDMi2XiAyaw3bN3XByZ0PXgjtZZRpnA5iN+XXwnJU7YWqH90Hir/M1e6B XnnKfgz8lzBMNtECABxH9e65149YFO+TmagngL7V0vnLN4PeHAtqp1C+IYtAFNJbllRK Pb4pltOQhH1TIPxcZL79KxcsV9noKGxQjEBrfpfsHpxm+Sv3G7Es2D2w0SuhzFBzQEpd PTE+GNXN45EhaiLTp4wM4amNdRBsCUqq4PEeAbz+KMBayiFNXSK01MJn7MYDZAGqgpVC c/LQ== X-Gm-Message-State: AFqh2kqW+Z+dy+QuyuhztjOS/f/SnhpkbPqNJUyaM0KuCfa5YtZzc+Mg AZqD1Sh/4wDmnJ5cxc9/ICLLRLRkmsok74bY X-Google-Smtp-Source: AMrXdXvipi4l4shvABg1HT3wr+bB85ljuZPI0YibuNZhd5rMpcphNImIBpPGFeLQB0CC73FoNj6PWA== X-Received: by 2002:a17:902:c50e:b0:194:586a:77ba with SMTP id o14-20020a170902c50e00b00194586a77bamr6311342plx.52.1673577024325; Thu, 12 Jan 2023 18:30:24 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:3a37:fd1a:48c:42e5]) by smtp.gmail.com with UTF8SMTPSA id q1-20020a170902dac100b00185402cfedesm12854409plx.246.2023.01.12.18.30.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Jan 2023 18:30:23 -0800 (PST) From: David Stevens X-Google-Original-From: David Stevens To: linux-mm@kvack.org Cc: Hugh Dickins , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, David Stevens Subject: [PATCH] mm: fix khugepaged with shmem_enabled=advise Date: Fri, 13 Jan 2023 11:30:11 +0900 Message-Id: <20230113023011.1784015-1-stevensd@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 8ra9jea3rkq39zq6giyfpr3hqxgbp9ou X-Rspamd-Queue-Id: 024BE4000C X-HE-Tag: 1673577025-291045 X-HE-Meta: U2FsdGVkX18GU2ZzbfMIZ6nbdlUBzsXl/G3VD+viVBilizqsGS7aov/V68bBd9a69o7CImyJAGhQj9nRZZbX38wAdTKPK3arw41o6hCIiCMZUKY2Y7GG5rXHRkMCbxBdYq5VX4mudGVUj0WKCWT4IHawdXmW3rl8LsXYch0KwNHScD1fXOZ+qT3isJTbk+c/JxgQBdJAoLdjw7lYesyqk70gMaXIUHPb4o7tRbOYDGOStOdwtbmqrnG5CW8l3Qnp/upPVBrPpbSaIOVy0BnSoyur0MLamNszcXNkqN9Twj+1GNMnU9kp5II6sp7TkhMbebKTNV6BIJ9WABlSCdoYGx0G7694a7cUAcx9LTjYeGJwyjmw3VopTC8RHtiaYCjm0Jvg6Mv2ouKc//gLlg8Eej7KHSzB2j2cBXVvqgqmrFbf5mRay5rYo+7V1wK4ElDN/+tsZ0KgAnvpr8LSr4b+h7RUB2LZqX2SS4mpMt9DKadd1PJVaXg3onJ+d9W4VXz2Ag/4W2MSyJPXynrsR2+9mSzV1XLPiSMCjtOeD8YYMiHlD+8DSprelK465vTFj+jLznsFNxdzw8dRqyI13n7IKHt8sqN0zN+SppYx/04X3iJ0Qo70iU3qU1gA4juDZhCebQYiS1taN+CCPN4QbgQh4McF5FzMEsIlPkd41UMkw1ZGGcpNazfBbdyAo/7Mq02HPlgR8jOTuGrf7RHATs6ldxziBUs1wxVm6/jk08lr0heE3FQG1+ol/HA3tuByQEx5Odbc+rBb9WZpQ147d1JSHYs+5ECIqVvf7+AGfeX99QJdEuMjrifM4BE/3KCDts3h64mPnY9XlUmr/EhdXxKxF6uLeeFUOzUYcA0I+ChWvchVilx9xKMH6Hn9/VZfbEtj6w4vcO31Ga4faGwJmihq5APCaT2oZWE/BZQz1ay5Ee3JB6okh0qdwH3CeYsaB1UGurbQ6ZZ/4L1WWR06/9Y 3fjGzDVF ew2PdeLCbthf0ByjPm2wDc1d8DB438tW9eScAEjMoWgIbiWM+T12YMXZvv5nFchOTqLM6eeQjAqsFtnGOaxi1gvXtz9CeyFh9jVAx 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: From: David Stevens Pass vm_flags as a parameter to shmem_is_huge, rather than reading the flags from the vm_area_struct in question. This allows the updated flags from hugepage_madvise to be passed to the check, which is necessary because madvise does not update the vm_area_struct's flags until after hugepage_madvise returns. This fixes in issue when shmem_enabled=madvise, where MADV_HUGEPAGE on shmem was not able to register the mm_struct with khugepaged. Prior to cd89fb065099, the mm_struct was registered by MADV_HUGEPAGE regardless of the value of shmem_enabled (which was only checked when scanning vmas). Fixes: cd89fb065099 ("mm,thp,shmem: make khugepaged obey tmpfs mount flags") Signed-off-by: David Stevens --- include/linux/shmem_fs.h | 10 ++-------- mm/huge_memory.c | 3 ++- mm/shmem.c | 18 +++++++++--------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index d500ea967dc7..d09d54be4ffd 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -92,14 +92,8 @@ extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end); int shmem_unuse(unsigned int type); -extern bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode, - pgoff_t index, bool shmem_huge_force); -static inline bool shmem_huge_enabled(struct vm_area_struct *vma, - bool shmem_huge_force) -{ - return shmem_is_huge(vma, file_inode(vma->vm_file), vma->vm_pgoff, - shmem_huge_force); -} +extern bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force, + struct mm_struct *mm, unsigned long vm_flags); extern unsigned long shmem_swap_usage(struct vm_area_struct *vma); extern unsigned long shmem_partial_swap_usage(struct address_space *mapping, pgoff_t start, pgoff_t end); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index abe6cfd92ffa..56bbaa931f97 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -119,7 +119,8 @@ bool hugepage_vma_check(struct vm_area_struct *vma, unsigned long vm_flags, * own flags. */ if (!in_pf && shmem_file(vma->vm_file)) - return shmem_huge_enabled(vma, !enforce_sysfs); + return shmem_is_huge(file_inode(vma->vm_file), vma->vm_pgoff, + !enforce_sysfs, vma->vm_mm, vm_flags); /* Enforce sysfs THP requirements as necessary */ if (enforce_sysfs && diff --git a/mm/shmem.c b/mm/shmem.c index c301487be5fb..1e515390b831 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -468,15 +468,14 @@ static bool shmem_confirm_swap(struct address_space *mapping, static int shmem_huge __read_mostly = SHMEM_HUGE_NEVER; -bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode, - pgoff_t index, bool shmem_huge_force) +bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force, + struct mm_struct *mm, unsigned long vm_flags) { loff_t i_size; if (!S_ISREG(inode->i_mode)) return false; - if (vma && ((vma->vm_flags & VM_NOHUGEPAGE) || - test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))) + if (mm && ((vm_flags & VM_NOHUGEPAGE) || test_bit(MMF_DISABLE_THP, &mm->flags))) return false; if (shmem_huge_force) return true; @@ -495,7 +494,7 @@ bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode, return true; fallthrough; case SHMEM_HUGE_ADVISE: - if (vma && (vma->vm_flags & VM_HUGEPAGE)) + if (mm && (vm_flags & VM_HUGEPAGE)) return true; fallthrough; default: @@ -678,8 +677,8 @@ static long shmem_unused_huge_count(struct super_block *sb, #define shmem_huge SHMEM_HUGE_DENY -bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode, - pgoff_t index, bool shmem_huge_force) +bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force, + struct mm_struct *mm, unsigned long vm_flags) { return false; } @@ -1070,7 +1069,7 @@ static int shmem_getattr(struct user_namespace *mnt_userns, STATX_ATTR_NODUMP); generic_fillattr(&init_user_ns, inode, stat); - if (shmem_is_huge(NULL, inode, 0, false)) + if (shmem_is_huge(inode, 0, false, NULL, 0)) stat->blksize = HPAGE_PMD_SIZE; if (request_mask & STATX_BTIME) { @@ -1911,7 +1910,8 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, return 0; } - if (!shmem_is_huge(vma, inode, index, false)) + if (!shmem_is_huge(inode, index, false, + vma ? vma->vm_mm : NULL, vma ? vma->vm_flags : 0)) goto alloc_nohuge; huge_gfp = vma_thp_gfp_mask(vma);