Received: by 2002:ab2:687:0:b0:1f4:6588:b3a7 with SMTP id s7csp150652lqe; Tue, 9 Apr 2024 18:45:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUfNqDdMRcDkYOKnFIzLkDg5sK9xeuJoI6Aweio3y2Az5KW+EAISvJjDnfxxKFcIKOk+9xCxXs0KPxiPL7nrZFNwYo2w0btlPnajeY2Cw== X-Google-Smtp-Source: AGHT+IHYdh5ZWIZvDujV0H9bKM6OPcC4TRhkPBTjr1cFJwuZoVu+5/TCElTFWzaasifBMGgFS/RS X-Received: by 2002:a05:651c:97:b0:2d7:9d4:f31c with SMTP id 23-20020a05651c009700b002d709d4f31cmr895730ljq.15.1712713528568; Tue, 09 Apr 2024 18:45:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712713528; cv=pass; d=google.com; s=arc-20160816; b=vHxFN5kiEFGGNb59F5Vi580NKHO42bmEWlBkQLvHD+qmjOBGgmFbADWbO62eY0aUAh VRsyOPhcPj2wxaDePjLMdxs3DkYS1Zcsv0RmqStdRGteGsK8piCnztO2ya6b6Vu8yJUG 9TO30m0CA3e19JUymaeFDekXsOhr5n36VD7R3YYAK+PbixmqGvxj41nHYezBi47X236A m62XFjgX6jPq+ZboiZLrMwBlDG7EEgNd8AqOkiUxXM7kN+S0uhrNZn8eC2HO9PasbfJ8 ormbyOcj+4Xwiu0+2r5LmJxydkuZhh2OiY8UFnIMRhnhytCQVA5iZmxn44Uz3d8kXCRi HIgQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:date:references:in-reply-to:subject:cc:to :from:dkim-signature; bh=joXiDCZK7EOV1T90av7RVYaoPz+QdfP5zfi1Y+Wls2o=; fh=v6Wa/L+cM+0Nr2eW4QKyICeRbfh3fvwfe7g1mooXGr4=; b=BcFTLq600S20QCQWbuXrzzC+pMvUNzzLKtoVf4bVPe5PWK/FdQ8AFhX1xdBcT38i2H KvN/lYQOZ7C8+c+PxqaslWqFarOTkuMxMtdlfUKPeDjfYKsZ89Gruc+nJEia8p010xd/ rGYRe4JYIKRpVlshuIX8Wrhn+rKp05KtR+97fSutbAxeDHSCJ/rZIrOaLCMhn/HtCcr6 EdqDRbvIzXLkpz87Uwy0zxMpXIBPpj5O3VKMmMwm14vo9vNmB2IMrRsudlOywv43O2cj 5XWN044uKvFgr/qlLPz/IYYUejb8Z+Er1LQhVTk9tyl6vv1u/fS6+eQ7CHBpcH3sejmV MgxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VGYQNmAm; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-137807-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137807-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v28-20020a50d59c000000b0056c134754d3si5220921edi.241.2024.04.09.18.45.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 18:45:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137807-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VGYQNmAm; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-137807-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137807-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 32A441F2271F for ; Wed, 10 Apr 2024 01:45:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B61288BF0; Wed, 10 Apr 2024 01:45:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VGYQNmAm" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C711748E for ; Wed, 10 Apr 2024 01:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712713517; cv=none; b=YbJ6QJL2XdCOLMUiD7DeXRfsEH7Wsv2EM50/oLEAMhy1CbzGYEJVGsje8vn/JhArTV8uQyz1tv618Zab5DJXdV1moohwf7IwBdn3aogZze94eUwmY1xmLTv0N4ZCzgHPIunNmwWa0KATO7N/di/RahV1Rg/txAZKp3we8VhH46A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712713517; c=relaxed/simple; bh=osvrbCNuDRWKD92JOCAWlIMjnGqLdxkwqulOcDIj/R0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=IOuHXklU/u48O/RlA4dNt5ux9c1jQk7r6SDm3SaWGVKOQ27Gw6+1L881zNgemc7AIezoYBISw/VP+gaARKoSSddlkXqSRBH3F7rHbj9XPq+yaXXOtPtpgPDU5Qn+W4Nnng1J11MZsbRAZmeQeFA25k78gVVixAQvgVoPieRvqI8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=VGYQNmAm; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712713516; x=1744249516; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=osvrbCNuDRWKD92JOCAWlIMjnGqLdxkwqulOcDIj/R0=; b=VGYQNmAmXbvZ+oxhIyajNuZkgoRVJZgdOlu+bZdYJoAvbGFC6jhnZ+xc 5FXMgIEclNNUWY5qcKkiuCFzSbd42a2xw1kKMIUsG/G8OjlP70LtIhR/d tVILEIQDEiJ1TrTzt9AYb4u1P+czGGdynGUzJXRysp7kNoHB2EOiQE/TB nC1yPLs8sY2IJOEkKzjTpBp3765j+Gp8HpI49ZKA/9kJ+70tEt8cegnmW KM/s5nxAqlAklLfqxWdThPL1rLHjzCDiRdJl1G73CVTeRmUGbfBI62Y8q CTaRh5EvGssnz3ONBEafdCFScOMCyf3gkgd0aTepTy2AJ2fV+hYjVjKC0 A==; X-CSE-ConnectionGUID: iGGTpbYtT/O+xYghYrgDkQ== X-CSE-MsgGUID: z9nz2hL2RMqT1QX4wuL5DQ== X-IronPort-AV: E=McAfee;i="6600,9927,11039"; a="8234897" X-IronPort-AV: E=Sophos;i="6.07,190,1708416000"; d="scan'208";a="8234897" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 18:45:15 -0700 X-CSE-ConnectionGUID: 4NFpHTcJR3SFnN2FWJfyIg== X-CSE-MsgGUID: He8+PYJaRxyFN6rRRn0/Hw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,190,1708416000"; d="scan'208";a="25012068" Received: from unknown (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 18:45:12 -0700 From: "Huang, Ying" To: Zhaoyu Liu Cc: Andrew Morton , ryncsn@gmail.com, nphamcs@gmail.com, songmuchun@bytedance.com, david@redhat.com, chrisl@kernel.org, guo.ziliang@zte.com.cn, yosryahmed@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2] mm: swap: prejudgement swap_has_cache to avoid page allocation In-Reply-To: <20240409144132.GA542987@bytedance> (Zhaoyu Liu's message of "Tue, 9 Apr 2024 22:41:32 +0800") References: <20240408121439.GA252652@bytedance> <20240408132704.f966adc8d3928df4d3b8c0a9@linux-foundation.org> <20240409144132.GA542987@bytedance> Date: Wed, 10 Apr 2024 09:43:19 +0800 Message-ID: <87bk6i6lhk.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Zhaoyu Liu writes: > On Mon, Apr 08, 2024 at 01:27:04PM -0700, Andrew Morton wrote: >> On Mon, 8 Apr 2024 20:14:39 +0800 Zhaoyu Liu wrote: >> >> > Based on qemu arm64 - latest kernel + 100M memory + 1024M swapfile. >> > Create 1G anon mmap and set it to shared, and has two processes >> > randomly access the shared memory. When they are racing on swap cache, >> > on average, each "alloc_pages_mpol + swapcache_prepare + folio_put" >> > took about 1475 us. >> >> And what effect does this patch have upon the measured time? ANd upon >> overall runtime? > > Hi Andrew, > > When share memory between two or more processes has swapped and pagefault now, > it would readahead swap and call __read_swap_cache_async(). > If one of the processes calls swapcache_prepare() and finds that the cache > has been EXIST(another process added), it will folio_put on the basis of the > alloc_pages_mpol() that has been called, and then try filemap_get_folio() again. > > I think the page alloc in this process is wasteful. > when the memory pressure is large, alloc_pages_mpol() will be time-consuming, > so the purpose of my patch is to judge whether the page has cache before page alloc, > then skip page alloc and retry filemap_get_folio() to save the time of the function. Please prove your theory with data, better with benchmark score. -- Best Regards, Huang, Ying >> >> > So skip page allocation if SWAP_HAS_CACHE was set, just >> > schedule_timeout_uninterruptible and continue to acquire page >> > via filemap_get_folio() from swap cache, to speedup >> > __read_swap_cache_async.