Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6689758rdb; Tue, 2 Jan 2024 09:54:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8U0MmYnyRHCJ3JGWto5LGJ5Xzyf9i1diGBUKCx67KO9QxTXKNZc25tEYpC7gaJRGiH2iG X-Received: by 2002:a17:906:db:b0:a27:f950:4587 with SMTP id 27-20020a17090600db00b00a27f9504587mr1238854eji.13.1704218041045; Tue, 02 Jan 2024 09:54:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704218041; cv=none; d=google.com; s=arc-20160816; b=tfnPnRgqwtOBc7ofIv1oS0P6wIHpQeiMLOwtGDhYTl187nRin2LeaIGdeoEsnriO70 85GOJRx6BhOQsyPh7It3v1D22oFturHJmelhS27l3HUrkH1KbmD1fKerpqYtxq5Qnudd 1xxbIZX9Qyp9hFL99ngU7yY+9V//+4BwN/+ppqX6myCKKNB/FszHt5FmoQEJA6UeaZ4i NBC0cIQqQb08Yd1hg/jRvYbxoNqI92mRPSVfZcYWct6uMWqtBmaTfiCtQL/Hs17xlFUw YgsWLtKwC1Qf17Fh3bQgvpWl1XpJjc71jlzWAMv/j7SSSZbwdljy/e049rsfIheJ8uOB x58g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=E8hA/72KITSlGftqc83O7J2ZNglP6mXl1Xu18eqxeHI=; fh=Fbr1DyqyU4AXoGdgH9B1rSiPZW5ZdMfZgg+2Nnb+xAQ=; b=OTp+xkRjkZHYWVOpx2hgjDwZ59FrDK9m5Y+14zNIc0UeTFQlAihNBWLWoxvx/WsJtG q6VIESgeGaxj0soMvuGmpxOLlRMKGkCsuTr4uMKhV0FVnyCpoomvI8F0YxnMiyvidv13 XAVmjxcqCWHm7bgNCaJ5DgNY3ix/UeoIB+3jjDbJG4t6oS/3fiubke3kedUmE9OQgKdB BnNb1IMX4jbFJYtjbNqDd6HJlesQQ9YqX0fZkMhJnTiBoYTBa0BeJJnjMjsZm/jJjlZ2 0PBV7HCnRsPe+IE0glaKykovjQFoBBKObT09buWg4aAe3nTyYs4EqqOA6vX4DG4Wrj2K LrCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PYCA3Euf; spf=pass (google.com: domain of linux-kernel+bounces-14677-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14677-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qh20-20020a170906ecb400b00a2786c24e83si3476402ejb.221.2024.01.02.09.54.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 09:54:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14677-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PYCA3Euf; spf=pass (google.com: domain of linux-kernel+bounces-14677-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14677-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C83F51F22787 for ; Tue, 2 Jan 2024 17:54:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F3AA2156D1; Tue, 2 Jan 2024 17:53:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PYCA3Euf" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E89C4156C3 for ; Tue, 2 Jan 2024 17:53:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1d409bcb0e7so31926065ad.1 for ; Tue, 02 Jan 2024 09:53:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704218032; x=1704822832; darn=vger.kernel.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=E8hA/72KITSlGftqc83O7J2ZNglP6mXl1Xu18eqxeHI=; b=PYCA3EufazMTcC21hYxbdZqKa08M4BYn1Um9vPJRS7a+7zO7eXCKaZ1rmOuCePkz12 3RZPYyP3FySPe90yf8IXk0sOhDbPhIZUoTCV4k0Ro84Pb7YFZtMqcW8H58ezMCSp45Ae DUG90gAGBHfNSMzI5fsPoQZOuMXuD7qxjWkKKOMrhy4n0qOBSrEYwlhOnOPF0kQVZv8B MIEuxsWN3S2kYDGIjUwY2UrkkRL4lahBsX9P0x7ioGtVoGrEt3xAkotnU+Eez5+5BLs2 MvRJZKuXBSwvianZda70EtjqwmujShTVSr1rWzmAOLZZi/7oFo9/jcx3x3mevZb2951v q9Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704218032; x=1704822832; 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=E8hA/72KITSlGftqc83O7J2ZNglP6mXl1Xu18eqxeHI=; b=HcqIZZeG0roDIcalBNBvXneQEZsB+OTrbKpYR7ZEsyc64BxSZD4bzTXIuVmWDkzrJd vpOpBuL1r05n815uBPwSRFyCa92FzykJy5sZAsMN3GiDXdsRc7hzByTgrfkRb50u3ZBh 1fY1jAt4Hutomt7qTRi4vtLP+nCC7prD95WAxD8zzPy5seQjRIfW1LznNJSEbL6DsqKT FEjqzfoLCW8rMwZQLGJ7FPWI/3DKbplPt+kIy89lnqGnJdkkDTv+8+7bnYCMCRF3vCyJ GWsW08Bkp5ukBVxp4YZ+TCRXAhWk3Rg7UIkQT5PsyF0J4SmbjSApHC0ttXwIDIUL5SvH rC/w== X-Gm-Message-State: AOJu0YwPRd3oKCkrOUiMYWImquIAZsvb3oHLC+fb07ECw947xmOVaUnR LvC3rALWzepW7ILMyaODM3ATREE1nJWxbxpe X-Received: by 2002:a17:902:ea04:b0:1d4:55e0:bd0e with SMTP id s4-20020a170902ea0400b001d455e0bd0emr8204290plg.18.1704218032001; Tue, 02 Jan 2024 09:53:52 -0800 (PST) Received: from KASONG-MB2.tencent.com ([115.171.41.9]) by smtp.gmail.com with ESMTPSA id be10-20020a170902aa0a00b001d3c3d486bfsm22151969plb.163.2024.01.02.09.53.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jan 2024 09:53:51 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Chris Li , "Huang, Ying" , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , Yosry Ahmed , David Hildenbrand , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v2 0/9] swapin refactor for optimization and unified readahead Date: Wed, 3 Jan 2024 01:53:29 +0800 Message-ID: <20240102175338.62012-1-ryncsn@gmail.com> X-Mailer: git-send-email 2.43.0 Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Kairui Song This series is rebased on latest mm-stable to avoid conflicts. This series tries to unify and clean up the swapin path, introduce minor optimization, and make both shmem swapoff make use of SWP_SYNCHRONOUS_IO flag to skip readahead and swapcache for better performance. 1. Some benchmark for dropping readahead and swapcache for shmem with ZRAM: - Single file sequence read: perf stat --repeat 20 dd if=/tmpfs/test of=/dev/null bs=1M count=8192 (/tmpfs/test is a zero filled file, using brd as swap, 4G memcg limit) Before: 22.248 +- 0.549 After: 22.021 +- 0.684 (-1.1%) - Random read stress test: fio -name=tmpfs --numjobs=16 --directory=/tmpfs \ --size=256m --ioengine=mmap --rw=randread --random_distribution=random \ --time_based --ramp_time=1m --runtime=5m --group_reporting (using brd as swap, 2G memcg limit) Before: 1818MiB/s After: 1888MiB/s (+3.85%) - Zipf biased random read stress test: fio -name=tmpfs --numjobs=16 --directory=/tmpfs \ --size=256m --ioengine=mmap --rw=randread --random_distribution=zipf:1.2 \ --time_based --ramp_time=1m --runtime=5m --group_reporting (using brd as swap, 2G memcg limit) Before: 31.1GiB/s After: 32.3GiB/s (+3.86%) Previously, shmem always used cluster readahead, it doesn't help much even for single sequence read, and for random stress tests, the performance is better without it. In reality, due to memory and swap fragmentation cluster read-head is less helpful for ZRAM. 2. Micro benchmark which use madvise to swap out 10G zero-filled data to ZRAM then read them in, shows a performance gain for swapin path: Before: 11143285 us After: 10692644 us (+4.1%) 3. Swap off an 10G ZRAM: Before: time swapoff /dev/zram0 real 0m12.337s user 0m0.001s sys 0m12.329s After: time swapoff /dev/zram0 real 0m9.728s user 0m0.001s sys 0m9.719s This also clean up the path to apply a per swap device readahead policy for all swapin paths. V1: https://lkml.org/lkml/2023/11/19/296 Update from V1: - Rebased based on mm-unstable. - Remove behaviour changing patches, will submit in seperate series later. - Code style, naming and comments updates. - Thanks to Chris Li for very detailed and helpful review of V1. Thanks to Matthew Wilcox and Huang Ying for helpful suggestions. Kairui Song (9): mm/swapfile.c: add back some comment mm/swap: move no readahead swapin code to a stand-alone helper mm/swap: avoid doing extra unlock error checks for direct swapin mm/swap: always account swapped in page into current memcg mm/swap: introduce swapin_entry for unified readahead policy mm/swap: also handle swapcache lookup in swapin_entry mm/swap: avoid a duplicated swap cache lookup for SWP_SYNCHRONOUS_IO mm/swap: introduce a helper for swapin without vmfault swap, shmem: use new swapin helper and skip readahead conditionally mm/memory.c | 74 +++++++------------------- mm/shmem.c | 67 +++++++++++------------ mm/swap.h | 39 ++++++++++---- mm/swap_state.c | 138 +++++++++++++++++++++++++++++++++++++++++------- mm/swapfile.c | 32 +++++------ 5 files changed, 218 insertions(+), 132 deletions(-) -- 2.43.0