From mboxrd@z Thu Jan 1 00:00:00 1970 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 A0AA8EE49A0 for ; Wed, 23 Aug 2023 03:27:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF8C1940035; Tue, 22 Aug 2023 23:27:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA90B940007; Tue, 22 Aug 2023 23:27:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D97DA940035; Tue, 22 Aug 2023 23:27:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id CAD3C940007 for ; Tue, 22 Aug 2023 23:27:21 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8B0FE140520 for ; Wed, 23 Aug 2023 03:27:21 +0000 (UTC) X-FDA: 81153933882.05.3B7BB74 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id 8532D2000B for ; Wed, 23 Aug 2023 03:27:19 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=sNvev0Kq; spf=none (imf03.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692761239; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uDL7hm5yS9tWFs+Rm0vZc8FkA60lmpSWoIIejWAe07Q=; b=jbI5Tws02tltJRxqB6GhtNK/D9K5VIATpTKzYTn9stjmBM8FbLy7ubU4isxHR7WYYKcJRr +fzJbRkwPlLBAKM14ViRDBoOyMbxcyW9AyoaRYeZ2rh2opQl5G8k1Z4cJ0e+mJg4e4gScS hhKufV6Hmtc7YTHlUnCZu8pZyxu3qsQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692761239; a=rsa-sha256; cv=none; b=owK62c6jwrc6Pgcu3Gp+TYEuzkpJJn/NVnoU+MH7uVRmEjxeErxTySRP3yrHKOtWtObsMN UY4kEYYPK5NJxNR2JKuPP7thjLVKLus0pCOgBh2bl+uOKefFBivjpmuFnd+OPkb+XPteaz H5Tw4ylM/s7lwmacLBrrK7K28F8rEA0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=sNvev0Kq; spf=none (imf03.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=uDL7hm5yS9tWFs+Rm0vZc8FkA60lmpSWoIIejWAe07Q=; b=sNvev0KqvYBXcUtrvRekkav2H8 2hoRFiZhd7Av8+NyDfwvNCKTxG4R0084ZyeonZvIThc3VyTmxZ7B/5AKLR793lwqG71Ks8C4F9Hx5 znBIz9/PyShj2NR77rTXVY5x2pf1HYrQSvYUtDG4W17z6YYN0qivchB5whtX1hx2NbUIeH/CY80kY 0apqZmOpaS/zJwA1zm0Ah9YYt/Nr8432CxArU9BVg0N2D3LLYydjY+LnDYSwa6gJQKas3QqYVcJTr An+1ArASBmWJ6XJWDt/21qBw8Z83/BqgKanp91n/Pk5hfniAvIlPVRC7cfVnWcJ9A1mCmw9RhP2IP savFnIlg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qYeWZ-002WU5-U7; Wed, 23 Aug 2023 03:27:15 +0000 Date: Wed, 23 Aug 2023 04:27:15 +0100 From: Matthew Wilcox To: Zi Yan Cc: linux-mm@kvack.org, David Hildenbrand , Yosry Ahmed , Mike Kravetz Subject: Re: [RFC PATCH] mm: use nth_page() for all memmap (struct page) position operations. Message-ID: References: <20230823030622.96112-1-zi.yan@sent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230823030622.96112-1-zi.yan@sent.com> X-Rspamd-Queue-Id: 8532D2000B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: y1sn5sjxojtck4owedir3zrmbozm9spw X-HE-Tag: 1692761239-67171 X-HE-Meta: U2FsdGVkX19kOL5XSEExufkR/+1QBdwWWk1snB8PDI76zSDorFxcS6T5GDp32XHD8OQsHPGrlfHRIpa3akRX4raqKj0AEUJJwE0goqVNBFHEBsrEMBIhpKc7/AeV5keNKJzU0C99BH2VldsfeZ7A2WQzFCVVec2949ZuIuQk3JFSueI/kH7PF/PYOb8FjSBIMG9PHdkaKOjxfZRS4THrYFGGDk7wF5MTcf6XJVYlGjqAKdyoQHNLiEoih5RT/rqEyRJZYYxlKgZrpuqXR8R6k4ODv9z8tJWS9dOmGUsCmy5XYwIUbbgwF2m+0HMkD/C0xFVnvXsKWd7N65wWHR5EbA3f3tKjERYOupkhSAg2GqRYSDqRp/4DrFYIMOp1/BUemdfWk0lvwwkM6iiCrB+dIN9d+pd0sY/ZMVlK7vhCLRMNaoGDjtT5/28XEo6Vg0zaj/Kbjqf04FiUfHh5wrcDa/siEqwAOGmqYqUBH1XTtqp+VSP5sFlSfWlHnWphKmz3jMlEX2zU4LYjqcBumdkdj7wcuZWiGYApz5yK6O03ukR6rGP4Gqbt6gIHnDpnUTcULbNWkqJuq1bLYV+1tk91kXyuQnmoKAF0PvyCiKlHqDupoNlZn69m+uspF2L/aQk14ypE+7klPPH7KDiN7PqKkLWMMWQLN0aMsSpfZimr6la5k3HQeZqnkijT50rXEEhAmYJEjbP9zEQo7nBwhm+7tgoPt60q+0Voemxs3HyiHsbf6yXDQATBNMyiLiW9CgNqxnTYuARSMD3GodUv5vcPCmth2J0Vbl98Jjim0JIG9V9iBDe0NO37xPuWSJ6evygmOOj6s7fIl6p7rldemXUE3k/TezDoT31yF7fv92fXwmflhc7qXGSsqVkbIWbomn7QVlzo0WMaRRqjKNrseoxqid4mC/hMKzu+R4oAy6r1Z53Ux3A/4lDjECkPb7Zju9Zs7BJVMn2zYpFUP3i1KJ6 GG7FazjG G3AOhXFFGK1vkH5MVoC03nOo0GbZ9BoccsFLU2Qyq0ZjwOsXJ5TVLNOmwPNU6c/GQ4aqF4fe/gw1Amn+Z8bXh04pqPl8v1uPNRtkUvXBiBcGHXnc4PbK90g5haGlQNjgAaG4jIJOOYm5vvWfH/ybyfudcvVeP9QWc7ec3JNLjR0Nw6cLD6htMmZMKDQ== 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: On Tue, Aug 22, 2023 at 11:06:22PM -0400, Zi Yan wrote: > With sparsemem and without vmemmap, memmap (struct page) array might not be > contiguous all the time. Thus, memmap position operations like page + N, > page++, might not give a valid struct page. Use nth_page() to properly > operate on struct page position changes. This is too big to be a single patch; you need to break it up by subsystem at least. And it's not against current -next; just the first one I'm looking at is wrecked by "block: move the bi_size update out of __bio_try_merge_page" from July 24th. > +++ b/block/bio.c > @@ -923,7 +923,7 @@ static inline bool page_is_mergeable(const struct bio_vec *bv, > return true; > else if (IS_ENABLED(CONFIG_KMSAN)) > return false; > - return (bv->bv_page + bv_end / PAGE_SIZE) == (page + off / PAGE_SIZE); > + return nth_page(bv->bv_page, bv_end / PAGE_SIZE) == nth_page(page, off / PAGE_SIZE); I think this one is actually wrong. We already checked the addresses were physically contiguous earlier in the function: phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) + bv_end - 1; phys_addr_t page_addr = page_to_phys(page); if (vec_end_addr + 1 != page_addr + off) return false; so this line is checking whether the struct pages are virtually contiguous. That makes me suspicious of the other changes in the block layer, because a bvec is defined to not cross a virtual discontiguity in memmap. > +++ b/fs/hfs/btree.c > @@ -270,7 +270,7 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree) > off = off16; > > off += node->page_offset; > - pagep = node->page + (off >> PAGE_SHIFT); > + pagep = nth_page(node->page, (off >> PAGE_SHIFT)); Are normal filesystems ever going to see folios that cross memmap discontiguities? I think hugetlb is the only way to see such things. > +++ b/mm/compaction.c > @@ -362,7 +362,7 @@ __reset_isolation_pfn(struct zone *zone, unsigned long pfn, bool check_source, > return true; > } > > - page += (1 << PAGE_ALLOC_COSTLY_ORDER); > + page = nth_page(page, (1 << PAGE_ALLOC_COSTLY_ORDER)); > } while (page <= end_page); > > return false; Isn't this within a single page block? > +++ b/mm/debug.c > @@ -67,7 +67,7 @@ static void __dump_page(struct page *page) > int mapcount; > char *type = ""; > > - if (page < head || (page >= head + MAX_ORDER_NR_PAGES)) { > + if (page < head || (page >= nth_page(head, MAX_ORDER_NR_PAGES))) { It's kind of right there in the name. MAX_ORDER_NR_PAGES.