From patchwork Tue Aug 17 08:06:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12440773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 533B3C4338F for ; Tue, 17 Aug 2021 08:06:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E177260295 for ; Tue, 17 Aug 2021 08:06:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E177260295 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7F5B98D0001; Tue, 17 Aug 2021 04:06:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A4BA6B0073; Tue, 17 Aug 2021 04:06:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66CE98D0001; Tue, 17 Aug 2021 04:06:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0087.hostedemail.com [216.40.44.87]) by kanga.kvack.org (Postfix) with ESMTP id 498AC6B0072 for ; Tue, 17 Aug 2021 04:06:26 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E8DE92203B for ; Tue, 17 Aug 2021 08:06:25 +0000 (UTC) X-FDA: 78483840330.07.F656390 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) by imf19.hostedemail.com (Postfix) with ESMTP id A1AE6B008C63 for ; Tue, 17 Aug 2021 08:06:25 +0000 (UTC) Received: by mail-qv1-f43.google.com with SMTP id c14so6815315qvs.9 for ; Tue, 17 Aug 2021 01:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=O9s4DPf1EPyNh/heSsyriAAWi5ei5uslG+fh5iqpDHM=; b=cPdYKEewpU4jCNb8wD3BV92DYOU1v3r7O6UXdBAqUA0jBAcX2Eb69vIKyir7IuKIuS VEYU7UFk/+56re91uN29M8zzUUMSeznJT69W2RwnfVFR2xVnZ6b9KeKrnniGWWTGqtvF qtFlja3Z7RebrnzlTDc1i1CLy+RETxEVVSUBDxKeRIt/wwM2idapdUdqNxkh30zVOXmQ ONlY7AYGaRXdVN4L4kNZYDyuCuT99wM4j3h+T99pMiOwZKIPQWUMpRClOPv3LGo5XLCq MFFtAwNPKcBP7v8wx2EHGfNhaEq1cEFSYvJrk/AL/9c1pVwUn7KU/BRCaLtf3ibh1/gA yM0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=O9s4DPf1EPyNh/heSsyriAAWi5ei5uslG+fh5iqpDHM=; b=TyhUODdijbIZJnkL8VBoC+Lic8GcdawLzz+OqVhGsE+9xSoe2PyGY3TDkKcDCjGiFQ gmcWRSQNasomP3aOY+XBbnOcmdt5+HqxobnrvFinlN3jebox69KtrNtvFH3vTGFqgHzq j+ac0MJLxcPVFz1tpvITXTm/eokiJ1OJcM9DVP6+dgmLw7wlvVdiERhyQVvg6WpHgeix smQ/8ELAw1mB5GLwCfehmOmxDeIa58zBb4sHZWOsTWwKXLCdZIa83NfWuun3MDoEk84c I7TCuGsB+xTBZUGcZxOi2wGxhfBLnU/OBrPuLPrld54MRPAVrxM+86WIS673iDTqLd3l meng== X-Gm-Message-State: AOAM532uAxiUpT7XBnwU3aB8dmraxTKlOo+8lthIemU+mx0Sg/SGqBa4 gWBEMPnoJjKXeIVEG+6sQLyzow== X-Google-Smtp-Source: ABdhPJwWtCeso79FFWIOIARYcHD6ce/4VjU95Aj+MM9ocNEv+dznWyCx4fajWaOxbQb+hvx/ZFX7aA== X-Received: by 2002:a0c:f20c:: with SMTP id h12mr2013192qvk.56.1629187584811; Tue, 17 Aug 2021 01:06:24 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id p187sm871565qkd.101.2021.08.17.01.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 01:06:24 -0700 (PDT) Date: Tue, 17 Aug 2021 01:06:22 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Shakeel Butt , "Kirill A. Shutemov" , Yang Shi , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/9] huge tmpfs: fix fallocate(vanilla) advance over huge pages In-Reply-To: Message-ID: <16201bd2-70e-37e2-e89b-5f929430da@google.com> References: MIME-Version: 1.0 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=cPdYKEew; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of hughd@google.com designates 209.85.219.43 as permitted sender) smtp.mailfrom=hughd@google.com X-Stat-Signature: u8kqjci4r7kc5a1pk5yxoe1hu3ynqupi X-Rspamd-Queue-Id: A1AE6B008C63 X-Rspamd-Server: rspam05 X-HE-Tag: 1629187585-32688 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: shmem_fallocate() goes to a lot of trouble to leave its newly allocated pages !Uptodate, partly to identify and undo them on failure, partly to leave the overhead of clearing them until later. But the huge page case did not skip to the end of the extent, walked through the tail pages one by one, and appeared to work just fine: but in doing so, cleared and Uptodated the huge page, so there was no way to undo it on failure. And by setting Uptodate too soon, it messed up both its nr_falloced and nr_unswapped counts, so that the intended "time to give up" heuristic did not work at all. Now advance immediately to the end of the huge extent, with a comment on why this is more than just an optimization. But although this speeds up huge tmpfs fallocation, it does leave the clearing until first use, and some users may have come to appreciate slow fallocate but fast first use: if they complain, then we can consider adding a pass to clear at the end. Fixes: 800d8c63b2e9 ("shmem: add huge pages support") Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi --- mm/shmem.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 70d9ce294bb4..0cd5c9156457 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2736,7 +2736,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, inode->i_private = &shmem_falloc; spin_unlock(&inode->i_lock); - for (index = start; index < end; index++) { + for (index = start; index < end; ) { struct page *page; /* @@ -2759,13 +2759,26 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, goto undone; } + index++; + /* + * Here is a more important optimization than it appears: + * a second SGP_FALLOC on the same huge page will clear it, + * making it PageUptodate and un-undoable if we fail later. + */ + if (PageTransCompound(page)) { + index = round_up(index, HPAGE_PMD_NR); + /* Beware 32-bit wraparound */ + if (!index) + index--; + } + /* * Inform shmem_writepage() how far we have reached. * No need for lock or barrier: we have the page lock. */ - shmem_falloc.next++; if (!PageUptodate(page)) - shmem_falloc.nr_falloced++; + shmem_falloc.nr_falloced += index - shmem_falloc.next; + shmem_falloc.next = index; /* * If !PageUptodate, leave it that way so that freeable pages From patchwork Tue Aug 17 08:08:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12440775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DEDEC432BE for ; Tue, 17 Aug 2021 08:08:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BFC1360F22 for ; Tue, 17 Aug 2021 08:08:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BFC1360F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5CEFE6B0072; Tue, 17 Aug 2021 04:08:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 580016B0073; Tue, 17 Aug 2021 04:08:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 447BC6B0074; Tue, 17 Aug 2021 04:08:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0094.hostedemail.com [216.40.44.94]) by kanga.kvack.org (Postfix) with ESMTP id 273B06B0072 for ; Tue, 17 Aug 2021 04:08:33 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C918B180ABF50 for ; Tue, 17 Aug 2021 08:08:32 +0000 (UTC) X-FDA: 78483845664.20.AD286B8 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf15.hostedemail.com (Postfix) with ESMTP id 726D5D00803B for ; Tue, 17 Aug 2021 08:08:32 +0000 (UTC) Received: by mail-qk1-f178.google.com with SMTP id t3so22080386qkg.11 for ; Tue, 17 Aug 2021 01:08:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=yPVqNjs8S0x0LLXwfSsq3Ltg/Qi8LUyfAy6QtPUapKA=; b=g/Fg6bZrAxIbupmhS5dSbFCnNgJkj/wYTVJIYprq/8PyNs3Gh15tIagFO6PrLyoCqa MHaXZtFVvPEsOwCWGrgU+lo74kMB+iqHHD3FYVq10vRvxDJwzhWzVxxiF93jjcYsSycr qPdR+niUBfn11+/fDaA4ZrZvFVb8pcAWADn3mxd0FdewnLiix0Zlgdbkd9UMxR6V+Iup 9ZrshxPtY8rrkOdvLUba+5ydIbYOl3WEyrowIF2GIgKajoYmIzvyenz99bvVv/bpwjx3 mlLMvrSfEMyD1g273t3m3+NmP9+NYcuk6GWJifpj07u5v0ut5zTx4suQM0YlTxUTMbTA K6AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=yPVqNjs8S0x0LLXwfSsq3Ltg/Qi8LUyfAy6QtPUapKA=; b=L30Hy18bpMCxul3DTLosE4o0uNPxFTuAw1QjBFfnrZ+Bcl4BeZbI5K2KXX2reRo+tq buYSPv4Nn/o1CyBhtrwZB/ETsy6bw0+xi3e9NyEP6S/cazBIG9+fhSsqNZcNhq40tmkg itGJSIPmbVZRt/PHO1ywR5uy46lBul/pO4SR7vluTadmDAxeRFVSia6/Dfn9Tpri2UfT dXvUfqBYkGGX2B0qiwhz2OCul8HK7lL3DkE+k5ziG0elQdtSfPWOX5wX2RJHp/1jsBVt 4hwSsFA6yQj5vtLYn3+EQMp+PsVbGDy+ks0KrhMDDsAzmgAivpXka8/Yypaim8TinUKF O1bA== X-Gm-Message-State: AOAM533NZNbgSM+ROC3/zPCOSBotlFQJmijNQbjVoLvGy78azXWP5rLB MbJm4sCkjyeLIhkfIBXJrgmNsw== X-Google-Smtp-Source: ABdhPJzGQykj6ORsSgfbNvY9x6ME3qPyZ0Focfx6ABQXFjHxBZquAYhAqcicy73+i54YlidrRixbcg== X-Received: by 2002:a37:e306:: with SMTP id y6mr2594089qki.203.1629187711636; Tue, 17 Aug 2021 01:08:31 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id ay36sm851455qkb.72.2021.08.17.01.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 01:08:31 -0700 (PDT) Date: Tue, 17 Aug 2021 01:08:28 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Shakeel Butt , "Kirill A. Shutemov" , Yang Shi , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/9] huge tmpfs: fix split_huge_page() after FALLOC_FL_KEEP_SIZE In-Reply-To: Message-ID: References: MIME-Version: 1.0 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b="g/Fg6bZr"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of hughd@google.com designates 209.85.222.178 as permitted sender) smtp.mailfrom=hughd@google.com X-Stat-Signature: ja5e9asp8fr3pweuf64gbrjjh91h1cns X-Rspamd-Queue-Id: 726D5D00803B X-Rspamd-Server: rspam05 X-HE-Tag: 1629187712-6804 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: A successful shmem_fallocate() guarantees that the extent has been reserved, even beyond i_size when the FALLOC_FL_KEEP_SIZE flag was used. But that guarantee is broken by shmem_unused_huge_shrink()'s attempts to split huge pages and free their excess beyond i_size; and by other uses of split_huge_page() near i_size. It's sad to add a shmem inode field just for this, but I did not find a better way to keep the guarantee. A flag to say KEEP_SIZE has been used would be cheaper, but I'm averse to unclearable flags. The fallocend field is not perfect either (many disjoint ranges might be fallocated), but good enough; and gains another use later on. Fixes: 779750d20b93 ("shmem: split huge pages beyond i_size under memory pressure") Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi --- include/linux/shmem_fs.h | 13 +++++++++++++ mm/huge_memory.c | 6 ++++-- mm/shmem.c | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 8e775ce517bb..9b7f7ac52351 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -18,6 +18,7 @@ struct shmem_inode_info { unsigned long flags; unsigned long alloced; /* data pages alloced to file */ unsigned long swapped; /* subtotal assigned to swap */ + pgoff_t fallocend; /* highest fallocate endindex */ struct list_head shrinklist; /* shrinkable hpage inodes */ struct list_head swaplist; /* chain of maybes on swap */ struct shared_policy policy; /* NUMA memory alloc policy */ @@ -119,6 +120,18 @@ static inline bool shmem_file(struct file *file) return shmem_mapping(file->f_mapping); } +/* + * If fallocate(FALLOC_FL_KEEP_SIZE) has been used, there may be pages + * beyond i_size's notion of EOF, which fallocate has committed to reserving: + * which split_huge_page() must therefore not delete. This use of a single + * "fallocend" per inode errs on the side of not deleting a reservation when + * in doubt: there are plenty of cases when it preserves unreserved pages. + */ +static inline pgoff_t shmem_fallocend(struct inode *inode, pgoff_t eof) +{ + return max(eof, SHMEM_I(inode)->fallocend); +} + extern bool shmem_charge(struct inode *inode, long pages); extern void shmem_uncharge(struct inode *inode, long pages); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index afff3ac87067..890fb73ac89b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2454,11 +2454,11 @@ static void __split_huge_page(struct page *page, struct list_head *list, for (i = nr - 1; i >= 1; i--) { __split_huge_page_tail(head, i, lruvec, list); - /* Some pages can be beyond i_size: drop them from page cache */ + /* Some pages can be beyond EOF: drop them from page cache */ if (head[i].index >= end) { ClearPageDirty(head + i); __delete_from_page_cache(head + i, NULL); - if (IS_ENABLED(CONFIG_SHMEM) && PageSwapBacked(head)) + if (shmem_mapping(head->mapping)) shmem_uncharge(head->mapping->host, 1); put_page(head + i); } else if (!PageAnon(page)) { @@ -2686,6 +2686,8 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) * head page lock is good enough to serialize the trimming. */ end = DIV_ROUND_UP(i_size_read(mapping->host), PAGE_SIZE); + if (shmem_mapping(mapping)) + end = shmem_fallocend(mapping->host, end); } /* diff --git a/mm/shmem.c b/mm/shmem.c index 0cd5c9156457..24c9da6b41c2 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -905,6 +905,9 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, if (lend == -1) end = -1; /* unsigned, so actually very big */ + if (info->fallocend > start && info->fallocend <= end && !unfalloc) + info->fallocend = start; + pagevec_init(&pvec); index = start; while (index < end && find_lock_entries(mapping, index, end - 1, @@ -2667,7 +2670,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); struct shmem_inode_info *info = SHMEM_I(inode); struct shmem_falloc shmem_falloc; - pgoff_t start, index, end; + pgoff_t start, index, end, undo_fallocend; int error; if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)) @@ -2736,6 +2739,15 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, inode->i_private = &shmem_falloc; spin_unlock(&inode->i_lock); + /* + * info->fallocend is only relevant when huge pages might be + * involved: to prevent split_huge_page() freeing fallocated + * pages when FALLOC_FL_KEEP_SIZE committed beyond i_size. + */ + undo_fallocend = info->fallocend; + if (info->fallocend < end) + info->fallocend = end; + for (index = start; index < end; ) { struct page *page; @@ -2750,6 +2762,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, else error = shmem_getpage(inode, index, &page, SGP_FALLOC); if (error) { + info->fallocend = undo_fallocend; /* Remove the !PageUptodate pages we added */ if (index > start) { shmem_undo_range(inode, From patchwork Tue Aug 17 08:10:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12440827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C778C4338F for ; Tue, 17 Aug 2021 08:10:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D458A60F22 for ; Tue, 17 Aug 2021 08:10:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D458A60F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7081F6B006C; Tue, 17 Aug 2021 04:10:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B5DE8D0001; Tue, 17 Aug 2021 04:10:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A3FD6B0073; Tue, 17 Aug 2021 04:10:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0235.hostedemail.com [216.40.44.235]) by kanga.kvack.org (Postfix) with ESMTP id 3F58F6B006C for ; Tue, 17 Aug 2021 04:10:35 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E000A8249980 for ; Tue, 17 Aug 2021 08:10:34 +0000 (UTC) X-FDA: 78483850788.31.422F5D9 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf02.hostedemail.com (Postfix) with ESMTP id 9FF09700CBC5 for ; Tue, 17 Aug 2021 08:10:34 +0000 (UTC) Received: by mail-qk1-f180.google.com with SMTP id e14so22132252qkg.3 for ; Tue, 17 Aug 2021 01:10:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=dfE3q4OXpiVQpbNfVoKLEaANxcYqC3T8XxC0IxCHZsc=; b=jPESYkkq91jeQiDwQs4TeKi/+i5vQZlhzi+wNgz4UA8+pT+Iw5xltta00A7jASrMoB xrv44XXsQwHqrHVXMR2cd3SY4K0izMU2zXd/4m1GMTquYERZQfvAMEek387dVCWk4LKH j4qdUn9mLTJ1n2M4X1UxIbJ+U3geInX2P+ixAWHZAG0+wyJxwOMa6DinwtUdyLJe7AFA hmpP1GHYz2xpXdLjGoKsGj5g9zYFWLcKoraRyUmRqBDNI8J4FXOMfXyOaf4ZbuAy/Lq3 YbtJFzJfmQgpsbfxXbKixpfBWtY+7izIQvaorACdBVAG1YglUcI28CUKVwfOxKzWri8j bIEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=dfE3q4OXpiVQpbNfVoKLEaANxcYqC3T8XxC0IxCHZsc=; b=JjxOZDmD2EMP+z+lo6Q0Ul4oL78WoTNEnHz9h2Fw/nKFTZS9lbAqomPdHBpJE8yFwA be96TtiDz9gHQejI4ooEYkrUUbyi9Nu8vMTvzbqiQ1wQBlv+yaIG3yWNRKkJyj/czcq0 7fQ0xxIiXNmDdqm4nykGYG5463VfyI0tvNe7RCsFlOBTKLiFTbXHdd2zWJYBQhc5PH/5 t0Wcosptypb2r1ZHwj0+/EU2pzhn3fnlQnMG6eYSD97FulI7buB7ZOHgDNICtqDOlI9x 0G8R7Q60z6EX9R2Sp/fivXWwc3GCEYb4g/56vQM3En774woB9IJniqU1umdsEgDK54YT LHKg== X-Gm-Message-State: AOAM530+NnAKnW1YxcMR7tJ8Jea27qL+RcwERGWYxQG2Z/77xytyvGmV n/YouMWe296BJgF6UMz5BJOwqQ== X-Google-Smtp-Source: ABdhPJxFjAb7CmwY9wmrY5DQiBrSQtn4PIJbTVaSnCE7ZjrwuE8MNykwjZ3v5ynbRguyyjSKqJolTg== X-Received: by 2002:a05:620a:110d:: with SMTP id o13mr2550467qkk.108.1629187833824; Tue, 17 Aug 2021 01:10:33 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id q72sm873408qka.104.2021.08.17.01.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 01:10:33 -0700 (PDT) Date: Tue, 17 Aug 2021 01:10:31 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Shakeel Butt , "Kirill A. Shutemov" , Yang Shi , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/9] huge tmpfs: remove shrinklist addition from shmem_setattr() In-Reply-To: Message-ID: References: MIME-Version: 1.0 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=jPESYkkq; spf=pass (imf02.hostedemail.com: domain of hughd@google.com designates 209.85.222.180 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9FF09700CBC5 X-Stat-Signature: 9qgnjj6ujab53wxwnmh5yiu5aoqdpcjt X-HE-Tag: 1629187834-856827 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: There's a block of code in shmem_setattr() to add the inode to shmem_unused_huge_shrink()'s shrinklist when lowering i_size: it dates from before 5.7 changed truncation to do split_huge_page() for itself, and should have been removed at that time. I am over-stating that: split_huge_page() can fail (notably if there's an extra reference to the page at that time), so there might be value in retrying. But there were already retries as truncation worked through the tails, and this addition risks repeating unsuccessful retries indefinitely: I'd rather remove it now, and work on reducing the chance of split_huge_page() failures separately, if we need to. Fixes: 71725ed10c40 ("mm: huge tmpfs: try to split_huge_page() when punching hole") Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi --- mm/shmem.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 24c9da6b41c2..ce3ccaac54d6 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1061,7 +1061,6 @@ static int shmem_setattr(struct user_namespace *mnt_userns, { struct inode *inode = d_inode(dentry); struct shmem_inode_info *info = SHMEM_I(inode); - struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); int error; error = setattr_prepare(&init_user_ns, dentry, attr); @@ -1097,24 +1096,6 @@ static int shmem_setattr(struct user_namespace *mnt_userns, if (oldsize > holebegin) unmap_mapping_range(inode->i_mapping, holebegin, 0, 1); - - /* - * Part of the huge page can be beyond i_size: subject - * to shrink under memory pressure. - */ - if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { - spin_lock(&sbinfo->shrinklist_lock); - /* - * _careful to defend against unlocked access to - * ->shrink_list in shmem_unused_huge_shrink() - */ - if (list_empty_careful(&info->shrinklist)) { - list_add_tail(&info->shrinklist, - &sbinfo->shrinklist); - sbinfo->shrinklist_len++; - } - spin_unlock(&sbinfo->shrinklist_lock); - } } } From patchwork Tue Aug 17 08:12:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12440829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E992C4320A for ; Tue, 17 Aug 2021 08:12:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 51F4F60F22 for ; Tue, 17 Aug 2021 08:12:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 51F4F60F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E7D466B0072; Tue, 17 Aug 2021 04:12:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E2DD46B0073; Tue, 17 Aug 2021 04:12:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1BAC8D0001; Tue, 17 Aug 2021 04:12:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0253.hostedemail.com [216.40.44.253]) by kanga.kvack.org (Postfix) with ESMTP id BAFF76B0072 for ; Tue, 17 Aug 2021 04:12:38 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5FE5C1F043 for ; Tue, 17 Aug 2021 08:12:38 +0000 (UTC) X-FDA: 78483855996.30.C69028D Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf26.hostedemail.com (Postfix) with ESMTP id 152B6200ECB2 for ; Tue, 17 Aug 2021 08:12:37 +0000 (UTC) Received: by mail-qk1-f177.google.com with SMTP id bj38so4264249qkb.9 for ; Tue, 17 Aug 2021 01:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=s8gWaJfJ4WIQanuDSV4XHG60BxCx9sgBhrowAqyXAGc=; b=NMiekobsOEwgOm3HulE+GsIzl99RzYQahhmJFly4RZa7Rcp/RO3vQlKPXR4EsRt0Wh A4E9h0z0d/fOVyHVKd1AQmLoEqzhZyLuBPZ6P/1oHXSsAw0cSzQF2oWBKeFBI++U12Tk SAV3vRG7YPWYGZrns9/CsT4lduY4sRLp7ljD80rN/9LGJ/4Zz97EJd+3fk9smW5tFgYt I4XKfbcRiRj3hb2tqEaOEcm2fUoGyqw0XdGiZW0AC1yvdCiMfKqRKOgWtNvuDMgJ20Ho ikyOqbYBBUPmjVZhYiIcj4K1IdUF+EKe6UbsZ78qiMnbcqm/7lWVj6TllIgRw/sKPxUJ ZXDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=s8gWaJfJ4WIQanuDSV4XHG60BxCx9sgBhrowAqyXAGc=; b=lw6ZnpGiqaPlrpKzq+4XCZWkfQWvoSYxyefxeFX+kJJrun36lZm2eD+Zkbr67zhOkG 0HkKVDddQ5Uxjk1TCG47TZZQJOdu/5YYNCg357tIAGn2XqTD23bxmRokolLc8mveMalF 0XFAg+qqkHhO6qVx2r6xaK4JPs8V2JqxVpNgYpni5gEXhz9hJnLgKy16KBIjJo20vLVx IZz8trcWrbH5E1riJ7IqH0z2LMQjo+VI00CTg6Q4CwiV1QRVc18kzZhnetGKk9MkCZmr mYSQ0fCQ3SWRKnRgiJBgdsKImbwpddeOXgrwWPyh0wPiIhgs3a3+pWMrJEoHwjhOI3Jk Rqkg== X-Gm-Message-State: AOAM5312nl4AviZRC2Awm00J7KQ/GwZy7GI08zK6uupfhA30XnW++LHJ wPNnlaArrSlrNky0xZTIfagLpw== X-Google-Smtp-Source: ABdhPJxVnbd3A4PYs7GXspwmAshRWlMAmJn5RmJc1m6XsPvUMZ3wXL6wVHX3SfxeuLk6rSHNu5MNJQ== X-Received: by 2002:a37:c09:: with SMTP id 9mr2543302qkm.73.1629187957273; Tue, 17 Aug 2021 01:12:37 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id x125sm903535qkd.8.2021.08.17.01.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 01:12:36 -0700 (PDT) Date: Tue, 17 Aug 2021 01:12:34 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Shakeel Butt , "Kirill A. Shutemov" , Yang Shi , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/9] huge tmpfs: revert shmem's use of transhuge_vma_enabled() In-Reply-To: Message-ID: <45e5338-18d-c6f9-c17e-34f510bc1728@google.com> References: MIME-Version: 1.0 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=NMiekobs; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of hughd@google.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=hughd@google.com X-Stat-Signature: zndr7kyg3jc7bwnundgxzouh9gyr4jor X-Rspamd-Queue-Id: 152B6200ECB2 X-Rspamd-Server: rspam05 X-HE-Tag: 1629187957-285353 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: 5.14 commit e6be37b2e7bd ("mm/huge_memory.c: add missing read-only THP checking in transparent_hugepage_enabled()") added transhuge_vma_enabled() as a wrapper for two very different checks (one check is whether the app has marked its address range not to use THPs, the other check is whether the app is running in a hierarchy that has been marked never to use THPs). shmem_huge_enabled() prefers to show those two checks explicitly, as before. Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi --- mm/shmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index ce3ccaac54d6..c6fa6f4f2db8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4003,7 +4003,8 @@ bool shmem_huge_enabled(struct vm_area_struct *vma) loff_t i_size; pgoff_t off; - if (!transhuge_vma_enabled(vma, vma->vm_flags)) + if ((vma->vm_flags & VM_NOHUGEPAGE) || + test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) return false; if (shmem_huge == SHMEM_HUGE_FORCE) return true; From patchwork Tue Aug 17 08:14:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12440831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC327C4320A for ; Tue, 17 Aug 2021 08:14:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 88FE460F22 for ; Tue, 17 Aug 2021 08:14:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 88FE460F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 220F96B006C; Tue, 17 Aug 2021 04:14:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CF9A6B0072; Tue, 17 Aug 2021 04:14:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 097286B0073; Tue, 17 Aug 2021 04:14:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id E07876B006C for ; Tue, 17 Aug 2021 04:14:33 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 91772181AC544 for ; Tue, 17 Aug 2021 08:14:33 +0000 (UTC) X-FDA: 78483860826.12.0C70D28 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by imf09.hostedemail.com (Postfix) with ESMTP id 477C13005530 for ; Tue, 17 Aug 2021 08:14:33 +0000 (UTC) Received: by mail-qt1-f177.google.com with SMTP id x5so7942089qtq.13 for ; Tue, 17 Aug 2021 01:14:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=DbxPYfIkUPggZAsAtUCUkg6hl6OjGtFlTtB9svwXDrQ=; b=MDYcRkXC9AzT6oic9Y7EK7P1oSIPrdRZWVwOjHsGLa0HsxCTUKzB+DS0sGLQjGY/9S e8e61iUUn8EsNT83aYltwJUcWEOHDUw/LXFBiZ453w5uthUmSUmdnFQbljDGEUQ9IbUt i2Ga/mi050hZMvUnlMdgWb4cjPD2weaNZUWBLmfKuUQ0JbseitjMlkdmG0Ecuq3Q7G9c TtWRWYq0W1t9gmpAABN+fQEqNoBoBZ/A1ozRzCbtl6t09dVevv0k1Uyt5gqORKWINAcn 0WsBBncQjV0O+CFNnf3eEuLfDDwXo15Bno8lhGwndXWjNXHHbLiIhoCmij6Et44IbzLx CbfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=DbxPYfIkUPggZAsAtUCUkg6hl6OjGtFlTtB9svwXDrQ=; b=ugyaD4/YECbandJucaNc3qyDDC9AfMZ2XDpcD/X/t6w2fsYzpxdF9t61AkSpMhp80O ex2Q9uFz58VGgPEhfo2WRUCwUb8YUQ/EQFYmgYCqhu3/RwCcsxUmsjsuXvb90gzuvLPa mwp1Tkmtj5ivxknf20VN/v9JMkE2l67IkH3KuaAyd8a0ZWZDwfZy4ah1q9qK3GReDoIV 8FLJqepOAf2Trq5TL7XrzeNHC3FWni4A1qG/QIYMoOJR4bzRjAgNYnnAhlmPloxTcb/e VG2Vq4NQAcf0IEgmhqZH9nIRkjZEcu/QGrk3EYiVC5PSxhr1335zYyGqfOPIVcHojY9K co5A== X-Gm-Message-State: AOAM532an/EThyRz7ik5IB7l4w53tX7X09otRUwk4dNoCaM6RgIQ2G5S Sddb7mOE23swUZM9vFyzuMYMSQ== X-Google-Smtp-Source: ABdhPJzvjRKbcrqPoj6rWq+pXSIKfeRz0vrhFSmbk/werhszUnq0bvTCdRv0bGfj0WZ24e/T5B6N3Q== X-Received: by 2002:a05:622a:255:: with SMTP id c21mr1947762qtx.128.1629188072480; Tue, 17 Aug 2021 01:14:32 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id x21sm891928qkf.76.2021.08.17.01.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 01:14:31 -0700 (PDT) Date: Tue, 17 Aug 2021 01:14:29 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Shakeel Butt , "Kirill A. Shutemov" , Yang Shi , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 5/9] huge tmpfs: move shmem_huge_enabled() upwards In-Reply-To: Message-ID: <16fec7b7-5c84-415a-8586-69d8bf6a6685@google.com> References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 477C13005530 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=MDYcRkXC; spf=pass (imf09.hostedemail.com: domain of hughd@google.com designates 209.85.160.177 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam01 X-Stat-Signature: xthhday5cnmrshz178x6mis5cq6x6ud8 X-HE-Tag: 1629188073-912662 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: shmem_huge_enabled() is about to be enhanced into shmem_is_huge(), so that it can be used more widely throughout: before making functional changes, shift it to its final position (to avoid forward declaration). Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi --- mm/shmem.c | 72 ++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index c6fa6f4f2db8..740d48ef1eb5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -476,6 +476,41 @@ static bool shmem_confirm_swap(struct address_space *mapping, static int shmem_huge __read_mostly; +bool shmem_huge_enabled(struct vm_area_struct *vma) +{ + struct inode *inode = file_inode(vma->vm_file); + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); + loff_t i_size; + pgoff_t off; + + if ((vma->vm_flags & VM_NOHUGEPAGE) || + test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) + return false; + if (shmem_huge == SHMEM_HUGE_FORCE) + return true; + if (shmem_huge == SHMEM_HUGE_DENY) + return false; + switch (sbinfo->huge) { + case SHMEM_HUGE_NEVER: + return false; + case SHMEM_HUGE_ALWAYS: + return true; + case SHMEM_HUGE_WITHIN_SIZE: + off = round_up(vma->vm_pgoff, HPAGE_PMD_NR); + i_size = round_up(i_size_read(inode), PAGE_SIZE); + if (i_size >= HPAGE_PMD_SIZE && + i_size >> PAGE_SHIFT >= off) + return true; + fallthrough; + case SHMEM_HUGE_ADVISE: + /* TODO: implement fadvise() hints */ + return (vma->vm_flags & VM_HUGEPAGE); + default: + VM_BUG_ON(1); + return false; + } +} + #if defined(CONFIG_SYSFS) static int shmem_parse_huge(const char *str) { @@ -3995,43 +4030,6 @@ struct kobj_attribute shmem_enabled_attr = __ATTR(shmem_enabled, 0644, shmem_enabled_show, shmem_enabled_store); #endif /* CONFIG_TRANSPARENT_HUGEPAGE && CONFIG_SYSFS */ -#ifdef CONFIG_TRANSPARENT_HUGEPAGE -bool shmem_huge_enabled(struct vm_area_struct *vma) -{ - struct inode *inode = file_inode(vma->vm_file); - struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); - loff_t i_size; - pgoff_t off; - - if ((vma->vm_flags & VM_NOHUGEPAGE) || - test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) - return false; - if (shmem_huge == SHMEM_HUGE_FORCE) - return true; - if (shmem_huge == SHMEM_HUGE_DENY) - return false; - switch (sbinfo->huge) { - case SHMEM_HUGE_NEVER: - return false; - case SHMEM_HUGE_ALWAYS: - return true; - case SHMEM_HUGE_WITHIN_SIZE: - off = round_up(vma->vm_pgoff, HPAGE_PMD_NR); - i_size = round_up(i_size_read(inode), PAGE_SIZE); - if (i_size >= HPAGE_PMD_SIZE && - i_size >> PAGE_SHIFT >= off) - return true; - fallthrough; - case SHMEM_HUGE_ADVISE: - /* TODO: implement fadvise() hints */ - return (vma->vm_flags & VM_HUGEPAGE); - default: - VM_BUG_ON(1); - return false; - } -} -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ - #else /* !CONFIG_SHMEM */ /* From patchwork Tue Aug 17 08:17:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12440857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B082EC4320A for ; Tue, 17 Aug 2021 08:17:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6781760FBF for ; Tue, 17 Aug 2021 08:17:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6781760FBF Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 095C76B0072; Tue, 17 Aug 2021 04:17:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 045488D0002; Tue, 17 Aug 2021 04:17:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E76718D0001; Tue, 17 Aug 2021 04:17:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id CEA666B0072 for ; Tue, 17 Aug 2021 04:17:46 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7FA3A8249980 for ; Tue, 17 Aug 2021 08:17:46 +0000 (UTC) X-FDA: 78483868932.06.4ECA719 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by imf29.hostedemail.com (Postfix) with ESMTP id 119A6901E5B3 for ; Tue, 17 Aug 2021 08:17:44 +0000 (UTC) Received: by mail-qk1-f182.google.com with SMTP id t68so22132604qkf.8 for ; Tue, 17 Aug 2021 01:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=ijowZ4jcrG0Ehbu0X7RLv2m890u4vuBU8RzGN0n7bL0=; b=hkL/t1N59snMllnmFaWkLsl2GgYb22030wlHiEeGop1btUrASwwzsFxbAV5LMYGE7q ozjKkck4uIJ4l1yp4GbhPSoqRVn8uj5D5eatF3Z9fVPNX22tkXoXqc2N+x1RNEw8XK+Y GS6Y74GADMaDC9HV+cat0PaBPrmtm9u64hTjHxzKGPZeEFb95d72hs6yQGUjYxhWnmhM LZ5cGAOGrIQNAeddwbzrpmiwIVtS/7Eg67KQ15w6ZNtFK9UZ7gUiFvDLYtXzmo9UjvuI PA9PwX/hWqQngtiDQwZygVZ85HzrBgyRHoJv+9zymjFDvvfF8iqcoQ492w0mOGbUv1Ds k1Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=ijowZ4jcrG0Ehbu0X7RLv2m890u4vuBU8RzGN0n7bL0=; b=DC4wrllpJEDedvxUthC3SoTiE/2gr4he5WS1eip1kKeaYPveBaKjeQur3lWnXpo9Gj pqSYF7XdSeKlX9bhN9ZfqL0dxU7wDpuVwchx3rFCVqTLEuDkExKyUIp2q2Lpjp13WjGL Ahbd5VPG3S94d/KbR/tKaw91TmAi340vVIQmDMVdVhnnS3qLdKNFSUcrGbZ8ud+cqdls vURAOX3ZlDHdZXn29ERtMm4sAEt7mCzGwql6SbMimZu1EfiJ9mzJF5tVYRTXoO6NHfBu EfgUvQ5QE6nsh5o0djMrRmtbvsH+gjFKxt36koyGdD/oByYx9B0Ej5AvZ3NtTv6v3D7x RMOQ== X-Gm-Message-State: AOAM532XVUD3CJSajs/3jqFyjafYrWnHOCfZylxQljOD2SravhkVFwfM zRyuK0Tb1qDbbyvyxI/Y4fa0Tw== X-Google-Smtp-Source: ABdhPJyDjNDrAfBVAAvGPzIj04mSmcEsVajGGsFy6FFaXWF2QwGM7GhbPjNQfw/JroHWC0p7JHupbg== X-Received: by 2002:a05:620a:1222:: with SMTP id v2mr2636380qkj.1.1629188264267; Tue, 17 Aug 2021 01:17:44 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id h140sm921535qke.112.2021.08.17.01.17.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 01:17:43 -0700 (PDT) Date: Tue, 17 Aug 2021 01:17:41 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Shakeel Butt , "Kirill A. Shutemov" , Yang Shi , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 6/9] huge tmpfs: SGP_NOALLOC to stop collapse_file() on race In-Reply-To: Message-ID: <1355343b-acf-4653-ef79-6aee40214ac5@google.com> References: MIME-Version: 1.0 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b="hkL/t1N5"; spf=pass (imf29.hostedemail.com: domain of hughd@google.com designates 209.85.222.182 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 119A6901E5B3 X-Stat-Signature: fubhp1rssdf6zq4d33n5u995jrykudm8 X-HE-Tag: 1629188264-787728 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: khugepaged's collapse_file() currently uses SGP_NOHUGE to tell shmem_getpage() not to try allocating a huge page, in the very unlikely event that a racing hole-punch removes the swapped or fallocated page as soon as i_pages lock is dropped. We want to consolidate shmem's huge decisions, removing SGP_HUGE and SGP_NOHUGE; but cannot quite persuade ourselves that it's okay to regress the protection in this case - Yang Shi points out that the huge page would remain indefinitely, charged to root instead of the intended memcg. collapse_file() should not even allocate a small page in this case: why proceed if someone is punching a hole? SGP_READ is almost the right flag here, except that it optimizes away from a fallocated page, with NULL to tell caller to fill with zeroes (like a hole); whereas collapse_file()'s sequence relies on using a cache page. Add SGP_NOALLOC just for this. There are too many consecutive "if (page"s there in shmem_getpage_gfp(): group it better; and fix the outdated "bring it back from swap" comment. Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi --- include/linux/shmem_fs.h | 1 + mm/khugepaged.c | 2 +- mm/shmem.c | 29 +++++++++++++++++------------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 9b7f7ac52351..7d97b15a2f7a 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -94,6 +94,7 @@ extern unsigned long shmem_partial_swap_usage(struct address_space *mapping, /* Flag allocation requirements to shmem_getpage */ enum sgp_type { SGP_READ, /* don't exceed i_size, don't allocate page */ + SGP_NOALLOC, /* similar, but fail on hole or use fallocated page */ SGP_CACHE, /* don't exceed i_size, may allocate page */ SGP_NOHUGE, /* like SGP_CACHE, but no huge pages */ SGP_HUGE, /* like SGP_CACHE, huge pages preferred */ diff --git a/mm/khugepaged.c b/mm/khugepaged.c index b0412be08fa2..045cc579f724 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1721,7 +1721,7 @@ static void collapse_file(struct mm_struct *mm, xas_unlock_irq(&xas); /* swap in or instantiate fallocated page */ if (shmem_getpage(mapping->host, index, &page, - SGP_NOHUGE)) { + SGP_NOALLOC)) { result = SCAN_FAIL; goto xa_unlocked; } diff --git a/mm/shmem.c b/mm/shmem.c index 740d48ef1eb5..226ac3a911e9 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1871,26 +1871,31 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, return error; } - if (page) + if (page) { hindex = page->index; - if (page && sgp == SGP_WRITE) - mark_page_accessed(page); - - /* fallocated page? */ - if (page && !PageUptodate(page)) { + if (sgp == SGP_WRITE) + mark_page_accessed(page); + if (PageUptodate(page)) + goto out; + /* fallocated page */ if (sgp != SGP_READ) goto clear; unlock_page(page); put_page(page); - page = NULL; - hindex = index; } - if (page || sgp == SGP_READ) - goto out; /* - * Fast cache lookup did not find it: - * bring it back from swap or allocate. + * SGP_READ: succeed on hole, with NULL page, letting caller zero. + * SGP_NOALLOC: fail on hole, with NULL page, letting caller fail. + */ + *pagep = NULL; + if (sgp == SGP_READ) + return 0; + if (sgp == SGP_NOALLOC) + return -ENOENT; + + /* + * Fast cache lookup and swap lookup did not find it: allocate. */ if (vma && userfaultfd_missing(vma)) { From patchwork Tue Aug 17 08:19:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12440859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FDCCC4338F for ; Tue, 17 Aug 2021 08:19:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F136960FBF for ; Tue, 17 Aug 2021 08:19:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F136960FBF Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 611D76B0073; Tue, 17 Aug 2021 04:19:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C0DB6B0074; Tue, 17 Aug 2021 04:19:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AFAB6B0075; Tue, 17 Aug 2021 04:19:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0078.hostedemail.com [216.40.44.78]) by kanga.kvack.org (Postfix) with ESMTP id 2FBA86B0073 for ; Tue, 17 Aug 2021 04:19:47 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id CA5BF8249980 for ; Tue, 17 Aug 2021 08:19:46 +0000 (UTC) X-FDA: 78483873972.15.3E7BB84 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf17.hostedemail.com (Postfix) with ESMTP id 84C33F0079B7 for ; Tue, 17 Aug 2021 08:19:46 +0000 (UTC) Received: by mail-qv1-f48.google.com with SMTP id bl13so10734256qvb.5 for ; Tue, 17 Aug 2021 01:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=BBBG4u4Q/TrT4lAkdPpvB6zA0ayuEUrcQgY7h86EFM4=; b=WSl4AhaxuHlksNyDmACm9oGZneBfx4KzHamzDNAmqmY4Pdy9pJfr3HmR9nQuTRoLx8 HSoE9LCAuaSzFhkeOmK7ROjATd5n+ArQEyGsIuh1/tM7U83Igi+7+FrsWsq+tUedkhCb hwsQy7xt2PrE649VqIky0CHBFIuSfG1Mk+0LklM+B+ivs/nhFl+L/8/bM6dZhn0fnb+q 9AFiWYh/J+AKn5MoFNagQ0H/UWh2LikYFY7kQ6pr+2b2rf7QDaCoPsnL4imkN4f8L13n CTHGWJuTvtrSVBGzHXyDqOH1VkYl/qcuJYuCsoymBH14ZNQLfRz8kR1mSCGwzBwNYLcK PG+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=BBBG4u4Q/TrT4lAkdPpvB6zA0ayuEUrcQgY7h86EFM4=; b=o6s+Z5z0LM6vQunxMipGZCZfTUYlEGk4oRjm1rvU5LwY2Rf2MOpO7rXHjjQ2QNjzhN S9sZd8AqgB6TMMvVOrZJWiwek8aoaJoCBaup88U3wsT0V/928e6tIc9wfDwDYzImZd/j fQzQOIiGulC9XX5/OSMCu4WwIBDQsUEN4Qxd9kZ0MkPSFwVQ0P07L5mEWOcS4v5/q/j8 vW/WwBLeqaKalxkM5iq3Sojb5mveaPFnPLrf9TIJ3bMBqlNnKVGnVaXIFA1mbrqbXVzo L1HEDsduuSAkTqHZD4nzBdVs1sX7D5u4yCAbFnB8ybWyW0aR4J8m9WzR05yixjalgBou OP8w== X-Gm-Message-State: AOAM533SkpT0yukDZB8b1AUeZ1oI7fNkgU7+ENErvPrKqfJxl2lqrg5o DJLRP6tNCZ7o9tVRgYlRPAx2bg== X-Google-Smtp-Source: ABdhPJySkXFUg0KpN6j9gXg6onC7FbzP//iOt3dKX58t3CeRPmZSmCWCpq1/j6mEhtfjUtDKIsgDfg== X-Received: by 2002:a05:6214:f6c:: with SMTP id iy12mr2072264qvb.10.1629188385741; Tue, 17 Aug 2021 01:19:45 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id i10sm881863qkl.51.2021.08.17.01.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 01:19:45 -0700 (PDT) Date: Tue, 17 Aug 2021 01:19:42 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Shakeel Butt , "Kirill A. Shutemov" , Yang Shi , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 7/9] huge tmpfs: shmem_is_huge(vma, inode, index) In-Reply-To: Message-ID: <23a77889-2ddc-b030-75cd-44ca27fd4d1@google.com> References: MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 84C33F0079B7 X-Stat-Signature: 4f4eqm9jmncmspsdqnpajy8s5ubgk56a Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=WSl4Ahax; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of hughd@google.com designates 209.85.219.48 as permitted sender) smtp.mailfrom=hughd@google.com X-HE-Tag: 1629188386-334295 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: Extend shmem_huge_enabled(vma) to shmem_is_huge(vma, inode, index), so that a consistent set of checks can be applied, even when the inode is accessed through read/write syscalls (with NULL vma) instead of mmaps (the index argument is seldom of interest, but required by mount option "huge=within_size"). Clean up and rearrange the checks a little. This then replaces the checks which shmem_fault() and shmem_getpage_gfp() were making, and eliminates the SGP_HUGE and SGP_NOHUGE modes. Replace a couple of 0s by explicit SHMEM_HUGE_NEVERs; and replace the obscure !shmem_mapping() symlink check by explicit S_ISLNK() - nothing else needs that symlink check, so leave it there in shmem_getpage_gfp(). Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi --- include/linux/shmem_fs.h | 9 +++-- mm/shmem.c | 84 ++++++++++++---------------------------- 2 files changed, 31 insertions(+), 62 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 7d97b15a2f7a..60c6e4eac275 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -86,7 +86,12 @@ extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end); extern int shmem_unuse(unsigned int type, bool frontswap, unsigned long *fs_pages_to_unuse); -extern 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); +static inline bool shmem_huge_enabled(struct vm_area_struct *vma) +{ + return shmem_is_huge(vma, file_inode(vma->vm_file), vma->vm_pgoff); +} 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); @@ -96,8 +101,6 @@ enum sgp_type { SGP_READ, /* don't exceed i_size, don't allocate page */ SGP_NOALLOC, /* similar, but fail on hole or use fallocated page */ SGP_CACHE, /* don't exceed i_size, may allocate page */ - SGP_NOHUGE, /* like SGP_CACHE, but no huge pages */ - SGP_HUGE, /* like SGP_CACHE, huge pages preferred */ SGP_WRITE, /* may exceed i_size, may allocate !Uptodate page */ SGP_FALLOC, /* like SGP_WRITE, but make existing page Uptodate */ }; diff --git a/mm/shmem.c b/mm/shmem.c index 226ac3a911e9..56ee56b1cab6 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -474,39 +474,35 @@ static bool shmem_confirm_swap(struct address_space *mapping, #ifdef CONFIG_TRANSPARENT_HUGEPAGE /* ifdef here to avoid bloating shmem.o when not necessary */ -static int shmem_huge __read_mostly; +static int shmem_huge __read_mostly = SHMEM_HUGE_NEVER; -bool shmem_huge_enabled(struct vm_area_struct *vma) +bool shmem_is_huge(struct vm_area_struct *vma, + struct inode *inode, pgoff_t index) { - struct inode *inode = file_inode(vma->vm_file); - struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); loff_t i_size; - pgoff_t off; - if ((vma->vm_flags & VM_NOHUGEPAGE) || - test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) - return false; - if (shmem_huge == SHMEM_HUGE_FORCE) - return true; if (shmem_huge == SHMEM_HUGE_DENY) return false; - switch (sbinfo->huge) { - case SHMEM_HUGE_NEVER: + if (vma && ((vma->vm_flags & VM_NOHUGEPAGE) || + test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))) return false; + if (shmem_huge == SHMEM_HUGE_FORCE) + return true; + + switch (SHMEM_SB(inode->i_sb)->huge) { case SHMEM_HUGE_ALWAYS: return true; case SHMEM_HUGE_WITHIN_SIZE: - off = round_up(vma->vm_pgoff, HPAGE_PMD_NR); + index = round_up(index, HPAGE_PMD_NR); i_size = round_up(i_size_read(inode), PAGE_SIZE); - if (i_size >= HPAGE_PMD_SIZE && - i_size >> PAGE_SHIFT >= off) + if (i_size >= HPAGE_PMD_SIZE && (i_size >> PAGE_SHIFT) >= index) return true; fallthrough; case SHMEM_HUGE_ADVISE: - /* TODO: implement fadvise() hints */ - return (vma->vm_flags & VM_HUGEPAGE); + if (vma && (vma->vm_flags & VM_HUGEPAGE)) + return true; + fallthrough; default: - VM_BUG_ON(1); return false; } } @@ -680,6 +676,12 @@ 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) +{ + return false; +} + static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo, struct shrink_control *sc, unsigned long nr_to_split) { @@ -1829,7 +1831,6 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, struct shmem_sb_info *sbinfo; struct mm_struct *charge_mm; struct page *page; - enum sgp_type sgp_huge = sgp; pgoff_t hindex = index; gfp_t huge_gfp; int error; @@ -1838,8 +1839,6 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, if (index > (MAX_LFS_FILESIZE >> PAGE_SHIFT)) return -EFBIG; - if (sgp == SGP_NOHUGE || sgp == SGP_HUGE) - sgp = SGP_CACHE; repeat: if (sgp <= SGP_CACHE && ((loff_t)index << PAGE_SHIFT) >= i_size_read(inode)) { @@ -1903,36 +1902,12 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, return 0; } - /* shmem_symlink() */ - if (!shmem_mapping(mapping)) - goto alloc_nohuge; - if (shmem_huge == SHMEM_HUGE_DENY || sgp_huge == SGP_NOHUGE) + /* Never use a huge page for shmem_symlink() */ + if (S_ISLNK(inode->i_mode)) goto alloc_nohuge; - if (shmem_huge == SHMEM_HUGE_FORCE) - goto alloc_huge; - switch (sbinfo->huge) { - case SHMEM_HUGE_NEVER: + if (!shmem_is_huge(vma, inode, index)) goto alloc_nohuge; - case SHMEM_HUGE_WITHIN_SIZE: { - loff_t i_size; - pgoff_t off; - - off = round_up(index, HPAGE_PMD_NR); - i_size = round_up(i_size_read(inode), PAGE_SIZE); - if (i_size >= HPAGE_PMD_SIZE && - i_size >> PAGE_SHIFT >= off) - goto alloc_huge; - fallthrough; - } - case SHMEM_HUGE_ADVISE: - if (sgp_huge == SGP_HUGE) - goto alloc_huge; - /* TODO: implement fadvise() hints */ - goto alloc_nohuge; - } - -alloc_huge: huge_gfp = vma_thp_gfp_mask(vma); huge_gfp = limit_gfp_mask(huge_gfp, gfp); page = shmem_alloc_and_acct_page(huge_gfp, inode, index, true); @@ -2088,7 +2063,6 @@ static vm_fault_t shmem_fault(struct vm_fault *vmf) struct vm_area_struct *vma = vmf->vma; struct inode *inode = file_inode(vma->vm_file); gfp_t gfp = mapping_gfp_mask(inode->i_mapping); - enum sgp_type sgp; int err; vm_fault_t ret = VM_FAULT_LOCKED; @@ -2151,15 +2125,7 @@ static vm_fault_t shmem_fault(struct vm_fault *vmf) spin_unlock(&inode->i_lock); } - sgp = SGP_CACHE; - - if ((vma->vm_flags & VM_NOHUGEPAGE) || - test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) - sgp = SGP_NOHUGE; - else if (vma->vm_flags & VM_HUGEPAGE) - sgp = SGP_HUGE; - - err = shmem_getpage_gfp(inode, vmf->pgoff, &vmf->page, sgp, + err = shmem_getpage_gfp(inode, vmf->pgoff, &vmf->page, SGP_CACHE, gfp, vma, vmf, &ret); if (err) return vmf_error(err); @@ -3966,7 +3932,7 @@ int __init shmem_init(void) if (has_transparent_hugepage() && shmem_huge > SHMEM_HUGE_DENY) SHMEM_SB(shm_mnt->mnt_sb)->huge = shmem_huge; else - shmem_huge = 0; /* just in case it was patched */ + shmem_huge = SHMEM_HUGE_NEVER; /* just in case it was patched */ #endif return 0; From patchwork Tue Aug 17 08:22:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12440871 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B75FAC4338F for ; Tue, 17 Aug 2021 08:22:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 62CBC60F41 for ; Tue, 17 Aug 2021 08:22:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 62CBC60F41 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id F357B8D0001; Tue, 17 Aug 2021 04:22:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE5F46B0074; Tue, 17 Aug 2021 04:22:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAF8C8D0001; Tue, 17 Aug 2021 04:22:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0186.hostedemail.com [216.40.44.186]) by kanga.kvack.org (Postfix) with ESMTP id BD9526B0073 for ; Tue, 17 Aug 2021 04:22:43 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 663BD183F68D7 for ; Tue, 17 Aug 2021 08:22:43 +0000 (UTC) X-FDA: 78483881406.04.4B930D6 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by imf02.hostedemail.com (Postfix) with ESMTP id 20E93700CBC6 for ; Tue, 17 Aug 2021 08:22:43 +0000 (UTC) Received: by mail-qk1-f171.google.com with SMTP id p22so20947599qki.10 for ; Tue, 17 Aug 2021 01:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=uMoWHC9cCmkGmKGRd5MKhVSuBe7FnrhK9vgIvOjVdUQ=; b=ZBCIu8JrSYXp32UHfr0V7Utr7kxWRAe1330WqMcSxMAU6EkiQqUl+y1J5Qgw9zu6HD NbkPMfRczuZxY7kB6NMOGMop7Adk9XdWy838R5kRiHLdhQnSwo+amn5PLFOZlFHq4xxu fuiU/mu3Z1aAmGE7CU3PikodGjnJJAXDr6m6cRNcOYdL7N1MEgpdgWzqOSxyRIHdrPGM eNZoVBUcsUl/lVaaIPFBHo1n96GV6/jnDvZpc8M88qKmmCutIfCz0r1Pwv550TNDZfb3 f5S0fTAcV1CggoawTLJg1zAyNa3uWYd8wePzYvXiseBVnqgsTnVYdKMYF4M1crB/QQrX fFfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=uMoWHC9cCmkGmKGRd5MKhVSuBe7FnrhK9vgIvOjVdUQ=; b=ZH/XpRwgB/CZH/NI6B1aEY/IgH75+mLoe6Ugd6L/IJaRevGL4Dh4lFbxKqUxMtfNlI 19RIjvYn7iFmNI5C9p78JmNNeLHtN/RXpcRDhExDFJ3OuGcuSwAEdszrzajh44Nollai eQheKyudhIVZz4h9o5vH8QMzegupOP5NbM/PVgAES5FShgV1hjNpOpTeZf99Ho2FwTJx pR0aaxNjbXDiMmD+BmULXsGrw9niQKom3JRBNAsBdTWo5VTCJcjZ6pDlIGrIcRAynuKd 1QJVyH3Zb4ggXmq/Nl39mB9MoVXAZ4YdEAshKPbHorC28UoaiCb13I9RJCIGejcrrkRg 2Zlw== X-Gm-Message-State: AOAM530z1Z7pBWJhr0lbnpylJlZSwfPibHXk1pUioxFFdWYekWkr5T/Y HwZHCZZANhFqXRaNIDxpnW1mRw== X-Google-Smtp-Source: ABdhPJysm9W9si8YZq6HQ/Q9doxawpakksZKCtswsPYBwhARLV5gH6YuEjM4S4T/sg5Os7AMzVnpvA== X-Received: by 2002:a05:620a:16b7:: with SMTP id s23mr2582871qkj.154.1629188562319; Tue, 17 Aug 2021 01:22:42 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id b25sm499732qka.23.2021.08.17.01.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 01:22:41 -0700 (PDT) Date: Tue, 17 Aug 2021 01:22:39 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Shakeel Butt , "Kirill A. Shutemov" , Yang Shi , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 8/9] huge tmpfs: decide stat.st_blksize by shmem_is_huge() In-Reply-To: Message-ID: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 20E93700CBC6 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=ZBCIu8Jr; spf=pass (imf02.hostedemail.com: domain of hughd@google.com designates 209.85.222.171 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam01 X-Stat-Signature: z6oy4z6jbju8fyfshrgagq4f9zdqnmon X-HE-Tag: 1629188563-27803 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: 4.18 commit 89fdcd262fd4 ("mm: shmem: make stat.st_blksize return huge page size if THP is on") added is_huge_enabled() to decide st_blksize: if hugeness is to be defined per file, that will need to be replaced by shmem_is_huge(). This does give a different answer (No) for small files on a "huge=within_size" mount: but that can be considered a minor bugfix. And a different answer (No) for default files on a "huge=advise" mount: I'm reluctant to complicate it, just to reproduce the same debatable answer as before. Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi --- mm/shmem.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 56ee56b1cab6..b60a7abff27d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -689,15 +689,6 @@ static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo, } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ -static inline bool is_huge_enabled(struct shmem_sb_info *sbinfo) -{ - if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && - (shmem_huge == SHMEM_HUGE_FORCE || sbinfo->huge) && - shmem_huge != SHMEM_HUGE_DENY) - return true; - return false; -} - /* * Like add_to_page_cache_locked, but error if expected item has gone. */ @@ -1078,7 +1069,6 @@ static int shmem_getattr(struct user_namespace *mnt_userns, { struct inode *inode = path->dentry->d_inode; struct shmem_inode_info *info = SHMEM_I(inode); - struct shmem_sb_info *sb_info = SHMEM_SB(inode->i_sb); if (info->alloced - info->swapped != inode->i_mapping->nrpages) { spin_lock_irq(&info->lock); @@ -1087,7 +1077,7 @@ static int shmem_getattr(struct user_namespace *mnt_userns, } generic_fillattr(&init_user_ns, inode, stat); - if (is_huge_enabled(sb_info)) + if (shmem_is_huge(NULL, inode, 0)) stat->blksize = HPAGE_PMD_SIZE; return 0; From patchwork Tue Aug 17 08:28:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12440875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CF00C4338F for ; Tue, 17 Aug 2021 08:29:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AF09160F58 for ; Tue, 17 Aug 2021 08:29:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AF09160F58 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3E4F66B0073; Tue, 17 Aug 2021 04:29:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 393A58D0001; Tue, 17 Aug 2021 04:29:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 282DA6B0075; Tue, 17 Aug 2021 04:29:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0046.hostedemail.com [216.40.44.46]) by kanga.kvack.org (Postfix) with ESMTP id 0DF3B6B0073 for ; Tue, 17 Aug 2021 04:29:01 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 98BDE18015871 for ; Tue, 17 Aug 2021 08:29:00 +0000 (UTC) X-FDA: 78483897240.17.BD5BE43 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by imf13.hostedemail.com (Postfix) with ESMTP id 57DC81024E07 for ; Tue, 17 Aug 2021 08:29:00 +0000 (UTC) Received: by mail-qt1-f175.google.com with SMTP id z24so16468205qtn.8 for ; Tue, 17 Aug 2021 01:29:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=4uvnY/LMX/fosu9BxO1MG6ugTMEZPtMwQldGntwsVH4=; b=NjCpK1NRhKmstHnpGiLXqM2SKOhBWtRSCCvP/5Amp0gqEwqp6QT1o+8ceJjU6jfYcL rDI6S2AFNamPsB4rByVDzyJlXKw4KZXU6D0rbktDv/9QfD0J2t8oUAaB2sOJGLBryTbW Eg9ME3auwtSoigl65liufDjtNbWJvOmgaeLq0eHHCyxJsULVCFf7GfGUgrPKsbxSwVQA cmdDUSbsnv+SoYjurKcsqszQmy4FQpbClnq9Zw42AWXe3ivRgU+PvAoZN1q5lME2rVm4 TE3/faPz6Y+vVIFyvh3bn7WAE5/J5u/v0idpkWltxqrs69YoF8K/Vp1jMsvycr72ZwZl rKrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=4uvnY/LMX/fosu9BxO1MG6ugTMEZPtMwQldGntwsVH4=; b=Q9CgzO37zkArKqu2Vn9rg/YO7foafFX0SAG6boK2AhY02LDnVXGnStAZDRdYp+oU2v 9pso0gd4O1BQqzc6XI6Urh5KkpYwEAgJHr3Btz6ZqXctGHpzGcNfXgsdxpykRtrdrzx8 AL+EM+s0G1UNg2m9GAmYD1BPrN16jXIrrJiBTgwFIQcX0GffAvdGGjwl3/TAdtfOHmOg worrqy1Il2ZjfMjnZBzASyfm+R+JMLJ4u7dFI/8kzx+jvzgvxc43JQXMdwDUupukHpyR s5AL7ARuh+QVr1TZB0hKEZdEVclHDade3RN6GOJneauDt/F0ua3BJBMa2De5C3AoiJFD A3vw== X-Gm-Message-State: AOAM532Xdcyl4uuePLnF2yp7h5kMequjeo6WnhbAMOKoQ5HubeOnt2uW ke1sef4K8Xlc7JyFcMCM0HXNxQ== X-Google-Smtp-Source: ABdhPJztKNjW9cvImVzVkZCglVqcSZySr11aNl7DJSxBXfIwHrFeR9hnzWG21G8vh8C8WBnA9lcvAg== X-Received: by 2002:a05:622a:13d4:: with SMTP id p20mr2056913qtk.380.1629188939512; Tue, 17 Aug 2021 01:28:59 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id y26sm884220qkm.65.2021.08.17.01.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 01:28:58 -0700 (PDT) Date: Tue, 17 Aug 2021 01:28:56 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Shakeel Butt , "Kirill A. Shutemov" , Yang Shi , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Matthew Wilcox , Chris Wilson , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 9/9] shmem: shmem_writepage() split unlikely i915 THP In-Reply-To: Message-ID: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 57DC81024E07 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=NjCpK1NR; spf=pass (imf13.hostedemail.com: domain of hughd@google.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam01 X-Stat-Signature: hktuwg9xgwwndbnx1xf1bdoss7ibu75e X-HE-Tag: 1629188940-808985 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: drivers/gpu/drm/i915/gem/i915_gem_shmem.c contains a shmem_writeback() which calls shmem_writepage() from a shrinker: that usually works well enough; but if /sys/kernel/mm/transparent_hugepage/shmem_enabled has been set to "always" (intended to be usable) or "force" (forces huge everywhere for easy testing), shmem_writepage() is surprised to be called with a huge page, and crashes on the VM_BUG_ON_PAGE(PageCompound) (I did not find out where the crash happens when CONFIG_DEBUG_VM is off). LRU page reclaim always splits the shmem huge page first: I'd prefer not to demand that of i915, so check and split compound in shmem_writepage(). Patch history: when first sent last year http://lkml.kernel.org/r/alpine.LSU.2.11.2008301401390.5954@eggly.anvils https://lore.kernel.org/linux-mm/20200919042009.bomzxmrg7%25akpm@linux-foundation.org/ Matthew Wilcox noticed that tail pages were wrongly left clean. This version brackets the split with Set and Clear PageDirty as he suggested: which works very well, even if it falls short of our aspirations. And recently I realized that the crash is not limited to the testing option "force", but affects "always" too: which is more important to fix. Fixes: 2d6692e642e7 ("drm/i915: Start writeback from the shrinker") Signed-off-by: Hugh Dickins Reviewed-by: Shakeel Butt Acked-by: Yang Shi --- mm/shmem.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index b60a7abff27d..a1ba03f39eaa 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1349,7 +1349,19 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) swp_entry_t swap; pgoff_t index; - VM_BUG_ON_PAGE(PageCompound(page), page); + /* + * If /sys/kernel/mm/transparent_hugepage/shmem_enabled is "always" or + * "force", drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages, + * and its shmem_writeback() needs them to be split when swapping. + */ + if (PageTransCompound(page)) { + /* Ensure the subpages are still dirty */ + SetPageDirty(page); + if (split_huge_page(page) < 0) + goto redirty; + ClearPageDirty(page); + } + BUG_ON(!PageLocked(page)); mapping = page->mapping; index = page->index;