Message ID | 20240415171857.19244-1-ryncsn@gmail.com (mailing list archive) |
---|---|
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 01B5EC4345F for <linux-mm@archiver.kernel.org>; Mon, 15 Apr 2024 17:19:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 729EA6B009B; Mon, 15 Apr 2024 13:19:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C5BB6B009D; Mon, 15 Apr 2024 13:19:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58D456B009F; Mon, 15 Apr 2024 13:19:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3A5BF6B009B for <linux-mm@kvack.org>; Mon, 15 Apr 2024 13:19:17 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B13F91A0416 for <linux-mm@kvack.org>; Mon, 15 Apr 2024 17:19:16 +0000 (UTC) X-FDA: 82012427112.04.8E50499 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf18.hostedemail.com (Postfix) with ESMTP id D2DA11C0012 for <linux-mm@kvack.org>; Mon, 15 Apr 2024 17:19:13 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hz566TJk; spf=pass (imf18.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.175 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=1713201553; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=qhpaLSgvqk0TlKEdREUcJYLS3jjnPGf0yK+OZWmxYdA=; b=YAcM1t/FBG6voUH0iRrexFe8bLgcz8L4HFea7uMqJ0/grVQHOVlXgBKWZ8/M6OGq7WAcIx OPjx2Ghyx2WvR8t2nBFqM6y7jf9+2WqIceYkw8qcrkVm5QvZ8GE9DdTUNfDIJeH76L/eaX 7fsKxsPWwpAWdhr1ywtuFns08WGZGy0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hz566TJk; spf=pass (imf18.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.175 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=1713201553; a=rsa-sha256; cv=none; b=6Sg5aEdMAeNPHPWBF/7qjR75p7FVoou3iR1oQn7KQ3lboCy8FsaKZ6P9iwpJypy4xFjizD Hd8uKiDoG7JqKo6UyzBeppKscU5NHWL8Qay7US1QdLV3XA1v5EaWd/vOv+0cxaSYFFE3Q6 6UrUrc4bnIy/IpZpKxSMYCWYYIdV+AE= Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-5bdbe2de25fso2893927a12.3 for <linux-mm@kvack.org>; Mon, 15 Apr 2024 10:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713201552; x=1713806352; 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=qhpaLSgvqk0TlKEdREUcJYLS3jjnPGf0yK+OZWmxYdA=; b=hz566TJkn6bzJ0xBY5PFU0p3Ev8VhrkCkMY3OVHJIJDAfdUuqi8xm+HXK1T8PuWIOn O7uZfGO3TmX+4z5hydoUM3t3SBGTrL30P6HFWyi8e1tWI/v5meLN9Ag7ThecMcCpEwCI iGuR9dtCaq7+1xH9kMIibPQgxh6TiHNLBCvEkOXVXeAajPSX1uhVMtSEVC4nVuiE9hJc YJVwAS7Fj2Kf7apYVvShQL5HdP0bhINM5iXL/Jj9AkGbssb97kBnUJNvYkvNJLLOtmV9 VScU6CZ+pEkL9SJ31KiWE0LQEu3FrOLzzIQ+LhbLwQO2C4Ix8dmZYrl4RYATP8XMQ+3/ quMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713201552; x=1713806352; 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=qhpaLSgvqk0TlKEdREUcJYLS3jjnPGf0yK+OZWmxYdA=; b=WP0UW4mofx/V3fWw9tXCtSsBsLWEMhYeeX8Y6qakzRwia57ZqI+5Vy7e0ylyIxCS++ MXhrAXwxarQQCg1iwCyN5psGW0uvylw2T/U5W7R4HxM1SqutlRdLDY0iJLk1OVCiCo3L 1O4LUQ0dlXr0xkx4SVpxiAOfKBP47Onu79IJqXulv2PT8JDEUg927NUnhvWTxyaJZev/ 96HwPYci7u3Bci/sK1aUGzm9F3iiWeFQg9Gz4tiXEWOBtOajZXkSbwHfteNwkUo//bzw DerWTeLxB3yvMGTMm+lMXHuswTIoTiShl+bsorPAEnXcfaHoi+wFGHYu2xs2YERiey12 S4Fg== X-Gm-Message-State: AOJu0YyPRAQDzF2m0ZfQR0yY3EwcQ/haRYh5KIZ06yQsZDtcxOHllZVj nhUQq4+pn1SACz8MxL509BxZ0Wk7Wbjta4Of1eOF7UIG1bWl7Qg18oiURu4b X-Google-Smtp-Source: AGHT+IH1XygPTZJ8SBU+edViR3oewT4fY61fTFui7u1KllICvytry838XCTHAaadyIDoFojVB+Sv5g== X-Received: by 2002:a17:90a:df08:b0:2a5:bdd7:bb17 with SMTP id gp8-20020a17090adf0800b002a5bdd7bb17mr9678006pjb.42.1713201551562; Mon, 15 Apr 2024 10:19:11 -0700 (PDT) Received: from localhost.localdomain ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id o19-20020a17090aac1300b002a537abb536sm8751648pjq.57.2024.04.15.10.19.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 15 Apr 2024 10:19:11 -0700 (PDT) From: Kairui Song <ryncsn@gmail.com> To: linux-mm@kvack.org Cc: Matthew Wilcox <willy@infradead.org>, Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org, Kairui Song <kasong@tencent.com> Subject: [PATCH v3 0/4] mm/filemap: optimize folio adding and splitting Date: Tue, 16 Apr 2024 01:18:52 +0800 Message-ID: <20240415171857.19244-1-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 Reply-To: Kairui Song <kasong@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: D2DA11C0012 X-Rspam-User: X-Stat-Signature: w9sw83bc13i8jza3wkwc8uet54rw8ae4 X-Rspamd-Server: rspam01 X-HE-Tag: 1713201553-441740 X-HE-Meta: U2FsdGVkX1+pZrePw1rHOiejut8wRiMt36P35DLYQ6BRdqCGhRPR4v8Fd1Xyrdvk6nibkrpZjUraFSjCy0Hiut5ySzBtloC96X5zQv/3S2VcLDPM4kC1tlGnT9HMIQqoQJ1vQbIvA2zPc6gQyccZxSISx7rJfHRtZyOQXcJcaVEuVityU3n1Uw4vJVXqbHffH9ZY20LS/3w/VVhOB2uOX1rqFZn33UsY5/oZWFfNUnxqasYIJvXx3sI/NsVkFmqdkjiDF/XfVl2DWjwxMWbH0HsnTA7yQrg7Y28EmqBnQxld8H1VxkfX/OgcFYnhbBuGb+Xlp2x6Q2DcL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zb7C6o5gTq1tvxYAKvy+W635iOmShKzsCxW1gpw7FK79DOAqlJ3ZlRn6eLITCkbMlNWQa7bnrVtbMem8fH/QHDXYb9FAIkHFzzt8Mh4wX1axBTubNg2E8um1ldaA9SajWFRE6dKJ9PX1wHxt5s1ijRAxwO7sQmJD70OQLLVkO6CW+bo4PnX4qEGfDSoZFtb24zsv4F2yEa/4thm+hF+v8M703pYQgSckI5dMM9iHx5jkyk+RvrD0TmxpaQwXydyMRdDq2IxV4lQwW2bFcDo7+AjODIDE9u0i2g11YXxI7SL3tk5gMSv+yNjq5f3jQfOc2MKES9Ox6u9b4ssLpnxO3yiRYMJHONgCR2usD/8AbalTxKe15zSe04loadpUnnLCr7Ql+alRYvQkI7dFFXsP97wuVqAe2LwDk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
mm/filemap: optimize folio adding and splitting
|
expand
|
From: Kairui Song <kasong@tencent.com> Currently, at least 3 tree walks are needed for filemap folio adding if the folio is previously evicted. One for getting the order of current slot, one for ranged conflict check, and one for another order retrieving. If a split is needed, more walks are needed. This series is trying to merge these walks, and speed up filemap_add_folio, I see a 7.5% - 12.5% performance gain for fio stress test. So instead of doing multiple tree walks, do one optimism range check with lock hold, and exit if raced with another insertion. If a shadow exists, check it with a new xas_get_order helper before releasing the lock to avoid redundant tree walks for getting its order. Drop the lock and do the allocation only if a split is needed. In the best case, it only need to walk the tree once. If it needs to alloc and split, 3 walks are issued (One for first ranged conflict check and order retrieving, one for the second check after allocation, one for the insert after split). Testing with 4K pages, in an 8G cgroup, with 16G brd as block device: echo 3 > /proc/sys/vm/drop_caches fio -name=cached --numjobs=16 --filename=/mnt/test.img \ --buffered=1 --ioengine=mmap --rw=randread --time_based \ --ramp_time=30s --runtime=5m --group_reporting Before: bw ( MiB/s): min= 1027, max= 3520, per=100.00%, avg=2445.02, stdev=18.90, samples=8691 iops : min=263001, max=901288, avg=625924.36, stdev=4837.28, samples=8691 After (+7.3%): bw ( MiB/s): min= 493, max= 3947, per=100.00%, avg=2625.56, stdev=25.74, samples=8651 iops : min=126454, max=1010681, avg=672142.61, stdev=6590.48, samples=8651 Test result with THP (do a THP randread then switch to 4K page in hope it issues a lot of splitting): echo 3 > /proc/sys/vm/drop_caches fio -name=cached --numjobs=16 --filename=/mnt/test.img \ --buffered=1 --ioengine=mmap -thp=1 --readonly \ --rw=randread --time_based --ramp_time=30s --runtime=10m \ --group_reporting fio -name=cached --numjobs=16 --filename=/mnt/test.img \ --buffered=1 --ioengine=mmap \ --rw=randread --time_based --runtime=5s --group_reporting Before: bw ( KiB/s): min= 4141, max=14202, per=100.00%, avg=7935.51, stdev=96.85, samples=18976 iops : min= 1029, max= 3548, avg=1979.52, stdev=24.23, samples=18976ยท READ: bw=4545B/s (4545B/s), 4545B/s-4545B/s (4545B/s-4545B/s), io=64.0KiB (65.5kB), run=14419-14419msec After (+10.4%): bw ( KiB/s): min= 4611, max=15370, per=100.00%, avg=8928.74, stdev=105.17, samples=19146 iops : min= 1151, max= 3842, avg=2231.27, stdev=26.29, samples=19146 READ: bw=4635B/s (4635B/s), 4635B/s-4635B/s (4635B/s-4635B/s), io=64.0KiB (65.5kB), run=14137-14137msec The performance is better for both 4K (+7.5%) and THP (+12.5%) cached read. V2: https://lore.kernel.org/lkml/20240325171405.99971-1-ryncsn@gmail.com/ Updates from V2: - Fix the misusage of locks in test module: https://lore.kernel.org/oe-lkp/202404151046.448e2d6e-lkp@intel.com V1: https://lore.kernel.org/lkml/20240319092733.4501-1-ryncsn@gmail.com/ Updates from V1: - Collect Acks. - Add tests for new xas_get_order and combined usage of xas_get_order with xas_for_each_conflict. - Fix a memleak for patch 4/4 and modify the function in place instead of adding a new helper. - Update benchmark, I forgot to drop cache and disable THP for pervious test, so the result was for mixed usaged of split and add. The result is even better now. Kairui Song (4): mm/filemap: return early if failed to allocate memory for split mm/filemap: clean up hugetlb exclusion code lib/xarray: introduce a new helper xas_get_order mm/filemap: optimize filemap folio adding include/linux/xarray.h | 6 +++ lib/test_xarray.c | 93 ++++++++++++++++++++++++++++++++++++++++++ lib/xarray.c | 49 ++++++++++++++-------- mm/filemap.c | 74 +++++++++++++++++++++------------ 4 files changed, 179 insertions(+), 43 deletions(-)