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 C5316C67861 for ; Wed, 10 Apr 2024 01:45:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B9066B007B; Tue, 9 Apr 2024 21:45:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3690B6B0082; Tue, 9 Apr 2024 21:45:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 257326B0083; Tue, 9 Apr 2024 21:45:20 -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 093656B007B for ; Tue, 9 Apr 2024 21:45:20 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 985211602B0 for ; Wed, 10 Apr 2024 01:45:19 +0000 (UTC) X-FDA: 81991929558.28.CF60E70 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) by imf04.hostedemail.com (Postfix) with ESMTP id 26B9A40002 for ; Wed, 10 Apr 2024 01:45:16 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ETGxbTh2; spf=pass (imf04.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.15 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712713517; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=joXiDCZK7EOV1T90av7RVYaoPz+QdfP5zfi1Y+Wls2o=; b=Wc6TNbuExRw10LLeV5awQDQZ5XkdVyomC61d3QYXhvoew/wqflOL8/0t7Zmcv6P5Wixuhq XKceggvyqGkUcy/sFwtRvZF8RdMMSmdb7lR26pox6Vj5Tikvz7p4IHAEXTcQOxrm4OGlxj pnA+0Jl5yOsnFEeG9j0uMQJ7W/GtInA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712713517; a=rsa-sha256; cv=none; b=ahoEfVigp01PJNvBG7FZnXPF4FmKh1QH4N3U5bjUI90g9iIGOdNAkmxm9GJDVd+uGTEnfI L3nz4RPjoE14V9B40edIBvN6SWOat9n4n/34gzUe6u2TmZkRw3uwlUVggRZUgHZMmBvE4N 4tWlJoCryRWztFO/3lqV2d8Oic/EyNA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ETGxbTh2; spf=pass (imf04.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.15 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712713517; x=1744249517; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=osvrbCNuDRWKD92JOCAWlIMjnGqLdxkwqulOcDIj/R0=; b=ETGxbTh2znkziHVtl3apPliAmn/7kfI/haeYPl2ldIhl6AV9sZcRBAX6 zvLq7+BNO6g+Sqop1q1q7lPc2ouAPiZs50TTTisHp7LnFRJn84yn9CSkJ LM2jfDD9L45RwHhcbYmH5qlHJGXLzthOClHdhavc3nLyBWWfvsrcPcXdt wgZHeQKe2Ml/sVVmVnnBu2vh94jO/DYToqk14WE710J7C78IMOlz9YoG1 gpxFNxLs1I9nL3zoQKGnAPNl3Bs2eE3uAt3FGSSn+y2bypXKwYb1lCzTB pt7dptOTJUYW/sYxS79e9laMd8UYr5kwA1iAiKZLEX7dlR+c36PiXZYTY g==; X-CSE-ConnectionGUID: xKnFgEtLSxOlaUFq/KvC7w== X-CSE-MsgGUID: BxYHBAtERUiQLvY7CujwEQ== X-IronPort-AV: E=McAfee;i="6600,9927,11039"; a="8234899" X-IronPort-AV: E=Sophos;i="6.07,190,1708416000"; d="scan'208";a="8234899" 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) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Rspamd-Queue-Id: 26B9A40002 X-Rspam-User: X-Stat-Signature: 3kztq7yg3db5w75b1ue7ds71a4eeynae X-Rspamd-Server: rspam03 X-HE-Tag: 1712713516-331474 X-HE-Meta: U2FsdGVkX1+GsG+aqW+hsFJ77yxbXVj8qdvPhHKFDr+P76JIHQeMHnrL6DjSvyhhCBADS4q98JVKaTnn/fMsVa4Z36Z2V1oh1DdJXrWhJ01yMrWGcetMhUgU2Lz4gZqKaolSNjR6rCdTUYWS0DrSitUWjW77p8nu3/Qp5bXtB28/u/lj7FNO/wx6bVSSYOnPOXgC9WFHEFQ/QGl4AroYDOuv8xQkeBdAtn45cWOPm8ztmRHftDPhbyXP1WA5AmqBziQdmZerQYfjL50uCB9e26gW3hF9vSXkBpipmbM1qVHNJnwodNshwjYcHcrrp+dWuw0mZYs0Lnz/GQmruNLdn7HvBwqjO+aPceotxKhx4WFQjTJ5Abp12lzC1se0mgkal/ctoJdP0Eix6f9/fEJDlGOf2Q7PyQHSZAKGL9MiQjMGIiHybFU+tT/DKSiONCaIeoyDrg2XfU8airSawQQpF4lLTOebwooy2X6b0Q2gvK4hps8rpUg6/alxEnYZS++oyMVr2ZW0gU9+6FFMjgFBRQSC+ZPgzn8TcT2YAamSgny5oOGEItJppuEDn0DMxiVAj9XMJaXt/OKltVBaoiMa4y/gmyGZml/7dO8A7oUqQopSDmlvc4C1IHsG8QGZLPaxJKflojXdH3sxiq16D1gczcVzGOk0xozZewr9yL+7hJiUplqTIhmeBfhjKAGQPy8dw2ZFDVjjugfrR14wM378441V+4mMfpzYnPTjLdg2yw0Y9muM3HWH5O5XmXHOlD8uxjWpSHvVdQMtPwPt6aKWI9I/+93vT0ilJwcG/lzFEqYX1DW8DFlvkbvQ6tcolbGPKRAQU5+ksC0pxPisnnxyhKVcrhnTzmnazXQsnDc0tRoDupOeEyCgNmZ6cVFaiPAXWE0Cpm5l1CU= 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: 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.