From patchwork Tue Feb 7 02:52: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: 13130899 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 D079DC636D3 for ; Tue, 7 Feb 2023 02:53:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FAD86B0075; Mon, 6 Feb 2023 21:53:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AB7D6B0078; Mon, 6 Feb 2023 21:53:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF1116B007B; Mon, 6 Feb 2023 21:53:11 -0500 (EST) 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 DAB6F6B0075 for ; Mon, 6 Feb 2023 21:53:11 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A63FFA0B69 for ; Tue, 7 Feb 2023 02:53:11 +0000 (UTC) X-FDA: 80438974182.22.0D7A222 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf10.hostedemail.com (Postfix) with ESMTP id 814ADC0007 for ; Tue, 7 Feb 2023 02:53:08 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Hyly4Ctg; spf=none (imf10.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=1675738389; 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=ppc+iA/4jLT/kyK/2EkWiSyEAfiza0foS2nW0M1ktaU=; b=Cj7ATU6IEqyYaf4ssZrNcXsDIic7RDDIl9Ox8u6fNct50/SNMOwe0mvJscrUecSJAeLeIh tV7dxCEpX/0N2ibOgd/I7mbx7spT798jSRv8jK1N1AgJFilPozc73SmnMjlp9jTCPFW+MH IykzDVx1gGc92oX/SqVILlYONM+Ju7U= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Hyly4Ctg; spf=none (imf10.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=1675738389; a=rsa-sha256; cv=none; b=LvlPkUcANleHQ3DUV4k/PUtbdH7YLVnVd9Sd61chF83RqiMNlStgeNucoz1l1/VoDfEe0I AIQ72O6pZu0sGjR0AxavfMk03GjcUFSCF7vIvITaOAvkuAiTxP/lO5Nz3ca2p0wHJxB4r7 115zdzUGzqU0h+YXrLuHTB/qSUhzbXc= 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=ppc+iA/4jLT/kyK/2EkWiSyEAfiza0foS2nW0M1ktaU=; b=Hyly4Ctgcl2ybcZ9Uf6YVJBbZj d8rXp8MTOtkLsYo89C6303qGny+ZLJ8X1/OlyBMSZJiK5eMMDXxjvBmjonKGnjQ60/1hfMX6pbfg8 yiKR4m6fBQf9AmmC/PJ3Sfm6BxquDZdjRcVWMEhdS6CAi2O3XaUWdAA1WK4305EBn7wctnsiPwLLc HlI1EXwYA1U1BLrsam0jMtbVPygKbeNK0X1ap6NHxElHw5Vshw6660O0DRiXF2lpD7cUTvkaqNDg+ fFL17wN/1bPIrceXZHl+j0O+JrhHxGb7P5oTJxapL85uPnZY8Kw3vxY2kKsojLU/jZ8kPUpN88pMo SMb57LLQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pPE6S-00AaIb-SN; Tue, 07 Feb 2023 02:53:04 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org Cc: linux-mm@kvack.org, p.raghav@samsung.com, dave@stgolabs.net, a.manzanares@samsung.com, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [RFC 1/2] shmem: set shmem_writepage() variables early Date: Mon, 6 Feb 2023 18:52:58 -0800 Message-Id: <20230207025259.2522793-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230207025259.2522793-1-mcgrof@kernel.org> References: <20230207025259.2522793-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 814ADC0007 X-Stat-Signature: ce9rbudagradmzsui37pnczaurgxh9gt X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1675738388-184319 X-HE-Meta: U2FsdGVkX19Gyb62NqwTqRnQp4p/7tNTt5cUB5kPrf4pXMTzcZiBhXg1LIzfxgt4fECuV5lg2vPWYgO/sEEmv+fKP9sqWPJM+adMpg+G6tEcui7hAiYSYS9zR19JIbPbnWsuofwJRZ/T3PaF6uPyjs0j4HfTuYUuLtrymg3biAmAikRC30+YRoMjIHI4GRJQ187YwcYZ6Cjmza75AWGYKx0D2OPv0s5Ac/D3j7DZ1UrE9mhJov/+0HH9L7Fz9He2J/ny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wFL4tVXLkx14iB2SncWrhzzWHvXBrlQ/aNUC2x6V0WK15skomeSJdCUkP5cUMBk/D2PFPjVQS4GUEAv4kb8B84yYbwNaE= 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_writepage() sets up variables typically used *after* a possible huge page split. However even if that does happen the address space mapping should not change. So it should be safe to set that from the beginning. The folio should always be locked from the start as well. It however was not clear if the folio address can / should change, as well as the first inode. This commit makes no functional changes other a double check on the folio locking which might be superflous. This change should help make the subsequent patch easier to review. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 28f3c699c8ce..a2c6aa11aab8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1332,11 +1332,13 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) { struct folio *folio = page_folio(page); struct shmem_inode_info *info; - struct address_space *mapping; - struct inode *inode; + struct address_space *mapping = folio->mapping; + struct inode *inode = mapping->host; swp_entry_t swap; pgoff_t index; + BUG_ON(!folio_test_locked(folio)); + /* * If /sys/kernel/mm/transparent_hugepage/shmem_enabled is "always" or * "force", drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages, @@ -1351,8 +1353,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) folio_clear_dirty(folio); } + /* Can the folio or first inode change on after a split? */ BUG_ON(!folio_test_locked(folio)); - mapping = folio->mapping; index = folio->index; inode = mapping->host; info = SHMEM_I(inode);