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 0F682C83F1D for ; Mon, 14 Jul 2025 02:39:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84C956B009B; Sun, 13 Jul 2025 22:39:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FCE06B009C; Sun, 13 Jul 2025 22:39:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 739D76B009D; Sun, 13 Jul 2025 22:39:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 663E46B009B for ; Sun, 13 Jul 2025 22:39:23 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E63BF1DA062 for ; Mon, 14 Jul 2025 02:39:22 +0000 (UTC) X-FDA: 83661313764.26.8B3A074 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf04.hostedemail.com (Postfix) with ESMTP id 08AF74000A for ; Mon, 14 Jul 2025 02:39:19 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=P2F7vEPi; spf=pass (imf04.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752460761; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jIfioZUBHoGFsP7FKsRJDuXJU5OENyKeKcZrcXTzBD4=; b=amcWoIvz83GH2/x5/LTBXlXQyMLpnLSZ9vLSOusGK/ojE1AsW95arouAoOExj5HzNnjkMB dpXaJqOzIbawGAiNsjcEWf9Ls9+EHoUzfTAUXzleBf9JqJSy3YUlvlhyOClRSCZlS+zZac uG58Vll+Ovg6jdrm1SIuhBHiOPbWp4M= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=P2F7vEPi; spf=pass (imf04.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752460761; a=rsa-sha256; cv=none; b=7e32PZyWOFh68cGf1sWaAzuz34CnCmhTjNVVRi85JS8u4QIChlo2p+45TP3qPT4KBp16jD Px6UN/zSy9ZRjln6jThtli7Oio4f5eJGk7HFhE6hrfWk3v1Vg3dckRtSkcVjM8Sg9BMIjm IUAyWih0K8IjBxEFJH+8j/vW0/+/mDs= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1752460757; h=Message-ID:Date:MIME-Version:Subject:From:To:Content-Type; bh=jIfioZUBHoGFsP7FKsRJDuXJU5OENyKeKcZrcXTzBD4=; b=P2F7vEPi0x+hBetsOLDd+mFQTbBGbLpMNBh0beDLOkwwsqVuIl8DWsr5B+02eaQs0SERssMUPQ+o9oKbRAT+uvJErl+QygDMo91IyegxLOZoWsqaedHAWCoqDbAKYPSuh1x8rq4ghOmVhHdcYo6CJLh7fcAN7b+DWCtShHe7NKU= Received: from 30.74.144.136(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WioG7Og_1752460754 cluster:ay36) by smtp.aliyun-inc.com; Mon, 14 Jul 2025 10:39:15 +0800 Message-ID: Date: Mon, 14 Jul 2025 10:39:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 7/8] mm/shmem, swap: rework swap entry and index calculation for large swapin From: Baolin Wang To: Kairui Song , linux-mm@kvack.org Cc: Andrew Morton , Hugh Dickins , Matthew Wilcox , Kemeng Shi , Chris Li , Nhat Pham , Baoquan He , Barry Song , linux-kernel@vger.kernel.org References: <20250710033706.71042-1-ryncsn@gmail.com> <20250710033706.71042-8-ryncsn@gmail.com> <6d6feb41-5cdd-4591-8e19-d9c247e16fcb@linux.alibaba.com> In-Reply-To: <6d6feb41-5cdd-4591-8e19-d9c247e16fcb@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 08AF74000A X-Stat-Signature: iqkwjh4wsj4eem1impoaxkcb7o8jey9a X-Rspamd-Server: rspam02 X-Rspam-User: X-HE-Tag: 1752460759-240158 X-HE-Meta: U2FsdGVkX1/1OjuYHsftsxijNbcNNL3agWvKtfatWuTx3qNfpCwcw03ph6JC7wpQ4blLAvrFC+8R175lT8ZfvgE6+iAEPMTy41Q9zECLvsvsGnW/DUUJKxnLbJARbTnLEiEgLqEb+Hno+c7/CyzUKvDwDV+gQHlQbI+qC167DAdLdLOoo44TCpcUqwWYnhR3Lq1tORDZn8XcGWgF4YkTTu9iCHJ3w5ldml/GRy0ZKPiDRzZeKD4CjYM8JFONOKOWHLJ+1lY260OaMNYcGX75117OU8RWNC/xvNqyKHjaBSXCD0XhSgG5fT9wuRWvYruqnh91dyj4x5t2FcukHIDZS24U1y8ePKul822KXh8MK8HTazCvI8sGnUxSFz/75ggukTlVmhQTDLXPaDjroY3K25zHQ9qbxN6kNqStRdaQZMi9jpweDPveX33TbJTpoUBsU8UEXeQAyuqgaKdNVA3SXeqkp/udDBOz8onv2oRph4hoOFM7GSEEfYcSwo2In0U+IG90MfCcC7F+3sJVmn1o/kFiRUjPMq7VK56sSvRBY3Q4sVt7qAwBVj5FHr55Cb9VHNOgxV0tuCd7s+mqZnqEqRCNAtw+hi+MKWUk+lusM8pIKPyD01vl37t4xGh1iQxLfUvIVHO8qXhlFvGcX5Jjolkey44qXcx5kNCmOUHZZjqcO9JCLPk5zoHYLPcfD2FfkZqhDO+xJ+ItGpFh6FnhlnVKm6KsI3+dwNAKRHzaML3088wGKYaXhDi0FDE9fspBqVueK+iD7BmdYy6epEzlMNGv4tmZ50QpjajXhgTKID0hGmeS/IFgpG/TiqZ59L5GdzAbqp5y1qINABLrkp0XEpVe2ie5ATu1KmXmtiVHDCjpzmTuEZvGXxnHZiQxKQNIJnj7lXSmHP9OFyy9mI4oqyJHsFmsL3JU+A7JSlP/5eNTJo6mH7v+j5JgYJl2RdeW+o284rIU96j6kIZk3bw 6j3pmkBn qZiYtnDTTNxcQYUT/jq+1PGqRoc1Vef0iaxMmsy5oEORRI7dOCSUMp5RU3ACdPYLntb4s/wG409pDkjReMEgFPauCBxNvo+d5hZIg5I7BRodlk7/TF8J8+ShVBJ521jME+wUT3NHV6o6ucljNFo+TyAFBoR8gp6yTsDt0mOi98Uq0SZ8a2+gLo2comDwZBodPpaSrZX+2Ov6nIbedY5d4VhGZO9j5kzlcT29QyjdEFz+YswlzdVQyGyE1P8A5C53vRKws8UhkZ4fRkv8glxGovNXAXHB9rVg7xCdUv749XafvDUkumcwiG3pll/axjgqzw26PW1qzxCSmU49mJGTlve6Qqfwm7I8ZeRj3ceIRkLT1ZnA= 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: On 2025/7/11 14:36, Baolin Wang wrote: > > > On 2025/7/10 11:37, Kairui Song wrote: >> From: Kairui Song >> >> Instead of calculating the swap entry differently in different swapin >> paths, calculate it early before the swap cache lookup and use that >> for the lookup and later swapin. And after swapin have brought a folio, >> simply round it down against the size of the folio. >> >> This is simple and effective enough to verify the swap value. A folio's >> swap entry is always aligned by its size. Any kind of parallel split or >> race is acceptable because the final shmem_add_to_page_cache ensures >> that all entries covered by the folio are correct, and thus there >> will be no data corruption. >> >> This also prevents false positive cache lookup. If a shmem read >> request's index points to the middle of a large swap entry, >> previously, shmem will try the swap cache lookup using the large swap >> entry's starting value (which is the first sub swap entry of this >> large entry). This will lead to false positive lookup results if only >> the first few swap entries are cached but the actual requested swap >> entry pointed by the index is uncached. This is not a rare event, >> as swap readahead always tries to cache order 0 folios when possible. >> >> And this shouldn't cause any increased repeated faults. Instead, no >> matter how the shmem mapping is split in parallel, as long as the >> mapping still contains the right entries, the swapin will succeed. >> >> The final object size and stack usage are also reduced due to >> simplified code: >> >> ./scripts/bloat-o-meter mm/shmem.o.old mm/shmem.o >> add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-233 (-233) >> Function                                     old     new   delta >> shmem_swapin_folio                          4040    3807    -233 >> Total: Before=33152, After=32919, chg -0.70% >> >> Stack usage (Before vs After): >> mm/shmem.c:2277:12:shmem_swapin_folio   264     static >> mm/shmem.c:2277:12:shmem_swapin_folio   256     static >> >> And while at it, round down the index too if swap entry is round down. >> The index is used either for folio reallocation or confirming the >> mapping content. In either case, it should be aligned with the swap >> folio. >> >> Signed-off-by: Kairui Song > > Overall, I don't see any obvious issues, but please give me some time to > run some tests and then get back to you. Thanks. LGTM. Reviewed-by: Baolin Wang Tested-by: Baolin Wang