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 70FA1ECAAD8 for ; Fri, 16 Sep 2022 22:23:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD0898D0002; Fri, 16 Sep 2022 18:23:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B804F8D0001; Fri, 16 Sep 2022 18:23:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A47FE8D0002; Fri, 16 Sep 2022 18:23:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 950278D0001 for ; Fri, 16 Sep 2022 18:23:04 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6AC5D1C6F79 for ; Fri, 16 Sep 2022 22:23:04 +0000 (UTC) X-FDA: 79919375088.19.2D37A57 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf16.hostedemail.com (Postfix) with ESMTP id 25B3A1800A4 for ; Fri, 16 Sep 2022 22:23:03 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id s18so16735212plr.4 for ; Fri, 16 Sep 2022 15:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=y8Pxj/xcXZKxaO0043xI3pHADs/M/D9Ct7+T8iYZvS4=; b=n9byK+Xla98dDRkSNwgCOutFwTs7hhhydnNxVaBpdmTs6Lvb6AOE1y9SaGbZjgNluK ZJxAqBF3vpa5dnDW1mDbTEHCk5WjUEo9SdprIYkPJQoC0n6iiuiXJJREVERoo9zvR9ZF OMzdTS5XeYPA7rOBFmqW5DVE5E7Lw1VlZJ2cMw8uRd2Hu5n4dnp8GeIRUQ02DQFz8aDb ABRlAX62ZwLpvnlbKgI5rOXzAlw2BIIqJJSA/mKvq5LvyViayIX7DuJz8CRxTFAC6DmK FNJ9t/HdMyYD6BSAQJkhoM6tYqvOBg69kqdRz6to9O+KNw+qiOJ9PHB0p/l/qFvxUrIk 7WKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=y8Pxj/xcXZKxaO0043xI3pHADs/M/D9Ct7+T8iYZvS4=; b=4M+zsR7UxDv4wEJYA5eIKMwbndJ/P1FoFGm7+J5KJ3/mrvSIuNaOWPpkToBn0ybkPq wqjD5gKjWSJG0iBrtpYQSaDEU++1a9EvULNRiQxIUspxTDSbVOW/Te3Xw5BzruoycuE4 3UufWn+A8Ets2VIW/DAaeuoj4OOZjHTwhs3qzeVC3zJrEq8z8u4l1TB3s/aK8r0SMgTm n9wN1fbqox/Xe55kZ8ygdAl5wmUt825ur2FVI3rnCsNG+tFbzczeXW2xIaVlbFlfruYr R7yBUP16rM2M9i5U0T0qCXpit53Uk42Io0yuAkz6kY/ceWtUyUYYjlOq2/KMw8r699NV pfBA== X-Gm-Message-State: ACrzQf05GmgbSmmYDKghvet8OCUMQqql/4kFIwupvUcpwehcLRFVFPaA dfKD1ph4iqNOJkyl1RnCzCG9iw== X-Google-Smtp-Source: AMsMyM79sV92fDMUai7ZIkQsZ8oz4lklJoYx1OUgoInKmlpSZH8mKJxxpNgGVFSaW9VI9+OTX7SRBw== X-Received: by 2002:a17:90a:8992:b0:202:f6b1:ef25 with SMTP id v18-20020a17090a899200b00202f6b1ef25mr18511741pjn.239.1663366982640; Fri, 16 Sep 2022 15:23:02 -0700 (PDT) Received: from google.com (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id l16-20020a170903121000b00178865002a2sm1332215plh.195.2022.09.16.15.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 15:23:02 -0700 (PDT) Date: Fri, 16 Sep 2022 15:22:58 -0700 From: Zach O'Keefe To: Yang Shi Cc: linux-mm@kvack.org, Andrew Morton , linux-api@vger.kernel.org, Axel Rasmussen , James Houghton , Hugh Dickins , Miaohe Lin , David Hildenbrand , David Rientjes , Matthew Wilcox , Pasha Tatashin , Peter Xu , Rongwei Wang , SeongJae Park , Song Liu , Vlastimil Babka , Chris Kennelly , "Kirill A. Shutemov" , Minchan Kim , Patrick Xia Subject: Re: [PATCH mm-unstable v3 01/10] mm/shmem: add flag to enforce shmem THP in hugepage_vma_check() Message-ID: References: <20220907144521.3115321-1-zokeefe@google.com> <20220907144521.3115321-2-zokeefe@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=n9byK+Xl; spf=pass (imf16.hostedemail.com: domain of zokeefe@google.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=zokeefe@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663366984; a=rsa-sha256; cv=none; b=aeBHQu30cRkoB/dyJgC7zsd3cUB2T6jiKd1UIzbrOvRifiy/E7LJgeVVY8y2g8QTHuNHGe CpzAt6ZxcvEcA/SohJfUOFn69Ntkrc1gVzq2jHO8rSdGrywHu2IqTw9p2wBhaT/JXFhH+M 1Jd03T+M9uOAPF9kMy5Qx7H8g1CoFWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663366984; 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=y8Pxj/xcXZKxaO0043xI3pHADs/M/D9Ct7+T8iYZvS4=; b=A6+mzvzk3iv19DZx2IqHuTfrQPys/f31GjIs6s+zg1gLeUNQyJKavTOhIoyIgMdHcUwK5A 1mCpl3b0po0UYJ8oMR+tuxTQ02FCLJ1uFOVfVKhY55hd/bbvIff6sUA3iK7dNI8gWwXQgM Z9X02nlD0BsTC1Q4jkAurhShzKsmXpc= X-Rspamd-Queue-Id: 25B3A1800A4 X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=n9byK+Xl; spf=pass (imf16.hostedemail.com: domain of zokeefe@google.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=zokeefe@google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: kzfbmeymwritmx6w5q1psqdd7hs9fsgj X-Rspamd-Server: rspam04 X-HE-Tag: 1663366983-280220 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 Sep 16 10:46, Yang Shi wrote: > On Wed, Sep 7, 2022 at 7:45 AM Zach O'Keefe wrote: > > > > Extend 'mm/thp: add flag to enforce sysfs THP in > > hugepage_vma_check()' to shmem, allowing callers to ignore > > /sys/kernel/transparent_hugepage/shmem_enabled and tmpfs huge= mount. > > > > This is intended to be used by MADV_COLLAPSE, and the rationale is > > analogous to the anon/file case: MADV_COLLAPSE is not coupled to > > directives that advise the kernel's decisions on when THPs should be > > considered eligible. shmem/tmpfs always claims large folio support, > > regardless of sysfs or mount options. > > > > Signed-off-by: Zach O'Keefe > > Reviewed-by: Yang Shi > > A nit below... > Hey Yang, Thanks for taking the time as always :) > > --- > > include/linux/shmem_fs.h | 10 ++++++---- > > mm/huge_memory.c | 2 +- > > mm/shmem.c | 18 +++++++++--------- > > 3 files changed, 16 insertions(+), 14 deletions(-) > > > > diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h > > index f24071e3c826..d500ea967dc7 100644 > > --- a/include/linux/shmem_fs.h > > +++ b/include/linux/shmem_fs.h > > @@ -92,11 +92,13 @@ 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); > > -static inline bool shmem_huge_enabled(struct vm_area_struct *vma) > > +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); > > + return shmem_is_huge(vma, file_inode(vma->vm_file), vma->vm_pgoff, > > + shmem_huge_force); > > } > > extern unsigned long shmem_swap_usage(struct vm_area_struct *vma); > > extern unsigned long shmem_partial_swap_usage(struct address_space *mapping, > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > index 7fa74b9749a6..53d170dac332 100644 > > --- a/mm/huge_memory.c > > +++ b/mm/huge_memory.c > > @@ -119,7 +119,7 @@ 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); > > + return shmem_huge_enabled(vma, !enforce_sysfs); > > > > /* Enforce sysfs THP requirements as necessary */ > > if (enforce_sysfs && > > diff --git a/mm/shmem.c b/mm/shmem.c > > index 99b7341bd0bf..47c42c566fd1 100644 > > --- a/mm/shmem.c > > +++ b/mm/shmem.c > > @@ -461,20 +461,20 @@ 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_is_huge(struct vm_area_struct *vma, struct inode *inode, > > + pgoff_t index, bool shmem_huge_force) > > { > > loff_t i_size; > > > > if (!S_ISREG(inode->i_mode)) > > return false; > > - if (shmem_huge == SHMEM_HUGE_DENY) > > - return false; > > if (vma && ((vma->vm_flags & VM_NOHUGEPAGE) || > > test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))) > > return false; > > - if (shmem_huge == SHMEM_HUGE_FORCE) > > + if (shmem_huge == SHMEM_HUGE_FORCE || shmem_huge_force) > > shmem_huge_force means ignore all sysfs and mount options, so it seems > better to have it test explicitly IMHO, like: > > if (shmem_huge_force) > return true; > > if (shmem_huge == SHMEM_HUGE_FORCE) > return true; > > This makes sense to me - a little bit cleaner / more direct. Thanks for the suggestion. Thank you again, Zach > > return true; > > + if (shmem_huge == SHMEM_HUGE_DENY) > > + return false; > > > > switch (SHMEM_SB(inode->i_sb)->huge) { > > case SHMEM_HUGE_ALWAYS: > > @@ -669,8 +669,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_is_huge(struct vm_area_struct *vma, struct inode *inode, > > + pgoff_t index, bool shmem_huge_force) > > { > > return false; > > } > > @@ -1056,7 +1056,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)) > > + if (shmem_is_huge(NULL, inode, 0, false)) > > stat->blksize = HPAGE_PMD_SIZE; > > > > if (request_mask & STATX_BTIME) { > > @@ -1888,7 +1888,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, > > return 0; > > } > > > > - if (!shmem_is_huge(vma, inode, index)) > > + if (!shmem_is_huge(vma, inode, index, false)) > > goto alloc_nohuge; > > > > huge_gfp = vma_thp_gfp_mask(vma); > > -- > > 2.37.2.789.g6183377224-goog > >