From patchwork Fri May 26 07:55:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13256584 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 F2314C7EE37 for ; Fri, 26 May 2023 07:56:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 289A4900006; Fri, 26 May 2023 03:56:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 14EA0900004; Fri, 26 May 2023 03:56:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B1BEC900005; Fri, 26 May 2023 03:56:08 -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 8E6DD900004 for ; Fri, 26 May 2023 03:56:08 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 60F67A0D67 for ; Fri, 26 May 2023 07:56:08 +0000 (UTC) X-FDA: 80831648016.03.BBCE669 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id AE2564001B for ; Fri, 26 May 2023 07:56:06 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=VIpL8dc4; spf=none (imf17.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=1685087766; 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=BlnfxGH65lfjvCr0EihUnLvC6Y04PW1nCflzWem/FI0=; b=sroNHDNAs2BKHsOW/ZXrPD4RgyBDBlh72YxuS6MSyucIsXZuuh4K3BykjBVyZ2f8vecsAH Kz6yMMdetrVhQU2dUb7t+y9VwK/ZJqgJ3JjJwcKm05AWqloeQDsz+D/omXMVGDrUvsdA7v zAAeQGc729VR/sbmnB9a7IFTEJtvZFA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685087766; a=rsa-sha256; cv=none; b=Bl6grI7tOIfscLj1mYKfhJtmiUHMoe8zx+PAMwIhyVlLlaIko/27J6RZplKV6Mbbogz80I 61yt1HIsKZ1OWi1yJ/OcSIIGleOaNES0n8IP+gg1JzqDlN/93dLuNMDfLTvGdlGVp9/X0L FB6UUNAPPNTmUjBpcPpnMXhKS6IhUQ8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=VIpL8dc4; spf=none (imf17.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=BlnfxGH65lfjvCr0EihUnLvC6Y04PW1nCflzWem/FI0=; b=VIpL8dc4hJnM3liOcBxChkT+dG qF/usCC/Wup5mmMJmU1p1ovRc9zKDrFe15DpGpCv7f4i3Mhkrt83uK85qdUAizZUBhBrM5tQg3muw w9qV6fP5s+45uiKWkhPQ/0p5NiELflVvmRKmEbG0pYPjuLPUHkYpxlLQuXAICLo5rrMdD6xkn+c+E rf9/tWnG/HUnZedSs/UfiehEuj5H7zzw7q2FxO93KyrsNh4jk7WDlLYwOr+uIr2u7nhmEjEfjoA1u SDKTfqMfG82ro8eQ/SBy9XVW9hsS7XM0naNEQIHkN+T3/w4EOl/8CsAlecOfKgU/m7H4ZeTp2v+wL YZeBlrZw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q2SIj-001WZm-2k; Fri, 26 May 2023 07:55:53 +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, rohan.puri@samsung.com, rpuri.linux@gmail.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 v2 3/8] shmem: account for high order folios Date: Fri, 26 May 2023 00:55:47 -0700 Message-Id: <20230526075552.363524-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230526075552.363524-1-mcgrof@kernel.org> References: <20230526075552.363524-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: AE2564001B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: n6aiput5tnjif41wygtsi7e5dfmjd4p7 X-HE-Tag: 1685087766-279638 X-HE-Meta: U2FsdGVkX193/WiEpwxaiSAsFX+I0i/x4REnIbk9H98QmBB5vi/g1iX3RJevvWUUyvAd8mZRbigA+ErJv3/lFf+hdvaII6uXKUyZWW9MraeewvfHQ2R7ICr4r9g4aXbgMMRU1Ow9e+95P8y7XyOc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TMsVWpG1aqzwvBfw1Jhpo7xFZmznDI9OCO20XHSySJ/zb8f82C3chHfB8bfBcrDquhMIUX5aQKEgnFyYt3ChtK6Kp6P/Z8eAqBUZUz0oC34Yp+gaJKgNOAnmgp6oLlQe0AEIz13RvpwA/EHXlUgB7+uxk6TIyt33aPrx7fp3XLWWbbBf/W8I+b2ybHERZXPD3f091RkD7ADzBo3gFokbIwuBU/fS7JNhckw== 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 | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index a947f2678a39..7bea4c5cb83a 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -803,15 +803,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); @@ -938,10 +938,12 @@ 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; 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)) + nr_swaps_freed += swaps_freed; continue; } @@ -1007,14 +1009,16 @@ 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; 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++; + nr_swaps_freed += swaps_freed; continue; } @@ -1445,7 +1449,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); @@ -1720,6 +1724,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, @@ -1729,6 +1734,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); /* @@ -1736,8 +1742,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); @@ -1827,7 +1833,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); @@ -2542,8 +2548,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);