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 39DDEC4345F for ; Mon, 22 Apr 2024 11:03:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C540C6B0087; Mon, 22 Apr 2024 07:03:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C03916B008C; Mon, 22 Apr 2024 07:03:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF3366B0092; Mon, 22 Apr 2024 07:03:57 -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 9276F6B0087 for ; Mon, 22 Apr 2024 07:03:57 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3C6D4A0BB7 for ; Mon, 22 Apr 2024 11:03:57 +0000 (UTC) X-FDA: 82036882914.15.05F9514 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf28.hostedemail.com (Postfix) with ESMTP id 5A993C0021 for ; Mon, 22 Apr 2024 11:03:54 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=mqmUocXs; spf=pass (imf28.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713783835; 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=gcKvfN037TA7hZSa4d4wVaW0uvAV7xIvSo/LgCapk+E=; b=NH4qsZ0j8TxU5orwjs203S2uWwUVyprvjlAS502DOQs/XGBQGQfTKLngHpouBdf6Sj5HGf jOVf2WlKBcbxTeLyyVUOkcBCpLKg9Eofvl7C5R7vQkxVzBnlRoCz5u8/Hztt2kQwdAiFn9 wKj8+pqf37aC8aRoEpuqzOQ9yaDe3jo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713783835; a=rsa-sha256; cv=none; b=fVPqpWAL4kuquLQwNJLYWOASzA4GZ7qiYG2nobBvozdGUVJJlgDWow/cnPyLJUYrr3QJvX Ao4GFtyZ0TBD1acl604Ww5aXYzXfjPlnMhWRsSuSKaKirudWnBxFSCLmoe2wkThaGe0Xf/ vFGq7VgHxNGb3Fh9KoQh2A8wB6rThHM= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=mqmUocXs; spf=pass (imf28.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4VNMnK3Nksz9svZ; Mon, 22 Apr 2024 13:03:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1713783829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gcKvfN037TA7hZSa4d4wVaW0uvAV7xIvSo/LgCapk+E=; b=mqmUocXsR3w50nQdtWP075s0eXt8c5DeM+rfi3aUvt846NgO+qnHJo4yQ7QUkHZi+6M1XA oJO0688sir/I+srkC0WLRug6oq1qkVdQAPXuW2ps6tHah0BNuNNq8jh+9+Oy68WDLOiO3o H2fpseCkE5oUuy5GwzGd4m40QKDQ/6Da8cnRhlU0QX17oh6vxC18/hmPqh9nMI3Vq3nyOW lvs5sKHvUnLlcjKR0ZYBIGV+xraV5tvf4//IYSXPvFSP3Sfr3X88gVh5VQBcLAPsMws0Tc 0EsYRbVASkL/dJ/7VA9ofv/A1nGnv3IhjqN1K+E+RQaxfTQGpL8w0sogSRT+rw== Date: Mon, 22 Apr 2024 13:03:45 +0200 From: "Pankaj Raghav (Samsung)" To: Matthew Wilcox Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, gost.dev@samsung.com, chandan.babu@oracle.com, hare@suse.de, mcgrof@kernel.org, djwong@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@fromorbit.com, akpm@linux-foundation.org, Pankaj Raghav Subject: Re: [PATCH v3 05/11] readahead: allocate folios with mapping_min_order in readahead Message-ID: References: <20240313170253.2324812-1-kernel@pankajraghav.com> <20240313170253.2324812-6-kernel@pankajraghav.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: 66nhoegqgstmmiw4ufmgzgp9zmdh96q6 X-Rspamd-Queue-Id: 5A993C0021 X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1713783834-264270 X-HE-Meta: U2FsdGVkX18Ykmz6d5yYCi32Df3sZCQ1y9TAKtEy2MEPgkzIZOTbILk5xK1wHYnbEgcBjvJF4ZymWFmfhiYFe/JdP60/P1Ayf9iEq9F4Vy0XGgFi11q+mp426HoTsQeT6j0DnIsomZyTMRLUbtPxHDw6Xum61urNYJasdh9AOG29IAISjiqqTNx8cFXp1XEbXIKw3ylYgYndl+ohSg1ZksgvH9wRwtupX7x9rx8Tls/w8pZjxq3BSc/QtujQirL1GCYqIqAVHjk6xYswjKS0s6z8ePPl7DyGWRoRjbanN/g8PiONPfxVsN9MY+I6HDWLk8U20xQUijLGt5iU8wUz3Mx66m8UhmC0KAECDx+MXowZ/G/wuDv+74RGq1ZdXBEQWZU/5psQ8H4yHadyvqluwt84Vpm0uMVeMDtPcjm3Ca22yMjs28yHlmk3AVb/kJbKeOjq2N77dAkzxi9jGyYgXZxDvsuwXLUq/MxqEsKEBjoCy/gD9nHX2Vy4H8ogkE0je8KUL+1PTjK/eNDM+M3rbu6tScEC3ufiniR++ItPB7ty3Fexfe9fFZyGUgQ1T+j0zr/CB5/iTZwrX55Rg/tryQTKUOVwJiOBJcI915GmVh9p/7tykJGq6BvpfuCjLR6CehcAnyp+oJriI0Ou/PHLslQ5yT9Tb+52PlVSLCYJps6EvnrMlV46By/oHYXp3s3AJXaCNEJHrgpl15VBa7ffbr5NGvpuLf7bE1wXzOmIs8hxE7QOPiJmku0Wi/v/ScQZbs+72Id1hWaNNGmD7b9gQ2lohDMDSXi4KMS+SHQOFsDUNFSVAWv8PFVcYi6KKpMQGzh3h8txlpTIz1TW4jvCw+wU9i+Er4k7K1aQf8UlcvC6xfgKN8Zy9glY+TTBMn+1xSRnDX4gzcrClJOlD4DR5/zct/CrCzZwJpjdDJwEZzY= 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: List-Subscribe: List-Unsubscribe: > > @@ -515,7 +562,7 @@ void page_cache_ra_order(struct readahead_control *ractl, > > if (index & ((1UL << order) - 1)) > > order = __ffs(index); > > /* Don't allocate pages past EOF */ > > - while (index + (1UL << order) - 1 > limit) > > + while (order > min_order && index + (1UL << order) - 1 > limit) > > order--; > > This raises an interesting question that I don't know if we have a test > for. POSIX says that if we mmap, let's say, the first 16kB of a 10kB > file, then we can store into offset 0-12287, but stores to offsets > 12288-16383 get a signal (I forget if it's SEGV or BUS). Thus far, > we've declined to even create folios in the page cache that would let us > create PTEs for offset 12288-16383, so I haven't paid too much attention > to this. Now we're going to have folios that extend into that range, so > we need to be sure that when we mmap(), we only create PTEs that go as > far as 12287. > > Can you check that we have such an fstest, and that we still pass it > with your patches applied and a suitably large block size? > So the mmap is giving the correct SIGBUS error when we try to do this: dd if=/dev/zero of=./test bs=10k count=1; xfs_io -c "mmap -w 0 16384" -c "mwrite 13000 10" test Logs on bs=64k ps=4k system: root@debian:/media/test# dd if=/dev/zero of=./test bs=10k count=1; root@debian:/media/test# du -sh test 64K test root@debian:/media/test# ls -l --block-size=k test -rw-r--r-- 1 root root 10K Apr 22 10:42 test root@debian:/media/test# xfs_io -c "mmap 0 16384" -c "mwrite 13000 10" test Bus error The check in filemap_fault takes care of this: max_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); if (unlikely(index >= max_idx)) return VM_FAULT_SIGBUS; The same operation for read should also give a bus error, but it didn't. Further investigation pointed out that the fault_around() does not take this condition into account for LBS configuration. When I set fault_around_bytes to 4096, things worked as expected as we skip fault_around for reads. I have a patch that return SIGBUS also for the following read operation: dd if=/dev/zero of=./test bs=10k count=1; xfs_io -c "mmap -r 0 16384" -c "mread 13000 10" test This is the patch I have for now that fixes fault_around() logic for LBS configuration: diff --git a/mm/filemap.c b/mm/filemap.c index f0c0cfbbd134..259531dd297b 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3600,12 +3600,15 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, } do { unsigned long end; + unsigned long i_size; addr += (xas.xa_index - last_pgoff) << PAGE_SHIFT; vmf->pte += xas.xa_index - last_pgoff; last_pgoff = xas.xa_index; end = folio_next_index(folio) - 1; - nr_pages = min(end, end_pgoff) - xas.xa_index + 1; + i_size = DIV_ROUND_UP(i_size_read(mapping->host), + PAGE_SIZE) - 1; + nr_pages = min3(end, end_pgoff, i_size) - xas.xa_index + 1; if (!folio_test_large(folio)) ret |= filemap_map_order0_folio(vmf, I will send a new version of the series this week after doing some more testing.