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 3CB42C7EE39 for ; Fri, 27 Jun 2025 06:22:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B25C88D000F; Fri, 27 Jun 2025 02:22:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD4AB8D0001; Fri, 27 Jun 2025 02:22:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 975A68D000F; Fri, 27 Jun 2025 02:22:45 -0400 (EDT) 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 818FC8D0001 for ; Fri, 27 Jun 2025 02:22:45 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F2F66C0573 for ; Fri, 27 Jun 2025 06:22:44 +0000 (UTC) X-FDA: 83600187048.30.DD3CE81 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf16.hostedemail.com (Postfix) with ESMTP id 3A33E180010 for ; Fri, 27 Jun 2025 06:22:43 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XkMmsKzs; spf=pass (imf16.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751005363; h=from:from:sender:reply-to: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:references:dkim-signature; bh=HJL93/WUy3VLLpG0Rd82iVgAz50hmnMPx17qiGzyaUE=; b=t/gzIhEr3556PD6bP81FXz+llonaRt4xzcHzVGGcdDQ5CzHWWgMgUgiMgJfiJjpHcJCu4s uHY9qMcfvSeQ3lxNqN4ZcTt0CJLEuURbou9DVRajgRfTctzn1cwdOyyw9fQOpmr9Pg56eX mxGNqqMb4dm57RPvr2Kg+yHbIi1qLgk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XkMmsKzs; spf=pass (imf16.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751005363; a=rsa-sha256; cv=none; b=mONQqFeaMXe85/4GW6h1vrsvho/lVuWTq+Rdbco+P1924MbvlkktaQQNYqFxfDMUIzf0Dr MIt5x5wYVpyqeAn7lkgn3HB9fS5YVmtJichyAVhpeUr9VU1euJNCCcOBNdKRwYCyG8gMaD XnS8tnFMbFG6yi23NzZ+SUSjm6thOr8= Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-748feca4a61so1161409b3a.3 for ; Thu, 26 Jun 2025 23:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751005361; x=1751610161; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=HJL93/WUy3VLLpG0Rd82iVgAz50hmnMPx17qiGzyaUE=; b=XkMmsKzsg6r/QyJqL5YjpenKRDWj4+pg+zmxx18MlRydtyYdzmjHANpYZJ3Dtq7myv YDpt0j/oaA4TizZXCFwHPn5K8d1iC49kFI3/9bIYmITEhiEiCS/3wSllmYuG5ibqE9R7 P2SbDbiuOiPFzGcv1k4yhBM6bD44sqlvuOxep//aVSByHyKvy0X+txsSswgYc/Nr1R+r U/vDjq250Fp2PSnBh3sctO+Fbmbaz2yTMxCqNK/kGu9J/7m3qO+hBvGfBFzlXHzKEyj9 nW8kOcrcrsrN2Z2UsA+Ft2u61RFfn5yHt+o9qH6iJxHYIslPof2+67o8ashz+m9VeVex Do+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751005361; x=1751610161; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HJL93/WUy3VLLpG0Rd82iVgAz50hmnMPx17qiGzyaUE=; b=wXsrga+mRIyPwMXyN2uFXsnkJG4X9il3zB4rwfvIeDgBiz+cnQamgMx42f9Cy9WyY6 usk0MbGfW7MT0k7cW29/3QJ2MGJaMr4e9RwTCfbecvO/WrZeNYTUjBOFcdS3dBctiPSd HEXXN2zQOJ6CEVZsasdmt76P7w3XlFiXhEshJDzYpIRewYmfv7mky2DVjHMJA+8xMA0g FwY5XLuRZPRLs0BL24JLPHF75Ph04UMCwIJGydAuwlBjXXNPfoxCYbJQZJe7MbTNMYGJ bU3ZTEuNbJLmR/KoKCPBzxUYVp2JrnVVd8peNKYQMdyD3vMF1oeCIWih3BM/MU8RvA8R hGcA== X-Gm-Message-State: AOJu0Yywao0dhzR7RfEo6HaceEuo/7dtZgApfF/u7Xw1dFGQmHXnK65j fdUn81pZMN7jF2gd91X12xpwaR4S3n0U48zWrSfxM1kO9b2bBPRLrZJ675Yn83dSqn8= X-Gm-Gg: ASbGncsRYJ2WCU3Kcm1KFo6apB/JbRwS6zvjBeR1bdrcwg8Wly9K3DD5KW+oT6px3zi BLizTMm/mrBxDqZsZ3cD1o931mE8jOTbiukY6Km8Q9MfAFewE7iJ7eGgVXJQSEJRjYMcyLCgUlb AMIkqqcQQzHUK/nFyNg62kHYoLQG5zi9MwtRTtkDceNH/5thmMEQD0fCfbvUFRagm83kI2Zksyq zbaR4aEUe4nZuPPhg6fkTzeYY66nrQ4VaAXSmer3j5hKljE4EqFNqf/cr+I7oMna5JPsJ5Jr+nl uzEMYUmX7JwYjLG33ETqGSa6u4hBSZT+t3Xn/QfTvOv1j4dzsaVJF9nU4cvTgDGXZSE5s3YAt6m s X-Google-Smtp-Source: AGHT+IHwbnmMhgqSTH/wSgQ4pCztKSBvv9lZlzowf10chmClNGllYjs7kOfUTi6qNk2axoi9C1sdEQ== X-Received: by 2002:a05:6a00:b8d:b0:742:3cc1:9485 with SMTP id d2e1a72fcca58-74af6fb9c61mr2758803b3a.12.1751005360817; Thu, 26 Jun 2025 23:22:40 -0700 (PDT) Received: from KASONG-MC4 ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74af5409cb6sm1456212b3a.23.2025.06.26.23.22.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 26 Jun 2025 23:22:40 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Hugh Dickins , Baolin Wang , Matthew Wilcox , Kemeng Shi , Chris Li , Nhat Pham , Baoquan He , Barry Song , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v3 0/7] mm/shmem, swap: bugfix and improvement of mTHP swap in Date: Fri, 27 Jun 2025 14:20:13 +0800 Message-ID: <20250627062020.534-1-ryncsn@gmail.com> X-Mailer: git-send-email 2.50.0 Reply-To: Kairui Song MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3A33E180010 X-Stat-Signature: okc6xbyhetbefx5joe6haeumorsguasu X-HE-Tag: 1751005363-157198 X-HE-Meta: U2FsdGVkX18c5FRr3xcT9KfZkvRzT5vd1TFU7J5PZ8OGmxoO6jOXq9XfGar0g4/ocuaWlsqY5Dq/tjTQCFpDXoXZL2ZomUPicpeQAKm6M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CEHsf+BibjZSd6Jnt7fBQobrGw+Gir8B7O/HSoBzH6X9psrOOCOXCucAdZgdPif3qiUQEDpyyH4E00spm+yJd3Yc1W1bvXppbWsN0urMRVvxlV4+EsEhfVycy54xAmfdfDonopOn5tsiTTNIUIdhCtb5zbaiOVztbHhDwSk22lso5YciCAtlGr2FRy7F/ByDtD+Ps1O/op1ptn9Pf4Vn/WSPPdIwIzDA537GsaL5XYhoNe6ZPlk9IvKOTdtCoEhPNpQqEwx/VaJKTx4yOeTmD2I8MQwIPuuLVozdgtgO/XEGyOk99QuTmtHv2ucm+KEPwWRNUkZbW837l0d6bNp1DcukLP0xeOr005M1SfdthadobzCHqe4+aqjhJsBjsuzJaTLm1IHKswHWewRanKlcGnJNZW2YbrH9VBW7Y3ATYtqhKU+SjqICxEXNIaJ1zQvdD+0iPmmmMxggQK/gT2iQA== 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: From: Kairui Song The current mTHP swapin path have some problems. It may potentially hang, may cause redundant faults due to false positive swap cache lookup, and it will involve at least 4 Xarray tree walks (get order, get order again, confirm swap, insert folio). And for !CONFIG_TRANSPARENT_HUGEPAGE builds, it will performs some mTHP related checks. This series fixes all of the mentioned issues, and the code should be more robust and prepared for the swap table series. Now tree walks is reduced to twice (get order & confirm, insert folio) and added more sanity checks and comments. !CONFIG_TRANSPARENT_HUGEPAGE build overhead is also minimized, and comes with a sanity check now. The performance is slightly better after this series, sequential swap in of 24G data from ZRAM, using transparent_hugepage_tmpfs=always (24 samples each): Before: 11.17, Standard Deviation: 0.02 After patch 1: 10.89, Standard Deviation: 0.05 After patch 2: 10.84, Standard Deviation: 0.03 After patch 3: 10.91, Standard Deviation: 0.03 After patch 4: 10.86, Standard Deviation: 0.03 After patch 5: 10.07, Standard Deviation: 0.04 After patch 7: 10.09, Standard Deviation: 0.03 Each patch improves the performance by a little, which is about ~10% faster in total. Build kernel test showed very slightly improvement, testing with make -j24 with defconfig in a 256M memcg also using ZRAM as swap, and transparent_hugepage_tmpfs=always (6 test runs): Before: system time avg: 3911.80s After: system time avg: 3863.76s --- V2: https://lore.kernel.org/linux-mm/20250619175538.15799-1-ryncsn@gmail.com/ Updates: - Split the clean up patch into 3 individual patches [ Baolin Wang ] - Fix a code error in the first patch [ Baolin Wang ] - I found there are some other remaining issue that can be fixed easily after the cleanups so includes these too: fix major fault counter, and clean up the goto labels. V1: https://lore.kernel.org/linux-mm/20250617183503.10527-1-ryncsn@gmail.com/ Updates: - Improve of funtion name and variable names, also commit message [ Kemeng Shi, Dev Jain ] - Correct Fixes: tag [ Andrew Morton ] - Collect Reviewed-by. Two of the patches in this series comes from the swap table series [1], and worth noting that the performance gain of this series is independent to the swap table series, we'll see another bigger performance gain and reduce of memory usage after the swap table series. I found these issues while trying to split the shmem changes out of the swap table series for easier reviewing, and found several more issues while doing stress tests for performance comparision. Barry also mentioned that CONFIG_TRANSPARENT_HUGEPAGE may have redundant checks [2] and I managed to clean them up properly too. No issue is found with a few days of stress testing. Link: https://lore.kernel.org/linux-mm/20250514201729.48420-1-ryncsn@gmail.com/ [1] Link: https://lore.kernel.org/linux-mm/CAMgjq7AsKFz7UN+seR5atznE_RBTDC9qjDmwN5saMe+KL3b1mQ@mail.gmail.com/ [2] Kairui Song (7): mm/shmem, swap: improve cached mTHP handling and fix potential hung mm/shmem, swap: avoid redundant Xarray lookup during swapin mm/shmem, swap: tidy up THP swapin checks mm/shmem, swap: clean up swap entry splitting mm/shmem, swap: never use swap cache and readahead for SWP_SYNCHRONOUS_IO mm/shmem, swap: fix major fault counting mm/shmem, swap: avoid false positive swap cache lookup mm/shmem.c | 283 ++++++++++++++++++++++++++++------------------------- 1 file changed, 149 insertions(+), 134 deletions(-) -- 2.50.0