From patchwork Fri Apr 21 21:43:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13220709 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 14FC7C77B7E for ; Fri, 21 Apr 2023 21:44:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E63556B0078; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB9D46B0071; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8709A6B0075; Fri, 21 Apr 2023 17:44:20 -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 494976B0075 for ; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0FCC0C0974 for ; Fri, 21 Apr 2023 21:44:20 +0000 (UTC) X-FDA: 80706727080.24.07D4C76 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf04.hostedemail.com (Postfix) with ESMTP id 10CC54001A for ; Fri, 21 Apr 2023 21:44:17 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=DnGs3ejE; spf=none (imf04.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682113458; h=from:from:sender: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=HAZkfNRruAgARTe618ACsQ6wCYRRSd9EZooPKA+qgbw=; b=pEP6lsoSagu8AX4f06EOnHGDr54g6t+zBL4AhfBj+llfd+2h95C20Z45fnapG0Ydg7wspJ XvVfOa33mCSbS5NOBY5Pr0MJ88xpLnoFmqxGSZUdCM80rIkvYWixUGE2qocMluhu/JwgDq o7ZvUaaPCCin/xplafw5yLQmbD+0wCI= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=DnGs3ejE; spf=none (imf04.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682113458; a=rsa-sha256; cv=none; b=7H4Zw9AsaGAnxS/V9DSNiirzrlYcRx2AcWvT1mCoBRJ0iG2jcuGw/Bzo5Sk8cuZa9Vdfi3 0Dx3Z507aVsPOYjmC7nd1Aj4c+hdPKP1kc7AVPa0jwe+VcGi9eAZ8aEu+Kehu1oVBtfjOh VKWWLshflIy4jKfYudZdd1jKrxRS+jE= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=HAZkfNRruAgARTe618ACsQ6wCYRRSd9EZooPKA+qgbw=; b=DnGs3ejEo/+K910m27ugy2zmJh qb5mcLlEfR2wdQNE/p1//CuFDbtuczZKd7j27Gu+GCzFIVBmDmCr5B7yxLhtPcDngNB4k80THHDuR w2DMyrzuDU9msgM7Zy+oghoVKusNkUcBRoJC/pAS7Cc8RxdQEaVjJ+Bd2tc6Z6+C7gpfmYibKo708 Vi5Tb7IXkNa4kvn4N3d3BddjBa5cCKcG9E33SvWZ4GkM7ZwxcmNuAPg77qD1HGAf/ilG221q1rmJ5 9ejkkgHgonznxoi20BOMaCnyIcdksGRblL0lJg1XSWnZUtylSqq5ykxsRsCRkUyoDucbBY5Vd4B0h p73Bmwcw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1ppyY1-00Btoi-1l; Fri, 21 Apr 2023 21:44:05 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org, djwong@kernel.org Cc: p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, hare@suse.de, kbusch@kernel.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC 1/8] shmem: replace BLOCKS_PER_PAGE with PAGE_SECTORS Date: Fri, 21 Apr 2023 14:43:53 -0700 Message-Id: <20230421214400.2836131-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230421214400.2836131-1-mcgrof@kernel.org> References: <20230421214400.2836131-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: syu3x8g99p3ouo4pisauggh8akbj91ne X-Rspamd-Queue-Id: 10CC54001A X-HE-Tag: 1682113457-994454 X-HE-Meta: U2FsdGVkX18zh4+URRC1dh1Wrb8jr3aPCrAvwxzvYrqnbbHjJ3PEEWsnbpmoNVmU5wRHCkqms4xIwC7UXUt3hdk/oGYbqZ2zeY3gR6343a8xg9Ytvyw8bNsU7Wj8eJXkvmiM4hWD88MiO7IoIhEPZG7xUK0VQi1hN+9sv1eURVA+DIMlMh9jm6/8NPJKEjZxU0RmI7XdY3ODKV+UtL+MVYC6X/UYszKE+9+YeUW/p8hj0vWOxukF+f2DTfYzeqXow/S4s1Xc4DaeZhqQdAFXRtiKL2POUxLJRbRtMkuWwfSyqtvul2A0vfZbCze3QPf2M9ZnEu5WoFncoBS5pej9AAmN24w7NsDyd1D7hAvRkkt+XoYXFuif1RtvJfgEQzPSrqzUw8T3jqdLDiAWNM+Et3qdeKMO8wPlQEq/O2f94Nd+8zKw/n02c//fNHSwfl0hjAJSbuwxzfnM5Y2XTLlJgiNse6YUSOmYOBMTy4jM8q39X+bWW85aCYEv6wfaCmVUjsOJ50GuCLcDOqSh1yCVbPrMXWVveJLgWENVQaYCIwD2rjVawLvf78PArNCOGI+rkvB96e5ewONV6m4CTolZcUP3AgPP5Yak/WYU23zXQVtxImYoJHzBuOvumRwnMY+wNKRHt7ypeoujHMFD8Fx0DkZf7tEIi6tqtgSvGjO/E5/aEpiaV5rOZOOQ9PTDjDXYcb3ODkDbhNXPEWNGMVG+Uhmrr9Q2x4uCgWC94Z1eiMhPsvNCKiL2LXYZPgEbpIHTGVWMXxLOF0XAVkxvziWddHr53YOEqNGeDb3kJVym7ZD1xv2F3k3GwMQUGBmmSwBi/0RevqWyenPVj+utIl+mAM7J8OwGqfhZgViblUOH5lYQOMStLFb5q11rTazmt2gUgjBNKTsvqUejk3lz7wMtjtG+AYcYdLPEMhkD8j08aUlQIwYAnBSrD9hfbElSDOJp8zij6K/lmbXtCC3R2py rTtXrdQc NFl3fj1S3PpX9UXns0CEQzGv9Upk8PXWSIzDxzRDFcd1tR6sc4EPOTBwithmBjeFmVrUo6C582KxVzCFCQN2w6EnNdydp3TGVrpIZR+oQRRjKuPFSmR3Ogw5sZI3wHVOF2lmBG9Gm/afWGLDWBdJPAKsOmCmb5WodzWB1Dxma720+DMMI4Nfn6sQ/6mAMQmL8DbQ0jj+fHZd+sDFLZOMmK5jmGJImZJysnlaeVzdY0hMXvuVpAbWFMs1x1hacAQSwHnJy970ym5C4vd0HKSVJvX4M8PDCFsLcvum7CNTsryhf2e85WPTMuchLaqXCYqL+yaFnoC7zr0xFTPG+HGxNKvJhP/sLmslYIIeg+QWrlShRQZOVFEsrHdWgegwJbYZtBCXOQGKCXru1e5xQGd2gg28FUVFXruOgVK4fQ86QrvAv7bT+PStKnvVlte0vPXtHCVJg 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: Instead of having our own macro use the generic PAGE_SECTORS. It also makes it clearer what we are trying to compute here on the inode->i_blocks. We get the inode size by as define din __inode_get_bytes() by: (inode->i_blocks << SECTOR_SHIFT) + inode->i_bytes This produces no functional changes. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index b5d102a2a766..5bf92d571092 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -86,7 +86,6 @@ static struct vfsmount *shm_mnt; #include "internal.h" -#define BLOCKS_PER_PAGE (PAGE_SIZE/512) #define VM_ACCT(size) (PAGE_ALIGN(size) >> PAGE_SHIFT) /* Pretend that each entry is of this size in directory's i_size */ @@ -363,7 +362,7 @@ static void shmem_recalc_inode(struct inode *inode) freed = info->alloced - info->swapped - inode->i_mapping->nrpages; if (freed > 0) { info->alloced -= freed; - inode->i_blocks -= freed * BLOCKS_PER_PAGE; + inode->i_blocks -= freed * PAGE_SECTORS; shmem_inode_unacct_blocks(inode, freed); } } @@ -381,7 +380,7 @@ bool shmem_charge(struct inode *inode, long pages) spin_lock_irqsave(&info->lock, flags); info->alloced += pages; - inode->i_blocks += pages * BLOCKS_PER_PAGE; + inode->i_blocks += pages * PAGE_SECTORS; shmem_recalc_inode(inode); spin_unlock_irqrestore(&info->lock, flags); @@ -397,7 +396,7 @@ void shmem_uncharge(struct inode *inode, long pages) spin_lock_irqsave(&info->lock, flags); info->alloced -= pages; - inode->i_blocks -= pages * BLOCKS_PER_PAGE; + inode->i_blocks -= pages * PAGE_SECTORS; shmem_recalc_inode(inode); spin_unlock_irqrestore(&info->lock, flags); @@ -2002,7 +2001,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, spin_lock_irq(&info->lock); info->alloced += folio_nr_pages(folio); - inode->i_blocks += (blkcnt_t)BLOCKS_PER_PAGE << folio_order(folio); + inode->i_blocks += (blkcnt_t) PAGE_SECTORS << folio_order(folio); shmem_recalc_inode(inode); spin_unlock_irq(&info->lock); alloced = true; @@ -2659,7 +2658,7 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, spin_lock_irq(&info->lock); info->alloced++; - inode->i_blocks += BLOCKS_PER_PAGE; + inode->i_blocks += PAGE_SECTORS; shmem_recalc_inode(inode); spin_unlock_irq(&info->lock); From patchwork Fri Apr 21 21:43:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13220714 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 C2D0DC7618E for ; Fri, 21 Apr 2023 21:44:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 31C216B007D; Fri, 21 Apr 2023 17:44:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2569B6B0081; Fri, 21 Apr 2023 17:44:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFFE76B0083; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D5ABA6B007D for ; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9FC97A061A for ; Fri, 21 Apr 2023 21:44:21 +0000 (UTC) X-FDA: 80706727122.14.C78AAB9 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP id 0762D20007 for ; Fri, 21 Apr 2023 21:44:19 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=l1UKRS+6; spf=none (imf13.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682113460; h=from:from:sender: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=Pwtny366FbTbrb7vPgMXDOxfQYz6bsR4vwvBIbUUYzg=; b=5OMpZwr6G6SSkXLVyZ2Dfy8sixszVEgwSPWOF4nHmP75RuSCAH9KP5XtTLiFl6gMwaFDH+ up7op0iDhpK3m7U9EbcC8koYk5CRc5u0XTMfjcAp8VN3kEwT5LkPbX4BvdaF9NfT4CZ2oG +XEBbDjD2ITTqQh5OaqXoJrkLRORWw4= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=l1UKRS+6; spf=none (imf13.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682113460; a=rsa-sha256; cv=none; b=MzhdqglAD8UpjFhlco1Z0IYyytxhh58K/4eD5/NVanrBIEtv0y2I+z3y/V/J+iZLcnUoHq vGBDWsD/7iTiYdS2NmE2pVlzRM6mgYYWyAFF7SI4ASXEAuap3caUq3QIDuut8Zg7s5Bcpb Um2TsIXv9eguvoUVKM0J9hktE8+M/BE= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=Pwtny366FbTbrb7vPgMXDOxfQYz6bsR4vwvBIbUUYzg=; b=l1UKRS+6uYC4EXAjJgBrQTAp5j xsYvwCnnNonL+zWZMEy71A3Ta6km8F6dSzKQvEcpRo5TV7XBXl9OERI0fsz5C845ifOI1VFCEHRc1 Zre0qUD7V89WFxot/x0Dllx9YnFxYQ7Yz7zDqe598RN0r0tdnLI/4pmF0Tvd/CygY81NUfyF7TcfO R1q/JTspIPOKlYq6NoZibJ4hLTLlDqaLHYjGQRhRwv9u7o7cGbziZ6ambxSZLU25fgMv7Z5We7Z9g 4m2TriUxFygO3OJdPvzDe0pBPp5xw1iklrlut7//xUpzOnTPbemmyDvmuxTGhDtulG3XxP+CyxfK9 9RMFdwJQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1ppyY1-00Btok-1t; Fri, 21 Apr 2023 21:44:05 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org, djwong@kernel.org Cc: p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, hare@suse.de, kbusch@kernel.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC 2/8] shmem: convert to use folio_test_hwpoison() Date: Fri, 21 Apr 2023 14:43:54 -0700 Message-Id: <20230421214400.2836131-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230421214400.2836131-1-mcgrof@kernel.org> References: <20230421214400.2836131-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Stat-Signature: gwh8g3yfamteiwsp163dio48cppf6o6c X-Rspam-User: X-Rspamd-Queue-Id: 0762D20007 X-Rspamd-Server: rspam06 X-HE-Tag: 1682113459-238465 X-HE-Meta: U2FsdGVkX1+5hGgtqwcsvSleHQEMpgu1jk4Yhny0zo+TbDaMrb2m1vScqRGtBssryH4xhzxIoMBGmJyMHNQmFQEQuIWC5dUxujBK7c/G91G31TMZ3xoYvrDhcUUPeidXL3MrYxyuFel1sNswGhT99x53I8NcE0tiiy2iO9Uic93tCa7UguxQqvKDYohgh/qKUh+Ryg+sFWBr591y5h1UeqnsF1J4yqRL0hNQ61Zf+qb575sZhLTyO19oZ5JOyuj+mHRBngthrCxLvb3A5EG2fWrz9eSOep230kJ4V5/ByS0VTHomah58iV9uQWSl5LDIqn48ZZ1+zurOyoBR4iaJWbdGtw9FWiDZLgMw+NzXUzfrLxu5uyt6R7TSQlZMPTzAol7i4UX52CH3jNxc/xikHax9qxqIMeEx80IhuzFZNXnGta/xSBnL6IC1v0UH8Na8e4cGgnQ9qwGyxRAMGjxYeriEpXJvuPK/lLFo075tL8jwJx0NaaWRip8PcmREquPwtq5FliaTEw6XMM0SQJFk9Z6WtDz04bpP0RJzaVMmAwBO3aojB/4sMQkV+t7ulzXXplmXu6AI76PPNYCNShmixP3NbP6ZLbPCpLdPC0oYiP8OpAEsyyAxfUY79dJzX2wizZ7AzqLMN/OQnoGCDDHYvubL8aKz5zgbc+g1JyMLbrgIY1U9xwARA+Oa+E/t8cla+XM40m/kcqaA0xlx6rKPyZ6UKVyiD3iFbg1zfGrLakCgSmE70IgYQLj5NqZOqiD+IxKghS90QIHjS7SC9j/LfGpp+n2oVWAOC3QLm958mBhaLFNJkyjVyKyysQUtv37YoQyRyK7qnnD2luqMfKSSaiGU6/x5GrVZbqM8FzeD9t7T1PxKJQMpXJt4oS+lQ+vgUEqPZoZuZRnHdl/56xvT1kN1L6iG87zSX4rNE1zXLgFjevOyR/cBwQOcMUIEvPwzuzXq6CSN6Bht05dWi6e WI2nNGJn 4zA04zW7AKmJaefgB82q3XViduTyb/OCQhjZ/c4upuLd+qwZPApa5Pg6hFPiKBn47PdnkNApMit2vfCpAaNhZ/fzZL4epurddyD1TxLDbR1SLnjTaEEWEho/hew86uE+rb8JyhJMvIbSN3OFhK5WRiTamC5oKgFsSpR6nLX0FHqXV0VBn6G1XikSi7MQmqD8L7H2hRcCn9dYVVY1Psc80lJw+pNDSeYYel1yn6LS3krswBDJekBlhjScnRuNu/v3UNxSyCB0tkrMfsl97ndRltX0iUlddrF0yaKje0k1t3ljDMFH0mFrJorQX3Ma68Auk1S31wt/MpY2GkgG39dclv/0eOD3RAaQdU6+SAQwdeGUUmwZ1NWwu1LhAxa9ar5DmtcNxQHpUFi//qruBlbCtuwaW7d2SfMKjLCGwjHIvPX/yK+ETrcT4+Iz/Yr7SRVMdXunS X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The PageHWPoison() call can be converted over to the respective folio call folio_test_hwpoison(). This introduces no functional changes. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 5bf92d571092..6f117c3cbe89 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3483,7 +3483,7 @@ static const char *shmem_get_link(struct dentry *dentry, folio = filemap_get_folio(inode->i_mapping, 0); if (IS_ERR(folio)) return ERR_PTR(-ECHILD); - if (PageHWPoison(folio_page(folio, 0)) || + if (folio_test_hwpoison(folio) || !folio_test_uptodate(folio)) { folio_put(folio); return ERR_PTR(-ECHILD); @@ -3494,7 +3494,7 @@ static const char *shmem_get_link(struct dentry *dentry, return ERR_PTR(error); if (!folio) return ERR_PTR(-ECHILD); - if (PageHWPoison(folio_page(folio, 0))) { + if (folio_test_hwpoison(folio)) { folio_unlock(folio); folio_put(folio); return ERR_PTR(-ECHILD); @@ -4672,7 +4672,7 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, return &folio->page; page = folio_file_page(folio, index); - if (PageHWPoison(page)) { + if (folio_test_hwpoison(folio)) { folio_put(folio); return ERR_PTR(-EIO); } From patchwork Fri Apr 21 21:43:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13220713 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 B6E9DC7EE23 for ; Fri, 21 Apr 2023 21:44:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE0A96B0072; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1B266B0081; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 849CE6B0072; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) 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 33B216B0074 for ; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F2C01A061A for ; Fri, 21 Apr 2023 21:44:20 +0000 (UTC) X-FDA: 80706727080.20.E0BB9A0 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf03.hostedemail.com (Postfix) with ESMTP id 556BE20012 for ; Fri, 21 Apr 2023 21:44:19 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=N942EdhF; spf=none (imf03.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682113459; h=from:from:sender: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=TaEL6wJEWmG7v/Kj+xMCxG7l/Tv1LU1WrJwnB3EGy3E=; b=lcuxInIoSo6fNhJRdMibTlvrKivKGDgBfiv+usPosWdV3AErRxBKxuTZul8b4tGMgmFZwb hfX1F3A3eFJQzjcQqVzwbLsXzp5DTKHoyVTTxlY2YYo8DK8fnSDgv3ZMIlr5LjpOe59b9m 1RgAn350YyUz35oFIWCere3mu7MimJ0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682113459; a=rsa-sha256; cv=none; b=Ap+K1M88zun9or5jOeiIBsYzrcN7T9HmrJGTZxbgm16JPoejofat3MsRLSdf931Fn8jOm7 njdQbf8qI44oYr7WMVIKntFtjiChcBT5O2U2bZXGIMSpCL0I2dYdS4PFK5Ro1JM3ZNa4zB eICnQrEKL9ZG8mJAwHYivP5quHtmy2g= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=N942EdhF; spf=none (imf03.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=TaEL6wJEWmG7v/Kj+xMCxG7l/Tv1LU1WrJwnB3EGy3E=; b=N942EdhFvz8Gq8X0vru14SS2Tz NSMMc3ogGzPG2/igUrApVOD7nvcB5K/4UI28nLVYOwAB52r3+fcJXP9APHpwXmOM3q6qrw2BgTt/j caFXw1rBuZp75667SgZQedCUy2WjgaS5ME72NMg2F8DmvIV9HV4lZYCengkZYqa2jjMLpEBGuGQm3 cAzPOhEk2Y75zB3VUvyjKzHud3xR7zENlmf188YTgv99Mkb7ucqaY9iy2HJd2LE35twbd41deBG5N HX2mbF5Ndbygf6Towllz/Gv1UT754OGwbCZbye8ao31rI5EjMABW1FJPa80ME9BC2gfYF+I0GujRk iyqZUPTw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1ppyY1-00Btom-22; Fri, 21 Apr 2023 21:44:05 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org, djwong@kernel.org Cc: p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, hare@suse.de, kbusch@kernel.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC 3/8] shmem: account for high order folios Date: Fri, 21 Apr 2023 14:43:55 -0700 Message-Id: <20230421214400.2836131-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230421214400.2836131-1-mcgrof@kernel.org> References: <20230421214400.2836131-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 556BE20012 X-Rspamd-Server: rspam09 X-Stat-Signature: j3bdf4pjpqq5p3rpfdg95f9acy3y1mjx X-HE-Tag: 1682113459-357755 X-HE-Meta: U2FsdGVkX1+3BaXJsdz1ZVNEROi9SAyWblzV5ifU9A2lel3sUJDSAHhSfbzGmZ/u2A6EX4bOFVxQbDRNXNsym45y2NpMzi9QVZJhhV1KmFRw26CcQW94KMutIwyg4yy4my9REgx1Sj34Qhc14ZYzidO1SYKHnSEPOmJDJO+sXdmUyWMk80MoJxk1zT6hVjmNUhLlf3nfefAL5mUtXyYj1clA3aONmfmfSQZsNcfwQ3k5jFFQdxHZxPT29ULa7LbNZEwaZK+JMWj1/MRK5glNjBp6JLBaGy5n1LSKuEoeFHoG1nLfDAGbghT43b6NvFVF26fV0+neYQdMC1MdMTW/jJjznEvU+WT5q68/0jCTFaoKA6KNuNzfpos/hX4OaqtQoIQzvmRR9H6pmiWRXLN4j8+x74HYB7/kFPFlHRoE9AXsMLcC0FWKrS+xPslh1kvVefYht8tlRFtas0Roi6pfTaOysYHT87Fty4IosnpnMfHN1o5ZPYTIlfFfBSOUhwF8nRXzHpv1tZfzGtVODrysifI0zAJpHKiYDlyyvRKmhNKfdfwgMNutHTJ80ARcgjl44WlHZE7VQOHa5AXf8ZjsSrt5sUh61Spp5ch7Zx7lzpTXGRuSZjFEK+caxZfna2yd3Kk3TUg3VzyfLyPGUnT6AKmDjgQTaKW59YZQ2oJvXUgYgCOTwhLRd0yb0BfKLnIhsCELLkSGIKomAHp314BSpx62TyFPh3/aAUvEeEB5LtSxZl1/+w5V1sprTse2TO+RVnb0ET+FflONyKHL02QiuArEXHT1g4TQ4h4IOHhmu9JVmkRBRiylg0LNYc0fPKkipM6ORDtsZW3DOtXo+oa1LDvJ3vNNWOAQVSTAV9arEP40JKG4ie7VZlSq5NuSll8Q++LMK1hYaRSSdow5LlPxFKMnM6oaER9DnHd5BZ6X4mLhrjnVWhujEBlfkv3VxAAaWhU/Z7AJ3DmXMgtVnCY aGNq+JQM QnSZK+aUj7Cc8NWl1FFE2SW7+8aIrXBLAKCtP1o/uXfXqhLs20SeopfXuDpHWuwz0ckVq85B6TT5TO6krepvbmiwj2HoDqFYqsfeZD1RjMFhLQOpXT4mW/QDi1seYHz81nbor3wG2fEKnhww7P5I6pdAX86I3NrKBRReGCaUSqt9XramPqlahACgT1vjhooidhtVO1yaCSRlcXSGle5uNnBF0VdKlJ50bWsnH7jVXSG72dGzXwBILmI9aMWuGa1XtrsYfuPENUy9H0hrxSs/jpkGo0T6dBNP1hIzrtnoE6ciCVqw9Xrz2pOeMcCAwiCpnK5xvBuhBNnBH/qCfM6KDqcPFH6MuPxtbBFwGVYmJ56XQOTZsQPkuFihxmoK83poUz8n4ifea0iG8xEs= 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 uses the shem_info_inode alloced, swapped to account for allocated pages and swapped pages. In preparation for high order folios adjust the accounting to use folio_nr_pages(). This should produce no functional changes yet as higher order folios are not yet used or supported in shmem. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 6f117c3cbe89..d76e86ff356e 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -806,15 +806,15 @@ unsigned long shmem_partial_swap_usage(struct address_space *mapping, pgoff_t start, pgoff_t end) { XA_STATE(xas, &mapping->i_pages, start); - struct page *page; + struct folio *folio; unsigned long swapped = 0; rcu_read_lock(); - xas_for_each(&xas, page, end - 1) { - if (xas_retry(&xas, page)) + xas_for_each(&xas, folio, end - 1) { + if (xas_retry(&xas, folio)) continue; - if (xa_is_value(page)) - swapped++; + if (xa_is_value(folio)) + swapped+=(folio_nr_pages(folio)); if (need_resched()) { xas_pause(&xas); @@ -941,10 +941,15 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, folio = fbatch.folios[i]; if (xa_is_value(folio)) { + long swaps_freed = 0; if (unfalloc) continue; - nr_swaps_freed += !shmem_free_swap(mapping, - indices[i], folio); + swaps_freed = folio_nr_pages(folio); + if (!shmem_free_swap(mapping, indices[i], folio)) { + if (swaps_freed > 1) + pr_warn("swaps freed > 1 -- %lu\n", swaps_freed); + nr_swaps_freed += swaps_freed; + } continue; } @@ -1010,14 +1015,18 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, folio = fbatch.folios[i]; if (xa_is_value(folio)) { + long swaps_freed = 0; if (unfalloc) continue; + swaps_freed = folio_nr_pages(folio); if (shmem_free_swap(mapping, indices[i], folio)) { /* Swap was replaced by page: retry */ index = indices[i]; break; } - nr_swaps_freed++; + if (swaps_freed > 1) + pr_warn("swaps freed > 1 -- %lu\n", swaps_freed); + nr_swaps_freed+=swaps_freed; continue; } @@ -1448,7 +1457,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) NULL) == 0) { spin_lock_irq(&info->lock); shmem_recalc_inode(inode); - info->swapped++; + info->swapped+=folio_nr_pages(folio); spin_unlock_irq(&info->lock); swap_shmem_alloc(swap); @@ -1723,6 +1732,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, struct shmem_inode_info *info = SHMEM_I(inode); swp_entry_t swapin_error; void *old; + long num_swap_pages; swapin_error = make_swapin_error_entry(); old = xa_cmpxchg_irq(&mapping->i_pages, index, @@ -1732,6 +1742,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, return; folio_wait_writeback(folio); + num_swap_pages = folio_nr_pages(folio); delete_from_swap_cache(folio); spin_lock_irq(&info->lock); /* @@ -1739,8 +1750,8 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, * be 0 when inode is released and thus trigger WARN_ON(inode->i_blocks) in * shmem_evict_inode. */ - info->alloced--; - info->swapped--; + info->alloced-=num_swap_pages; + info->swapped-=num_swap_pages; shmem_recalc_inode(inode); spin_unlock_irq(&info->lock); swap_free(swap); @@ -1830,7 +1841,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, goto failed; spin_lock_irq(&info->lock); - info->swapped--; + info->swapped-= folio_nr_pages(folio); shmem_recalc_inode(inode); spin_unlock_irq(&info->lock); @@ -2657,8 +2668,8 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, goto out_delete_from_cache; spin_lock_irq(&info->lock); - info->alloced++; - inode->i_blocks += PAGE_SECTORS; + info->alloced += folio_nr_pages(folio); + inode->i_blocks += PAGE_SECTORS << folio_order(folio); shmem_recalc_inode(inode); spin_unlock_irq(&info->lock); From patchwork Fri Apr 21 21:43:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13220710 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 59FF6C7EE26 for ; Fri, 21 Apr 2023 21:44:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19FEE6B0071; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C8EC56B007E; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4CB26B0072; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4D8F66B0072 for ; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 253DD16069E for ; Fri, 21 Apr 2023 21:44:20 +0000 (UTC) X-FDA: 80706727080.25.CF490A6 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf23.hostedemail.com (Postfix) with ESMTP id 8EE0F140003 for ; Fri, 21 Apr 2023 21:44:18 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=4Ut9M+mn; spf=none (imf23.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682113458; a=rsa-sha256; cv=none; b=2PRRlsVW9F01PhjzKLitbMlY+qt4m+0rq7HoQGTLXTGY80PlCNCE8wvJcWEVDDuwQezp9p QdRJAnUyr3eqANoHVHLhWTBdxPJ52/WE70gExg1WV2ToDFwLXeZFdHYfOFYUrX5KtP05Bn 3/zFi7PzJ132JlDAj4cNWW3EixoOOSo= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=4Ut9M+mn; spf=none (imf23.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682113458; h=from:from:sender: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=nny3k9GHvISmRebv/wiZT4olnvrgRU1LTkzNA8FqTDM=; b=eOFvuCjzTmi+3rxICLDv28/xlkKiPySOeH/v0ij4RVzCB/s4ukrNoksjKkJXY5cWds/3/x 7vV5DuE04womn1mi1oNlrzxu2hJljm1ObpDZQSLMEsxCFqmSkp9aWrinOJJvv09AIG68C1 +Kr3HorVp/smwpuXCEU31j3In6C8G68= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=nny3k9GHvISmRebv/wiZT4olnvrgRU1LTkzNA8FqTDM=; b=4Ut9M+mnDbLVzS5mn357NtXNVg iW973AulcqLzyWup7ygr0muRVGEjzVtqC6kqytGxva5A/sIYSQFeBlshjjpIhF6OYCvi05IojwxWE tsKCO6qUCenqfN9MsAZAdEWGPc3v0HjGDax4M6XvZmaBXtzA5v2C3KaFqloimB+8x6u/npTruKLQs 036sfUHB5iNErVxwNzS974BCSyU1Ar0fEOvtLbwggh51AghvUuMZYxAGZfc5IZ52Xmohp9mLGlsCy TaULQnEPNlB7MAFVSLGTPIcEwbgWNxO2AlGc26ENLqMM/u81jGPh5M591B/wApNppCBuEnfc313kb pACYjTwA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1ppyY1-00Btoo-2A; Fri, 21 Apr 2023 21:44:05 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org, djwong@kernel.org Cc: p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, hare@suse.de, kbusch@kernel.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC 4/8] shmem: add helpers to get block size Date: Fri, 21 Apr 2023 14:43:56 -0700 Message-Id: <20230421214400.2836131-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230421214400.2836131-1-mcgrof@kernel.org> References: <20230421214400.2836131-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 8EE0F140003 X-Rspamd-Server: rspam01 X-Stat-Signature: ai8nf6wgceg5mjx9za1da8ur8wz6hsby X-HE-Tag: 1682113458-466572 X-HE-Meta: U2FsdGVkX18tK045+uD6tt0HnAF5jbC+YVUt7BygkHrJ+nlw6pYtyzKhfc0ZgUokG830bAR1g6ybXiXtaPvDnPDP4nOFwwcf7I5odBt7M8UuVRzT4v+czLVQCVMG4ksR+yAXgGm3vEFeD6ueSuTZz0K8IVOt9zpO13pQOgPYpOrK3yi1B3c0DVjecjIxzkDJNW8dx1gfCoH2jx8yscl6bbYfqNTN2UqnP5a6g+45IZl+Z25x/jdHEIwmdenR9/m2MMA/cbIfJWlzVTPv1jZ344Z0n6SWVh5Y9OOXQaOLidTBnypBvfUs8A7Ri4QRs9UeagPtUfHJ+ZPwpq830Pyd7O0052gTdd/4klVM1HpuUyX3bxbTRUewMhcTz3ysjHu3qA+7XSJpW/42ZdbqF/EH6X+/neJSQJq4UE+FSdcH9pSjmSZuQE26jERjTbdUdOsUew0/Z505Co7Qagmubi5Mcgftp5MCJpP9ape5AMFQUm7KAwh6wtflMSHPhC5BjvvbNyzYu03SvYuWhjRUZ6KPz7JTl48ssi4GEQgHXLAwhER6yrFmOugbQHAAofl1aW7A0RVSA8Rm+b2jglBFr6HuyNKvdVsANBS84CPErIo08L4ptw1l/WHknqA9SwjIBbwTqcLj+wf381ZylxMcIIGHQcMiL/9QSiiDEK+GKvlycwXH/h2SdC1yMAcKW97EbCM9a+SbPXFf8Sjasv5rU0kZjxacuRdI7RHucKcSCM36gJy/tE96uSpv7mKSagDRcJn1yu3hI1BoHVAq/Av+G3PBx/8kYgoTHcNlWRm7MyX7erfywmy6QSsoNenev0nefwYVoKr3jv2+iPYZBjYnY/rpZEDbCKtitkAZCknoyxA9hui0BmP8ISJkWDFxePdxvVHQ12j+4V621Sh+S2y3T9iq9F8tYREosDn4vJ0BFpzzVH1vdw0Mo4D9Ww9bcESAqePMjTHZff7kKOZo93kEtrL Mdrgf9LY NTOXDWgBlNhEfp1GjFs3jetrdiqClutIPg3lM57LwlCJvxzuQx9zbN0BbNADT2BNyxbGW32YW5peKRM1nu8DzgkNB73U6OSf1pkJ8g3dopxtFzkte7Ky4lsJOVY9tyHCSa5uj2Eh+phtUW0N+bPaR3WFYcnk8gSj8Rgz+DwOa63VRK9FfSuKpu5uYY04W2CMF0mggECIcuDEXhskOv7iDDDUlk5zodmSdSQrxfnM1bOLCnre9DO6CunUL/2ncX/l7mSnCKX7lZmxHdSoyqGpRsQZKGvy+zV4DwuQVTHB6rHFxmw9dUsuH30YNxmlWxRpCvf0RAxp/XyLssLSavsM2Dh6azZikrtCOIVME6fNgv7g2OfUjz8t1ZuJB2CptMXj6BKu+u+8hoUsGa2Q= 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: Stuff the block size as a struct shmem_sb_info member when CONFIG_TMPFS is enabled, but keep the current static value for now, and use helpers to get the blocksize. This will make the subsequent change easier to read. The static value for block size of PAGE_SIZE is used currently. The struct super_block s_blocksize_bits represents the blocksize in power of two, since the block size is always PAGE_SIZE this is PAGE_SHIFT today, but to help make this a bit more apt to scale we can use __ffs() for it instead. This commit introduces no functional changes other than __ffs() for the s_blocksize_bits and extending the struct shmem_sb_info with the blocksize. Signed-off-by: Luis Chamberlain --- include/linux/shmem_fs.h | 3 +++ mm/shmem.c | 24 +++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 9029abd29b1c..89e471fcde1d 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -36,6 +36,9 @@ struct shmem_inode_info { #define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL) struct shmem_sb_info { +#ifdef CONFIG_TMPFS + u64 blocksize; +#endif unsigned long max_blocks; /* How many blocks are allowed */ struct percpu_counter used_blocks; /* How many are allocated */ unsigned long max_inodes; /* How many inodes are allowed */ diff --git a/mm/shmem.c b/mm/shmem.c index d76e86ff356e..162384b58a5c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -125,7 +125,17 @@ struct shmem_options { #define SHMEM_SEEN_NOSWAP 16 }; +static u64 shmem_default_bsize(void) +{ + return PAGE_SIZE; +} + #ifdef CONFIG_TMPFS +static u64 shmem_sb_blocksize(struct shmem_sb_info *sbinfo) +{ + return sbinfo->blocksize; +} + static unsigned long shmem_default_max_blocks(void) { return totalram_pages() / 2; @@ -137,6 +147,12 @@ static unsigned long shmem_default_max_inodes(void) return min(nr_pages - totalhigh_pages(), nr_pages / 2); } +#else +static u64 shmem_sb_blocksize(struct shmem_sb_info *sbinfo) +{ + return shmem_default_bsize(); +} + #endif static int shmem_swapin_folio(struct inode *inode, pgoff_t index, @@ -3190,7 +3206,7 @@ static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf) struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb); buf->f_type = TMPFS_MAGIC; - buf->f_bsize = PAGE_SIZE; + buf->f_bsize = shmem_sb_blocksize(sbinfo); buf->f_namelen = NAME_MAX; if (sbinfo->max_blocks) { buf->f_blocks = sbinfo->max_blocks; @@ -4100,6 +4116,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) } sb->s_export_op = &shmem_export_ops; sb->s_flags |= SB_NOSEC | SB_I_VERSION; + sbinfo->blocksize = shmem_default_bsize(); #else sb->s_flags |= SB_NOUSER; #endif @@ -4125,8 +4142,9 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) INIT_LIST_HEAD(&sbinfo->shrinklist); sb->s_maxbytes = MAX_LFS_FILESIZE; - sb->s_blocksize = PAGE_SIZE; - sb->s_blocksize_bits = PAGE_SHIFT; + sb->s_blocksize = shmem_sb_blocksize(sbinfo); + sb->s_blocksize_bits = __ffs(sb->s_blocksize); + WARN_ON_ONCE(sb->s_blocksize_bits != PAGE_SHIFT); sb->s_magic = TMPFS_MAGIC; sb->s_op = &shmem_ops; sb->s_time_gran = 1; From patchwork Fri Apr 21 21:43:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13220707 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 2AE33C77B7F for ; Fri, 21 Apr 2023 21:44:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8877E6B007B; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AFCF6B007E; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C6726B007B; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 25FE26B0072 for ; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EEAC41C6B05 for ; Fri, 21 Apr 2023 21:44:19 +0000 (UTC) X-FDA: 80706727038.22.ABB1B40 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf26.hostedemail.com (Postfix) with ESMTP id 3F43D140003 for ; Fri, 21 Apr 2023 21:44:18 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qwUcweMc; spf=none (imf26.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682113458; h=from:from:sender: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=qZHhB8oJRc4fNtBxtSdci4h920oOcANZrFW/y3BBdxc=; b=jHIq5SyICrK/1kbTItNYuOwafXvddHmswMIlZ1IJgr9BABFbyivuPdw7FoQXXd6m/cyQWp g1zoIQeomoDJrcITdK4QlbpadtIoGAwPdN+HtNFQEEUJRaPonodkqf+VKnPZCS6nUPpiSC c8YE1kuPDl7ZsjGhbz5gDgAQIVF5C3M= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qwUcweMc; spf=none (imf26.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682113458; a=rsa-sha256; cv=none; b=PQOJQntFbAScTuHCijECXnr4ZCT7ZokJ3wr0pJrwF9ouCf8u9fCgClKiFPVRtlZ7ODL7nx ZNDyT+tWz/YZur+0VfykhYWsCGEFT3juP1sFMMMCeFef2yTU/HsEWGFr/e8awqgtz0BfuV 3oShlQZUHhUApwxLRGm2yU0OFibSXLw= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=qZHhB8oJRc4fNtBxtSdci4h920oOcANZrFW/y3BBdxc=; b=qwUcweMcO4pJRMTax4NLy0VSpN KXR/HutcTxUAf1AkUOpohVQt9D1HYkGbVjqLunH8jowN6HHKGq80LixliXi2Hao7TSPjFNtf1/IzO 7hDxeIEAYf+PFCY6rZWFQl4IGZWfP0KyQ5vipRU6TqfGLflWy21DT0TJE7R0QUnYRa/WxByUTqiII BuHGKTgRoWB8MbgfuNMvCOuGnM+sX/c7GBDhVEJw9LJtgPKEyst4dKWFE7LdUCITswqVJpNqKk8W9 slkIqwAA4DulGimTxOQmf5WZEzZP8nrP9FTqQ4fOvBM8gc8Qmz0rtULu5SAg6nZRtVW89WyRdSDAo le8pzh1w==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1ppyY1-00Btoq-2J; Fri, 21 Apr 2023 21:44:05 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org, djwong@kernel.org Cc: p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, hare@suse.de, kbusch@kernel.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC 5/8] shmem: account for larger blocks sizes for shmem_default_max_blocks() Date: Fri, 21 Apr 2023 14:43:57 -0700 Message-Id: <20230421214400.2836131-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230421214400.2836131-1-mcgrof@kernel.org> References: <20230421214400.2836131-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: s6i5ea41k4aubint8d51my55i6bxnj6c X-Rspamd-Queue-Id: 3F43D140003 X-HE-Tag: 1682113458-565718 X-HE-Meta: U2FsdGVkX19D2D6VgeaO94DFwQLGb22d2EqpQ6DZLrDglj5Y+NvfzXKhWsAdRZa1zJMl478xOVSUfNodRaghUKvUPAXSzXQ/g+jKzNsdW0JWLZHtfjzJI1M1Pwwd+nnKwUOwAsC6zayVYhC7ho5SJGhvhVjtFt0gBnT5NAKdg5oLS1tkCTE/nkxrKkTArtaMrepTZv3axlPtb97jz7VlRrxkNCtDvKkBdJWvbZNrUBAvpC3Wi4Dwbk+vNXFqm8cs5aiAAKL0UFGKW5OIVdR8V8l+mtqY6HFlPDeWbmufTfKFLFWYyjkEFm2t4b9rNGy5I1cbgRB9MfG7oL1Y/77e+zVcfQZlVf+BrWPsds3TzIvdg2PDqLMjLxOpR6nDClT3w+cREQ+OqrKzzenWiXvrf6RdCPK03BdumrESqiWlDWqYr2GJgs77C7L8JxvKg3lux07sJlsknqn51elsQgBGb1Pla4LVVKsVoTMI0XcY39mN8tk6/u05Cnv6Hpbjr2UrAWlAKHPuNJGazM3lmbbvftWbPhfdo9vnQPCCOBXUHgSPU3EaiwvqbBvPkfzj8u1Vraj8WtfzbNxgwNFPU03SBDAucVfSWDX/fubUoff33TqWHJPNSgA8jFsKoAXDda64U+IG0DxShQvggXQIjj4D+WEs8gUdFJADliDUk7cAvhbEjPiPi/jYX12p1k/Mp1RinqldVO1yCAMKpIXMFGIyJAB+YwLi8xypCCgF4u8xxvbwcdf0xcrQEunbNChLKxC+5KYMLWmXXWfwZ5kdwQjwKMNVCiAIyBsxQmdkDXV49yl803i3SuRa1VCrTCI0dssyVSKRyAcXbKlLGCH4W4S4mZoEQ/4ad9MkLtvBmMCLQ6hetY9CJrbNwAIiIWaibsgv9NzZ83munhTFRxaXOcV9ojdx9B+JCLM29peGtCLwlpYYXJxTQEdOKx9pz7rMenwk5pDm6SB7sLpqeD3XgVi 2Vtia7d4 bdNuUbkRv6ZVmiR26cJn7AOdMsLvgISe3jVB2xBLY2E/L+8oJ9D+56lKv1i/AT5zuy+E/lQGlTaIRXw+18zDY0nyWCjDzB7rofb1RHHW5ki6epugc0LfdMiE7FWJLAPbEaRlWaWfxKxCvFRIDrkyhZvgeBGP1asUCn+C/sTeznnOs999FdtO4u4KjBz544UhFGDh97FQuIjVk/f1HmI2ihnj1bzPs3zE06vunfpYMhpoxG/fFoBYqXEvKVtB+R3++u7x6jeEmrhV4i2ATmae64i70A+dO+elZ/rVz/klXJ2BCCf4hCFDRpnr7l5vkUYz6APMoe/QbbGc60IKY8kaBXp4Jrr62eVydiYvo65QOtNHt6HtwlstTZdhAcEgNblfp1L/TioOlBx52tRphkkAylUE8O95uUjw3kZ3q8yoVS9WSw/ed53eLm6uE9Q70vEhb99Lh 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: If we end up supporting a larger block size than PAGE_SIZE the calculations in shmem_default_max_blocks() need to be modified to take into account the fact that multiple pages would be required for a single block. Today the max number of blocks is computed based on the fact that we will by default use half of the available memory and each block is of PAGE_SIZE. And so we end up with: totalram_pages() / 2 That's becauase blocksize == PAGE_SIZE. When blocksize > PAGE_SIZE we need to consider how how many blocks fit into totalram_pages() first, then just divide by 2. This ends up being: totalram_pages * PAGE_SIZE / blocksize / 2 totalram_pages * 2^PAGE_SHIFT / 2^bbits / 2 totalram_pages * 2^(PAGE_SHIFT - bbits - 1) We know bbits > PAGE_SHIFT so we'll end up with a negative power of 2. 2^(-some_val). We can factor the -1 out by changing this to a division of power of 2 and flipping the values for the signs: -1 * (PAGE_SHIFT - bbits -1) = (-PAGE_SHIFT + bbits + 1) = (bbits - PAGE_SHIFT + 1) And so we end up with: totalram_pages / 2^(bbits - PAGE_SHIFT + 1) We use __ffs(blocksize) as this computation is needed early on before any inode is established. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 162384b58a5c..b83596467706 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -136,9 +136,11 @@ static u64 shmem_sb_blocksize(struct shmem_sb_info *sbinfo) return sbinfo->blocksize; } -static unsigned long shmem_default_max_blocks(void) +static unsigned long shmem_default_max_blocks(u64 blocksize) { - return totalram_pages() / 2; + if (blocksize == shmem_default_bsize()) + return totalram_pages() / 2; + return totalram_pages() >> (__ffs(blocksize) - PAGE_SHIFT + 1); } static unsigned long shmem_default_max_inodes(void) @@ -3816,7 +3818,7 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) } if (*rest) goto bad_value; - ctx->blocks = DIV_ROUND_UP(size, PAGE_SIZE); + ctx->blocks = DIV_ROUND_UP(size, shmem_default_bsize()); ctx->seen |= SHMEM_SEEN_BLOCKS; break; case Opt_nr_blocks: @@ -4023,7 +4025,7 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root) { struct shmem_sb_info *sbinfo = SHMEM_SB(root->d_sb); - if (sbinfo->max_blocks != shmem_default_max_blocks()) + if (sbinfo->max_blocks != shmem_default_max_blocks(shmem_default_bsize())) seq_printf(seq, ",size=%luk", sbinfo->max_blocks << (PAGE_SHIFT - 10)); if (sbinfo->max_inodes != shmem_default_max_inodes()) @@ -4105,7 +4107,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) */ if (!(sb->s_flags & SB_KERNMOUNT)) { if (!(ctx->seen & SHMEM_SEEN_BLOCKS)) - ctx->blocks = shmem_default_max_blocks(); + ctx->blocks = shmem_default_max_blocks(shmem_default_bsize()); if (!(ctx->seen & SHMEM_SEEN_INODES)) ctx->inodes = shmem_default_max_inodes(); if (!(ctx->seen & SHMEM_SEEN_INUMS)) From patchwork Fri Apr 21 21:43:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13220712 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 71ED5C7EE29 for ; Fri, 21 Apr 2023 21:44:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84D306B0074; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75F196B0081; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B1BD6B0082; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 166F66B0072 for ; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E44F6AC9D9 for ; Fri, 21 Apr 2023 21:44:20 +0000 (UTC) X-FDA: 80706727080.19.F5C1E82 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id F031740006 for ; Fri, 21 Apr 2023 21:44:17 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=4faVVxfy; spf=none (imf07.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682113458; h=from:from:sender: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=ZUAOcNqD6LayzeKVCuQ/BLskBnjlrIyvlaP+338TFj0=; b=UXrE7Z+wAhoUOzrLwEk02pmYMm/eUPZPB1g07AwQxeuEK/9kEBOjkWyrfmrzBi3BZd23Gk H1vgquAjLzM3GncqwUt5O4TuUOLrs+fBwyO9zzguvtuNPDhEpzS3iSSja0ARV7BUBq/qkJ 4oMpexa5mOIKczGrB8jy+QLKAFYPXx8= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=4faVVxfy; spf=none (imf07.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682113458; a=rsa-sha256; cv=none; b=p/sMwq3ymH9rg277ua2xj/+heZ3lN+MdJOi0I0QOU3wwAYow+/ii4dhT1N3fYnAnlliFZz u1asFcJVLNpnYADxEAdRyVsFgPhYHpwy+Aym4jSk6VGMNOKLhhm8A2CsuvMDsAaR10qKXU k1SQnNrqriDqyR7rHipeETqb/scK4Ww= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=ZUAOcNqD6LayzeKVCuQ/BLskBnjlrIyvlaP+338TFj0=; b=4faVVxfybgSKlFUw4CjuG22i97 71PGGt9QIrJ/HwbknwCDE//N0MK6Lp3ra+wQrXZsk0eWG60sRW0X5RUf4Kenfek+eG2paFJP/MaZa 0pWwiy4StWWh+SSoxTEvENx27Ue1WY0nZEQ5jvksW4DR5M1zwWo9akRwduyxRxOL7u3B+Vg/sEuOs 8Ct23zxr9jtxEu1k9C79r6F1cOvTy0vfzN2gpw8diBX/Hb0y0aSu/dsvGfqVJ/FI8leP+YAgddYgn hK5IlPwLjcORNIqVDFOLTCGjGCfsFF6VGnKA9PA/rSAOR6sQOrz+AG5XTaTPZkVnxF4ht9+1OwIlY CcAZD47g==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1ppyY1-00Btos-2R; Fri, 21 Apr 2023 21:44:05 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org, djwong@kernel.org Cc: p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, hare@suse.de, kbusch@kernel.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC 6/8] shmem: consider block size in shmem_default_max_inodes() Date: Fri, 21 Apr 2023 14:43:58 -0700 Message-Id: <20230421214400.2836131-7-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230421214400.2836131-1-mcgrof@kernel.org> References: <20230421214400.2836131-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: F031740006 X-Rspam-User: X-Stat-Signature: 4ogt7bxos5864xdsc6as6ciqbpyqkprr X-HE-Tag: 1682113457-329381 X-HE-Meta: U2FsdGVkX18HQn5WpeG4Gz6ohMp7Ija6pJ8wJtYd4OXvGZg7e7iE8dAc7ihA9Yf7oCDnVl4SLrCKeMQ+b5Ay1+eFfkAsROPkMdE4fgJCSfPisJruY76a/H4XZXCj9UmHZ/tTfx5xMHRCjg7KZkvncIAFPnQ39KEjz9hPNxEQ+U3oWFMk5RMOkMc+3wp0QGkQ+JOitWmy8nhUxixLXLZf3pN4UHVdMzbYlKmvQeADdXUeuX/pw/4qEvyJnv+CL6wXgXpwezmdSKYBsZ6j7bG2x8wzlnC81rbWGWbqJ+C37qfLFmRk3XnIGd//SuXmIo2x9ZH1L8B001RDYC3+Yt/ypHiFrIXhFd6daINSQNdOFDGLNDsTtu3rhRzbdxH5rmCxAi1QSgeo6RvlQ+SageLQCjQbRB2GXdceC6VAlIw9HKhGT7LozxdEk0L6nc/pCk6e4vbh4FJ8RtM6uUY5eUdWYiwAr0pxOXUVrqmmvRpVvWmTS1yl3OTfl+FkyFUTmx+MY9oZh8uiwZvs7/q1hQKIcxwRyHkJjyy4p5OqbDYVFE+yjNvxSglTA+Sm3XT+mK4jcFHmxlvWNc1EGoZ9AHZrbRmqA+nRd6t39S/ahgs8PQ9SMwx4FvesvLnwo38a/wYBrN4t5QKGPD/fI5YM+ket0vxRFpP33aT63eUmiNyrAy8ohNvs16bznY+nal8Ys9TAUm4xbg/HbcG3ZPUoAdyJdwE29M7II+ZVUy793XfXxBRjT06wf5a6X4zlHo+XsuG3O5nhlcsK/8ArfsmV/jsp8CrlPjImmSjNV7YIinaCDKOjxMf/s1C2kRwXLyohjiij62d8luWHOJTWUmadFUhkWrxSRlIqKgUS/HPymiZtv/8j+pPKPvhVBiGdqF5U4aO8xE6HtrYL7hhpjr9kqHEA39oCRTOcmrUF5g2I8TjtdcDkrz9s/lzti2JTT3/ivnIe3oMIg6eg+18fUsYRbyD znx+hTLM t2zvbvMg/8u4ibyjahlmb9joPvSPnVEwvX2+sTjid6ZFCD/f8MTPJGDSmBlmkvSTYBnY4pswUpx91UBF/xqJ8cmo53vhl1vlVKzHb4/zvcw5ZU7gYAyQTp5KfT6SaEy3wFGzdyiQptBXXx/itA1qWOAzqkKt+FeqeTjEUA99oTqhp6gGw6uDIZ2TEriTzhtku2R4k6F/Io9PuTqJDeTr4mCl/iTl9yU+YL44yPCsQULAi6ijbMpECv1b5r/7hrPvyaF0+Biqkj0twvgsKY97ntKAkyggkyHUmIkf7cc7J1aa0Vt3HTzLYXYBfKssjS0GlZfCQePH8LPb0JRBY1usCerQymsRixLM37R8kW/HHqeTuweQWNpzYxijA1VpbgNMgDERcXTKwowr+v9kV32ZzPKeXfdJGJsJPahNKq/MvkNwbCjYMjs8Lzi6GoM2k/bhqrPku 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: Today we allow for a max number of inodes in consideration for the smallest possible inodes with just one block of size PAGE_SIZE. The max number of inodes depend on the size of the block size then, and if we want to support higher block sizes we end up with less number of inodes. Account for this in the computation for the max number of inodes. If the blocksize is greater than the PAGE_SIZE, we simply divide the number of pages usable, multiply by the page size and divide by the blocksize. This produces no functional changes right now as we don't support larger block sizes yet. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index b83596467706..5a64efd1f3c2 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -143,11 +143,14 @@ static unsigned long shmem_default_max_blocks(u64 blocksize) return totalram_pages() >> (__ffs(blocksize) - PAGE_SHIFT + 1); } -static unsigned long shmem_default_max_inodes(void) +static unsigned long shmem_default_max_inodes(u64 blocksize) { unsigned long nr_pages = totalram_pages(); + unsigned long pages_for_inodes = min(nr_pages - totalhigh_pages(), nr_pages / 2); - return min(nr_pages - totalhigh_pages(), nr_pages / 2); + if (blocksize == shmem_default_bsize()) + return pages_for_inodes; + return pages_for_inodes >> (__ffs(blocksize) - PAGE_SHIFT); } #else static u64 shmem_sb_blocksize(struct shmem_sb_info *sbinfo) @@ -4028,7 +4031,7 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root) if (sbinfo->max_blocks != shmem_default_max_blocks(shmem_default_bsize())) seq_printf(seq, ",size=%luk", sbinfo->max_blocks << (PAGE_SHIFT - 10)); - if (sbinfo->max_inodes != shmem_default_max_inodes()) + if (sbinfo->max_inodes != shmem_default_max_inodes(shmem_default_bsize())) seq_printf(seq, ",nr_inodes=%lu", sbinfo->max_inodes); if (sbinfo->mode != (0777 | S_ISVTX)) seq_printf(seq, ",mode=%03ho", sbinfo->mode); @@ -4109,7 +4112,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) if (!(ctx->seen & SHMEM_SEEN_BLOCKS)) ctx->blocks = shmem_default_max_blocks(shmem_default_bsize()); if (!(ctx->seen & SHMEM_SEEN_INODES)) - ctx->inodes = shmem_default_max_inodes(); + ctx->inodes = shmem_default_max_inodes(shmem_default_bsize()); if (!(ctx->seen & SHMEM_SEEN_INUMS)) ctx->full_inums = IS_ENABLED(CONFIG_TMPFS_INODE64); sbinfo->noswap = ctx->noswap; From patchwork Fri Apr 21 21:43:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13220708 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 9D210C7EE21 for ; Fri, 21 Apr 2023 21:44:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA4C66B0075; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9343F6B0078; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64E556B007D; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2FFA86B0074 for ; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0B72D16069B for ; Fri, 21 Apr 2023 21:44:20 +0000 (UTC) X-FDA: 80706727080.23.C0D5D56 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf15.hostedemail.com (Postfix) with ESMTP id D598EA000B for ; Fri, 21 Apr 2023 21:44:17 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Gv4xXUfw; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf15.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682113458; h=from:from:sender: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=LRGm8v+C2VnFh3pJYXzbKwj2NvliqmXVbLHOoz9D9rs=; b=1e1/TXegRQVagR3Lls3TFwrL9a1yPCXnYwNVUPIxsQmnLcefQmygB39IOjUAcKS0DnDkf5 gCjfTneWgqaxTZGbxd0up6kFwgoaIEVU10xSEp28dBPRT/xLZ51nnTBvCUIj8H09jStKHl qulLHQv3EA2W4lY/d7gLCWPXj7pNUqs= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Gv4xXUfw; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf15.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682113458; a=rsa-sha256; cv=none; b=jr7Mpkk35krWxApKaUx7dWzwCgAZEgZTZ+JNTZVzsQBMevYCtqNOlhNz+PFk8OsFmcbCnU DQmTNEtyFnJWzJ1hTn1RuZnqSa1HseKXVfZ7nwTlKIzBhpiN3ilS+VCf5N9PicIVQhQRAq CeTNTHnLdts9nDiBFe3+wKBxrxQUJuw= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=LRGm8v+C2VnFh3pJYXzbKwj2NvliqmXVbLHOoz9D9rs=; b=Gv4xXUfwg6Tqrov7HtOq12Iot5 YO5wR1wBRRe+FoidC8runo8IO16BDwaMfjnowR194HePAotck078Dc52Y5LhgHsJWaSdFz/ExDOoW 7UvJg+gaENVFRZFuUklS2jbQPIu6sP031vvUKDVO8op0VWHJ/pcNAbKtxQ6EJtE3JOGWA8i9aCI4G c82Y5dwvzAyUa4CC4Jt/QPxPn6XSF0jejQ+JpFEAjr1mjFYM6xQTv/oz9ZsmadJRNPxXXDoGL2kGk x5ARZON7gmkNiGzDhbMd8jQFJ5x3RYgTnUCgMJhDF50jxO3kH/6kEmfu6+iJAJL3r0nsysDSme+ZO aDY1SY0g==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1ppyY1-00Btou-2Z; Fri, 21 Apr 2023 21:44:05 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org, djwong@kernel.org Cc: p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, hare@suse.de, kbusch@kernel.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC 7/8] shmem: add high order page support Date: Fri, 21 Apr 2023 14:43:59 -0700 Message-Id: <20230421214400.2836131-8-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230421214400.2836131-1-mcgrof@kernel.org> References: <20230421214400.2836131-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D598EA000B X-Stat-Signature: czk46iq68rp1w9u77d4qu4ryror4js5b X-HE-Tag: 1682113457-241303 X-HE-Meta: U2FsdGVkX1/fe6vvRXN8Nvj7VZMfrqWSS67Jd9Ktuy4KN8E9VCQnoQXHhf8h2Rl+0dY2ixJH2UrCPnXsZZ1l5Ml+kVB1xqp2EH5pIZ3hFFnFzLCNoQMV6fmJyqK5uDOiQc+uS0TrmARMwUy2SrSm2ETch8mUUlOQGxXmGG3EDn9l2ee63FhOLTUKyNl+AU0osVXj52hx767rH+2T4hI2M3XMDrHimiYpG/EVL8kAuFX2hzqBum7RSBKcAvAeaHTTaOEX03AOXCxNlYveRhgSgAUijcrun78oKXv+Uef4Z1NaO29iw28ws2uDWcpZRCfMiZH/rsLgv7/KHPteYJPhVMhRlVMDbamdBy2QrM9r8OMKJfkvhN4PT9E7BA8TBOfpBMrxuZEf0zPYjPUroIAfEwBxEcXGFVft+qFL7j56BHt92ebQSTdPG4wRNBQWbSfaRYyuyrWEnqBrXKmGERV/SYCbxtTAS2fzC+W7yJfhn3KPDTNQ5TyimdJ23TBRQu24l8sk8g6QKxJMsjRoAkPvFqpOeR9GqhNOXBFq631yXtiM9ztdCG/3BUGIk6xgvvmRRI4u71YKn8mkBNhZiefPXYdZne4MPDkCLtxkFnhgrKh+l/4pRozosuBtFFbp5idVwKntd6cGmTgo6Re5jvGUlCmRKLM6vDyPIGE+U0sYF/65PY7NExbQ3Eeo+9gNCLuG3MHRQVQgkeBQ5w2xHusZ3HZlb8vHaLcG5n7Q3+2xIHNWz5zYVxG/wPB1jQUnnR2+11aS87YnrNOVqyKDs1olwFCdeH5yiqlDKANK4acIU2PolnC/LLtdnYfqghcB4MTW8hZQkNvV2RmD/hpUFUa730Zn5xwq2lrvOXlWrfj1R4MSZm6MWPIoUkmE+/ysrb4nyK9LNsskyMA6UQsLB19F+89/xNKMlyq/f3tbQjRO0CcQAwZFyOfONt4fs6TzWRqApSwJv7W4ZGWDlNKcnfa zp4ETQWD WgnL8t/gWS/GnyQHTEIPQ/nwTE/xVJXIhTk/Oq24woJCByjYg/6ICa8AQFaZh6hVOrCPDmsHNoG47QyPbQpyhfQH9t3fjCeg5UBDOFmqiKLjQZIjKLLj3WVHtpv50qI0N2PcFhaWPY5s7IFq8GFF7Ihk1aF+ydNp8ox/cj0NdZ2viXT/II6Xhl6GH6HLKefSJab0zzdYsqC40AjoSSxMGHT/XoqYgM30M/Kfh78EgnOprLRlgXUyjp0/kX8k6CTW2LS9/km2KvDJExuNJQYUTR2d4zFp2qFFYd6N1lEFIiQG2+6GeA9P0530iclc1wyFDycAa6cto6pppfR0+WqpcLljaSGVBiIgOyJG/sH5FpKIfPD1M2C22BYAcsVU3QPUw8sZ672pObC8fl1I= 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: To support high order block sizes we want to support a high order folios so to treat the larger block atomically. Add support for this for tmpfs mounts. Right now this produces no functional changes since we only allow one single block size, matching the PAGE_SIZE and so the order is always 0. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 5a64efd1f3c2..740b4448f936 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1621,9 +1621,15 @@ static struct folio *shmem_alloc_folio(gfp_t gfp, { struct vm_area_struct pvma; struct folio *folio; + struct inode *inode = &info->vfs_inode; + struct super_block *i_sb = inode->i_sb; + int order = 0; + + if (!(i_sb->s_flags & SB_KERNMOUNT)) + order = i_sb->s_blocksize_bits - PAGE_SHIFT; shmem_pseudo_vma_init(&pvma, info, index); - folio = vma_alloc_folio(gfp, 0, &pvma, 0, false); + folio = vma_alloc_folio(gfp, order, &pvma, 0, false); shmem_pseudo_vma_destroy(&pvma); return folio; From patchwork Fri Apr 21 21:44:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13220711 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 AF250C77B7F for ; Fri, 21 Apr 2023 21:44:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C96E6B007E; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00C206B007D; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B56786B0074; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5F00B6B0074 for ; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 387ED40657 for ; Fri, 21 Apr 2023 21:44:20 +0000 (UTC) X-FDA: 80706727080.24.788A64C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf18.hostedemail.com (Postfix) with ESMTP id 364A41C0005 for ; Fri, 21 Apr 2023 21:44:18 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=oFywjwIN; spf=none (imf18.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682113458; h=from:from:sender: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=QZSPgijKCu3Y3/12/R8LbE206e1fX9dQfHKdMNON/W8=; b=PunVMrqXgTPCo6BjGbb5ZYl6jYi5e/f8hA6Oh7pFEzixV5PjSpim/Y1zHEhf9DL2Ig/uQq ufGC2MpGODLQQn5/wvWUd5eY6Q56ryAgVc75YB0a6K2i+74XP9FiYLuO2NRi8rQqFPShAa AdAIRuiaoE/ysxlOIKxxVZIkf6IZpFM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=oFywjwIN; spf=none (imf18.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682113458; a=rsa-sha256; cv=none; b=vWzatBlZ+5QnuN+HUNBoQUBMp4euo6tEjia0dAGRJ6HMB3QS9s5BeqV7y1ITv+heSy2Jlb 0NDSmRmCDPpqVr4wQeF9zLylBvEGMPb8KnNvphseu5RPckXZFBGSsvHDIbwkv3MzLNhWMy Rh+/EA3rjjWJ7IPkprHwYLVlqY8vk/U= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=QZSPgijKCu3Y3/12/R8LbE206e1fX9dQfHKdMNON/W8=; b=oFywjwINQnJi1wLFD/p2jy2j7L YzaKpUjXYeUccWb/Nv5aW9K9NT0ZiPfQ5qLf6tyvltqi0NzPK5Dqiyjep/DwF9A0si0uEBf/bxZ1a gC3ggPEPcz4//L5fnHODuyCTOEd+G0oIS3iCLNKOjC8gFEP6lxkUml1fa0r33CKeLmcMdw+EKZ/rz EyUHrfWth/uiSWRR9n5AjEBXdeZUg2klO11cMNtkhUKw0bjosgZvqzfu1mlsfgxOhbCOoRLqLq3BB w3QKnGmL5aC2RSOu972POaXT0PC9eMLB7F2HwvVQ38UMYkfPO3/V1FNdAdEMLhrhATJUDT86vHTiQ 0AVSMYmQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1ppyY1-00Btow-2i; Fri, 21 Apr 2023 21:44:05 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org, djwong@kernel.org Cc: p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, hare@suse.de, kbusch@kernel.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC 8/8] shmem: add support to customize block size on multiple PAGE_SIZE Date: Fri, 21 Apr 2023 14:44:00 -0700 Message-Id: <20230421214400.2836131-9-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230421214400.2836131-1-mcgrof@kernel.org> References: <20230421214400.2836131-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 364A41C0005 X-Stat-Signature: wycrgmkemd4q7up87achy4qcc3aojzu6 X-Rspam-User: X-HE-Tag: 1682113457-948426 X-HE-Meta: U2FsdGVkX18i3zeLBlzxJVGUT6DJ83nUHKF/6CXaI949aiiZeE18lAOglkR8O6CqhaKQOjX/RQ/SpfzLtWbtXG2xjr1CTYMe2FYZVtZdZAJl0Nyg7b1cZCeyEh9VTutlj3OzLB9SW+Qqmr/08c+64tmABP24p5DpkFOPOcVc84FiJ3CRFaUSoihF6bu8qA/2QYwxdy6lxiA2HpE4jO5ApUsjs4cP2+FylgxwDnV7g7awDRmqsPQwkzLCFapYrHSPN8I4fINZ3D3d+0eFh5SOStPG1znsd7Fc4fcKthpnhMKf+ekrX4JcivQUN3IMvS2eTcyeOKxVAtHJyBTMBuQhoAusFst9VPpNZbRDpVR6FgvMdQhROWedT+S5uVy6NoaVjvDtGeVKCcQRVTViN/b+fWtLyCRtkUb3s1AZEVKuMi9QRiCJN8cmW+5LTccxmwodxJqJ2s5VueLT0ZeGTXEOoLXNfDzbmW8VTgT3MDiYt4rOphl6RlmVx9Ix4qQAQBr9zcYATYzskz2KJZ16quIGWb/lR5No6oRoTeIaGcN8jqT70lphFE4liTWPglw27e9o/4eEYEzGRnBVQ0qYu2rJMUwcsScBePDMVl5zk/6revK9cTmqX6Rl0s9B4MSvXTnRUArvQIE7KcSy596h6/ME34Yf/nag9+7FFiWRPMzcRg1mUOw3fFKsu2jIh1NTOXMYM82RfBVN1FuD6edymVWx+7rrKPAsj8EK2qyxdWY55oZ1N1Tk7wTYiU/B+qjvfWYV5SNH+auFY55Pi/6YT+VkPUgW/wA2Z0XCoi2dXA9FWrm1FOm7CgUBczUglRg4zt7cOXaP2CMQWmz3oArzgkRGQUpUBbEwWbwsS96CkvTyXP49z8OzFLIhXhxxo3S6jwuBC2oe5lWG4Vr46Ofzr9xJo6CYU/UnukTzu+Lk8IDfKbQwh8uZSsCuYsjYI3P7eUPEove9pF760unbYcz9VgR DeKnkrau n5uMtywLYWdFdrCJ2RRnklZ8LyO9C8zIDgdmqGjMRmBCzvViLDtbaHjLuPVe7RuSdEoEhS5V/vZop+tg4jqpcizwsdeDLwAfU5pcpvAbTrhcpPZ5KihNp8ljN2HnWXX5vdKSHoHPYO+miXQXTkgN5uJadIYNWKg2hczBebQXZT+IYbveBMiEeELYBzNgKkHRO8quWrHvLjAw/dbpyxbwoZ5QmwFdpRvyjUT/0yXI+5CF6GTIwEKgjUt/oxxh+dvnmTLL5ulXVorjC8Ps4U+jZnKWaAayxyUHO6U2IjUqwkvD8j66XAzILuJYvGSavqz4fhLAdxg7/kjcCzfATVW6Ik5ymmbqeuYq9maPKb5kyrqCO1SRiJIDhlKuhYunxaukxVOLFMQOdImd3+LQmli7puMJAWyIKFxdgrs9FD5peEITfsmqFO59+D23d5r+vwQJiN+T0 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: This allows tmpfs mounts to use a custom block size. We only allow block sizes greater than PAGE_SIZE, and these must also be a multiple of the PAGE_SIZE too. Only simple tests have been run so far: time for i in $(seq 1 1000000); do echo $i >> /root/ordered.txt; done real 0m21.392s user 0m8.077s sys 0m13.098s du -h /root/ordered.txt 6.6M /root/ordered.txt sha1sum /root/ordered.txt 2dcc06b7ca3b7dd8b5626af83c1be3cb08ddc76c /root/ordered.txt stat /root/ordered.txt File: /root/ordered.txt Size: 6888896 Blocks: 13456 IO Block: 4096 regular file Device: 254,1 Inode: 655717 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2023-04-21 19:34:20.709869093 +0000 Modify: 2023-04-21 19:34:43.833900042 +0000 Change: 2023-04-21 19:34:43.833900042 +0000 Birth: 2023-04-21 19:34:20.709869093 +0000 8 KiB block size: sha1sum /root/ordered.txt mount -t tmpfs -o size=10M,bsize=$((4096*2)) -o noswap tmpfs /data-tmpfs/ cp /root/ordered.txt sha1sum /data-tmpfs/ordered.txt stat /data-tmpfs/ordered.txt 2dcc06b7ca3b7dd8b5626af83c1be3cb08ddc76c /root/ordered.txt 2dcc06b7ca3b7dd8b5626af83c1be3cb08ddc76c /data-tmpfs/ordered.txt File: /data-tmpfs/ordered.txt Size: 6888896 Blocks: 13456 IO Block: 8192 regular file Device: 0,42 Inode: 2 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2023-04-21 19:31:16.078390405 +0000 Modify: 2023-04-21 19:31:16.070391363 +0000 Change: 2023-04-21 19:31:16.070391363 +0000 Birth: 2023-04-21 19:31:16.034395676 +0000 64 KiB block size: sha1sum /root/ordered.txt mount -t tmpfs -o size=10M,bsize=$((4096*16)) -o noswap tmpfs /data-tmpfs/ cp /root/ordered.txt /data-tmpfs/; sha1sum /data-tmpfs/ordered.txt stat /data-tmpfs/ordered.txt 2dcc06b7ca3b7dd8b5626af83c1be3cb08ddc76c /root/ordered.txt 2dcc06b7ca3b7dd8b5626af83c1be3cb08ddc76c /data-tmpfs/ordered.txt File: /data-tmpfs/ordered.txt Size: 6888896 Blocks: 13568 IO Block: 65536 regular file Device: 0,42 Inode: 2 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2023-04-21 19:32:14.669796970 +0000 Modify: 2023-04-21 19:32:14.661796959 +0000 Change: 2023-04-21 19:32:14.661796959 +0000 Birth: 2023-04-21 19:32:14.649796944 +0000 Signed-off-by: Luis Chamberlain --- mm/shmem.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 740b4448f936..64108c28eebd 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -118,11 +118,13 @@ struct shmem_options { int huge; int seen; bool noswap; + u64 blocksize; #define SHMEM_SEEN_BLOCKS 1 #define SHMEM_SEEN_INODES 2 #define SHMEM_SEEN_HUGE 4 #define SHMEM_SEEN_INUMS 8 #define SHMEM_SEEN_NOSWAP 16 +#define SHMEM_SEEN_BLOCKSIZE 32 }; static u64 shmem_default_bsize(void) @@ -3779,6 +3781,7 @@ enum shmem_param { Opt_inode32, Opt_inode64, Opt_noswap, + Opt_bsize, }; static const struct constant_table shmem_param_enums_huge[] = { @@ -3801,6 +3804,7 @@ const struct fs_parameter_spec shmem_fs_parameters[] = { fsparam_flag ("inode32", Opt_inode32), fsparam_flag ("inode64", Opt_inode64), fsparam_flag ("noswap", Opt_noswap), + fsparam_u32 ("bsize", Opt_bsize), {} }; @@ -3827,7 +3831,14 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) } if (*rest) goto bad_value; - ctx->blocks = DIV_ROUND_UP(size, shmem_default_bsize()); + if (!(ctx->seen & SHMEM_SEEN_BLOCKSIZE) || + ctx->blocksize == shmem_default_bsize()) + ctx->blocks = DIV_ROUND_UP(size, shmem_default_bsize()); + else { + if (size < ctx->blocksize || size % ctx->blocksize != 0) + goto bad_value; + ctx->blocks = DIV_ROUND_UP(size, ctx->blocksize); + } ctx->seen |= SHMEM_SEEN_BLOCKS; break; case Opt_nr_blocks: @@ -3892,6 +3903,23 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) ctx->noswap = true; ctx->seen |= SHMEM_SEEN_NOSWAP; break; + case Opt_bsize: + ctx->blocksize = result.uint_32; + ctx->seen |= SHMEM_SEEN_BLOCKSIZE; + /* Must be >= PAGE_SIZE */ + if (ctx->blocksize < PAGE_SIZE) + goto bad_value; + /* + * We cap this to allow a block to be at least allowed to + * be allocated using the buddy allocator. That's MAX_ORDER + * pages. So 4 MiB on x86_64. + */ + if (ctx->blocksize > (1 << (MAX_ORDER + PAGE_SHIFT))) + goto bad_value; + /* The blocksize must be a multiple of the page size so must be aligned */ + if (!PAGE_ALIGNED(ctx->blocksize)) + goto bad_value; + break; } return 0; @@ -3963,6 +3991,12 @@ static int shmem_reconfigure(struct fs_context *fc) raw_spin_lock(&sbinfo->stat_lock); inodes = sbinfo->max_inodes - sbinfo->free_inodes; + if (ctx->seen & SHMEM_SEEN_BLOCKSIZE) { + if (ctx->blocksize != shmem_sb_blocksize(sbinfo)) { + err = "Cannot modify block size on remount"; + goto out; + } + } if ((ctx->seen & SHMEM_SEEN_BLOCKS) && ctx->blocks) { if (!sbinfo->max_blocks) { err = "Cannot retroactively limit size"; @@ -4078,6 +4112,8 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root) shmem_show_mpol(seq, sbinfo->mpol); if (sbinfo->noswap) seq_printf(seq, ",noswap"); + if (shmem_sb_blocksize(sbinfo) != shmem_default_bsize()) + seq_printf(seq, ",bsize=%llu", shmem_sb_blocksize(sbinfo)); return 0; } @@ -4115,10 +4151,12 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) * but the internal instance is left unlimited. */ if (!(sb->s_flags & SB_KERNMOUNT)) { + if (!(ctx->seen & SHMEM_SEEN_BLOCKSIZE)) + ctx->blocksize = shmem_default_bsize(); if (!(ctx->seen & SHMEM_SEEN_BLOCKS)) - ctx->blocks = shmem_default_max_blocks(shmem_default_bsize()); + ctx->blocks = shmem_default_max_blocks(ctx->blocksize); if (!(ctx->seen & SHMEM_SEEN_INODES)) - ctx->inodes = shmem_default_max_inodes(shmem_default_bsize()); + ctx->inodes = shmem_default_max_inodes(ctx->blocksize); if (!(ctx->seen & SHMEM_SEEN_INUMS)) ctx->full_inums = IS_ENABLED(CONFIG_TMPFS_INODE64); sbinfo->noswap = ctx->noswap; @@ -4127,7 +4165,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) } sb->s_export_op = &shmem_export_ops; sb->s_flags |= SB_NOSEC | SB_I_VERSION; - sbinfo->blocksize = shmem_default_bsize(); + sbinfo->blocksize = ctx->blocksize; #else sb->s_flags |= SB_NOUSER; #endif @@ -4155,7 +4193,6 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_maxbytes = MAX_LFS_FILESIZE; sb->s_blocksize = shmem_sb_blocksize(sbinfo); sb->s_blocksize_bits = __ffs(sb->s_blocksize); - WARN_ON_ONCE(sb->s_blocksize_bits != PAGE_SHIFT); sb->s_magic = TMPFS_MAGIC; sb->s_op = &shmem_ops; sb->s_time_gran = 1;