From patchwork Thu Dec 19 07:30:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13914584 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 373C0E7718A for ; Thu, 19 Dec 2024 07:30:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5D826B0083; Thu, 19 Dec 2024 02:30:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0CB66B0089; Thu, 19 Dec 2024 02:30:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D4926B00A1; Thu, 19 Dec 2024 02:30:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 708476B0083 for ; Thu, 19 Dec 2024 02:30:23 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E7DF28122B for ; Thu, 19 Dec 2024 07:30:22 +0000 (UTC) X-FDA: 82910884518.26.022BE8B Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by imf03.hostedemail.com (Postfix) with ESMTP id A24E120007 for ; Thu, 19 Dec 2024 07:30:05 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=UyRUd3lW; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.101 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734593406; 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=M8zYKBBFJV3f7n/1X2H/QO/djeX/cWE2BXzLzdK+uwg=; b=77Z7TEULAIc2BsB5vGDzkCSY+Blq6P6TY6nXxns0UGQC2lBpkO33ojmArkjgRiOBgKO7zP qzIaI6GSXRjGcgyPz2CGEm+xNx/cI16FOpjfuRJ6ASspp8ueWlVz9oOpnUL5d2P6rBSsaE JV50gKkT0IowVDJPY01FFYulOwIDCgs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=UyRUd3lW; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.101 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734593406; a=rsa-sha256; cv=none; b=tTyBt51ZASi5qm+qVjLgLr3r681l3CD1TLMcEsjS8sx+oFTcyzvFST924oNwtzWk5m3Ibd A0zLmJU4v/DAoCsx6s1UHACoDE6msiO2/iJMDJFw2dAJMCBdabCkW3WYFmVgDK/lQoV1cu WSK0XEYqXCHGpu5HUAF3iEjwmEiedC8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1734593417; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=M8zYKBBFJV3f7n/1X2H/QO/djeX/cWE2BXzLzdK+uwg=; b=UyRUd3lWzBOY96nrVGV9o328bJXnzTt4Lq6Z8Vm3SOA7GRUAKErgrxhZHENe7M0FBk7Hp87XskG0AWNgku9iVg1hw4SeHpGEYBfECymQRVGnsJlngIghn1kjmOEx1qQ+CUQ2b1ruXy3/2V2rHnqueJhOtrSVVYQv6nyRUJA1XzA= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WLpQru._1734593415 cluster:ay36) by smtp.aliyun-inc.com; Thu, 19 Dec 2024 15:30:16 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mm: shmem: fix incorrect index alignment for within_size policy Date: Thu, 19 Dec 2024 15:30:08 +0800 Message-Id: <77d8ef76a7d3d646e9225e9af88a76549a68aab1.1734593154.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspamd-Queue-Id: A24E120007 X-Stat-Signature: z6prbt5o6np5w3fn8jtn9zj777m73wcr X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1734593405-222503 X-HE-Meta: U2FsdGVkX1/sJxqSty7w4M1dijVPg0SW8kHmlnS0irBb6rpHBFPN5fgvCkQtAZ/ac8YyFk+hBbufS42enZwbES5X0HNvNx4y59bF+ZEZ8n2S0TsDaXcT51xjQPA91GcKyVAO2a/L65NVwrpVHifOSg3/SfL4cV0gmBmO5yUXMn2hE5UqAKkimRSnAWHHMP5/S5VsYInHjW6nznKFHY8EMulngdPydlJM/+g9Twb6mnc52o9f/yytI1uqIpTaOPFBhP15Ec2jqZyq20wGpQDimm5AGq5zCy+oXz5L3Sy4wj4cFU7H85pGMyEtVFvMYVxpnYfNOVktVuugy4NWToQLK5rHl07lWX1cRhiLwENJ/HUxiPYN2oFsUXck/4aWm4RvUY3xJoDH0JAzGZXTP8a64rvKGqRFmA7DyUNN2n9x2hv7+wSivc/jMDnn7Gi3QPtr2YIaxNFWoosj/XFxmvUff5l7JkuJfRdQK+NlptKsx/xm6iu2VAgkCqBRg1598jKbzkF+rbcjHaxBbL/BYi5QqpESBP1ERycLaO7xQFaMWX1qMcN1XgHO5jmaj50A/v8lMOuEwjyULElbGy4cOlJVK5ZjweoXpyxh72Q2bhLUBbx6UlgG0M78rmVQMu0C/WKHL7vS+Ys4AvXn+NE2c37/92p4T+a7pglBX3g9mSgVBgKT89WxuZy1eLIRlEVAIF4fOWUrrSUnEkSmrgMkalEBfDC92aQkIOmNjimTMzWlYegYcEz72/UurdHZYUBlxwiCb9xZxzZthLQz1KXZYLdYmSgJCWO/VTZnElzkxEkBkr1Dg9L1I74pCqjjb/2H2oazK36NjuoXjIENqq974GF2mYIK1TNPpFd5Ng7QiSNJSKzzW2zSv3TJxWMy31+aZ7kZCY+uVUWvqBawUmOSAVDTVZoPuv4Ce/8AN7f3BOe+NXTcUb7dSf6yJEmT/UaKE7FNMVG8akD421YDRlMRLgG rU+QGFvd OeJwBFmaBrMyDwGk3OQXYe76Cw5/Wc2D0Yf9J9RW5Pv6bddolvtUZ5LAYG+7iUqv5b2QjxMACxemjfTkMGkQvKKi8uEMwdwhBCg3KeGVrC8GQDyJfI2Jp73tgKatRafGJepOb4HigVyUQCpCIM12rb+WQs38tUS3Tkt4DcreM4qY8btIW9zIfN8V7WuVKp09JXtLBOw/7INmIT4RpD2ETNU/7C4LaqyvyD0J8+/g6ONXVt0G9Md4nqvPiNrKSnEAgLVOjDKMMcx//Afg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.093963, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: With enabling the shmem per-size within_size policy, using an incorrect 'order' size to round_up() the index can lead to incorrect i_size checks, resulting in an inappropriate large orders being returned. Changing to use '1 << order' to round_up() the index to fix this issue. Additionally, adding an 'aligned_index' variable to avoid affecting the index checks. Fixes: e7a2ab7b3bb5 ("mm: shmem: add mTHP support for anonymous shmem") Signed-off-by: Baolin Wang --- Hi Andrew, These two bugfix patches are based on the mm-hotfixes-unstable branch, and this patch has a slight conflict with my previous patch set: "Support large folios for tmpfs". However, I think the conflicts are easy to resolve. If you need me to rebase and resend the "Support large folios for tmpfs" patch set, please let me know. Sorry for the troubles :) --- mm/shmem.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index f6fb053ac50d..dec659e84562 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1689,6 +1689,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, unsigned long mask = READ_ONCE(huge_shmem_orders_always); unsigned long within_size_orders = READ_ONCE(huge_shmem_orders_within_size); unsigned long vm_flags = vma ? vma->vm_flags : 0; + pgoff_t aligned_index; bool global_huge; loff_t i_size; int order; @@ -1723,9 +1724,9 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, /* Allow mTHP that will be fully within i_size. */ order = highest_order(within_size_orders); while (within_size_orders) { - index = round_up(index + 1, order); + aligned_index = round_up(index + 1, 1 << order); i_size = round_up(i_size_read(inode), PAGE_SIZE); - if (i_size >> PAGE_SHIFT >= index) { + if (i_size >> PAGE_SHIFT >= aligned_index) { mask |= within_size_orders; break; } From patchwork Thu Dec 19 07:30:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13914585 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 E155DE77184 for ; Thu, 19 Dec 2024 07:30:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 736636B00A1; Thu, 19 Dec 2024 02:30:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D8736B00A7; Thu, 19 Dec 2024 02:30:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5065C6B00A4; Thu, 19 Dec 2024 02:30:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2445B6B0089 for ; Thu, 19 Dec 2024 02:30:25 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 837F01A14A8 for ; Thu, 19 Dec 2024 07:30:24 +0000 (UTC) X-FDA: 82910884014.01.AAAC36A Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by imf06.hostedemail.com (Postfix) with ESMTP id 6D7C0180012 for ; Thu, 19 Dec 2024 07:29:59 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=P6VVKt2L; spf=pass (imf06.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.118 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734593398; 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:in-reply-to:references:references:dkim-signature; bh=dA/uo5tghpmaqVajoyvSrLkgzd8pWgdsOMRxw06MACI=; b=gF8NZoQ/MM44sNcD3q/s7yrnvXDdJDkAdbU9+RzYzp2tuqB/9EoAdDIKFNspkiMln4u768 4gIVcFPcPBG8Rtmm9Andm0vZhBwDhlPYQcwVH8i4BjPiraCdv94EiQ0E7X+s4dt9RUL4Zx 953HN2G8sZ12QL+Hu0uS/dnxpXwlFeE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=P6VVKt2L; spf=pass (imf06.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.118 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734593398; a=rsa-sha256; cv=none; b=J6RGQkKWukLqssfXBOg8dRcrVD7GAdHg4N8G4CkSyeaKYZ6ECTOheNx4KnudCmxjqxU5Sb OoPh2TMhtwblaf/lEtoM17FEv94mmiqVDuqeMjfUrqdX/2exBG6J6N8hGqVSxzEqF3zNxo 5RBP8jlXJ0/NEdk7gxgnUsLjg9vK1Zo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1734593419; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=dA/uo5tghpmaqVajoyvSrLkgzd8pWgdsOMRxw06MACI=; b=P6VVKt2L1a4rINlkoSrkC4Y3m4A8M5uQHZ90DiXCXrALDbr9gvEcTwbo0/lEQyYh4znyEGTA0S7j+K4DJUhuTe/PtIyIHts6JJ/BtynGUCcjcQfRyC7xx7PM9rySbCVua5GCQ5oxXCdfteI+bfPSVNAcUadRBqI2kV6zWgyEC8U= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WLpQrub_1734593416 cluster:ay36) by smtp.aliyun-inc.com; Thu, 19 Dec 2024 15:30:16 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm: shmem: fix the update of 'shmem_falloc->nr_unswapped' Date: Thu, 19 Dec 2024 15:30:09 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: <77d8ef76a7d3d646e9225e9af88a76549a68aab1.1734593154.git.baolin.wang@linux.alibaba.com> References: <77d8ef76a7d3d646e9225e9af88a76549a68aab1.1734593154.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6D7C0180012 X-Rspamd-Server: rspam12 X-Stat-Signature: p7ip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69TxS0agScBVPHQ49q14U9v5ekKqa+/mLs3hpjVWdA3HwAMMww4MomBx/ClCG1f9nOGa3BlBjn6aUqMpT7iFKMFItbwB5w/jxwCkYEvQXfHs2LNeJN6FsA0AOliUqUg3qgegk+ho1blcsMMw3n7ZB5TnO4MTKx4oAmfdNZTGq0wFLSgOaF07HIVV3X/djXNePJ+/IotT61IgG4sMoL8hb2yfi+Pg0D4F8pPr+XoAYgmwzEaNLvmR0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.036826, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The 'shmem_falloc->nr_unswapped' is used to record how many writepage refused to swap out because fallocate() is allocating, but after shmem supports large folio swap out, the update of 'shmem_falloc->nr_unswapped' does not use the correct number of pages in the large folio, which may lead to fallocate() not exiting as soon as possible. Anyway, this is found through code inspection, and I am not sure whether it would actually cause serious issues. Fixes: 809bc86517cc ("mm: shmem: support large folio swap out") Signed-off-by: Baolin Wang --- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index dec659e84562..ac58d4fb2e6f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1535,7 +1535,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) !shmem_falloc->waitq && index >= shmem_falloc->start && index < shmem_falloc->next) - shmem_falloc->nr_unswapped++; + shmem_falloc->nr_unswapped += nr_pages; else shmem_falloc = NULL; spin_unlock(&inode->i_lock);